Add and use convenience function ui_is_keyval_enter_or_return() and add it to the plugin API.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@4737 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Enrico Tröger 2010-03-07 19:33:15 +00:00
parent 46e7e124d9
commit f72f6381df
10 changed files with 35 additions and 25 deletions

View File

@ -35,6 +35,11 @@
* plugins/filebrowser.c:
After opening files, focus the editor widget
(based on a patch by Can Koy, thanks).
* plugins/filebrowser.c, plugins/geanyfunctions.h, src/msgwindow.c,
src/plugindata.h, src/plugins.c, src/sidebar.c, src/ui_utils.c,
src/ui_utils.h, src/vte.c:
Add and use convenience function ui_is_keyval_enter_or_return() and
add it to the plugin API.
2010-03-05 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>

View File

@ -35,7 +35,7 @@ GeanyData *geany_data;
GeanyFunctions *geany_functions;
PLUGIN_VERSION_CHECK(163)
PLUGIN_VERSION_CHECK(175)
PLUGIN_SET_INFO(_("File Browser"), _("Adds a file browser tab to the sidebar."), VERSION,
_("The Geany developer team"))
@ -649,9 +649,7 @@ static gboolean on_button_press(GtkWidget *widget, GdkEventButton *event, gpoint
static gboolean on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
if (event->keyval == GDK_Return
|| event->keyval == GDK_ISO_Enter
|| event->keyval == GDK_KP_Enter)
if (ui_is_keyval_enter_or_return(event->keyval))
{
on_open_clicked(NULL, NULL);
return TRUE;

View File

@ -262,6 +262,8 @@
geany_functions->p_ui->ui_menu_add_document_items
#define ui_widget_modify_font_from_string \
geany_functions->p_ui->ui_widget_modify_font_from_string
#define ui_is_keyval_enter_or_return \
geany_functions->p_ui->ui_is_keyval_enter_or_return
#define dialogs_show_question \
geany_functions->p_dialogs->dialogs_show_question
#define dialogs_show_msgbox \

View File

@ -111,15 +111,9 @@ void msgwin_finalize(void)
}
static gboolean is_keyval_enter_or_return(guint keyval)
{
return (keyval == GDK_Return || keyval == GDK_ISO_Enter || keyval == GDK_KP_Enter);
}
static gboolean on_msgwin_key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
if (is_keyval_enter_or_return(event->keyval) || event->keyval == GDK_space)
if (ui_is_keyval_enter_or_return(event->keyval) || event->keyval == GDK_space)
{
switch (GPOINTER_TO_INT(data))
{
@ -643,7 +637,7 @@ static gboolean goto_compiler_file_line(const gchar *filename, gint line, guint
editor_indicator_set_on_line(doc->editor, GEANY_INDICATOR_ERROR, line - 1);
ret = navqueue_goto_line(old_doc, doc, line);
if (ret && is_keyval_enter_or_return(keyval))
if (ret && ui_is_keyval_enter_or_return(keyval))
gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci));
return ret;
@ -986,7 +980,7 @@ gboolean msgwin_goto_messages_file_line(guint keyval)
if (line >= 0 && DOC_VALID(doc))
{
ret = navqueue_goto_line(old_doc, doc, line);
if (ret && is_keyval_enter_or_return(keyval))
if (ret && ui_is_keyval_enter_or_return(keyval))
gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci));
}
else if (line < 0 && string != NULL)
@ -1000,7 +994,7 @@ gboolean msgwin_goto_messages_file_line(guint keyval)
if (doc != NULL)
{
ret = navqueue_goto_line(old_doc, doc, line);
if (ret && is_keyval_enter_or_return(keyval))
if (ret && ui_is_keyval_enter_or_return(keyval))
gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci));
}
}

View File

@ -50,7 +50,7 @@
enum {
/** The Application Programming Interface (API) version, incremented
* whenever any plugin data types are modified or appended to. */
GEANY_API_VERSION = 174,
GEANY_API_VERSION = 175,
/** The Application Binary Interface (ABI) version, incremented whenever
* existing fields in the plugin data types have to be changed or reordered. */
@ -426,6 +426,7 @@ typedef struct UIUtilsFuncs
void (*ui_menu_add_document_items) (GtkMenu *menu, struct GeanyDocument *active,
GCallback callback);
void (*ui_widget_modify_font_from_string) (GtkWidget *widget, const gchar *str);
gboolean (*ui_is_keyval_enter_or_return) (guint keyval);
}
UIUtilsFuncs;

View File

@ -209,7 +209,7 @@ static UtilsFuncs utils_funcs = {
&utils_string_replace_first,
&utils_str_middle_truncate,
&utils_str_remove_chars,
&utils_get_file_list_full
&utils_get_file_list_full,
};
static UIUtilsFuncs uiutils_funcs = {
@ -227,7 +227,8 @@ static UIUtilsFuncs uiutils_funcs = {
&ui_progress_bar_stop,
&ui_entry_add_clear_icon,
&ui_menu_add_document_items,
&ui_widget_modify_font_from_string
&ui_widget_modify_font_from_string,
&ui_is_keyval_enter_or_return
};
static DialogFuncs dialog_funcs = {

View File

@ -784,10 +784,7 @@ static gboolean sidebar_key_press_cb(GtkWidget *widget, GdkEventKey *event,
gpointer user_data)
{
may_steal_focus = FALSE;
if (event->keyval == GDK_Return ||
event->keyval == GDK_ISO_Enter ||
event->keyval == GDK_KP_Enter ||
event->keyval == GDK_space)
if (ui_is_keyval_enter_or_return(event->keyval) || event->keyval == GDK_space)
{
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
may_steal_focus = TRUE;

View File

@ -28,6 +28,7 @@
#include "geany.h"
#include <string.h>
#include <gdk/gdkkeysyms.h>
#include "ui_utils.h"
#include "prefs.h"
@ -2245,3 +2246,14 @@ void ui_menu_add_document_items(GtkMenu *menu, GeanyDocument *active, GCallback
}
/** Check whether the passed @a keyval is the Enter or Return key.
* There are three different Enter/Return key values
* (@c GDK_Return, @c GDK_ISO_Enter, @c GDK_KP_Enter).
* This is just a convenience function.
* @param keyval A keyval.
* @return @c TRUE if @a keyval is the one of the Enter/Return key values, otherwise @c FALSE.
* @since 0.19 */
gboolean ui_is_keyval_enter_or_return(guint keyval)
{
return (keyval == GDK_Return || keyval == GDK_ISO_Enter|| keyval == GDK_KP_Enter);
}

View File

@ -304,4 +304,6 @@ void ui_progress_bar_stop(void);
void ui_swap_sidebar_pos(void);
gboolean ui_is_keyval_enter_or_return(guint keyval);
#endif

View File

@ -296,9 +296,7 @@ void vte_close(void)
static gboolean vte_keyrelease_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
if (event->keyval == GDK_Return ||
event->keyval == GDK_ISO_Enter ||
event->keyval == GDK_KP_Enter ||
if (ui_is_keyval_enter_or_return(event->keyval) ||
((event->keyval == GDK_c) && (event->state & GDK_CONTROL_MASK)))
{
/* assume any text on the prompt has been executed when pressing Enter/Return */