[nemiver/varobjs-support] Preliminary support of variable editing in VarInspector2



commit 229985f966bbb3219b29f0ee772578c3c706ffed
Author: Dodji Seketeli <dodji redhat com>
Date:   Sun Apr 26 11:01:49 2009 +0200

    Preliminary support of variable editing in VarInspector2
    
    	* src/dbgengine/nmv-i-debugger.h (IDebugger::is_variable_editable):
    	  New entry point abstract entry point declaration.
    	* src/dbgengine/nmv-gdb-engine.h (GDBEngine::is_variable_editable):
    	  New concrete entry point declaration ...
    	* src/dbgengine/nmv-gdb-engine.cc (GDBEngine::is_variable_editable):
    	  ... Defined here.
    	* src/persp/dbgperspective/nmv-variables-utils.h:
    	(struct VariableColumns): Add a new hidden column at offset
    	VARIABLE_VALUE_EDITABLE_OFFSET to hold the variable_value_editable flag
    	about the editability of a variable.
    	* src/persp/dbgperspective/nmv-vars-treeview.h:
    	(VarsTreeView::ColumnIndex): New enum to hold the indexes the
    	columns of the VarsTreeView.
    	* src/persp/dbgperspective/nmv-vars-treeview.cc:
    	(VarsTreeView::VarsTreeView): Connect the "editable" attribute
    	of the cell renderer of the variable value with the new hidden flag
    	of VariableColumns at VARIABLE_VALUE_EDITABLE_OFFSET offset.
    	* src/persp/dbgperspective/nmv-var-inspector2.cc:
    	(VarInspector2::Priv::connect_to_signals): Connect
    	VarInspector2::Priv::on_cell_edited_signal to the
    	signal_edited of the text cell renderer of the variable values.
    	(VarInspector2::Priv::on_cell_edited_signal): New signal handler.
    	When the value of a given variable is edited, assign the variable
    	to the new value.
    	(VarInspector2::Priv::on_tree_view_selection_changed_signal):
    	When a variable is selected, detected if the variable is editable
    	or not, and set the editability property of the variable's value
    	cell accordingly.
    	(VarInspector2::Priv::on_variable_assigned_signal): New signal
    	handler called when a variable gets assigned. Just update the
    	variable node that got modified.
---
 src/dbgengine/nmv-gdb-engine.cc                |   21 ++++++++
 src/dbgengine/nmv-gdb-engine.h                 |    2 +
 src/dbgengine/nmv-i-debugger.h                 |    2 +
 src/persp/dbgperspective/nmv-var-inspector2.cc |   64 +++++++++++++++++++++++-
 src/persp/dbgperspective/nmv-variables-utils.h |    5 ++-
 src/persp/dbgperspective/nmv-vars-treeview.cc  |    9 ++-
 src/persp/dbgperspective/nmv-vars-treeview.h   |    5 ++
 7 files changed, 102 insertions(+), 6 deletions(-)

diff --git a/src/dbgengine/nmv-gdb-engine.cc b/src/dbgengine/nmv-gdb-engine.cc
index c268489..7f1323f 100644
--- a/src/dbgengine/nmv-gdb-engine.cc
+++ b/src/dbgengine/nmv-gdb-engine.cc
@@ -3134,6 +3134,27 @@ GDBEngine::get_language_trait ()
     return m_priv->lang_trait;
 }
 
