From 16a47e287f44f4ea154f9bfc1d3a6fa083a0f43e Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Fri, 21 Nov 2014 19:36:01 +0100 Subject: finally implemented the CLOSE and QUIT hooks the QUIT hook is actually not that trivial and required some architectural changes. First, the QUIT hook execution and any error that might occurr cannot always be attached to an existing error stack frame. Thereforce, to give a stack frame for QUIT hooks and to improve the readability of error traces for ED hooks in general, a special EDHookFrame is added to every ED hook execution error. Secondly, since QUIT hooks can themselves throw errors, we cannot run it from an atexit() handler. Instead it's always called manually before __successful__ program termination. An error in a QUIT hook will result in a failure return code nevertheless. Thirdly, errors in QUIT hooks should not prevent program termination (in interactive mode), therefore they are only invoked from main() and always in batch mode. I.e. if the interactive mode is terminated (EX$$), SciTECO will switch back to batch mode and run the QUIT hook there. This is also symmetric to program startup, which is always in batch mode. This means that Interface::event_loop() no longer runs indefinitely. If it returns, this signals that the interface shut down and batch mode may be restored by SciTECO. --- src/interface-gtk.cpp | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'src/interface-gtk.cpp') diff --git a/src/interface-gtk.cpp b/src/interface-gtk.cpp index 3421d6f..e94c42c 100644 --- a/src/interface-gtk.cpp +++ b/src/interface-gtk.cpp @@ -253,20 +253,10 @@ scintilla_notify(ScintillaObject *sci, uptr_t idFrom, interface.process_notify(notify); } -static gboolean -cmdline_key_pressed(GtkWidget *widget, GdkEventKey *event, - gpointer user_data) +static inline void +handle_key_press(bool is_shift, bool is_ctl, guint keyval) { - bool is_shift = event->state & GDK_SHIFT_MASK; - bool is_ctl = event->state & GDK_CONTROL_MASK; - -#ifdef DEBUG - g_printf("KEY \"%s\" (%d) SHIFT=%d CNTRL=%d\n", - event->string, *event->string, - event->state & GDK_SHIFT_MASK, event->state & GDK_CONTROL_MASK); -#endif - - switch (event->keyval) { + switch (keyval) { case GDK_Escape: cmdline_keypress('\x1B'); break; @@ -296,7 +286,7 @@ cmdline_key_pressed(GtkWidget *widget, GdkEventKey *event, gchar macro_name[3+1]; g_snprintf(macro_name, sizeof(macro_name), - "F%d", event->keyval - GDK_F1 + 1); + "F%d", keyval - GDK_F1 + 1); cmdline_fnmacro(macro_name); break; } @@ -316,7 +306,7 @@ cmdline_key_pressed(GtkWidget *widget, GdkEventKey *event, * Control keys and keys with printable representation */ default: - gunichar u = gdk_keyval_to_unicode(event->keyval); + gunichar u = gdk_keyval_to_unicode(keyval); if (u && g_unichar_to_utf8(u, NULL) == 1) { gchar key; @@ -330,6 +320,30 @@ cmdline_key_pressed(GtkWidget *widget, GdkEventKey *event, cmdline_keypress(key); } } +} + +static gboolean +cmdline_key_pressed(GtkWidget *widget, GdkEventKey *event, + gpointer user_data) +{ + bool is_shift = event->state & GDK_SHIFT_MASK; + bool is_ctl = event->state & GDK_CONTROL_MASK; + +#ifdef DEBUG + g_printf("KEY \"%s\" (%d) SHIFT=%d CNTRL=%d\n", + event->string, *event->string, + event->state & GDK_SHIFT_MASK, event->state & GDK_CONTROL_MASK); +#endif + + try { + handle_key_press(is_shift, is_ctl, event->keyval); + } catch (Quit) { + /* + * SciTECO should terminate, so we exit + * the main loop. event_loop() will return. + */ + gtk_main_quit(); + } return TRUE; } -- cgit v1.2.3