1 # include "mode.hh" 2 # include "main_window.hh" 3 # include "keybindings.hh" 4 5 namespace Astroid { Mode(MainWindow * mw)6 Mode::Mode (MainWindow * mw) : 7 Gtk::Box (Gtk::ORIENTATION_VERTICAL) 8 { 9 set_main_window (mw); 10 invincible = false; 11 12 tab_label.set_can_focus (false); 13 14 keys.title = "Mode"; 15 } 16 set_main_window(MainWindow * mw)17 void Mode::set_main_window (MainWindow *mw) { 18 main_window = mw; 19 } 20 set_label(ustring s)21 void Mode::set_label (ustring s) { 22 if (static_cast<int>(s.size()) > MAX_TAB_LEN) 23 s = s.substr(0, MAX_TAB_LEN - 3) + "..."; 24 25 tab_label.set_text (s); 26 label = s; 27 28 main_window->update_title_dispatcher.emit (); 29 } 30 pre_close()31 void Mode::pre_close () { 32 /* allow sub-modes to clean up anything when we are sure that the 33 * mode will be closed */ 34 } 35 close(bool force)36 void Mode::close (bool force) { 37 /* close current page */ 38 int c = main_window->notebook.page_num (*this); 39 40 if (((Mode*) main_window->notebook.get_nth_page (c))->invincible && !force) { 41 LOG (debug) << "mode: mode invincible, not closing."; 42 } else { 43 main_window->del_mode (c); 44 } 45 } 46 ask_yes_no(ustring question,std::function<void (bool)> closure)47 void Mode::ask_yes_no ( 48 ustring question, 49 std::function <void (bool)> closure) 50 { 51 return main_window->ask_yes_no (question, closure); 52 } 53 multi_key(Keybindings & kb,Key k)54 bool Mode::multi_key (Keybindings & kb, Key k) 55 { 56 return main_window->multi_key (kb, k); 57 } 58 on_key_press_event(GdkEventKey * event)59 bool Mode::on_key_press_event (GdkEventKey *event) { 60 /* check if there are any dialogs (question-bars) open on the main_window */ 61 62 if (main_window->mode_key_handler (event)) return true; 63 64 if (get_keys ()->handle (event)) return true; 65 66 return false; 67 } 68 get_label()69 ustring Mode::get_label () { 70 return label; 71 } 72 get_keys()73 Keybindings * Mode::get_keys () { 74 return &keys; 75 } 76 } 77 78