+/// Dectect if the variable should be editable or not.
+/// For now, only scalar variable are said to be editable.
+/// An aggregate (array or structure) is not editable yet, as
+/// we need lots of hacks to detect for instance if an array is a string,
+/// for instance.
+/// \param a_var the variable to consider.
+/// \return true if the variable is editable, false otherwise.
+bool
+GDBEngine::is_variable_editable (const VariableSafePtr a_var) const
+{
+    LOG_FUNCTION_SCOPE_NORMAL_DD;
+    // TODO: make this depend on the current language trait, maybe ?
+    // Also, be less strict and allow editing of certain aggregate
+    // variables.
+    if (!a_var)
+        return false;
+    if (a_var->members ().empty () && !a_var->has_expected_children ())
+        return true;
+    return false;
+}
+
 bool
 GDBEngine::stop_target ()
 {
diff --git a/src/dbgengine/nmv-gdb-engine.h b/src/dbgengine/nmv-gdb-engine.h
index 55a44e5..d91ac6e 100644
--- a/src/dbgengine/nmv-gdb-engine.h
+++ b/src/dbgengine/nmv-gdb-engine.h
@@ -281,6 +281,8 @@ public:
 
     ILangTraitSafePtr get_language_trait () ;
 
+    bool is_variable_editable (const VariableSafePtr) const;
+
     IDebugger::State get_state () const ;
 
     int get_current_frame_level () const;
diff --git a/src/dbgengine/nmv-i-debugger.h b/src/dbgengine/nmv-i-debugger.h
index 2a60058..74d4832 100644
--- a/src/dbgengine/nmv-i-debugger.h
+++ b/src/dbgengine/nmv-i-debugger.h
@@ -959,6 +959,8 @@ public:
 
     virtual ILangTraitSafePtr get_language_trait () = 0;
 
+    virtual bool is_variable_editable (const VariableSafePtr a_var) const = 0;
+
     virtual void do_continue (const UString &a_cookie="") = 0;
 
     virtual void run (const UString &a_cookie="") = 0;
diff --git a/src/persp/dbgperspective/nmv-var-inspector2.cc b/src/persp/dbgperspective/nmv-var-inspector2.cc
index b465aed..0082323 100644
--- a/src/persp/dbgperspective/nmv-var-inspector2.cc
+++ b/src/persp/dbgperspective/nmv-var-inspector2.cc
@@ -81,6 +81,15 @@ class VarInspector2::Priv : public sigc::trackable {
 
         tree_view->signal_row_expanded ().connect
             (sigc::mem_fun (*this, &Priv::on_tree_view_row_expanded_signal));
+
+        Gtk::CellRenderer *r = tree_view->get_column_cell_renderer
+            (VarsTreeView::VARIABLE_VALUE_COLUMN_INDEX);
+        THROW_IF_FAIL (r);
+
+        Gtk::CellRendererText *t =
+            dynamic_cast<Gtk::CellRendererText*> (r);
+        t->signal_edited ().connect (sigc::mem_fun
+                                     (*this, &Priv::on_cell_edited_signal));
     }
 
     void
@@ -181,10 +190,21 @@ class VarInspector2::Priv : public sigc::trackable {
         THROW_IF_FAIL (sel);
         cur_selected_row = sel->get_selected ();
         if (!cur_selected_row) {return;}
-        IDebugger::VariableSafePtr variable =
+        IDebugger::VariableSafePtr var =
             (IDebugger::VariableSafePtr)cur_selected_row->get_value
                                     (vutil::get_variable_columns ().variable);
-        if (!variable) {return;}
+        if (!var)
+            return;
+
+        variable = var;
+
+        // If the variable should be editable, set the cell of the variable value
+        // editable.
+        cur_selected_row->set_value
+                    (vutil::get_variable_columns ().variable_value_editable,
+                     debugger->is_variable_editable (variable));
+
+        // Dump some log about the variable that got selected.
         UString qname;
         variable->build_qname (qname);
         LOG_DD ("row of variable '" << qname << "'");
@@ -239,6 +259,28 @@ class VarInspector2::Priv : public sigc::trackable {
     }
 
     void
+    on_cell_edited_signal (const Glib::ustring &a_path,
+                           const Glib::ustring &a_text)
+    {
+        LOG_FUNCTION_SCOPE_NORMAL_DD;
+
+        NEMIVER_TRY
+
+        Gtk::TreeModel::iterator row = tree_store->get_iter (a_path);
+        IDebugger::VariableSafePtr var =
+            (*row)[vutil::get_variable_columns ().variable];
+        THROW_IF_FAIL (var);
+
+        debugger->assign_variable
+            (var, a_text,
+             sigc::bind (sigc::mem_fun
+                                 (*this, &Priv::on_variable_assigned_signal),
+                         a_path));
+
+        NEMIVER_CATCH
+    }
+
+    void
     on_variable_created_signal (const IDebugger::VariableSafePtr a_var)
     {
         LOG_FUNCTION_SCOPE_NORMAL_DD;
@@ -265,6 +307,24 @@ class VarInspector2::Priv : public sigc::trackable {
         NEMIVER_CATCH
     }
 
+    void
+    on_variable_assigned_signal (const IDebugger::VariableSafePtr a_var,
+                                 const UString &a_var_path)
+    {
+        LOG_FUNCTION_SCOPE_NORMAL_DD;
+
+        NEMIVER_TRY
+
+        Gtk::TreeModel::iterator var_row
+                                = tree_store->get_iter (a_var_path);
+        THROW_IF_FAIL (var_row);
+        THROW_IF_FAIL (tree_view);
+        vutil::update_a_variable_node (a_var, *tree_view,
+                                       var_row, false, false);
+
+        NEMIVER_CATCH
+    }
+
     // ******************
     // </signal handlers>
     // ******************
diff --git a/src/persp/dbgperspective/nmv-variables-utils.h b/src/persp/dbgperspective/nmv-variables-utils.h
index 6ffe739..69d4869 100644
--- a/src/persp/dbgperspective/nmv-variables-utils.h
+++ b/src/persp/dbgperspective/nmv-variables-utils.h
@@ -45,7 +45,8 @@ struct VariableColumns : public Gtk::TreeModelColumnRecord {
         VARIABLE_OFFSET,
         IS_HIGHLIGHTED_OFFSET,
         NEEDS_UNFOLDING,
-        FG_COLOR_OFFSET
+        FG_COLOR_OFFSET,
+        VARIABLE_VALUE_EDITABLE_OFFSET
     };
 
     Gtk::TreeModelColumn<Glib::ustring> name;
@@ -56,6 +57,7 @@ struct VariableColumns : public Gtk::TreeModelColumnRecord {
     Gtk::TreeModelColumn<bool> is_highlighted;
     Gtk::TreeModelColumn<bool> needs_unfolding;
     Gtk::TreeModelColumn<Gdk::Color> fg_color;
+    Gtk::TreeModelColumn<bool> variable_value_editable;
 
     VariableColumns ()
     {
@@ -67,6 +69,7 @@ struct VariableColumns : public Gtk::TreeModelColumnRecord {
         add (is_highlighted);
         add (needs_unfolding);
         add (fg_color);
+        add (variable_value_editable);
     }
 };//end VariableColumns
 
diff --git a/src/persp/dbgperspective/nmv-vars-treeview.cc b/src/persp/dbgperspective/nmv-vars-treeview.cc
index a6fa132..f759719 100644
--- a/src/persp/dbgperspective/nmv-vars-treeview.cc
+++ b/src/persp/dbgperspective/nmv-vars-treeview.cc
@@ -49,7 +49,7 @@ VarsTreeView::VarsTreeView (Glib::RefPtr<Gtk::TreeStore>& model) :
     //create the columns of the tree view
     append_column (_("Variable"),
                    vutil::get_variable_columns ().name);
-    Gtk::TreeViewColumn * col = get_column (0);
+    Gtk::TreeViewColumn * col = get_column (VARIABLE_NAME_COLUMN_INDEX);
     THROW_IF_FAIL (col);
     col->set_resizable (true);
     col->add_attribute (*col->get_first_cell_renderer (),
@@ -57,16 +57,19 @@ VarsTreeView::VarsTreeView (Glib::RefPtr<Gtk::TreeStore>& model) :
                         vutil::VariableColumns::FG_COLOR_OFFSET);
 
     append_column (_("Value"), vutil::get_variable_columns ().value);
-    col = get_column (1);
+    col = get_column (VARIABLE_VALUE_COLUMN_INDEX);
     THROW_IF_FAIL (col);
     col->set_resizable (true);
     col->add_attribute (*col->get_first_cell_renderer (),
                         "foreground-gdk",
                         vutil::VariableColumns::FG_COLOR_OFFSET);
+    col->add_attribute (*col->get_first_cell_renderer (),
+                        "editable",
+                        vutil::VariableColumns::VARIABLE_VALUE_EDITABLE_OFFSET);
 
     append_column (_("Type"),
                    vutil::get_variable_columns ().type_caption);
-    col = get_column (2);
+    col = get_column (VARIABLE_TYPE_COLUMN_INDEX);
     THROW_IF_FAIL (col);
     col->set_resizable (true);
 }
diff --git a/src/persp/dbgperspective/nmv-vars-treeview.h b/src/persp/dbgperspective/nmv-vars-treeview.h
index 7516276..3be799d 100644
--- a/src/persp/dbgperspective/nmv-vars-treeview.h
+++ b/src/persp/dbgperspective/nmv-vars-treeview.h
@@ -42,6 +42,11 @@ typedef SafePtr<VarsTreeView,
 class NEMIVER_API VarsTreeView : public Gtk::TreeView
 {
     public:
+        enum ColumIndex {
+            VARIABLE_NAME_COLUMN_INDEX = 0,
+            VARIABLE_VALUE_COLUMN_INDEX,
+            VARIABLE_TYPE_COLUMN_INDEX
+        };
         static VarsTreeViewSafePtr create ();
         Glib::RefPtr<Gtk::TreeStore>& get_tree_store ();
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]