# HG changeset patch # User John Donoghue # Date 1365307138 14400 # Node ID 744ff2fe11ce1322672f01830afe2204ea34e8ce # Parent d4c3736e1e28c63b9df5fd93a80ecf688f15a9a8 add create script context menu to history window * history-dockwidget.h (history_doc_widget::command_create_script): New signal. * history-dockwidget.cc, history-dockwidget.h (history_dock_widget::ctxMenu): New menu item, Create script. (history_dock_widget::handle_contextmenu_create_script): New function. * file-editor-interface.h (file-editor-interface::request_new_file): New argument, commands. * file-editor-tab.h, file-editor-tab.cc (file_editor_tab::new_file): New argument, commands. * m-editor/file-editor.h, m-editor/file-editor.cc (file_editor::new_file, file_editor::request_new_file): New argument, commands. * main-window.h, main-window.cc (main_window::new_file): New argument, commands. main_window::construct): Connect history_window::command_create_script signal to main_window::new_file. diff -r d4c3736e1e28 -r 744ff2fe11ce libgui/src/history-dockwidget.cc --- a/libgui/src/history-dockwidget.cc Sat Apr 06 23:43:23 2013 -0400 +++ b/libgui/src/history-dockwidget.cc Sat Apr 06 23:58:58 2013 -0400 @@ -98,6 +98,7 @@ QMenu menu(this); menu.addAction(tr("Copy"), this, SLOT(handle_contextmenu_copy(bool))); menu.addAction(tr("Evaluate"), this, SLOT(handle_contextmenu_evaluate(bool))); + menu.addAction(tr("Create script"), this, SLOT(handle_contextmenu_create_script(bool))); menu.exec(_history_list_view->mapToGlobal(xpos)); } @@ -128,6 +129,24 @@ } void +history_dock_widget::handle_contextmenu_create_script (bool) +{ + QString text; + QItemSelectionModel *selectionModel = _history_list_view->selectionModel (); + QModelIndexList rows = selectionModel->selectedRows (); + + for (QModelIndexList::iterator it = rows.begin (); it != rows.end (); it++) + { + if ((*it).isValid ()) + text += (*it).data().toString() + "\n"; + } + + if (text.length () > 0) + emit command_create_script (text); +} + + +void history_dock_widget::handle_double_click (QModelIndex modelIndex) { emit command_double_clicked (modelIndex.data().toString()+"\n"); diff -r d4c3736e1e28 -r 744ff2fe11ce libgui/src/history-dockwidget.h --- a/libgui/src/history-dockwidget.h Sat Apr 06 23:43:23 2013 -0400 +++ b/libgui/src/history-dockwidget.h Sat Apr 06 23:58:58 2013 -0400 @@ -55,11 +55,16 @@ /** Emitted, whenever the user double-clicked a command in the history. */ void command_double_clicked (const QString& command); + /** Emitted whenever the user selects command and chooses Create + script from popupmenu. */ + void command_create_script (const QString& commands); + private slots: void handle_double_click (QModelIndex modelIndex); void handle_contextmenu_copy(bool flag); void handle_contextmenu_evaluate(bool flag); + void handle_contextmenu_create_script(bool flag); void ctxMenu(const QPoint &pos); private: diff -r d4c3736e1e28 -r 744ff2fe11ce libgui/src/m-editor/file-editor-interface.h --- a/libgui/src/m-editor/file-editor-interface.h Sat Apr 06 23:43:23 2013 -0400 +++ b/libgui/src/m-editor/file-editor-interface.h Sat Apr 06 23:58:58 2013 -0400 @@ -62,7 +62,7 @@ virtual void set_focus () = 0; public slots: - virtual void request_new_file () = 0; + virtual void request_new_file (const QString& command = QString ()) = 0; virtual void request_open_file () = 0; virtual void request_open_file (const QString& openFileName, int line = -1, bool debug_pointer = false, diff -r d4c3736e1e28 -r 744ff2fe11ce libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc Sat Apr 06 23:43:23 2013 -0400 +++ b/libgui/src/m-editor/file-editor-tab.cc Sat Apr 06 23:58:58 2013 -0400 @@ -794,10 +794,10 @@ } void -file_editor_tab::new_file () +file_editor_tab::new_file (const QString &commands) { update_window_title (false); // window title (no modification) - _edit_area->setText (""); + _edit_area->setText (commands); _edit_area->setModified (false); // new file is not modified yet } diff -r d4c3736e1e28 -r 744ff2fe11ce libgui/src/m-editor/file-editor-tab.h --- a/libgui/src/m-editor/file-editor-tab.h Sat Apr 06 23:43:23 2013 -0400 +++ b/libgui/src/m-editor/file-editor-tab.h Sat Apr 06 23:58:58 2013 -0400 @@ -87,7 +87,7 @@ void set_modified (bool modified = true); QString load_file (const QString& fileName); - void new_file (); + void new_file (const QString& commands = QString ()); void file_has_changed (const QString& fileName); diff -r d4c3736e1e28 -r 744ff2fe11ce libgui/src/m-editor/file-editor.cc --- a/libgui/src/m-editor/file-editor.cc Sat Apr 06 23:43:23 2013 -0400 +++ b/libgui/src/m-editor/file-editor.cc Sat Apr 06 23:58:58 2013 -0400 @@ -112,7 +112,7 @@ } void -file_editor::request_new_file () +file_editor::request_new_file (const QString& commands) { // New file isn't a file_editor_tab function since the file // editor tab has yet to be created and there is no object to @@ -122,7 +122,7 @@ if (fileEditorTab) { add_file_editor_tab (fileEditorTab, ""); // new tab with empty title - fileEditorTab->new_file (); // title is updated here + fileEditorTab->new_file (commands); // title is updated here set_focus (); // focus editor and new tab } } diff -r d4c3736e1e28 -r 744ff2fe11ce libgui/src/m-editor/file-editor.h --- a/libgui/src/m-editor/file-editor.h Sat Apr 06 23:43:23 2013 -0400 +++ b/libgui/src/m-editor/file-editor.h Sat Apr 06 23:58:58 2013 -0400 @@ -96,7 +96,7 @@ void fetab_set_focus (const QWidget* ID); public slots: - void request_new_file (); + void request_new_file (const QString& commands); void request_open_file (); void request_mru_open_file (); void request_print_file (); diff -r d4c3736e1e28 -r 744ff2fe11ce libgui/src/main-window.cc --- a/libgui/src/main-window.cc Sat Apr 06 23:43:23 2013 -0400 +++ b/libgui/src/main-window.cc Sat Apr 06 23:58:58 2013 -0400 @@ -103,10 +103,10 @@ } void -main_window::new_file () +main_window::new_file (const QString& commands) { #ifdef HAVE_QSCINTILLA - _file_editor->request_new_file (); + _file_editor->request_new_file (commands); #endif } @@ -1022,6 +1022,8 @@ this, SLOT (set_current_working_directory(QString))); connect (this, SIGNAL (relay_command_signal (const QString&)), command_window, SLOT (relay_command (const QString&))); + connect (history_window, SIGNAL (command_create_script (const QString&)), + this, SLOT (new_file (const QString&))); connect (save_workspace_action, SIGNAL (triggered ()), this, SLOT (handle_save_workspace_request ())); connect (load_workspace_action, SIGNAL (triggered ()), diff -r d4c3736e1e28 -r 744ff2fe11ce libgui/src/main-window.h --- a/libgui/src/main-window.h Sat Apr 06 23:43:23 2013 -0400 +++ b/libgui/src/main-window.h Sat Apr 06 23:58:58 2013 -0400 @@ -1,6 +1,5 @@ /* -Copyright (C) 2013 John W. Eaton Copyright (C) 2011-2012 Jacob Dawid This file is part of Octave. @@ -81,7 +80,7 @@ void handle_load_workspace_request (); void handle_clear_workspace_request (); void handle_clear_history_request (void); - void new_file (); + void new_file (const QString& commands = QString ()); void open_file (); void open_file (const QString& file_name); void open_online_documentation_page ();