[nemiver/gtk2-branch] 577496 561100 533437 656093 564992 Support Copy/Paste/Reset on target terminal



commit 84ef75906197918fc850aa811ec2f1f38ab33c21
Author: Fabien Parent <parent f gmail com>
Date:   Sun Aug 7 12:34:43 2011 +0200

    577496 561100 533437 656093 564992 Support Copy/Paste/Reset on target terminal
    
    	* src/persp/dbgperspective/menus/Makefile.am: Add terminal menu file
    	* src/persp/dbgperspective/menus/terminalmenu.xml: New file
    	* src/persp/dbgperspective/nmv-dbg-perspective.cc
    	(DBGPerspective::get_terminal): pass the ui manager to the terminal
    	* src/uicommon/nmv-terminal.cc
    	(on_button_press_signal): New API
    	(Terminal::Priv::Priv): Move code into a new method init_body, and call it
    	along with init_actions.
    	(Terminal::Priv::init_body): Code moved from Terminal::Priv::Priv.
    	(Terminal::Priv::init_actions): New API
    	(Terminal::Priv::on_reset_signal): Likewise
    	(Terminal::Priv::on_copy_signal): Likewise
    	(Terminal::Priv::on_paste_signal): Likewise
    	(Terminal::Priv::reset): Likewise
    	(Terminal::Priv::copy): Likewise
    	(Terminal::Priv::paste): Likewise
    	(Terminal::Terminal): Add a new paramater
    	* src/uicommon/nmv-terminal.h
    	(Terminal::Terminal): Set constructor explicit and add a new parameter.

 src/persp/dbgperspective/menus/Makefile.am      |    3 +-
 src/persp/dbgperspective/menus/terminalmenu.xml |   10 ++
 src/persp/dbgperspective/nmv-dbg-perspective.cc |    9 ++-
 src/uicommon/nmv-terminal.cc                    |  155 ++++++++++++++++++++++-
 src/uicommon/nmv-terminal.h                     |    8 +-
 5 files changed, 178 insertions(+), 7 deletions(-)
---
diff --git a/src/persp/dbgperspective/menus/Makefile.am b/src/persp/dbgperspective/menus/Makefile.am
index d4d6efe..a6dc6d8 100644
--- a/src/persp/dbgperspective/menus/Makefile.am
+++ b/src/persp/dbgperspective/menus/Makefile.am
@@ -7,7 +7,8 @@ breakpointspopup.xml \
 callstackpopup.xml \
 varinspectorpopup.xml \
 localvarsinspectorpopup.todelete.xml \
-localvarsinspectorpopup.xml
+localvarsinspectorpopup.xml \
+terminalmenu.xml
 
 menusdir = @NEMIVER_PLUGINS_DIR@/$(PLUGIN_NAME)/menus
 menus_DATA = $(menusfiles)
