From a8d422fc53271f479bc0a8a27abeb3c5469ad909 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Fri, 15 Oct 2010 17:00:23 -0400 Subject: C code cleanup. --- src/lua_interface.c | 32 ++++++++++++++------------------ src/textadept.c | 45 ++++++++++++++++++++------------------------- 2 files changed, 34 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/lua_interface.c b/src/lua_interface.c index a23360b5..5e8b6ec6 100644 --- a/src/lua_interface.c +++ b/src/lua_interface.c @@ -26,9 +26,8 @@ lua_State *lua; int closing = FALSE; -static int tVOID = 0, tINT = 1, tLENGTH = 2, /*tPOSITION = 3,*/ - /*tCOLOUR = 4,*/ tBOOL = 5, tKEYMOD = 6, tSTRING = 7, - tSTRINGRESULT = 8; +static int tVOID = 0, tINT = 1, tLENGTH = 2, /*tPOSITION = 3, tCOLOUR = 4,*/ + tBOOL = 5, tKEYMOD = 6, tSTRING = 7, tSTRINGRESULT = 8; static void clear_table(lua_State *lua, int index); static void warn(const char *s) { printf("Warning: %s\n", s); } @@ -656,20 +655,20 @@ void l_emit_scnnotification(struct SCNotification *n) { l_pushscninteger(n->position, "position"); l_pushscninteger(n->ch, "ch"); l_pushscninteger(n->modifiers, "modifiers"); - l_pushscninteger(n->modificationType, "modification_type"); + //l_pushscninteger(n->modificationType, "modification_type"); lua_pushstring(lua, n->text); lua_setfield(lua, -2, "text"); - l_pushscninteger(n->length, "length"); - l_pushscninteger(n->linesAdded, "lines_added"); - l_pushscninteger(n->message, "message"); + //l_pushscninteger(n->length, "length"); + //l_pushscninteger(n->linesAdded, "lines_added"); + //l_pushscninteger(n->message, "message"); l_pushscninteger(n->wParam, "wParam"); l_pushscninteger(n->lParam, "lParam"); l_pushscninteger(n->line, "line"); - l_pushscninteger(n->foldLevelNow, "fold_level_now"); - l_pushscninteger(n->foldLevelPrev, "fold_level_prev"); + //l_pushscninteger(n->foldLevelNow, "fold_level_now"); + //l_pushscninteger(n->foldLevelPrev, "fold_level_prev"); l_pushscninteger(n->margin, "margin"); - l_pushscninteger(n->x, "x"); - l_pushscninteger(n->y, "y"); + //l_pushscninteger(n->x, "x"); + //l_pushscninteger(n->y, "y"); l_call_function(1, 0, FALSE); } @@ -920,9 +919,9 @@ static int l_gui_mt_newindex(lua_State *lua) { if (streq(key, "title")) gtk_window_set_title(GTK_WINDOW(window), lua_tostring(lua, 3)); else if (streq(key, "statusbar_text")) - set_statusbar_text(lua_tostring(lua, 3), FALSE); + set_statusbar_text(lua_tostring(lua, 3), 0); else if (streq(key, "docstatusbar_text")) - set_statusbar_text(lua_tostring(lua, 3), TRUE); + set_statusbar_text(lua_tostring(lua, 3), 1); else if (streq(key, "focused_doc_pointer") || streq(key, "clipboard_text")) luaL_argerror(lua, 3, "read-only property"); else if (streq(key, "menubar")) { @@ -939,11 +938,8 @@ static int l_gui_mt_newindex(lua_State *lua) { } else if (streq(key, "size")) { luaL_argcheck(lua, lua_istable(lua, 3) && lua_objlen(lua, 3) == 2, 3, "{ width, height } table expected"); - lua_rawgeti(lua, 3, 1); - lua_rawgeti(lua, 3, 2); - int width = lua_tointeger(lua, -2); - int height = lua_tointeger(lua, -1); - lua_pop(lua, 2); // width, height + int width = l_rawgeti_int(lua, 3, 1); + int height = l_rawgeti_int(lua, 3, 2); if (width > 0 && height > 0) gtk_window_resize(GTK_WINDOW(window), width, height); } else lua_rawset(lua, 1); diff --git a/src/textadept.c b/src/textadept.c index 94fe1fb3..504b0bb4 100644 --- a/src/textadept.c +++ b/src/textadept.c @@ -7,6 +7,7 @@ #elif MAC #include #include "ige-mac-menu.h" +#define GDK_MOD1_MASK GDK_META_MASK #elif __BSD__ #include #include @@ -16,7 +17,7 @@ #define signal(o, s, c) g_signal_connect(G_OBJECT(o), s, G_CALLBACK(c), 0) // Textadept -GtkWidget *window, *focused_editor, *menubar, *statusbar, *docstatusbar; +GtkWidget *window, *focused_editor, *menubar, *statusbar[2]; char *textadept_home; static void s_notification(GtkWidget *, gint, gpointer, gpointer); @@ -161,10 +162,10 @@ void create_ui() { GtkWidget *hboxs = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), hboxs, FALSE, FALSE, 0); - statusbar = gtk_statusbar_new(); - gtk_statusbar_push(GTK_STATUSBAR(statusbar), 0, ""); - gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(statusbar), FALSE); - gtk_box_pack_start(GTK_BOX(hboxs), statusbar, TRUE, TRUE, 0); + statusbar[0] = gtk_statusbar_new(); + gtk_statusbar_push(GTK_STATUSBAR(statusbar[0]), 0, ""); + gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(statusbar[0]), FALSE); + gtk_box_pack_start(GTK_BOX(hboxs), statusbar[0], TRUE, TRUE, 0); command_entry = gtk_entry_new(); gtk_widget_set_name(command_entry, "textadept-command-entry"); @@ -183,13 +184,13 @@ void create_ui() { GTK_TREE_MODEL(cc_store)); gtk_entry_set_completion(GTK_ENTRY(command_entry), command_entry_completion); - docstatusbar = gtk_statusbar_new(); - gtk_statusbar_push(GTK_STATUSBAR(docstatusbar), 0, ""); - g_object_set(G_OBJECT(docstatusbar), "width-request", 400, NULL); + statusbar[1] = gtk_statusbar_new(); + gtk_statusbar_push(GTK_STATUSBAR(statusbar[1]), 0, ""); + g_object_set(G_OBJECT(statusbar[1]), "width-request", 400, NULL); #if MAC - gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(docstatusbar), FALSE); + gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(statusbar[1]), FALSE); #endif - gtk_box_pack_start(GTK_BOX(hboxs), docstatusbar, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(hboxs), statusbar[1], FALSE, FALSE, 0); gtk_widget_show_all(window); gtk_widget_hide(menubar); // hide initially @@ -379,14 +380,12 @@ void set_menubar(GtkWidget *new_menubar) { /** * Sets the notification statusbar text. * @param text The text to display. - * @param docbar Flag indicating whether or not the statusbar text is for the - * docstatusbar. + * @param bar Statusbar. 0 for statusbar, 1 for docstatusbar. */ -void set_statusbar_text(const char *text, int docbar) { - GtkWidget *bar = docbar ? docstatusbar : statusbar; - 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); +void set_statusbar_text(const char *text, int bar) { + if (!statusbar[0] || !statusbar[1]) return; // unavailable on startup + gtk_statusbar_pop(GTK_STATUSBAR(statusbar[bar]), 0); + gtk_statusbar_push(GTK_STATUSBAR(statusbar[bar]), 0, text); } // Notifications/signals @@ -435,11 +434,7 @@ static gbool s_keypress(GtkWidget *editor, GdkEventKey *event, gpointer udata) { LUA_TNUMBER, event->keyval, LUA_TBOOLEAN, event->state & GDK_SHIFT_MASK, LUA_TBOOLEAN, event->state & GDK_CONTROL_MASK, -#if !MAC LUA_TBOOLEAN, event->state & GDK_MOD1_MASK, -#else - LUA_TBOOLEAN, event->state & GDK_META_MASK, -#endif -1) ? TRUE : FALSE; } @@ -673,13 +668,13 @@ static void find_button_clicked(GtkWidget *button, gpointer udata) { */ void ce_toggle_focus() { if (!GTK_WIDGET_HAS_FOCUS(command_entry)) { - gtk_widget_hide(statusbar); - gtk_widget_hide(docstatusbar); + gtk_widget_hide(statusbar[0]); + gtk_widget_hide(statusbar[1]); gtk_widget_show(command_entry); gtk_widget_grab_focus(command_entry); } else { - gtk_widget_show(statusbar); - gtk_widget_show(docstatusbar); + gtk_widget_show(statusbar[0]); + gtk_widget_show(statusbar[1]); gtk_widget_hide(command_entry); gtk_widget_grab_focus(focused_editor); } -- cgit v1.2.3