comparison 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
comparison
equal deleted inserted replaced
17008:21ed3e2c3be6 17009:adf06e03fbdd
672 _tab_widget->removeTab (i); 672 _tab_widget->removeTab (i);
673 delete fileEditorTab; 673 delete fileEditorTab;
674 } 674 }
675 } 675 }
676 } 676 }
677 check_actions ();
677 } 678 }
678 679
679 void 680 void
680 file_editor::handle_add_filename_to_list (const QString& fileName, QWidget *ID) 681 file_editor::handle_add_filename_to_list (const QString& fileName, QWidget *ID)
681 { 682 {
773 774
774 _previous_bookmark_action = new QAction (tr ("Pre&vious Bookmark"), _tool_bar); 775 _previous_bookmark_action = new QAction (tr ("Pre&vious Bookmark"), _tool_bar);
775 776
776 _toggle_bookmark_action = new QAction (tr ("Toggle &Bookmark"), _tool_bar); 777 _toggle_bookmark_action = new QAction (tr ("Toggle &Bookmark"), _tool_bar);
777 778
778 QAction *remove_bookmark_action 779 _remove_bookmark_action
779 = new QAction (tr ("&Remove All Bookmarks"), _tool_bar); 780 = new QAction (tr ("&Remove All Bookmarks"), _tool_bar);
780 781
781 QAction *next_breakpoint_action 782 QAction *next_breakpoint_action
782 = new QAction (QIcon (":/actions/icons/bp_next.png"), 783 = new QAction (QIcon (":/actions/icons/bp_next.png"),
783 tr ("&Next breakpoint"), _tool_bar); 784 tr ("&Next breakpoint"), _tool_bar);
873 fileMenu->addSeparator (); 874 fileMenu->addSeparator ();
874 _close_action = 875 _close_action =
875 fileMenu->addAction (QIcon::fromTheme("window-close", 876 fileMenu->addAction (QIcon::fromTheme("window-close",
876 QIcon (":/actions/icons/fileclose.png")), 877 QIcon (":/actions/icons/fileclose.png")),
877 tr ("&Close"), this, SLOT (request_close_file (bool))); 878 tr ("&Close"), this, SLOT (request_close_file (bool)));
878 fileMenu->addAction (QIcon::fromTheme("window-close", 879 _close_all_action =
880 fileMenu->addAction (QIcon::fromTheme("window-close",
879 QIcon (":/actions/icons/fileclose.png")), 881 QIcon (":/actions/icons/fileclose.png")),
880 tr ("Close All"), 882 tr ("Close All"),
881 this, SLOT (request_close_all_files (bool))); 883 this, SLOT (request_close_all_files (bool)));
884 _close_others_action =
882 fileMenu->addAction (QIcon::fromTheme("window-close", 885 fileMenu->addAction (QIcon::fromTheme("window-close",
883 QIcon (":/actions/icons/fileclose.png")), 886 QIcon (":/actions/icons/fileclose.png")),
884 tr ("Close Other Files"), 887 tr ("Close Other Files"),
885 this, SLOT (request_close_other_files (bool))); 888 this, SLOT (request_close_other_files (bool)));
886 889
904 editMenu->addAction (_uncomment_selection_action); 907 editMenu->addAction (_uncomment_selection_action);
905 editMenu->addSeparator (); 908 editMenu->addSeparator ();
906 editMenu->addAction (_toggle_bookmark_action); 909 editMenu->addAction (_toggle_bookmark_action);
907 editMenu->addAction (_next_bookmark_action); 910 editMenu->addAction (_next_bookmark_action);
908 editMenu->addAction (_previous_bookmark_action); 911 editMenu->addAction (_previous_bookmark_action);
909 editMenu->addAction (remove_bookmark_action); 912 editMenu->addAction (_remove_bookmark_action);
910 editMenu->addSeparator (); 913 editMenu->addSeparator ();
911 editMenu->addAction (_goto_line_action); 914 editMenu->addAction (_goto_line_action);
912 _menu_bar->addMenu (editMenu); 915 _menu_bar->addMenu (editMenu);
913 916
914 _debug_menu = new QMenu (tr ("&Debug"), _menu_bar); 917 _debug_menu = new QMenu (tr ("&Debug"), _menu_bar);
983 this, SLOT (request_next_bookmark ())); 986 this, SLOT (request_next_bookmark ()));
984 987
985 connect (_previous_bookmark_action, SIGNAL (triggered ()), 988 connect (_previous_bookmark_action, SIGNAL (triggered ()),
986 this, SLOT (request_previous_bookmark ())); 989 this, SLOT (request_previous_bookmark ()));
987 990
988 connect (remove_bookmark_action, SIGNAL (triggered ()), 991 connect (_remove_bookmark_action, SIGNAL (triggered ()),
989 this, SLOT (request_remove_bookmark ())); 992 this, SLOT (request_remove_bookmark ()));
990 993
991 connect (toggle_breakpoint_action, SIGNAL (triggered ()), 994 connect (toggle_breakpoint_action, SIGNAL (triggered ()),
992 this, SLOT (request_toggle_breakpoint ())); 995 this, SLOT (request_toggle_breakpoint ()));
993 996
1034 = settings->value ("editor/savedSessionTabs", QStringList ()).toStringList (); 1037 = settings->value ("editor/savedSessionTabs", QStringList ()).toStringList ();
1035 1038
1036 for (int n = 0; n < sessionFileNames.count (); ++n) 1039 for (int n = 0; n < sessionFileNames.count (); ++n)
1037 request_open_file (sessionFileNames.at (n)); 1040 request_open_file (sessionFileNames.at (n));
1038 } 1041 }
1042
1043 check_actions ();
1039 } 1044 }
1040 1045
1041 void 1046 void
1042 file_editor::add_file_editor_tab (file_editor_tab *f, const QString& fn) 1047 file_editor::add_file_editor_tab (file_editor_tab *f, const QString& fn)
1043 { 1048 {
1162 connect (this, SIGNAL (fetab_do_breakpoint_marker (bool, const QWidget*, 1167 connect (this, SIGNAL (fetab_do_breakpoint_marker (bool, const QWidget*,
1163 int)), 1168 int)),
1164 f, SLOT (do_breakpoint_marker (bool, const QWidget*, int))); 1169 f, SLOT (do_breakpoint_marker (bool, const QWidget*, int)));
1165 1170
1166 _tab_widget->setCurrentWidget (f); 1171 _tab_widget->setCurrentWidget (f);
1172
1173 check_actions ();
1167 } 1174 }
1168 1175
1169 void 1176 void
1170 file_editor::copyClipboard () 1177 file_editor::copyClipboard ()
1171 { 1178 {
1244 _redo_action->setShortcut (no_key); 1251 _redo_action->setShortcut (no_key);
1245 _undo_action->setShortcut (no_key); 1252 _undo_action->setShortcut (no_key);
1246 } 1253 }
1247 } 1254 }
1248 1255
1256 void
1257 file_editor::check_actions ()
1258 {
1259 bool have_tabs = _tab_widget->count () > 0;
1260
1261 _comment_selection_action->setEnabled (have_tabs);
1262 _uncomment_selection_action->setEnabled (have_tabs);
1263
1264 _copy_action->setEnabled (have_tabs);
1265 _cut_action->setEnabled (have_tabs);
1266 _paste_action->setEnabled (have_tabs);
1267
1268 _find_action->setEnabled (have_tabs);
1269 _goto_line_action->setEnabled (have_tabs);
1270
1271 _next_bookmark_action->setEnabled (have_tabs);
1272 _previous_bookmark_action->setEnabled (have_tabs);
1273 _toggle_bookmark_action->setEnabled (have_tabs);
1274
1275 _print_action->setEnabled (have_tabs);
1276 _run_action->setEnabled (have_tabs);
1277
1278 _save_action->setEnabled (have_tabs);
1279 _save_as_action->setEnabled (have_tabs);
1280 _close_action->setEnabled (have_tabs);
1281 _close_all_action->setEnabled (have_tabs);
1282 _close_others_action->setEnabled (have_tabs && _tab_widget->count () > 1);
1283
1284 _undo_action->setEnabled (have_tabs);
1285 _redo_action->setEnabled (have_tabs);
1286 }
1287
1249 1288
1250 #endif 1289 #endif