aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+667e-11@users.noreply.github.com>2009-02-15 14:46:45 -0500
committerGravatar mitchell <70453897+667e-11@users.noreply.github.com>2009-02-15 14:46:45 -0500
commit98f1c9b84bcc7ad535dbabe2c2c270c43e9eeb7d (patch)
treeadbb55de6e4887bf9da1bf484f347a40aba6ddf4
parent86ef9ed4b1b74970c85c0fd319ba0dc8eb0b2b8d (diff)
Minor refactoring, more encapsulation, and code cleanup.
-rw-r--r--src/lua_interface.c118
-rw-r--r--src/textadept.c213
-rw-r--r--src/textadept.h22
3 files changed, 158 insertions, 195 deletions
diff --git a/src/lua_interface.c b/src/lua_interface.c
index 97b59c14..29d22e54 100644
--- a/src/lua_interface.c
+++ b/src/lua_interface.c
@@ -160,6 +160,7 @@ bool l_init(int argc, char **argv, bool reinit) {
lua_pop(lua, 1); // textadept
return true;
}
+ lua_close(lua);
return false;
}
@@ -527,7 +528,7 @@ bool l_call_function(int nargs, int retn=0, bool keep_return=false) {
bool result = (retn > 0) ? lua_toboolean(lua, -1) == 1 : true;
if (retn > 0 && !keep_return) lua_pop(lua, retn); // retn
return result;
- } else l_handle_error(lua, NULL);
+ } else l_handle_error(NULL);
return false;
}
@@ -602,7 +603,7 @@ GtkWidget *l_create_gtkmenu(lua_State *lua, GCallback callback, bool submenu) {
reinterpret_cast<gpointer>(menu_id));
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
}
- } else warn("gtkmenu: { 'menu label', id_number } expected.");
+ } else warn("gtkmenu: { 'menu label', id_number } expected");
}
lua_pop(lua, 1); // value
}
@@ -654,7 +655,7 @@ static void l_check_focused_buffer(lua_State *lua, int narg) {
* @param lua The Lua State.
* @param extramsg An additional error message to display.
*/
-void l_handle_error(lua_State *lua, const char *extramsg) {
+void l_handle_error(const char *extramsg) {
if (focused_editor && l_ista2function("events", "error")) {
l_insert(lua, -1); // shift error message down
if (extramsg) lua_pushstring(lua, extramsg);
@@ -762,7 +763,7 @@ void l_ta_popup_context_menu(GdkEventButton *event) {
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.");
+ warn("textadept.context_menu: gtkmenu expected");
lua_pop(lua, 1); // textadept.context_menu
} else lua_pop(lua, 1);
}
@@ -774,10 +775,11 @@ void l_ta_popup_context_menu(GdkEventButton *event) {
* treeview path.
* The first table item is the PM Entry text, the next items are parents of the
* given node in descending order, and the last item is the given node itself.
+ * @param store The GtkTreeStore of the PM view.
* @param path The GtkTreePath of the node. If NULL, only the PM Entry text is
* contained in the resulting table.
*/
-void l_pushpathtable(GtkTreePath *path) {
+void l_pushpathtable(GtkTreeStore *store, GtkTreePath *path) {
lua_newtable(lua);
lua_pushstring(lua, gtk_entry_get_text(GTK_ENTRY(pm_entry)));
lua_rawseti(lua, -2, 1);
@@ -785,8 +787,8 @@ void l_pushpathtable(GtkTreePath *path) {
GtkTreeIter iter;
while (gtk_tree_path_get_depth(path) > 0) {
char *item = 0;
- gtk_tree_model_get_iter(GTK_TREE_MODEL(pm_store), &iter, path);
- gtk_tree_model_get(GTK_TREE_MODEL(pm_store), &iter, 1, &item, -1);
+ gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path);
+ gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 1, &item, -1);
lua_pushstring(lua, item);
lua_rawseti(lua, -2, gtk_tree_path_get_depth(path) + 1);
g_free(item);
@@ -796,49 +798,50 @@ void l_pushpathtable(GtkTreePath *path) {
/**
* Requests and adds contents to the Project Manager view.
+ * @param store The GtkTreeStore of the PM view.
* @param initial_iter An initial GtkTreeIter. If NULL, contents will be added
* to the treeview root. Otherwise they will be added to this parent node.
*/
-void l_pm_view_fill(GtkTreeIter *initial_iter) {
+void l_pm_view_fill(GtkTreeStore *store, GtkTreeIter *initial_iter) {
if (!l_ista2function("pm", "get_contents_for")) return;
if (initial_iter) {
GtkTreePath *path =
- gtk_tree_model_get_path(GTK_TREE_MODEL(pm_store), initial_iter);
- l_pushpathtable(path);
+ gtk_tree_model_get_path(GTK_TREE_MODEL(store), initial_iter);
+ l_pushpathtable(store, path);
gtk_tree_path_free(path);
- } else l_pushpathtable(NULL);
+ } else l_pushpathtable(store, NULL);
lua_pushboolean(lua, initial_iter != NULL);
l_call_function(2, 1, true);
if (!lua_istable(lua, -1)) {
- if (!lua_isnil(lua, -1)) warn("pm.get_contents_for: return not a table.");
+ if (!lua_isnil(lua, -1)) warn("pm.get_contents_for: table expected");
lua_pop(lua, 1); // non-table return
return;
}
- GtkTreeIter iter, child;
- if (!initial_iter) gtk_tree_store_clear(pm_store);
+ if (!initial_iter) gtk_tree_store_clear(store);
lua_pushnil(lua);
while (lua_next(lua, -2)) {
if (lua_istable(lua, -1) && lua_type(lua, -2) == LUA_TSTRING) {
- gtk_tree_store_append(pm_store, &iter, initial_iter);
- gtk_tree_store_set(pm_store, &iter, 1, lua_tostring(lua, -2), -1);
+ GtkTreeIter iter, child;
+ gtk_tree_store_append(store, &iter, initial_iter);
+ gtk_tree_store_set(store, &iter, 1, lua_tostring(lua, -2), -1);
lua_getfield(lua, -1, "parent");
if (lua_toboolean(lua, -1)) {
- gtk_tree_store_append(pm_store, &child, &iter);
- gtk_tree_store_set(pm_store, &child, 1, "\0dummy", -1);
+ gtk_tree_store_append(store, &child, &iter);
+ gtk_tree_store_set(store, &child, 1, "\0dummy", -1);
}
lua_pop(lua, 1); // parent
lua_getfield(lua, -1, "pixbuf");
if (lua_isstring(lua, -1))
- gtk_tree_store_set(pm_store, &iter, 0, lua_tostring(lua, -1), -1);
+ gtk_tree_store_set(store, &iter, 0, lua_tostring(lua, -1), -1);
else if (!lua_isnil(lua, -1))
- warn("pm.populate: pixbuf key must have string value.");
+ warn("pm.fill: non-string pixbuf key ignored");
lua_pop(lua, 1); // pixbuf
lua_getfield(lua, -1, "text");
- gtk_tree_store_set(pm_store, &iter, 2, lua_isstring(lua, -1) ?
+ gtk_tree_store_set(store, &iter, 2, lua_isstring(lua, -1) ?
lua_tostring(lua, -1) : lua_tostring(lua, -3), -1);
lua_pop(lua, 1); // display text
- } else warn("pm.populate: string id key must have table value.");
+ } else warn("pm.fill: string id key must have table value");
lua_pop(lua, 1); // value
}
lua_pop(lua, 1); // returned table
@@ -848,14 +851,15 @@ void l_pm_view_fill(GtkTreeIter *initial_iter) {
/**
* Requests and pops up a context menu for a selected Project Manager item.
+ * @param store The GtkTreeStore of the PM view.
* @param path The GtkTreePath of the item.
* @param event The mouse button event.
* @param callback The GCallback associated with each menu item.
*/
-void l_pm_popup_context_menu(GtkTreePath *path, GdkEventButton *event,
- GCallback callback) {
+void l_pm_popup_context_menu(GtkTreeStore *store, GtkTreePath *path,
+ GdkEventButton *event, GCallback callback) {
if (!l_ista2function("pm", "get_context_menu")) return;
- l_pushpathtable(path);
+ l_pushpathtable(store, path);
l_call_function(1, 1, true);
if (lua_istable(lua, -1)) {
GtkWidget *menu = l_create_gtkmenu(lua, callback, false);
@@ -863,29 +867,31 @@ void l_pm_popup_context_menu(GtkTreePath *path, GdkEventButton *event,
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
event ? event->button : 0,
gdk_event_get_time(reinterpret_cast<GdkEvent*>(event)));
- } else warn("pm.get_context_menu: return was not a table.");
+ } else warn("pm.get_context_menu: table expected");
lua_pop(lua, 1); // returned value
}
/**
* Performs an action for the selected Project Manager item.
+ * @param store The GtkTreeStore of the PM view.
* @param path The GtkTreePath of the item.
*/
-void l_pm_perform_action(GtkTreePath *path) {
+void l_pm_perform_action(GtkTreeStore *store, GtkTreePath *path) {
if (!l_ista2function("pm", "perform_action")) return;
- l_pushpathtable(path);
+ l_pushpathtable(store, path);
l_call_function(1);
}
/**
* Performs a selected menu action from a Project Manager item's context menu.
+ * @param store The GtkTreeStore of the PM view.
* @param path The GtkTreePath of the item.
- * @param menu_id The numeric ID for the menu item.
+ * @param id The numeric ID for the menu item.
*/
-void l_pm_perform_menu_action(GtkTreePath *path, int menu_id) {
+void l_pm_perform_menu_action(GtkTreeStore *store, GtkTreePath *path, int id) {
if (!l_ista2function("pm", "perform_menu_action")) return;
- lua_pushnumber(lua, menu_id);
- l_pushpathtable(path);
+ lua_pushnumber(lua, id);
+ l_pushpathtable(store, path);
l_call_function(2);
}
@@ -937,37 +943,31 @@ void l_ce_command(const char *command) {
if (luaL_dostring(lua, command) == 0) {
l_handle_event("update_ui");
lua_settop(lua, top);
- } else l_handle_error(lua, "Error executing command.");
-}
-
-/**
- * Requests completions for the Command Entry Completion.
- * @param entry_text The text in the Command Entry.
- * @see l_cec_populate
- */
-bool l_cec_get_completions_for(const char *entry_text) {
- if (!l_ista2function("command_entry", "get_completions_for")) return false;
- lua_pushstring(lua, entry_text);
- return l_call_function(1, 1, true);
+ } else l_handle_error("Error executing command");
}
/**
- * Populates the Command Entry Completion with the contents of a Lua table at
- * the stack top.
+ * Requests and adds completions for the Command Entry Completion.
* @param store The GtkListStore to populate.
- * @see l_cec_get_completions_for
*/
-void l_cec_populate(GtkListStore *store) {
- GtkTreeIter iter;
- if (!lua_istable(lua, -1))
- return warn("command_entry.get_completions_for return not a table.");
+void l_cec_fill(GtkListStore *store) {
+ if (!l_ista2function("command_entry", "get_completions_for")) return;
+ lua_pushstring(lua, gtk_entry_get_text(GTK_ENTRY(command_entry)));
+ l_call_function(1, 1, true);
+ if (!lua_istable(lua, -1)) {
+ if (!lua_isnil(lua, -1)) warn("ce.get_completions_for: table expected");
+ lua_pop(lua, 1); // non-table return
+ return;
+ }
+
gtk_list_store_clear(store);
lua_pushnil(lua);
while (lua_next(lua, -2)) {
if (lua_type(lua, -1) == LUA_TSTRING) {
+ GtkTreeIter iter;
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, lua_tostring(lua, -1), -1);
- } else warn("command_entry.get_completions_for: string value expected.");
+ } else warn("ce.get_completions_for: non-string value ignored");
lua_pop(lua, 1); // value
}
lua_pop(lua, 1); // returned table
@@ -1117,8 +1117,8 @@ static int l_bufferp_mt_(lua_State *lua, int n, const char *prop, int arg) {
p1_type = p2_type;
p2_type = temp;
}
- luaL_argcheck(lua, msg != 0, arg, (n == 1) ? "write-only property"
- : "read-only property");
+ luaL_argcheck(lua, msg != 0, arg,
+ (n == 1) ? "write-only property" : "read-only property");
return l_call_scintilla(lua, sci, msg, p1_type, p2_type, rt_type, arg);
} else lua_pop(lua, 1); // non-table
@@ -1377,6 +1377,7 @@ static int l_cf_buffer_text_range(lua_State *lua) {
static int l_cf_view_focus(lua_State *lua) {
GtkWidget *editor = l_checkview(lua, 1);
+ // editor might be an old reference; GTK_IS_WIDGET checks for a valid widget
if (GTK_IS_WIDGET(editor)) gtk_widget_grab_focus(editor);
return 0;
}
@@ -1461,10 +1462,10 @@ static int l_cf_view_goto_buffer(lua_State *lua) {
return 0;
}
-static void t_menu_activate(GtkWidget *, gpointer menu_id) {
- int id = GPOINTER_TO_INT(menu_id);
+static void t_menu_activate(GtkWidget *, gpointer id) {
+ int menu_id = GPOINTER_TO_INT(id);
char *menu_id_str = static_cast<char*>(malloc(sizeof(char) * 12));
- sprintf(menu_id_str, "%i", id);
+ sprintf(menu_id_str, "%i", menu_id);
l_handle_event("menu_clicked", menu_id_str);
g_free(menu_id_str);
}
@@ -1504,7 +1505,8 @@ static int l_cf_pm_focus(lua_State *) {
}
static int l_cf_pm_clear(lua_State *) {
- gtk_tree_store_clear(pm_store);
+ gtk_tree_store_clear(
+ GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(pm_view))));
return 0;
}
diff --git a/src/textadept.c b/src/textadept.c
index a53cc48f..1edef15f 100644
--- a/src/textadept.c
+++ b/src/textadept.c
@@ -7,6 +7,8 @@
#ifdef MAC
#include "ige-mac-menu.h"
+#define CFURL_TO_STR(u) \
+ CFStringGetCStringPtr(CFURLCopyFileSystemPath(u, kCFURLPOSIXPathStyle), 0)
using namespace Scintilla;
#endif
@@ -27,11 +29,11 @@ static gbool w_exit(GtkWidget *, GdkEventAny *, gpointer);
#ifdef MAC
static OSErr w_ae_open(const AppleEvent *event, AppleEvent *, long);
static OSErr w_ae_quit(const AppleEvent *event, AppleEvent *, long);
-void cfurlref_to_char(CFURLRef url, char *path, int len);
#endif
// Project Manager
GtkWidget *pm_view, *pm_entry, *pm_container;
+GtkWidget *pm_create_ui();
GtkTreeStore *pm_store;
static int pm_search_equal_func(GtkTreeModel *model, int col, const char *key,
@@ -45,39 +47,37 @@ static void pm_row_expanded(GtkTreeView *, GtkTreeIter *iter, GtkTreePath *,
gpointer);
static void pm_row_collapsed(GtkTreeView *, GtkTreeIter *iter, GtkTreePath *,
gpointer);
-static void pm_row_activated(GtkTreeView *, GtkTreePath *path,
+static void pm_row_activated(GtkTreeView *view, GtkTreePath *path,
GtkTreeViewColumn *, gpointer);
-static gbool pm_button_press(GtkTreeView *, GdkEventButton *event, gpointer);
+static gbool pm_buttonpress(GtkTreeView *, GdkEventButton *event, gpointer);
static gbool pm_popup_menu(GtkWidget *, gpointer);
-static void pm_menu_activate(GtkWidget *, gpointer menu_id);
+static void pm_menu_activate(GtkWidget *, gpointer id);
// Find/Replace
GtkWidget *findbox, *find_entry, *replace_entry, *fnext_button, *fprev_button,
*r_button, *ra_button, *match_case_opt, *whole_word_opt, *lua_opt,
*in_files_opt;
+GtkWidget *find_create_ui();
GtkListStore *find_store, *repl_store;
-GtkAttachOptions
- ao_normal = static_cast<GtkAttachOptions>(GTK_SHRINK | GTK_FILL),
- ao_expand = static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL);
-static void button_clicked(GtkWidget *button, gpointer);
+static void find_button_clicked(GtkWidget *button, gpointer);
// Command Entry
GtkWidget *command_entry;
GtkListStore *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);
+static void c_activated(GtkWidget *widget, gpointer);
+static gbool c_keypress(GtkWidget *, GdkEventKey *event, gpointer);
/**
* Runs Textadept in Linux or Mac.
- * Inits the Lua State, creates the user interface, and loads the core/init.lua
- * script.
+ * Inits the Lua State, creates the user interface, loads the core/init.lua
+ * script, and also loads init.lua.
* @param argc The number of command line params.
* @param argv The array of command line params.
*/
@@ -85,13 +85,9 @@ int main(int argc, char **argv) {
#ifdef MAC
CFBundleRef bundle = CFBundleGetMainBundle();
if (bundle) {
- char *bundle_path = static_cast<char*>(malloc(FILENAME_MAX * sizeof(char)));
- CFURLRef bundle_url = CFBundleCopyBundleURL(bundle);
- cfurlref_to_char(bundle_url, bundle_path, FILENAME_MAX);
+ const char *bundle_path = CFURL_TO_STR(CFBundleCopyBundleURL(bundle));
char *res_path = g_strconcat(bundle_path, "/Contents/Resources/", NULL);
textadept_home = static_cast<char*>(res_path);
- g_free(bundle_path);
- CFRelease(bundle_url);
} else textadept_home = "";
// GTK-OSX does not parse ~/.gtkrc-2.0; parse it manually
char *user_home = g_strconcat(getenv("HOME"), "/.gtkrc-2.0", NULL);
@@ -99,13 +95,11 @@ int main(int argc, char **argv) {
g_free(user_home);
#endif
gtk_init(&argc, &argv);
- if (l_init(argc, argv, false)) {
- create_ui();
- l_load_script("init.lua");
- gtk_main();
- return 0;
- } else if (lua) lua_close(lua);
- return 1;
+ if (!l_init(argc, argv, false)) return 1;
+ create_ui();
+ l_load_script("init.lua");
+ gtk_main();
+ return 0;
}
#ifdef WIN32
@@ -139,27 +133,24 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int) {
* - Two status bars: one for notifications, the other for document status.
*/
void create_ui() {
- GList *icons = NULL;
- const char *icon_files[] = {
- "ta_16x16.png", "ta_32x32.png", "ta_48x48.png", "ta_64x64.png",
- "ta_128x128.png"
- };
+ GList *icon_list = NULL;
+ const char *icons[] = { "16x16", "32x32", "48x48", "64x64", "128x128" };
for (int i = 0; i < 5; i++) {
char *icon_file =
- g_strconcat(textadept_home, "/core/images/", icon_files[i], NULL);
+ g_strconcat(textadept_home, "/core/images/ta_", icons[i], ".png", NULL);
GdkPixbuf *pb = gdk_pixbuf_new_from_file(icon_file, NULL);
- if (pb) icons = g_list_prepend(icons, pb);
+ if (pb) icon_list = g_list_prepend(icon_list, pb);
g_free(icon_file);
}
- gtk_window_set_default_icon_list(icons);
- g_list_foreach(icons, reinterpret_cast<GFunc>(g_object_unref), NULL);
- g_list_free(icons);
+ gtk_window_set_default_icon_list(icon_list);
+ g_list_foreach(icon_list, reinterpret_cast<GFunc>(g_object_unref), NULL);
+ g_list_free(icon_list);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 500, 400);
- signal(window, "delete_event", w_exit);
+ signal(window, "delete-event", w_exit);
signal(window, "focus-in-event", w_focus);
- signal(window, "key_press_event", w_keypress);
+ signal(window, "key-press-event", w_keypress);
#ifdef MAC
AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
@@ -200,7 +191,7 @@ void create_ui() {
command_entry = gtk_entry_new();
gtk_widget_set_name(command_entry, "textadept-command-entry");
signal(command_entry, "activate", c_activated);
- signal(command_entry, "key_press_event", c_keypress);
+ signal(command_entry, "key-press-event", c_keypress);
g_object_set(G_OBJECT(command_entry), "width-request", 200, NULL);
gtk_box_pack_start(GTK_BOX(hboxs), command_entry, TRUE, TRUE, 0);
@@ -247,8 +238,8 @@ GtkWidget *new_scintilla_window(sptr_t buffer_id) {
SS(SCINTILLA(editor), SCI_USEPOPUP, 0, 0);
signal(editor, SCINTILLA_NOTIFY, s_notification);
signal(editor, "command", s_command);
- signal(editor, "key_press_event", s_keypress);
- signal(editor, "button_press_event", s_buttonpress);
+ signal(editor, "key-press-event", s_keypress);
+ signal(editor, "button-press-event", s_buttonpress);
l_add_scintilla_window(editor);
gtk_widget_grab_focus(editor);
focused_editor = editor;
@@ -421,7 +412,7 @@ void set_menubar(GtkWidget *new_menubar) {
*/
void set_statusbar_text(const char *text, bool docbar) {
GtkWidget *bar = docbar ? docstatusbar : statusbar;
- if (!bar) return;
+ if (!bar) return; // this is sometimes called before a bar is available
gtk_statusbar_pop(GTK_STATUSBAR(bar), 0);
gtk_statusbar_push(GTK_STATUSBAR(bar), 0, text);
}
@@ -536,16 +527,13 @@ static OSErr w_ae_open(const AppleEvent *event, AppleEvent *, long) {
AECountItems(&file_list, &count);
for (int i = 1; i <= count; i++) {
FSRef fsref;
- char *path = static_cast<char*>(malloc(FILENAME_MAX * sizeof(char)));
AEGetNthPtr(&file_list, i, typeFSRef, NULL, NULL, &fsref, sizeof(FSRef),
NULL);
CFURLRef url = CFURLCreateFromFSRef(kCFAllocatorDefault, &fsref);
if (url) {
- cfurlref_to_char(url, path, FILENAME_MAX);
- l_handle_event("appleevent_odoc", path);
+ l_handle_event("appleevent_odoc", CFURL_TO_STR(url));
CFRelease(url);
}
- g_free(path);
}
AEDisposeDesc(&file_list);
}
@@ -560,17 +548,6 @@ static OSErr w_ae_open(const AppleEvent *event, AppleEvent *, long) {
static OSErr w_ae_quit(const AppleEvent *event, AppleEvent *, long) {
return w_exit(NULL, NULL, NULL) ? (OSErr) noErr : errAEEventNotHandled;
}
-
-/**
- * Helper function to convert an Apple CFURLRef to a char*.
- * @param url The CFURLRef for a file URL.
- * @return char* containing the filepath in POSIX style.
- */
-void cfurlref_to_char(CFURLRef url, char *path, int len) {
- CFStringRef str = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
- CFStringGetCString(str, path, len, kCFStringEncodingASCII);
- CFRelease(str);
-}
#endif
// Project Manager
@@ -623,12 +600,12 @@ GtkWidget *pm_create_ui() {
signal(pm_entry, "activate", pm_entry_activated);
signal(pm_combo, "changed", pm_entry_changed);
- signal(pm_entry, "key_press_event", pm_keypress);
- signal(pm_view, "key_press_event", pm_keypress);
- signal(pm_view, "row_expanded", pm_row_expanded);
- signal(pm_view, "row_collapsed", pm_row_collapsed);
- signal(pm_view, "row_activated", pm_row_activated);
- signal(pm_view, "button_press_event", pm_button_press);
+ signal(pm_entry, "key-press-event", pm_keypress);
+ signal(pm_view, "key-press-event", pm_keypress);
+ signal(pm_view, "row-expanded", pm_row_expanded);
+ signal(pm_view, "row-collapsed", pm_row_collapsed);
+ signal(pm_view, "row-activated", pm_row_activated);
+ signal(pm_view, "button-press-event", pm_buttonpress);
signal(pm_view, "popup-menu", pm_popup_menu);
return pm_container;
@@ -687,7 +664,7 @@ static int pm_sort_iter_compare_func(GtkTreeModel *model, GtkTreeIter *a,
* @see l_pm_view_fill
*/
static void pm_entry_activated(GtkWidget *, gpointer) {
- l_pm_view_fill(NULL);
+ l_pm_view_fill(pm_store, NULL);
}
/**
@@ -696,18 +673,16 @@ static void pm_entry_activated(GtkWidget *, gpointer) {
* @see l_pm_view_fill
*/
static void pm_entry_changed(GtkComboBoxEntry *, gpointer) {
- l_pm_view_fill(NULL);
+ l_pm_view_fill(pm_store, NULL);
}
/**
* Signal for a Project Manager keypress.
* Currently handled keypresses:
- * - Ctrl+Tab - Refocuses the Scintilla view.
* - Escape - Refocuses the Scintilla view.
*/
static gbool pm_keypress(GtkWidget *, GdkEventKey *event, gpointer) {
- if ((event->keyval == 0xff09 && event->state == GDK_CONTROL_MASK) ||
- event->keyval == 0xff1b) {
+ if (event->keyval == 0xff1b) {
gtk_widget_grab_focus(focused_editor);
return TRUE;
} else return FALSE;
@@ -722,7 +697,7 @@ static gbool pm_keypress(GtkWidget *, GdkEventKey *event, gpointer) {
*/
static void pm_row_expanded(GtkTreeView *, GtkTreeIter *iter, GtkTreePath *,
gpointer) {
- l_pm_view_fill(iter);
+ l_pm_view_fill(pm_store, iter);
GtkTreeIter child;
char *item;
gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(pm_store), &child, iter, 0);
@@ -755,16 +730,11 @@ static void pm_row_collapsed(GtkTreeView *, GtkTreeIter *iter, GtkTreePath *,
* collapsed. If the node is not a parent at all, a Lua action is performed.
* @see l_pm_perform_action
*/
-static void pm_row_activated(GtkTreeView *, GtkTreePath *path,
+static void pm_row_activated(GtkTreeView *view, GtkTreePath *path,
GtkTreeViewColumn *, gpointer) {
- GtkTreeIter iter;
- gtk_tree_model_get_iter(GTK_TREE_MODEL(pm_store), &iter, path);
- if (gtk_tree_model_iter_has_child(GTK_TREE_MODEL(pm_store), &iter)) {
- if (gtk_tree_view_row_expanded(GTK_TREE_VIEW(pm_view), path))
- gtk_tree_view_collapse_row(GTK_TREE_VIEW(pm_view), path);
- else
- gtk_tree_view_expand_row(GTK_TREE_VIEW(pm_view), path, FALSE);
- } else l_pm_perform_action(path);
+ if (!gtk_tree_view_expand_row(view, path, FALSE))
+ if (!gtk_tree_view_collapse_row(view, path))
+ l_pm_perform_action(pm_store, path);
}
/**
@@ -786,10 +756,10 @@ static GtkTreePath *pm_view_get_selection_path() {
* If it is a right-click, popup a context menu for the selected item.
* @see l_pm_popup_context_menu
*/
-static gbool pm_button_press(GtkTreeView *, GdkEventButton *event, gpointer) {
+static gbool pm_buttonpress(GtkTreeView *, GdkEventButton *event, gpointer) {
if (event->type != GDK_BUTTON_PRESS || event->button != 3) return FALSE;
GtkTreePath *path = pm_view_get_selection_path();
- l_pm_popup_context_menu(path, event, G_CALLBACK(pm_menu_activate));
+ l_pm_popup_context_menu(pm_store, path, event, G_CALLBACK(pm_menu_activate));
if (path) gtk_tree_path_free(path);
return TRUE;
}
@@ -801,7 +771,7 @@ static gbool pm_button_press(GtkTreeView *, GdkEventButton *event, gpointer) {
*/
static gbool pm_popup_menu(GtkWidget *, gpointer) {
GtkTreePath *path = pm_view_get_selection_path();
- l_pm_popup_context_menu(path, NULL, G_CALLBACK(pm_menu_activate));
+ l_pm_popup_context_menu(pm_store, path, NULL, G_CALLBACK(pm_menu_activate));
if (path) gtk_tree_path_free(path);
return TRUE;
}
@@ -809,12 +779,12 @@ static gbool pm_popup_menu(GtkWidget *, gpointer) {
/**
* Signal for a selected Project Manager menu item.
* Performs a Lua action for a selected menu item.
- * @param menu_id The numeric ID for the menu item.
+ * @param id The numeric ID for the menu item.
* @see l_pm_perform_menu_action
*/
-static void pm_menu_activate(GtkWidget *, gpointer menu_id) {
+static void pm_menu_activate(GtkWidget *, gpointer id) {
GtkTreePath *path = pm_view_get_selection_path();
- l_pm_perform_menu_action(path, GPOINTER_TO_INT(menu_id));
+ l_pm_perform_menu_action(pm_store, path, GPOINTER_TO_INT(id));
if (path) gtk_tree_path_free(path);
}
@@ -822,6 +792,8 @@ static void pm_menu_activate(GtkWidget *, gpointer menu_id) {
#define attach(w, x1, x2, y1, y2, xo, yo, xp, yp) \
gtk_table_attach(GTK_TABLE(findbox), w, x1, x2, y1, y2, xo, yo, xp, yp)
+#define ao_expand static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL)
+#define ao_normal static_cast<GtkAttachOptions>(GTK_SHRINK | GTK_FILL)
/**
* Creates the Find/Replace text frame.
@@ -858,7 +830,6 @@ GtkWidget *find_create_ui() {
gtk_label_set_mnemonic_widget(GTK_LABEL(flabel), find_entry);
gtk_label_set_mnemonic_widget(GTK_LABEL(rlabel), replace_entry);
- //gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lua_opt), TRUE);
attach(find_combo, 1, 2, 0, 1, ao_expand, ao_normal, 5, 0);
attach(replace_combo, 1, 2, 1, 2, ao_expand, ao_normal, 5, 0);
@@ -873,10 +844,10 @@ GtkWidget *find_create_ui() {
attach(lua_opt, 5, 6, 0, 1, ao_normal, ao_normal, 5, 0);
attach(in_files_opt, 5, 6, 1, 2, ao_normal, ao_normal, 5, 0);
- signal(fnext_button, "clicked", button_clicked);
- signal(fprev_button, "clicked", button_clicked);
- signal(r_button, "clicked", button_clicked);
- signal(ra_button, "clicked", button_clicked);
+ signal(fnext_button, "clicked", find_button_clicked);
+ signal(fprev_button, "clicked", find_button_clicked);
+ signal(r_button, "clicked", find_button_clicked);
+ signal(ra_button, "clicked", find_button_clicked);
GTK_WIDGET_SET_FLAGS(fnext_button, GTK_CAN_DEFAULT);
GTK_WIDGET_UNSET_FLAGS(fnext_button, GTK_CAN_FOCUS);
@@ -930,10 +901,10 @@ static void find_add_to_history(const char *text, GtkListStore *store) {
// Signals
/**
- * Signal for a button click.
+ * Signal for a Find frame button click.
* Performs the appropriate action depending on the button clicked.
*/
-static void button_clicked(GtkWidget *button, gpointer) {
+static void find_button_clicked(GtkWidget *button, gpointer) {
const char *find_text = gtk_entry_get_text(GTK_ENTRY(find_entry));
const char *repl_text = gtk_entry_get_text(GTK_ENTRY(replace_entry));
if (strlen(find_text) == 0) return;
@@ -969,39 +940,6 @@ void ce_toggle_focus() {
}
}
-// 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_ce_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(cec_store);
- 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
@@ -1039,3 +977,34 @@ static gbool cec_match_selected(GtkEntryCompletion *, GtkTreeModel *model,
gtk_list_store_clear(cec_store);
return TRUE;
}
+
+// 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_ce_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 *, GdkEventKey *event, gpointer) {
+ if (event->state == 0)
+ switch(event->keyval) {
+ case 0xff1b:
+ ce_toggle_focus();
+ return TRUE;
+ case 0xff09:
+ l_cec_fill(cec_store);
+ gtk_entry_completion_complete(command_entry_completion);
+ return TRUE;
+ }
+ return FALSE;
+}
diff --git a/src/textadept.h b/src/textadept.h
index 771d90dd..1c8f0b3a 100644
--- a/src/textadept.h
+++ b/src/textadept.h
@@ -34,8 +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 GtkTreeStore *pm_store;
-extern lua_State *lua;
#if !(WIN32 || MAC)
static const char *textadept_home = "/usr/share/textadept/";
#else
@@ -57,13 +55,8 @@ void split_window(GtkWidget *editor, bool vertical);
bool unsplit_window(GtkWidget *editor);
void set_menubar(GtkWidget *menubar);
void set_statusbar_text(const char *text, bool docbar);
-
-GtkWidget *pm_create_ui();
void pm_toggle_focus();
-
-GtkWidget *find_create_ui();
void find_toggle_focus();
-
void ce_toggle_focus();
// lua_interface.c
@@ -79,24 +72,23 @@ void l_remove_scintilla_buffer(sptr_t doc);
void l_goto_scintilla_buffer(GtkWidget *editor, int n, bool absolute);
void l_set_buffer_global(ScintillaObject *sci);
-void l_handle_error(lua_State *lua, const char *errmsg);
+void l_handle_error(const char *errmsg);
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_popup_context_menu(GdkEventButton *event);
-void l_pm_view_fill(GtkTreeIter *initial_iter);
-void l_pm_perform_action(GtkTreePath *path);
-void l_pm_popup_context_menu(GtkTreePath *path, GdkEventButton *event,
- GCallback callback);
-void l_pm_perform_menu_action(GtkTreePath *path, int menu_id);
+void l_pm_view_fill(GtkTreeStore *store, GtkTreeIter *initial_iter);
+void l_pm_perform_action(GtkTreeStore *store, GtkTreePath *path);
+void l_pm_popup_context_menu(GtkTreeStore *store, GtkTreePath *path,
+ GdkEventButton *event, GCallback callback);
+void l_pm_perform_menu_action(GtkTreeStore *store, GtkTreePath *path, int id);
void l_find(const char *ftext, bool next);
void l_find_replace(const char *rtext);
void l_find_replace_all(const char *ftext, const char *rtext);
void l_ce_command(const char *command);
-bool l_cec_get_completions_for(const char *entry_text);
-void l_cec_populate(GtkListStore *store);
+void l_cec_fill(GtkListStore *store);
#endif