aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+667e-11@users.noreply.github.com>2009-01-27 09:25:33 -0500
committerGravatar mitchell <70453897+667e-11@users.noreply.github.com>2009-01-27 09:25:33 -0500
commit569c79a5c7b36fc31c5850c9da8ca51fa340f8d6 (patch)
tree9496f7b237f9a2141acb140d8e931b287d4f38c1 /src
parent53ecaa8672d90dad389b1ce2828dec9ea50b4396 (diff)
Moved Lua Command Entry code into its own separate section like PM and Find.
Diffstat (limited to 'src')
-rw-r--r--src/textadept.c167
-rw-r--r--src/textadept.h1
2 files changed, 88 insertions, 80 deletions
diff --git a/src/textadept.c b/src/textadept.c
index ebc0d6d2..5411e2c1 100644
--- a/src/textadept.c
+++ b/src/textadept.c
@@ -15,17 +15,8 @@ char *textadept_home;
#endif
// Textadept
-GtkWidget *window, *focused_editor, *command_entry, *menubar, *statusbar,
- *docstatusbar;
-GtkEntryCompletion *command_entry_completion;
-GtkTreeStore *cec_store;
+GtkWidget *window, *focused_editor, *menubar, *statusbar, *docstatusbar;
-static void c_activated(GtkWidget *widget, gpointer);
-static gbool c_keypress(GtkWidget *widget, GdkEventKey *event, gpointer);
-static int cec_match_func(GtkEntryCompletion *, const char *, GtkTreeIter *,
- gpointer);
-static gbool cec_match_selected(GtkEntryCompletion *, GtkTreeModel *model,
- GtkTreeIter *iter, gpointer);
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);
@@ -68,6 +59,18 @@ GtkAttachOptions
static void button_clicked(GtkWidget *button, gpointer);
+// Command Entry
+GtkWidget *command_entry;
+GtkTreeStore *cec_store;
+GtkEntryCompletion *command_entry_completion;
+
+static void c_activated(GtkWidget *widget, gpointer);
+static gbool c_keypress(GtkWidget *widget, GdkEventKey *event, gpointer);
+static int cec_match_func(GtkEntryCompletion *, const char *, GtkTreeIter *,
+ gpointer);
+static gbool cec_match_selected(GtkEntryCompletion *, GtkTreeModel *model,
+ GtkTreeIter *iter, gpointer);
+
/**
* Runs Textadept in Linux or Mac.
* Inits the Lua State, creates the user interface, and loads the core/init.lua
@@ -440,75 +443,6 @@ void ce_toggle_focus() {
// Notifications/signals
/**
- * Signal for the 'enter' key being pressed in the Lua command entry.
- * Evaluates the input text as Lua code.
- */
-static void c_activated(GtkWidget *widget, gpointer) {
- l_ta_command(gtk_entry_get_text(GTK_ENTRY(widget)));
- ce_toggle_focus();
-}
-
-/**
- * Signal for a keypress inside the Lua command entry.
- * Currently handled keypresses:
- * - Escape - Hide the completion buffer if it is open.
- * - Tab - Display possible completions.
- */
-static gbool c_keypress(GtkWidget *widget, GdkEventKey *event, gpointer) {
- if (event->state == 0)
- switch(event->keyval) {
- case 0xff1b:
- ce_toggle_focus();
- return TRUE;
- case 0xff09:
- if (l_cec_get_completions_for(gtk_entry_get_text(GTK_ENTRY(widget)))) {
- l_cec_populate();
- gtk_entry_completion_complete(command_entry_completion);
- }
- return TRUE;
- }
- return FALSE;
-}
-
-/**
- * Sets every item in the Command Entry Model to be a match.
- * For each attempted completion, the Command Entry Model is filled with the
- * results from a call to Lua to make a list of possible completions. Therefore,
- * every item in the list is valid.
- */
-static int cec_match_func(GtkEntryCompletion*, const char*, GtkTreeIter*,
- gpointer) {
- return 1;
-}
-
-/**
- * Enters the requested completion text into the Command Entry.
- * The last word at the cursor is replaced with the completion. A word consists
- * of any alphanumeric character or underscore.
- */
-static gbool cec_match_selected(GtkEntryCompletion*, GtkTreeModel *model,
- GtkTreeIter *iter, gpointer) {
- const char *entry_text = gtk_entry_get_text(GTK_ENTRY(command_entry));
- const char *p = entry_text + strlen(entry_text) - 1;
- while ((*p >= 'A' && *p <= 'Z') || (*p >= 'a' && *p <= 'z') ||
- (*p >= '0' && *p <= '9') || *p == '_') {
- g_signal_emit_by_name(G_OBJECT(command_entry), "move-cursor",
- GTK_MOVEMENT_VISUAL_POSITIONS, -1, TRUE, 0);
- p--;
- }
- if (p < entry_text + strlen(entry_text) - 1)
- g_signal_emit_by_name(G_OBJECT(command_entry), "backspace", 0);
-
- char *text;
- gtk_tree_model_get(model, iter, 0, &text, -1);
- g_signal_emit_by_name(G_OBJECT(command_entry), "insert-at-cursor", text, 0);
- g_free(text);
-
- gtk_tree_store_clear(cec_store);
- return TRUE;
-}
-
-/**
* Helper function for switching the focused view to the given one.
* @param editor The Scintilla window to focus.
* @see t_notification
@@ -986,6 +920,8 @@ void find_toggle_focus() {
}
}
+// Signals
+
/**
* Signal for a button click.
* Performs the appropriate action depending on the button clicked.
@@ -1000,3 +936,76 @@ static void button_clicked(GtkWidget *button, gpointer) {
l_find(find_text, true);
} else l_find(find_text, button == fnext_button);
}
+
+// Command Entry
+
+// Signals
+
+/**
+ * Signal for the 'enter' key being pressed in the Lua command entry.
+ * Evaluates the input text as Lua code.
+ */
+static void c_activated(GtkWidget *widget, gpointer) {
+ l_ta_command(gtk_entry_get_text(GTK_ENTRY(widget)));
+ ce_toggle_focus();
+}
+
+/**
+ * Signal for a keypress inside the Lua command entry.
+ * Currently handled keypresses:
+ * - Escape - Hide the completion buffer if it is open.
+ * - Tab - Display possible completions.
+ */
+static gbool c_keypress(GtkWidget *widget, GdkEventKey *event, gpointer) {
+ if (event->state == 0)
+ switch(event->keyval) {
+ case 0xff1b:
+ ce_toggle_focus();
+ return TRUE;
+ case 0xff09:
+ if (l_cec_get_completions_for(gtk_entry_get_text(GTK_ENTRY(widget)))) {
+ l_cec_populate();
+ gtk_entry_completion_complete(command_entry_completion);
+ }
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/**
+ * Sets every item in the Command Entry Model to be a match.
+ * For each attempted completion, the Command Entry Model is filled with the
+ * results from a call to Lua to make a list of possible completions. Therefore,
+ * every item in the list is valid.
+ */
+static int cec_match_func(GtkEntryCompletion*, const char*, GtkTreeIter*,
+ gpointer) {
+ return 1;
+}
+
+/**
+ * Enters the requested completion text into the Command Entry.
+ * The last word at the cursor is replaced with the completion. A word consists
+ * of any alphanumeric character or underscore.
+ */
+static gbool cec_match_selected(GtkEntryCompletion*, GtkTreeModel *model,
+ GtkTreeIter *iter, gpointer) {
+ const char *entry_text = gtk_entry_get_text(GTK_ENTRY(command_entry));
+ const char *p = entry_text + strlen(entry_text) - 1;
+ while ((*p >= 'A' && *p <= 'Z') || (*p >= 'a' && *p <= 'z') ||
+ (*p >= '0' && *p <= '9') || *p == '_') {
+ g_signal_emit_by_name(G_OBJECT(command_entry), "move-cursor",
+ GTK_MOVEMENT_VISUAL_POSITIONS, -1, TRUE, 0);
+ p--;
+ }
+ if (p < entry_text + strlen(entry_text) - 1)
+ g_signal_emit_by_name(G_OBJECT(command_entry), "backspace", 0);
+
+ char *text;
+ gtk_tree_model_get(model, iter, 0, &text, -1);
+ g_signal_emit_by_name(G_OBJECT(command_entry), "insert-at-cursor", text, 0);
+ g_free(text);
+
+ gtk_tree_store_clear(cec_store);
+ return TRUE;
+}
diff --git a/src/textadept.h b/src/textadept.h
index f991cc77..0f0f60e8 100644
--- a/src/textadept.h
+++ b/src/textadept.h
@@ -34,7 +34,6 @@ extern GtkWidget *window, *focused_editor, *command_entry, *pm_container,
*pm_entry, *pm_view, *findbox, *find_entry, *replace_entry,
*fnext_button, *fprev_button, *r_button, *ra_button,
*match_case_opt, *whole_word_opt, *lua_opt, *in_files_opt;
-extern GtkEntryCompletion *command_entry_completion;
extern GtkTreeStore *cec_store, *pm_store;
extern lua_State *lua;
#if !(WIN32 || MAC)