# HG changeset patch # User Torsten # Date 1375298704 -7200 # Node ID 47b504503a3fd207f068361b7e7b1854a0b8a6b3 # Parent 59acfe9209dd425d412f6045efac240ac9cbfb2a 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 diff -r 59acfe9209dd -r 47b504503a3f libgui/src/main-window.cc --- a/libgui/src/main-window.cc Wed Jul 31 13:14:09 2013 +0100 +++ b/libgui/src/main-window.cc Wed Jul 31 21:25:04 2013 +0200 @@ -77,7 +77,8 @@ workspace_window (new workspace_view (this)), find_files_dlg (0), _octave_main_thread (0), - _octave_qt_link (0) + _octave_qt_link (0), + _clipboard (QApplication::clipboard ()) { // We have to set up all our windows, before we finally launch octave. construct (); @@ -852,8 +853,6 @@ construct_octave_qt_link (); - set_global_shortcuts (true); - #ifdef HAVE_QSCINTILLA connect (this, SIGNAL (insert_debugger_pointer_signal (const QString&, int)), @@ -875,6 +874,9 @@ set_current_working_directory (curr_dir.absolutePath ()); octave_link::post_event (this, &main_window::resize_command_window_callback); + + set_global_shortcuts (true); + } void @@ -1083,15 +1085,19 @@ tr ("Copy"), this, SLOT (copyClipboard ())); _copy_action->setShortcut (QKeySequence::Copy); + _paste_action = edit_menu->addAction (QIcon (":/actions/icons/editpaste.png"), tr ("Paste"), this, SLOT (pasteClipboard ())); _paste_action->setShortcut (QKeySequence::Paste); + _clear_clipboard_action + = edit_menu->addAction (tr ("Clear Clipboard"), this, + SLOT (clear_clipboard ())); + edit_menu->addSeparator (); - _find_files_action - = edit_menu->addAction (tr ("Find Files...")); + _find_files_action = edit_menu->addAction (tr ("Find Files...")); edit_menu->addSeparator (); @@ -1115,6 +1121,10 @@ connect (clear_workspace_action, SIGNAL (triggered ()), this, SLOT (handle_clear_workspace_request ())); + + connect (_clipboard, SIGNAL (changed (QClipboard::Mode)), + this, SLOT (clipboard_has_changed (QClipboard::Mode))); + clipboard_has_changed (QClipboard::Clipboard); } QAction * @@ -1638,4 +1648,26 @@ emit show_doc_signal (file); } +void +main_window::clipboard_has_changed (QClipboard::Mode cp_mode) +{ + if (cp_mode == QClipboard::Clipboard) + { + if (_clipboard->text ().isEmpty ()) + { + _paste_action->setEnabled (false); + _clear_clipboard_action->setEnabled (false); + } + else + { + _paste_action->setEnabled (true); + _clear_clipboard_action->setEnabled (true); + } + } +} +void +main_window::clear_clipboard () +{ + _clipboard->clear (QClipboard::Clipboard); +} diff -r 59acfe9209dd -r 47b504503a3f libgui/src/main-window.h --- a/libgui/src/main-window.h Wed Jul 31 13:14:09 2013 +0100 +++ b/libgui/src/main-window.h Wed Jul 31 21:25:04 2013 +0200 @@ -182,6 +182,11 @@ // setting global shortcuts void set_global_shortcuts (bool enable); + // handling the clipboard + void clipboard_has_changed (QClipboard::Mode); + void clear_clipboard (); + + protected: void closeEvent (QCloseEvent * closeEvent); @@ -286,6 +291,7 @@ QAction *_copy_action; QAction *_paste_action; + QAction *_clear_clipboard_action; QAction *_undo_action; QAction *_find_files_action; @@ -305,6 +311,8 @@ octave_qt_link *_octave_qt_link; + QClipboard *_clipboard; + // Flag for closing whole application. bool _closing; };