changeset 16452:744ff2fe11ce

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.
author John Donoghue <john.donoghue@ieee.org>
date Sat, 06 Apr 2013 23:58:58 -0400
parents d4c3736e1e28
children 2e3c652c89d1
files libgui/src/history-dockwidget.cc libgui/src/history-dockwidget.h libgui/src/m-editor/file-editor-interface.h libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/main-window.cc libgui/src/main-window.h
diffstat 9 files changed, 36 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- 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");
--- 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:
--- 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,
--- 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
 }
 
--- 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);
 
--- 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
     }
 }
--- 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 ();
--- 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 ()),
--- 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 ();