diff --git a/src/persp/dbgperspective/menus/terminalmenu.xml b/src/persp/dbgperspective/menus/terminalmenu.xml
new file mode 100644
index 0000000..78911e8
--- /dev/null
+++ b/src/persp/dbgperspective/menus/terminalmenu.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+ <ui>
+  <popup name='TerminalMenu'>
+    <menuitem action='CopyAction'/>
+    <menuitem action='PasteAction'/>
+    <separator/>
+    <menuitem action='ResetAction'/>
+  </popup>
+ </ui>
+
diff --git a/src/persp/dbgperspective/nmv-dbg-perspective.cc b/src/persp/dbgperspective/nmv-dbg-perspective.cc
index 94d3ef7..435d50a 100644
--- a/src/persp/dbgperspective/nmv-dbg-perspective.cc
+++ b/src/persp/dbgperspective/nmv-dbg-perspective.cc
@@ -8111,7 +8111,14 @@ DBGPerspective::get_terminal ()
 {
     THROW_IF_FAIL (m_priv);
     if (!m_priv->terminal) {
-        m_priv->terminal.reset (new Terminal);
+        string relative_path = Glib::build_filename ("menus",
+                                                     "terminalmenu.xml");
+        string absolute_path;
+        THROW_IF_FAIL (build_absolute_resource_path
+                (Glib::filename_to_utf8 (relative_path), absolute_path));
+
+        m_priv->terminal.reset(new Terminal
+                (absolute_path, workbench ().get_ui_manager ()));
     }
     THROW_IF_FAIL (m_priv->terminal);
     return *m_priv->terminal;
diff --git a/src/uicommon/nmv-terminal.cc b/src/uicommon/nmv-terminal.cc
index c2fdff1..410112c 100644
--- a/src/uicommon/nmv-terminal.cc
+++ b/src/uicommon/nmv-terminal.cc
@@ -37,16 +37,63 @@
 #endif
 #include <unistd.h>
 #include <iostream>
+#include <tr1/tuple>
 #include <gtkmm/bin.h>
 #include <gtkmm/main.h>
 #include <gtkmm/window.h>
 #include <gtkmm/adjustment.h>
+#include <gtkmm/menu.h>
+#include <gtkmm/builder.h>
+#include <gtkmm/uimanager.h>
 #include <vte/vte.h>
+#include <glib/gi18n.h>
 #include "common/nmv-exception.h"
 #include "common/nmv-log-stream-utils.h"
+#include "common/nmv-env.h"
+#include "nmv-ui-utils.h"
 
 NEMIVER_BEGIN_NAMESPACE(nemiver)
 
+using namespace common;
+
+typedef std::tr1::tuple<VteTerminal*&,
+                   Gtk::Menu*&,
+                   Glib::RefPtr<Gtk::ActionGroup>&> TerminalPrivDataTuple;
+
+static bool
+on_button_press_signal (GtkWidget*,
+                        GdkEventButton *a_event,
+                        TerminalPrivDataTuple *a_tuple)
+{
+    if (a_event->type != GDK_BUTTON_PRESS || a_event->button != 3) {
+        return false;
+    }
+
+    NEMIVER_TRY
+
+    THROW_IF_FAIL (a_tuple);
+    VteTerminal*& vte = std::tr1::get<0> (*a_tuple);
+    Gtk::Menu*& menu = std::tr1::get<1> (*a_tuple);
+    Glib::RefPtr<Gtk::ActionGroup>& action_group = std::tr1::get<2> (*a_tuple);
+
+    THROW_IF_FAIL (vte);
+    THROW_IF_FAIL (action_group);
+    THROW_IF_FAIL (a_event);
+
+    Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
+    if (clipboard) {
+         action_group->get_action ("PasteAction")->set_sensitive
+                (clipboard->wait_is_text_available ());
+    }
+
+    action_group->get_action ("CopyAction")->set_sensitive
+            (vte_terminal_get_has_selection (vte));
+    menu->popup (a_event->button, a_event->time);
+
+    NEMIVER_CATCH
+    return true;
+}
+
 struct Terminal::Priv {
     //the master pty of the terminal (and of the whole process)
     int master_pty;
@@ -57,13 +104,29 @@ struct Terminal::Priv {
     //m_vte, but wrapped as a Gtk::Widget
     Gtk::Widget *widget;
     Gtk::Adjustment *adjustment;
+    Gtk::Menu *menu;
+    Glib::RefPtr<Gtk::ActionGroup> action_group;
 
-    Priv () :
+    // Point to vte, menu, and action_group variables
+    // Used by the on_button_press_signal event to show contextual menu
+    TerminalPrivDataTuple popup_user_data;
+
+    Priv (const string &a_menu_file_path,
+          const Glib::RefPtr<Gtk::UIManager> &a_ui_manager) :
         master_pty (0),
         slave_pty (0),
         vte (0),
         widget (0),
-        adjustment (0)
+        adjustment (0),
+        menu (0),
+        popup_user_data (vte, menu, action_group)
+    {
+        init_actions ();
+        init_body (a_menu_file_path, a_ui_manager);
+    }
+
+    void init_body (const string &a_menu_file_path,
+                    const Glib::RefPtr<Gtk::UIManager> &a_ui_manager)
     {
         GtkWidget *w = vte_terminal_new ();
         vte = VTE_TERMINAL (w);
@@ -86,6 +149,89 @@ struct Terminal::Priv {
 
         widget->reference ();
         THROW_IF_FAIL (init_pty ());
+
+        THROW_IF_FAIL (a_ui_manager);
+        a_ui_manager->add_ui_from_file (a_menu_file_path);
+        a_ui_manager->insert_action_group (action_group);
+        menu = dynamic_cast<Gtk::Menu*>
+                (a_ui_manager->get_widget ("/TerminalMenu"));
+        THROW_IF_FAIL (menu);
+
+        g_signal_connect (vte,
+                          "button-press-event",
+                          G_CALLBACK (on_button_press_signal),
+                          &popup_user_data);
+    }
+
+    void init_actions ()
+    {
+        action_group = Gtk::ActionGroup::create ();
+        action_group->add (Gtk::Action::create
+                ("CopyAction",
+                 Gtk::Stock::COPY,
+                 "_Copy",
+                 _("Copy the selection")),
+                 sigc::mem_fun (*this,
+                                &Terminal::Priv::on_copy_signal));
+        action_group->add (Gtk::Action::create
+                ("PasteAction",
+                 Gtk::Stock::PASTE,
+                 "_Paste",
+                 _("Paste the clipboard")),
+                 sigc::mem_fun (*this,
+                                &Terminal::Priv::on_paste_signal));
+        action_group->add (Gtk::Action::create
+                ("ResetAction",
+                 Gtk::StockID (""),
+                 "_Reset",
+                 _("Reset the terminal")),
+                 sigc::mem_fun (*this,
+                                &Terminal::Priv::on_reset_signal));
+    }
+
+    void on_reset_signal ()
+    {
+        NEMIVER_TRY
+
+        reset ();
+
+        NEMIVER_CATCH
+    }
+
+    void on_copy_signal ()
+    {
+        NEMIVER_TRY
+
+        copy ();
+
+        NEMIVER_CATCH
+    }
+
+    void on_paste_signal ()
+    {
+        NEMIVER_TRY
+
+        paste ();
+
+        NEMIVER_CATCH
+    }
+
+    void reset ()
+    {
+        THROW_IF_FAIL (vte);
+        vte_terminal_reset (vte, true, true);
+    }
+
+    void copy ()
+    {
+        THROW_IF_FAIL (vte);
+        vte_terminal_copy_clipboard (vte);
+    }
+
+    void paste ()
+    {
+        THROW_IF_FAIL (vte);
+        vte_terminal_paste_clipboard (vte);
     }
 
     ~Priv ()
@@ -131,9 +277,10 @@ struct Terminal::Priv {
     }
 };//end Terminal::Priv
 
-Terminal::Terminal ()
+Terminal::Terminal (const string &a_menu_file_path,
+                    const Glib::RefPtr<Gtk::UIManager> &a_ui_manager)
 {
-    m_priv.reset (new Priv);
+    m_priv.reset (new Priv (a_menu_file_path, a_ui_manager));
 }
 
 Terminal::~Terminal ()
diff --git a/src/uicommon/nmv-terminal.h b/src/uicommon/nmv-terminal.h
index 137c19a..ca9fac5 100644
--- a/src/uicommon/nmv-terminal.h
+++ b/src/uicommon/nmv-terminal.h
@@ -30,14 +30,19 @@
 #include "common/nmv-env.h"
 #include "common/nmv-ustring.h"
 #include "common/nmv-object.h"
+#include <string>
+#include <glibmm/refptr.h>
 
 using nemiver::common::UString;
 using nemiver::common::Object;
 using nemiver::common::SafePtr;
 
+using std::string;
+
 namespace Gtk {
     class Widget;
     class Adjustment;
+    class UIManager;
 }
 
 namespace Pango {
@@ -56,7 +61,8 @@ class Terminal : public Object {
 
 public:
 
-    Terminal ();
+    Terminal (const string &a_menu_file_path,
+              const Glib::RefPtr<Gtk::UIManager> &a_ui_manager);
     ~Terminal ();
     Gtk::Widget& widget () const;
     Gtk::Adjustment& adjustment () const;



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