aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lua_interface.c20
-rw-r--r--src/textadept.c14
-rw-r--r--src/textadept.h1
3 files changed, 35 insertions, 0 deletions
diff --git a/src/lua_interface.c b/src/lua_interface.c
index b6739c15..369fd90d 100644
--- a/src/lua_interface.c
+++ b/src/lua_interface.c
@@ -748,6 +748,26 @@ void l_handle_scnnotification(SCNotification *n) {
}
/**
+ * Requests and pops up a context menu for the Scintilla view.
+ * @param event The mouse button event.
+ */
+void l_ta_popup_context_menu(GdkEventButton *event) {
+ lua_getglobal(lua, "textadept");
+ if (lua_istable(lua, -1)) {
+ lua_getfield(lua, -1, "context_menu");
+ if (lua_isuserdata(lua, -1)) {
+ GtkWidget *menu = l_togtkwidget(lua, -1);
+ gtk_widget_show_all(menu);
+ gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
+ event ? event->button : 0,
+ gdk_event_get_time(reinterpret_cast<GdkEvent*>(event)));
+ } else if (!lua_isnil(lua, -1))
+ warn("textadept.context_menu is not a gtkmenu.");
+ lua_pop(lua, 1); // textadept.context_menu
+ } else lua_pop(lua, 1);
+}
+
+/**
* Executes a given command string as Lua code.
* @param command Lua code to execute.
*/
diff --git a/src/textadept.c b/src/textadept.c
index ee2f4da6..2b0a17d0 100644
--- a/src/textadept.c
+++ b/src/textadept.c
@@ -20,6 +20,7 @@ GtkWidget *window, *focused_editor, *menubar, *statusbar, *docstatusbar;
static void t_notification(GtkWidget*, gint, gpointer lParam, gpointer);
static void t_command(GtkWidget *editor, gint wParam, gpointer, gpointer);
static gbool t_keypress(GtkWidget*, GdkEventKey *event, gpointer);
+static gbool t_buttonpress(GtkWidget*, GdkEventButton *event, gpointer);
static gbool w_focus(GtkWidget*, GdkEventFocus *, gpointer);
static gbool w_keypress(GtkWidget*, GdkEventKey *event, gpointer);
static gbool w_exit(GtkWidget*, GdkEventAny*, gpointer);
@@ -243,7 +244,9 @@ void create_ui() {
GtkWidget *new_scintilla_window(sptr_t buffer_id) {
GtkWidget *editor = scintilla_new();
gtk_widget_set_size_request(editor, 1, 1); // minimum size
+ SS(SCINTILLA(editor), SCI_USEPOPUP, 0, 0);
signal(editor, "key_press_event", t_keypress);
+ signal(editor, "button_press_event", t_buttonpress);
signal(editor, "command", t_command);
signal(editor, SCINTILLA_NOTIFY, t_notification);
l_add_scintilla_window(editor);
@@ -491,6 +494,17 @@ static gbool t_keypress(GtkWidget*, GdkEventKey *event, gpointer) {
}
/**
+ * Signal for a Scintilla mouse click.
+ * If it is a right-click, popup a context menu.
+ * @see l_ta_popup_context_menu
+ */
+static gbool t_buttonpress(GtkWidget*, GdkEventButton *event, gpointer) {
+ if (event->type != GDK_BUTTON_PRESS || event->button != 3) return FALSE;
+ l_ta_popup_context_menu(event);
+ return TRUE;
+}
+
+/**
* Signal for a Textadept window focus change.
*/
static gbool w_focus(GtkWidget*, GdkEventFocus*, gpointer) {
diff --git a/src/textadept.h b/src/textadept.h
index 303c3ddf..f017ad82 100644
--- a/src/textadept.h
+++ b/src/textadept.h
@@ -88,6 +88,7 @@ bool l_handle_event(const char *e, const char *arg=NULL);
bool l_handle_keypress(int keyval, bool shift, bool control, bool alt);
void l_handle_scnnotification(SCNotification *n);
void l_ta_command(const char *command);
+void l_ta_popup_context_menu(GdkEventButton *event);
bool l_cec_get_completions_for(const char *entry_text);
void l_cec_populate(GtkListStore *store);