Buffer: support creation of temporary windows to apply commands when no windows are in context

This commit is contained in:
Maxime Coste 2012-01-31 14:03:10 +00:00
parent 830d96f7a1
commit 3ef9895a97
3 changed files with 14 additions and 1 deletions

View File

@ -243,6 +243,11 @@ void Buffer::delete_window(Window* window)
m_windows.erase(window_it); m_windows.erase(window_it);
} }
std::unique_ptr<Window> Buffer::create_temporary_window()
{
return std::unique_ptr<Window>(new Window(*this));
}
bool Buffer::is_modified() const bool Buffer::is_modified() const
{ {
size_t history_cursor_index = m_history_cursor - m_history.begin(); size_t history_cursor_index = m_history_cursor - m_history.begin();

View File

@ -151,6 +151,8 @@ public:
Window* get_or_create_window(); Window* get_or_create_window();
void delete_window(Window* window); void delete_window(Window* window);
std::unique_ptr<Window> create_temporary_window();
bool is_modified() const; bool is_modified() const;
Type type() const { return m_type; } Type type() const { return m_type; }
void notify_saved(); void notify_saved();

View File

@ -1048,6 +1048,12 @@ void exec_string(const CommandParameters& params,
return keys[pos++]; return keys[pos++];
}; };
std::unique_ptr<Window> temp_window;
if (not context.has_window())
temp_window = context.buffer().create_temporary_window();
Window& window = context.has_window() ? context.window() : *temp_window;
int count = 0; int count = 0;
while(pos < keys.size()) while(pos < keys.size())
{ {
@ -1059,7 +1065,7 @@ void exec_string(const CommandParameters& params,
{ {
auto it = keymap.find(key); auto it = keymap.find(key);
if (it != keymap.end()) if (it != keymap.end())
it->second(context.window(), count); it->second(window, count);
count = 0; count = 0;
} }
} }