diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/ui.cc | 29 | ||||
-rw-r--r-- | src/ui/ui.h | 3 | ||||
-rw-r--r-- | src/ui/window.cc | 10 | ||||
-rw-r--r-- | src/ui/window.h | 13 |
4 files changed, 52 insertions, 3 deletions
diff --git a/src/ui/ui.cc b/src/ui/ui.cc index bba9ea6..8242381 100644 --- a/src/ui/ui.cc +++ b/src/ui/ui.cc @@ -89,9 +89,11 @@ void help_menu() con_print << "^Bmenu functions" << std::endl; con_print << " menu help show this help" << std::endl; con_print << " menu list list available menus" << std::endl; - con_print << " menu hide hide the current menu" << std::endl; - con_print << " menu close close the current menu" << std::endl; con_print << " menu [name] show a menu" << std::endl; + con_print << " menu back return to the previous menu" << std::endl; + con_print << " menu previous return to the previous menu" << std::endl; + con_print << " menu close close the current menu" << std::endl; + con_print << " menu hide hide the current menu" << std::endl; root()->list_menus(); } @@ -117,6 +119,12 @@ void func_menu(std::string const &args) } else if (command.compare("close") == 0) { root()->hide_window(); + } else if (command.compare("back") == 0) { + root()->previous_window(); + + } else if (command.compare("previous") == 0) { + root()->previous_window(); + } else if (command.compare("list") == 0) { root()->list_menus(); } else { @@ -345,8 +353,12 @@ void UI::show_window(const char *label) Window *window = find_window(label); if (window) { - if (ui_active_window) + if (ui_active_window) { ui_active_window->hide(); + window->set_previous(ui_active_window); + } else { + window->clear_previous(); + } ui_active_window = window; ui_active_window->event_resize(); ui_active_window->raise(); @@ -365,6 +377,17 @@ void UI::hide_window() } } +void UI::previous_window() +{ + if (ui_active_window) { + if (ui_active_window->previous().size()) { + show_window(ui_active_window->previous().c_str()); + } else { + hide_window(); + } + } +} + void UI::frame() { ui_focus = event_focus(mouse_cursor); diff --git a/src/ui/ui.h b/src/ui/ui.h index 3a4ba75..a555e97 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -37,6 +37,9 @@ public: /// hide the active window void hide_window(); + /// show previous window + void previous_window(); + /// return the active window Window *active() { return ui_active_window; } diff --git a/src/ui/window.cc b/src/ui/window.cc index b18348b..cc9f3b5 100644 --- a/src/ui/window.cc +++ b/src/ui/window.cc @@ -24,6 +24,16 @@ Window::~Window() window_children.clear(); } +void Window::set_previous(Window *previous) +{ + window_previous.assign(previous->label()); +} + +void Window::clear_previous() +{ + window_previous.clear(); +} + void Window::draw_border() { if (!border()) diff --git a/src/ui/window.h b/src/ui/window.h index f88d5aa..a134f04 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -19,6 +19,13 @@ public: virtual void draw_border(); + /// set the label of the previous window + void set_previous(Window *previous); + /// clear the label of the previous window + void clear_previous(); + + inline std::string const &previous() const { return window_previous; } + protected: typedef std::list<Window *> Windows; Windows window_children; @@ -27,6 +34,12 @@ protected: virtual void add_window(Window *window); virtual void remove_window(Window *window); + + /// label of the previous window that got activated + /** This label is used to implement the 'menu previous' + * command + */ + std::string window_previous; }; } |