-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcbTerminalView_VTE.cpp
More file actions
134 lines (121 loc) · 4.38 KB
/
cbTerminalView_VTE.cpp
File metadata and controls
134 lines (121 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/***************************************************************
* Name: cbTerminalView
* Purpose: This class implements the panel that is added to
* Code::Blocks Message notebook or C::B layout.
* Author: Jerome ANTOINE
* Created: 2007-10-08
* Copyright: Jerome ANTOINE
* Copyright: Christo Joseph
* License: GPL
**************************************************************/
#include <wx/bitmap.h>
#include <wx/bmpbuttn.h>
#include <wx/display.h>
#include <wx/statline.h>
#ifndef CB_PRECOMP
#include <wx/combobox.h>
#include <wx/menu.h>
#include <wx/sizer.h>
#include <wx/splitter.h>
#include <wx/statbox.h>
#include <wx/stattext.h>
#include <wx/settings.h>
#include <wx/toolbar.h>
#endif
#include "cbTerminal.hpp"
#include "cbTerminalView.hpp"
#include "cbproject.h"
#include <wx/nativewin.h>
#include <vte/vte.h>
class VteNativeWindow : public wxNativeWindow
{
public:
VteNativeWindow(wxWindow* parent, wxWindowID winid, VteTerminal* vteTerminal) :
wxNativeWindow(parent, winid, GTK_WIDGET(vteTerminal))
, m_vteTerminal(vteTerminal)
{
g_signal_connect(GTK_WIDGET(vteTerminal), "button-press-event",
G_CALLBACK (handleButtonPressEvent), this);
}
private:
static gboolean handleButtonPressEvent(GtkWidget *widget,
GdkEventButton *event, VteNativeWindow *vteNativeWindow)
{
fprintf(stderr, "%s:%d event->button %d event->type %d\n", __FUNCTION__, __LINE__, event->button, event->type);
if (event->button == 3)
{
if (GTK_WIDGET_CLASS(VTE_TERMINAL_GET_CLASS(widget))->
button_press_event(widget, event))
{
abort();
return TRUE;
}
if (event->type == GDK_BUTTON_PRESS)
{
vteNativeWindow->OnRightMouseDown();
}
}
return FALSE;
}
void OnRightMouseDown()
{
wxPoint pos = ScreenToClient(wxGetMousePosition());
wxMenu menu;
menu.Append(wxID_COPY, "Copy\tc");
menu.Append(wxID_PASTE, "Paste\tp");
menu.Append(wxID_DEFAULT, "Goto project directory\tG");
menu.Bind(wxEVT_MENU, &VteNativeWindow::OnCopy, this, wxID_COPY);
menu.Bind(wxEVT_MENU, &VteNativeWindow::OnPaste, this, wxID_PASTE);
menu.Bind(wxEVT_MENU, &VteNativeWindow::OnGotoProjectDirectory, this, wxID_DEFAULT);
PopupMenu(&menu, pos);
}
void OnCopy(wxCommandEvent& event)
{
vte_terminal_copy_clipboard_format(m_vteTerminal, VTE_FORMAT_TEXT);
}
void OnPaste(wxCommandEvent& event)
{
vte_terminal_paste_clipboard(m_vteTerminal);
}
void OnGotoProjectDirectory(wxCommandEvent& event)
{
constexpr size_t commandMaxLen = FILENAME_MAX + 4;
char command[commandMaxLen];
strncpy(command, "cd ", commandMaxLen);
cbProject* pActiveProject = Manager::Get()->GetProjectManager()->GetActiveProject();
if (pActiveProject)
{
wxString topLevelPath = pActiveProject->GetCommonTopLevelPath();
strncpy(command + 3, topLevelPath.ToUTF8().data(), FILENAME_MAX);
}
size_t len = strlen(command);
command[len] = '\n';
len++;
vte_terminal_feed_child(m_vteTerminal,command, len);
}
VteTerminal *m_vteTerminal;
};
cbTerminalView::cbTerminalView(cbTerminal& terminalPlugin) :
wxPanel(Manager::Get()->GetAppWindow()),
m_cbTerminalPlugin(terminalPlugin)
{
VteTerminal* vteTerminal = VTE_TERMINAL(vte_terminal_new());
if (!vteTerminal)
{
fprintf(stderr, "Could not create VTE terminal\n");
return;
}
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
char* bash_args[] = { "/bin/bash", NULL }; //NOLINT
#if 0 //FIXME for async, codeblocks hangs on startup.
vte_terminal_spawn_async(m_vte, VTE_PTY_DEFAULT, NULL, bash_args, NULL,
(GSpawnFlags)0, NULL, NULL, NULL, -1, NULL, NULL, NULL);
#else
vte_terminal_spawn_sync(vteTerminal, VTE_PTY_DEFAULT, NULL, bash_args, NULL, //NOLINT
(GSpawnFlags)0, NULL, NULL, NULL, NULL, NULL );
#endif
wxNativeWindow* nativeWindow = new VteNativeWindow(this, wxID_ANY, vteTerminal);
sizer->Add(nativeWindow, 1, wxEXPAND);
SetSizer(sizer);
}
cbTerminalView::~cbTerminalView() = default;