changeset 24775:3da6c628873a

clear variable via context menu of workspace view (bug #53149) * workspace-view.cc (contextmenu_requested): add action for clearing variable; (handle_contextmenu_clear): new slot for new action; (relay_contextmenu_command): new boolean argument whether variable is used as value or as string in the executed command * workspace-view.h: new boolean argument for relay_contextmenu_command, default is false
author Torsten <mttl@mailbox.org>
date Sun, 18 Feb 2018 20:59:47 +0100
parents 90bd5649983c
children 240bd1e4f31e
files libgui/src/workspace-view.cc libgui/src/workspace-view.h
diffstat 2 files changed, 18 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/workspace-view.cc	Fri Feb 16 22:59:14 2018 +0100
+++ b/libgui/src/workspace-view.cc	Sun Feb 18 20:59:47 2018 +0100
@@ -365,6 +365,9 @@
             rename->setToolTip (tr ("Only top-level symbols may be renamed"));
           }
 
+        menu.addAction ("Clear " + var_name, this,
+                        SLOT (handle_contextmenu_clear ()));
+
         menu.addSeparator ();
 
         menu.addAction ("disp (" + var_name + ')', this,
@@ -473,6 +476,12 @@
   }
 
   void
+  workspace_view::handle_contextmenu_clear (void)
+  {
+    relay_contextmenu_command ("clear", true);
+  }
+
+  void
   workspace_view::handle_contextmenu_disp (void)
   {
     relay_contextmenu_command ("disp");
@@ -526,13 +535,18 @@
   }
 
   void
-  workspace_view::relay_contextmenu_command (const QString& cmdname)
+  workspace_view::relay_contextmenu_command (const QString& cmdname, bool str)
   {
     QModelIndex index = m_view->currentIndex ();
 
     if (index.isValid ())
       {
-        QString var_name = get_var_name (index);
+        QString var_name;
+
+        if (str)
+          var_name = "\'" + get_var_name (index) + "\'";
+        else
+          var_name = get_var_name (index);
 
         emit command_requested (cmdname + " (" + var_name + ");");
       }
--- a/libgui/src/workspace-view.h	Fri Feb 16 22:59:14 2018 +0100
+++ b/libgui/src/workspace-view.h	Sun Feb 18 20:59:47 2018 +0100
@@ -87,6 +87,7 @@
     void handle_contextmenu_copy_value (void);
     void handle_contextmenu_rename (void);
     void handle_contextmenu_edit (void);
+    void handle_contextmenu_clear (void);
     void handle_contextmenu_disp (void);
     void handle_contextmenu_plot (void);
     void handle_contextmenu_stem (void);
@@ -99,7 +100,7 @@
 
   private:
 
-    void relay_contextmenu_command (const QString& cmdname);
+    void relay_contextmenu_command (const QString& cmdname, bool str = false);
 
     QString get_var_name (const QModelIndex& index);