# HG changeset patch # User John Donoghue # Date 1374172231 14400 # Node ID adf06e03fbdd0b7a58e6c3d8a66fec0729e0c454 # Parent 21ed3e2c3be619ee1f67bf7eb9c1c4ce7a69ddda Enable/disable editor actions based on available editor windows * libgui/src/m-editor/file-editor.h, libgui/src/m-editor/file-editor.cc (class file_editor): Added remove_bookmark, close_all and close_others actions as class variables. (file_editor::check_actions): New functions. (file_editor::add_file_editor_tab): call check_actions. (file_editor::construct): call check_actions, use new class vars where added. (file_editor::handle_tab_remove_request): call check_actions. diff --git a/libgui/src/m-editor/file-editor.cc b/libgui/src/m-editor/file-editor.cc --- a/libgui/src/m-editor/file-editor.cc +++ b/libgui/src/m-editor/file-editor.cc @@ -674,6 +674,7 @@ } } } + check_actions (); } void @@ -775,7 +776,7 @@ _toggle_bookmark_action = new QAction (tr ("Toggle &Bookmark"), _tool_bar); - QAction *remove_bookmark_action + _remove_bookmark_action = new QAction (tr ("&Remove All Bookmarks"), _tool_bar); QAction *next_breakpoint_action @@ -875,10 +876,12 @@ fileMenu->addAction (QIcon::fromTheme("window-close", QIcon (":/actions/icons/fileclose.png")), tr ("&Close"), this, SLOT (request_close_file (bool))); - fileMenu->addAction (QIcon::fromTheme("window-close", + _close_all_action = + fileMenu->addAction (QIcon::fromTheme("window-close", QIcon (":/actions/icons/fileclose.png")), tr ("Close All"), this, SLOT (request_close_all_files (bool))); + _close_others_action = fileMenu->addAction (QIcon::fromTheme("window-close", QIcon (":/actions/icons/fileclose.png")), tr ("Close Other Files"), @@ -906,7 +909,7 @@ editMenu->addAction (_toggle_bookmark_action); editMenu->addAction (_next_bookmark_action); editMenu->addAction (_previous_bookmark_action); - editMenu->addAction (remove_bookmark_action); + editMenu->addAction (_remove_bookmark_action); editMenu->addSeparator (); editMenu->addAction (_goto_line_action); _menu_bar->addMenu (editMenu); @@ -985,7 +988,7 @@ connect (_previous_bookmark_action, SIGNAL (triggered ()), this, SLOT (request_previous_bookmark ())); - connect (remove_bookmark_action, SIGNAL (triggered ()), + connect (_remove_bookmark_action, SIGNAL (triggered ()), this, SLOT (request_remove_bookmark ())); connect (toggle_breakpoint_action, SIGNAL (triggered ()), @@ -1036,6 +1039,8 @@ for (int n = 0; n < sessionFileNames.count (); ++n) request_open_file (sessionFileNames.at (n)); } + + check_actions (); } void @@ -1164,6 +1169,8 @@ f, SLOT (do_breakpoint_marker (bool, const QWidget*, int))); _tab_widget->setCurrentWidget (f); + + check_actions (); } void @@ -1246,5 +1253,37 @@ } } +void +file_editor::check_actions () +{ + bool have_tabs = _tab_widget->count () > 0; + + _comment_selection_action->setEnabled (have_tabs); + _uncomment_selection_action->setEnabled (have_tabs); + + _copy_action->setEnabled (have_tabs); + _cut_action->setEnabled (have_tabs); + _paste_action->setEnabled (have_tabs); + + _find_action->setEnabled (have_tabs); + _goto_line_action->setEnabled (have_tabs); + + _next_bookmark_action->setEnabled (have_tabs); + _previous_bookmark_action->setEnabled (have_tabs); + _toggle_bookmark_action->setEnabled (have_tabs); + + _print_action->setEnabled (have_tabs); + _run_action->setEnabled (have_tabs); + + _save_action->setEnabled (have_tabs); + _save_as_action->setEnabled (have_tabs); + _close_action->setEnabled (have_tabs); + _close_all_action->setEnabled (have_tabs); + _close_others_action->setEnabled (have_tabs && _tab_widget->count () > 1); + + _undo_action->setEnabled (have_tabs); + _redo_action->setEnabled (have_tabs); +} + #endif diff --git a/libgui/src/m-editor/file-editor.h b/libgui/src/m-editor/file-editor.h --- a/libgui/src/m-editor/file-editor.h +++ b/libgui/src/m-editor/file-editor.h @@ -57,6 +57,7 @@ void handle_enter_debug_mode (void); void handle_exit_debug_mode (void); + void check_actions (void); signals: void fetab_settings_changed (const QSettings *settings); @@ -196,6 +197,7 @@ QAction *_next_bookmark_action; QAction *_previous_bookmark_action; QAction *_toggle_bookmark_action; + QAction * _remove_bookmark_action; QAction *_print_action; QAction *_run_action; @@ -203,6 +205,8 @@ QAction *_save_action; QAction *_save_as_action; QAction *_close_action; + QAction *_close_all_action; + QAction *_close_others_action; QAction *_redo_action; QAction *_undo_action;