Skip to content

Commit

Permalink
577496 561100 533437 656093 564992 Support Copy/Paste/Reset on target…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
Fabo committed Aug 29, 2011
1 parent 32c2e94 commit 0725677
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/persp/dbgperspective/menus/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions src/persp/dbgperspective/menus/terminalmenu.xml
Original file line number Diff line number Diff line change
@@ -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>

9 changes: 8 additions & 1 deletion src/persp/dbgperspective/nmv-dbg-perspective.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7950,7 +7950,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;
Expand Down
155 changes: 151 additions & 4 deletions src/uicommon/nmv-terminal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -57,13 +104,29 @@ struct Terminal::Priv {
//m_vte, but wrapped as a Gtk::Widget
Gtk::Widget *widget;
Glib::RefPtr<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);
Expand All @@ -86,6 +149,89 @@ struct Terminal::Priv {
adjustment->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 ()
Expand Down Expand Up @@ -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 ()
Expand Down
8 changes: 7 additions & 1 deletion src/uicommon/nmv-terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Glib::RefPtr<Gtk::Adjustment> adjustment () const;
Expand Down

0 comments on commit 0725677

Please sign in to comment.