comparison libgui/src/main-window.cc @ 17117:47b504503a3f

disable global paste action when clipboard is empty * main_window.cc(constructor): initialize class variable for the clipboard, (construct_edit_menu): don't set shortcut for paste action here, add new menu for clearing the clipboard, connect the clipboard's change signal to the new slot clipboard_has_changed, (clipboard_has_changed): new slot enabling or disabling the paste and clear clipboard action when clipboard has changed (clear_clipboard): new slot for the clear clipboard action * main_window.h: new slots clipboard-has_changed and clear_clipboard, new class variable _clipboard, new action _clear_clipboard
author Torsten <ttl@justmail.de>
date Wed, 31 Jul 2013 21:25:04 +0200
parents 1d544ac39369
children 352b442a72a5
comparison
equal deleted inserted replaced
17116:59acfe9209dd 17117:47b504503a3f
75 doc_browser_window (new documentation_dock_widget (this)), 75 doc_browser_window (new documentation_dock_widget (this)),
76 editor_window (create_default_editor (this)), 76 editor_window (create_default_editor (this)),
77 workspace_window (new workspace_view (this)), 77 workspace_window (new workspace_view (this)),
78 find_files_dlg (0), 78 find_files_dlg (0),
79 _octave_main_thread (0), 79 _octave_main_thread (0),
80 _octave_qt_link (0) 80 _octave_qt_link (0),
81 _clipboard (QApplication::clipboard ())
81 { 82 {
82 // We have to set up all our windows, before we finally launch octave. 83 // We have to set up all our windows, before we finally launch octave.
83 construct (); 84 construct ();
84 } 85 }
85 86
850 851
851 setStatusBar (status_bar); 852 setStatusBar (status_bar);
852 853
853 construct_octave_qt_link (); 854 construct_octave_qt_link ();
854 855
855 set_global_shortcuts (true);
856
857 #ifdef HAVE_QSCINTILLA 856 #ifdef HAVE_QSCINTILLA
858 connect (this, 857 connect (this,
859 SIGNAL (insert_debugger_pointer_signal (const QString&, int)), 858 SIGNAL (insert_debugger_pointer_signal (const QString&, int)),
860 editor_window, 859 editor_window,
861 SLOT (handle_insert_debugger_pointer_request (const QString&, int))); 860 SLOT (handle_insert_debugger_pointer_request (const QString&, int)));
873 872
874 QDir curr_dir; 873 QDir curr_dir;
875 set_current_working_directory (curr_dir.absolutePath ()); 874 set_current_working_directory (curr_dir.absolutePath ());
876 875
877 octave_link::post_event (this, &main_window::resize_command_window_callback); 876 octave_link::post_event (this, &main_window::resize_command_window_callback);
877
878 set_global_shortcuts (true);
879
878 } 880 }
879 881
880 void 882 void
881 main_window::construct_octave_qt_link (void) 883 main_window::construct_octave_qt_link (void)
882 { 884 {
1081 _copy_action 1083 _copy_action
1082 = edit_menu->addAction (QIcon (":/actions/icons/editcopy.png"), 1084 = edit_menu->addAction (QIcon (":/actions/icons/editcopy.png"),
1083 tr ("Copy"), this, SLOT (copyClipboard ())); 1085 tr ("Copy"), this, SLOT (copyClipboard ()));
1084 _copy_action->setShortcut (QKeySequence::Copy); 1086 _copy_action->setShortcut (QKeySequence::Copy);
1085 1087
1088
1086 _paste_action 1089 _paste_action
1087 = edit_menu->addAction (QIcon (":/actions/icons/editpaste.png"), 1090 = edit_menu->addAction (QIcon (":/actions/icons/editpaste.png"),
1088 tr ("Paste"), this, SLOT (pasteClipboard ())); 1091 tr ("Paste"), this, SLOT (pasteClipboard ()));
1089 _paste_action->setShortcut (QKeySequence::Paste); 1092 _paste_action->setShortcut (QKeySequence::Paste);
1090 1093
1094 _clear_clipboard_action
1095 = edit_menu->addAction (tr ("Clear Clipboard"), this,
1096 SLOT (clear_clipboard ()));
1097
1091 edit_menu->addSeparator (); 1098 edit_menu->addSeparator ();
1092 1099
1093 _find_files_action 1100 _find_files_action = edit_menu->addAction (tr ("Find Files..."));
1094 = edit_menu->addAction (tr ("Find Files..."));
1095 1101
1096 edit_menu->addSeparator (); 1102 edit_menu->addSeparator ();
1097 1103
1098 QAction *clear_command_window_action 1104 QAction *clear_command_window_action
1099 = edit_menu->addAction (tr ("Clear Command Window")); 1105 = edit_menu->addAction (tr ("Clear Command Window"));
1113 connect (clear_command_history, SIGNAL (triggered ()), 1119 connect (clear_command_history, SIGNAL (triggered ()),
1114 this, SLOT (handle_clear_history_request ())); 1120 this, SLOT (handle_clear_history_request ()));
1115 1121
1116 connect (clear_workspace_action, SIGNAL (triggered ()), 1122 connect (clear_workspace_action, SIGNAL (triggered ()),
1117 this, SLOT (handle_clear_workspace_request ())); 1123 this, SLOT (handle_clear_workspace_request ()));
1124
1125 connect (_clipboard, SIGNAL (changed (QClipboard::Mode)),
1126 this, SLOT (clipboard_has_changed (QClipboard::Mode)));
1127 clipboard_has_changed (QClipboard::Clipboard);
1118 } 1128 }
1119 1129
1120 QAction * 1130 QAction *
1121 main_window::construct_debug_menu_item (const char *icon_file, 1131 main_window::construct_debug_menu_item (const char *icon_file,
1122 const QString& item, 1132 const QString& item,
1636 { 1646 {
1637 doc_browser_window->setVisible (true); 1647 doc_browser_window->setVisible (true);
1638 emit show_doc_signal (file); 1648 emit show_doc_signal (file);
1639 } 1649 }
1640 1650
1641 1651 void
1652 main_window::clipboard_has_changed (QClipboard::Mode cp_mode)
1653 {
1654 if (cp_mode == QClipboard::Clipboard)
1655 {
1656 if (_clipboard->text ().isEmpty ())
1657 {
1658 _paste_action->setEnabled (false);
1659 _clear_clipboard_action->setEnabled (false);
1660 }
1661 else
1662 {
1663 _paste_action->setEnabled (true);
1664 _clear_clipboard_action->setEnabled (true);
1665 }
1666 }
1667 }
1668
1669 void
1670 main_window::clear_clipboard ()
1671 {
1672 _clipboard->clear (QClipboard::Clipboard);
1673 }