Mercurial > hg > octave-lyh
changeset 16881:944ade6e7f66
Make main window copy and paste global for current focused window
* libgui/src/workspace-view.h, libgui/src/workspace-view.cc
(workspace_view::copyClipboard): New function.
* libgui/src/qtinfo/webinfo.h, libgui/src/qtinfo/webinfo.cc
(webinfo::pasteClipboard): New function.
(webinfo::copyClipboard): New function.
* libgui/src/octave-dock-widget.h, libgui/src/octave-dock-widget.cc
(octave_dock_widget::copyClipboard): New function.
(octave_dock_widget::pasteClipboard): New function.
(octave_dock_widget::focusWidget): New function.
(octave_dock_widget::octave_dock_widget): Connect copy/paste to main window signals.
* libgui/src/main-window.cc
(main_window::copyClipboard): process current directory copy if is focused.
(main_window::pasteClipboard): process current directory paste if is focused.
* libgui/src/m-editor/file-editor.h, libgui/src/m-editor/file-editor.cc
(file_editor::copyClipboard): New function.
(file_editor::pasteClipboard): New function.
* libgui/src/history-dock-widget.h, libgui/src/history-dock-widget.cc
(history_dock_widget::pasteClipboard): New function.
(history_dock_widget::copyClipboard): New function.
* libgui/src/files-dock-widget.h, libgui/src/files-dock-widget.cc
(files_dock_widget::copyClipboard): New function.
(files_dock_widget::pasteClipboard): New function.
* libgui/src/documentation-dock-widget.h, libgui/src/documentation-dock-widget.cc
(documentation_dock_widget::copyClipboard): New function.
(documentation_dock_widget::pasteClipboard): New function.
* libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h, libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cc
(QWinTerminalImpl::copyClipboard): dont copy unless is focused widget.
(QWinTerminalImpl::pasteClipboard): dont paste unless is focused widget.
* libgui/qterminal/libqterminal/unix/TerminalView.h, libgui/qterminal/libqterminal/unix/TerminalView.cc
(TerminalView::copyClipboard): only copy is focused widget.
(TerminalView::pasteClipboard): only paste is focused widget.
author | John Donoghue <john.donoghue@ieee.org> |
---|---|
date | Sun, 30 Jun 2013 20:33:20 -0400 |
parents | 1aebb613a5ac |
children | dc24773d1acc |
files | libgui/qterminal/libqterminal/unix/TerminalView.cpp libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp libgui/src/documentation-dock-widget.cc libgui/src/documentation-dock-widget.h libgui/src/files-dock-widget.cc libgui/src/files-dock-widget.h libgui/src/history-dock-widget.cc libgui/src/history-dock-widget.h libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/main-window.cc libgui/src/octave-dock-widget.cc libgui/src/octave-dock-widget.h libgui/src/qtinfo/webinfo.cc libgui/src/qtinfo/webinfo.h libgui/src/workspace-view.cc libgui/src/workspace-view.h |
diffstat | 17 files changed, 198 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/qterminal/libqterminal/unix/TerminalView.cpp +++ b/libgui/qterminal/libqterminal/unix/TerminalView.cpp @@ -2260,7 +2260,7 @@ void TerminalView::copyClipboard() { - if ( !_screenWindow ) + if ( !_screenWindow || !hasFocus()) return; QString text = _screenWindow->selectedText(_preserveLineBreaks); @@ -2278,7 +2278,10 @@ void TerminalView::pasteClipboard() { - emitSelection(false,false); + if(hasFocus ()) + { + emitSelection(false,false); + } } void TerminalView::pasteSelection()
--- a/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp +++ b/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp @@ -1436,6 +1436,8 @@ void QWinTerminalImpl::copyClipboard (void) { + if(!hasFocus()) return; + QClipboard *clipboard = QApplication::clipboard (); QString selection = d->getSelection (); @@ -1456,6 +1458,8 @@ void QWinTerminalImpl::pasteClipboard (void) { + if(!hasFocus()) return; + QString text = QApplication::clipboard()->text (QClipboard::Clipboard); if (! text.isEmpty ())
--- a/libgui/src/documentation-dock-widget.cc +++ b/libgui/src/documentation-dock-widget.cc @@ -37,3 +37,14 @@ _webinfo = new webinfo (this); setWidget (_webinfo); } + +void +documentation_dock_widget::copyClipboard () +{ + _webinfo->copyClipboard (); +} +void +documentation_dock_widget::pasteClipboard () +{ + _webinfo->pasteClipboard (); +}
--- a/libgui/src/documentation-dock-widget.h +++ b/libgui/src/documentation-dock-widget.h @@ -35,6 +35,10 @@ documentation_dock_widget (QWidget *parent = 0); +protected slots: + void copyClipboard (); + void pasteClipboard (); + private: webinfo *_webinfo;
--- a/libgui/src/files-dock-widget.cc +++ b/libgui/src/files-dock-widget.cc @@ -708,3 +708,35 @@ emit find_files_signal(dir); } +void +files_dock_widget::copyClipboard () +{ + if (_file_tree_view->hasFocus ()) + contextmenu_copy_selection (true); + if (_current_directory->hasFocus ()) + { + QClipboard *clipboard = QApplication::clipboard (); + + QLineEdit * edit = _current_directory->lineEdit (); + if (edit && edit->hasSelectedText ()) + { + clipboard->setText (edit->selectedText ()); + } + } +} + +void +files_dock_widget::pasteClipboard () +{ + if (_current_directory->hasFocus ()) + { + QClipboard *clipboard = QApplication::clipboard (); + QString str = clipboard->text (); + QLineEdit * edit = _current_directory->lineEdit (); + if (edit && str.length () > 0) + edit->insert (str); + } +} + + +
--- a/libgui/src/files-dock-widget.h +++ b/libgui/src/files-dock-widget.h @@ -103,6 +103,10 @@ void popdownmenu_findfiles (bool); void popdownmenu_home (bool); + /* from octave_doc_widget */ + void copyClipboard (); + void pasteClipboard (); + signals: /** Emitted, whenever the user requested to open a file. */
--- a/libgui/src/history-dock-widget.cc +++ b/libgui/src/history-dock-widget.cc @@ -169,3 +169,28 @@ { _history_model->setStringList (QStringList ()); } + +void +history_dock_widget::copyClipboard () +{ + if(_history_list_view->hasFocus()) + handle_contextmenu_copy(true); + if(_filter_line_edit->hasFocus () && _filter_line_edit->hasSelectedText ()) + { + QClipboard *clipboard = QApplication::clipboard (); + clipboard->setText ( _filter_line_edit->selectedText ()); + } +} + +void +history_dock_widget::pasteClipboard () +{ + if(_filter_line_edit->hasFocus ()) + { + QClipboard *clipboard = QApplication::clipboard (); + QString str = clipboard->text (); + if (str.length() > 0) + _filter_line_edit->insert (str); + } +} +
--- a/libgui/src/history-dock-widget.h +++ b/libgui/src/history-dock-widget.h @@ -62,6 +62,9 @@ void handle_contextmenu_create_script(bool flag); void ctxMenu(const QPoint &pos); + void copyClipboard (); + void pasteClipboard (); + private: void construct ();
--- a/libgui/src/m-editor/file-editor.cc +++ b/libgui/src/m-editor/file-editor.cc @@ -1171,4 +1171,25 @@ _tab_widget->setCurrentWidget (f); } +void +file_editor::copyClipboard () +{ + QWidget * foc_w = focusWidget (); + + if(foc_w && foc_w->inherits ("octave_qscintilla")) + { + request_copy (); + } +} +void +file_editor::pasteClipboard () +{ + QWidget * foc_w = focusWidget (); + + if(foc_w && foc_w->inherits ("octave_qscintilla")) + { + request_paste (); + } +} + #endif
--- a/libgui/src/m-editor/file-editor.h +++ b/libgui/src/m-editor/file-editor.h @@ -152,6 +152,10 @@ // Tells the editor to react on changed settings. void notice_settings (const QSettings *settings); +protected slots: + void copyClipboard (); + void pasteClipboard (); + private slots: void request_open_file (const QString& fileName, int line = -1,
--- a/libgui/src/main-window.cc +++ b/libgui/src/main-window.cc @@ -613,13 +613,34 @@ void main_window::copyClipboard (void) { - emit copyClipboard_signal (); + if (_current_directory_combo_box->hasFocus ()) + { + QLineEdit * edit = _current_directory_combo_box->lineEdit (); + if (edit && edit->hasSelectedText ()) + { + QClipboard *clipboard = QApplication::clipboard (); + clipboard->setText (edit->selectedText ()); + } + } + else + emit copyClipboard_signal (); } void main_window::pasteClipboard (void) { - emit pasteClipboard_signal (); + if (_current_directory_combo_box->hasFocus ()) + { + QLineEdit * edit = _current_directory_combo_box->lineEdit (); + QClipboard *clipboard = QApplication::clipboard (); + QString str = clipboard->text (); + if (edit && str.length () > 0) + { + edit->insert (str); + } + } + else + emit pasteClipboard_signal (); } // Connect the signals emitted when the Octave thread wants to create
--- a/libgui/src/octave-dock-widget.cc +++ b/libgui/src/octave-dock-widget.cc @@ -21,7 +21,7 @@ */ - +#include <QApplication> #include <QToolBar> #include <QToolButton> #include <QAction> @@ -76,6 +76,9 @@ title_widget->setLayout (h_layout); setTitleBarWidget (title_widget); + // copy & paste handling + connect (p, SIGNAL (copyClipboard_signal ()), this, SLOT (copyClipboard ())); + connect (p, SIGNAL (pasteClipboard_signal()), this, SLOT (pasteClipboard ())); } octave_dock_widget::~octave_dock_widget () @@ -193,3 +196,11 @@ emit active_changed (false); } +// get focus widget +QWidget * +octave_dock_widget::focusWidget () +{ + QWidget * w = QApplication::focusWidget (); + if(w && w->focusProxy ()) w = w->focusProxy (); + return w; +}
--- a/libgui/src/octave-dock-widget.h +++ b/libgui/src/octave-dock-widget.h @@ -58,6 +58,7 @@ QDockWidget::closeEvent (e); } + QWidget * focusWidget(); public slots: @@ -91,6 +92,13 @@ if (visible) emit active_changed (true); } + /** slots to handle copy & paste */ + virtual void copyClipboard () + { + } + virtual void pasteClipboard () + { + } private slots:
--- a/libgui/src/qtinfo/webinfo.cc +++ b/libgui/src/qtinfo/webinfo.cc @@ -31,6 +31,8 @@ #include "webinfo.h" #include <QVBoxLayout> #include <QHBoxLayout> +#include <QApplication> +#include <QClipboard> #include "file-ops.h" #include "help.h" @@ -218,3 +220,30 @@ _text_browser->setFont (_font_web); } +void +webinfo::copyClipboard () +{ + if (_search_line_edit->hasFocus () && _search_line_edit->hasSelectedText ()) + { + QClipboard *clipboard = QApplication::clipboard (); + + clipboard->setText (_search_line_edit->selectedText ()); + } + if (_text_browser->hasFocus ()) + { + _text_browser->copy (); + } +} + +void +webinfo::pasteClipboard () +{ + if (_search_line_edit->hasFocus ()) + { + QClipboard *clipboard = QApplication::clipboard (); + QString str = clipboard->text (); + if (str.length () > 0) + _search_line_edit->insert (str); + } +} +
--- a/libgui/src/qtinfo/webinfo.h +++ b/libgui/src/qtinfo/webinfo.h @@ -49,6 +49,9 @@ void zoom_in (); void zoom_out (); + void copyClipboard (); + void pasteClipboard (); + private: QTextBrowser *_text_browser; QTabBar *_tab_bar;