Mercurial > hg > octave-nkf
diff libgui/src/m-editor/file-editor.cc @ 17009:adf06e03fbdd
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.
author | John Donoghue <john.donoghue@ieee.org> |
---|---|
date | Thu, 18 Jul 2013 14:30:31 -0400 |
parents | e86df0d43309 |
children | 811019b9ef57 |
line wrap: on
line diff
--- 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