# HG changeset patch # User Torsten # Date 1398616519 -7200 # Node ID 99e26cb0f87f4f9423e1df65bf94179d78da9f70 # Parent 74ef7fed8b9a5369e2d3f7eae1e3f2808909d440 use the actions from the editor for the context menu * octave-qscintilla.cc (contextMenuEvent): emit new signal for adding the actions from the editor to the edit areas context menu * octave-qscintilla.h: new signal * file-editor-tab.cc (create_context_menu): new slot for the new signal from the edit area, (constructor): connect the edit areas signal for creating the context menu to this new slot * file-edit-tab.h: new slot and new signal for the editor dock widget * file-editor.cc (create_context_menu): new slot for the new signal from the edit tab adding the actions from the editor menu to the context menu, (add_new_edit_tab): connect the edit tabs signal for creating the context menu to this new slot * file-editor.h: new slot diff -r 74ef7fed8b9a -r 99e26cb0f87f libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc Sun Apr 27 15:13:05 2014 +0200 +++ b/libgui/src/m-editor/file-editor-tab.cc Sun Apr 27 18:35:19 2014 +0200 @@ -89,6 +89,9 @@ this, SLOT (handle_cursor_moved (int,int))); + connect (_edit_area, SIGNAL (create_context_menu_signal (QMenu*)), + this, SLOT (create_context_menu (QMenu*))); + // create statusbar for row/col indicator _status_bar = new QStatusBar (this); @@ -1613,6 +1616,12 @@ } void +file_editor_tab::create_context_menu (QMenu *menu) +{ + emit create_context_menu_tab_signal (menu); +} + +void file_editor_tab::edit_area_has_focus (bool focus) { emit set_global_edit_shortcuts_signal (! focus); diff -r 74ef7fed8b9a -r 99e26cb0f87f libgui/src/m-editor/file-editor-tab.h --- a/libgui/src/m-editor/file-editor-tab.h Sun Apr 27 15:13:05 2014 +0200 +++ b/libgui/src/m-editor/file-editor-tab.h Sun Apr 27 18:35:19 2014 +0200 @@ -116,6 +116,7 @@ void execute_command_in_terminal (const QString& command); void edit_area_has_focus (bool foucs); + void create_context_menu (QMenu *); signals: @@ -129,6 +130,7 @@ void run_file_signal (const QFileInfo& info); void execute_command_in_terminal_signal (const QString&); void set_global_edit_shortcuts_signal (bool); + void create_context_menu_tab_signal (QMenu *); protected: diff -r 74ef7fed8b9a -r 99e26cb0f87f libgui/src/m-editor/file-editor.cc --- a/libgui/src/m-editor/file-editor.cc Sun Apr 27 15:13:05 2014 +0200 +++ b/libgui/src/m-editor/file-editor.cc Sun Apr 27 18:35:19 2014 +0200 @@ -940,12 +940,33 @@ editor_tab_map[fileName] = ID; } +// context menu of edit area void file_editor::active_tab_changed (int index) { emit fetab_change_request (_tab_widget->widget (index)); } +void file_editor::create_context_menu (QMenu *menu) +{ + // remove all standard actions from scintilla + QList all_actions = menu->actions (); + QAction* a; + + foreach (a, all_actions) + menu->removeAction (a); + + // add editor's actions with icons and customized shortcuts + menu->addAction (_undo_action); + menu->addAction (_redo_action); + menu->addSeparator (); + menu->addAction (_cut_action); + menu->addAction (_copy_action); + menu->addAction (_paste_action); + menu->addSeparator (); + menu->addAction (_selectall_action); +} + void file_editor::zoom_in (bool) { @@ -1395,6 +1416,9 @@ connect (f, SIGNAL (mru_add_file (const QString&)), this, SLOT (handle_mru_add_file (const QString&))); + connect (f, SIGNAL (create_context_menu_tab_signal (QMenu *)), + this, SLOT (create_context_menu (QMenu *))); + connect (f, SIGNAL (run_file_signal (const QFileInfo&)), main_win (), SLOT (run_file_in_terminal (const QFileInfo&))); diff -r 74ef7fed8b9a -r 99e26cb0f87f libgui/src/m-editor/file-editor.h --- a/libgui/src/m-editor/file-editor.h Sun Apr 27 15:13:05 2014 +0200 +++ b/libgui/src/m-editor/file-editor.h Sun Apr 27 18:35:19 2014 +0200 @@ -213,6 +213,8 @@ void zoom_out (bool); void zoom_normal (bool); + void create_context_menu (QMenu *); + protected: void dragEnterEvent(QDragEnterEvent *event); diff -r 74ef7fed8b9a -r 99e26cb0f87f libgui/src/m-editor/octave-qscintilla.cc --- a/libgui/src/m-editor/octave-qscintilla.cc Sun Apr 27 15:13:05 2014 +0200 +++ b/libgui/src/m-editor/octave-qscintilla.cc Sun Apr 27 18:35:19 2014 +0200 @@ -155,11 +155,13 @@ void octave_qscintilla::contextMenuEvent (QContextMenuEvent *e) { + QPoint global_pos, local_pos; // the menu's position QMenu *context_menu = createStandardContextMenu ( ); // standard menu - // the menu's position - QPoint global_pos, local_pos; + // fill context menu with editor's standard actions + emit create_context_menu_signal (context_menu); + // determine position depending on mouse or keyboard event if (e->reason () == QContextMenuEvent::Mouse) { // context menu by mouse diff -r 74ef7fed8b9a -r 99e26cb0f87f libgui/src/m-editor/octave-qscintilla.h --- a/libgui/src/m-editor/octave-qscintilla.h Sun Apr 27 15:13:05 2014 +0200 +++ b/libgui/src/m-editor/octave-qscintilla.h Sun Apr 27 18:35:19 2014 +0200 @@ -50,6 +50,7 @@ signals: void execute_command_in_terminal_signal (const QString&); + void create_context_menu_signal (QMenu*); void qsci_has_focus_signal (bool); private slots: