SF.net SVN: geany:[4188] trunk
ntrel at users.sourceforge.net
ntrel at xxxxx
Mon Sep 14 17:10:22 UTC 2009
Revision: 4188
http://geany.svn.sourceforge.net/geany/?rev=4188&view=rev
Author: ntrel
Date: 2009-09-14 17:10:22 +0000 (Mon, 14 Sep 2009)
Log Message:
-----------
Add 'Allow' button when showing the conflicting keybinding dialog.
Make dialogs_show_question_full() use GTK dialog on Windows if
button text is not the stock yes/no items.
Add dialogs_show_prompt() which also has an 'Apply' button.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/dialogs.c
trunk/src/dialogs.h
trunk/src/prefs.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-09-14 14:48:24 UTC (rev 4187)
+++ trunk/ChangeLog 2009-09-14 17:10:22 UTC (rev 4188)
@@ -9,6 +9,11 @@
highlighting colors' pref, instead of requiring a restart.
Remove filetypes.common invert_all option - use 'Invert syntax
highlighting colors' pref instead (closes #2854525).
+ * src/prefs.c, src/dialogs.c, src/dialogs.h:
+ Add 'Allow' button when showing the conflicting keybinding dialog.
+ Make dialogs_show_question_full() use GTK dialog on Windows if
+ button text is not the stock yes/no items.
+ Add dialogs_show_prompt() which also has an 'Apply' button.
2009-09-13 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
Modified: trunk/src/dialogs.c
===================================================================
--- trunk/src/dialogs.c 2009-09-14 14:48:24 UTC (rev 4187)
+++ trunk/src/dialogs.c 2009-09-14 17:10:22 UTC (rev 4188)
@@ -1344,19 +1344,36 @@
}
-static gboolean show_question(GtkWidget *parent, const gchar *yes_btn, const gchar *no_btn,
- const gchar *question_text, const gchar *extra_text)
+/* extra_text can be NULL; otherwise it is displayed below main_text.
+ * if parent is NULL, main_widgets.window will be used
+ * yes_btn, no_btn, apply_btn can be NULL.
+ * returns GTK_RESPONSE_YES, GTK_RESPONSE_NO, GTK_RESPONSE_APPLY */
+static gint show_prompt(GtkWidget *parent,
+ const gchar *yes_btn, const gchar *no_btn, const gchar *apply_btn,
+ const gchar *question_text, const gchar *extra_text)
{
gboolean ret = FALSE;
+ GtkWidget *dialog;
+ GtkWidget *btn;
+
+ if (!yes_btn)
+ yes_btn = GTK_STOCK_YES;
+ if (!no_btn)
+ no_btn = GTK_STOCK_NO;
+
#ifdef G_OS_WIN32
- gchar *string = (extra_text == NULL) ? g_strdup(question_text) :
- g_strconcat(question_text, "\n\n", extra_text, NULL);
+ /* our native dialog code doesn't support custom buttons */
+ if (yes_btn == GTK_STOCK_YES && no_btn == GTK_STOCK_NO && !apply_btn)
+ {
+ gchar *string = (extra_text == NULL) ? g_strdup(question_text) :
+ g_strconcat(question_text, "\n\n", extra_text, NULL);
- ret = win32_message_dialog(parent, GTK_MESSAGE_QUESTION, string);
- g_free(string);
-#else
- GtkWidget *dialog;
-
+ ret = win32_message_dialog(parent, GTK_MESSAGE_QUESTION, string);
+ ret = ret ? GTK_RESPONSE_YES : GTK_RESPONSE_NO;
+ g_free(string);
+ return ret;
+ }
+#endif
if (parent == NULL && main_status.main_window_realized)
parent = main_widgets.window;
@@ -1377,15 +1394,21 @@
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
"%s", extra_text);
+ if (apply_btn)
+ gtk_dialog_add_button(GTK_DIALOG(dialog), apply_btn, GTK_RESPONSE_APPLY);
+
/* For a cancel button, use cancel response so user can press escape to cancel */
- gtk_dialog_add_button(GTK_DIALOG(dialog), no_btn,
+ btn = gtk_dialog_add_button(GTK_DIALOG(dialog), no_btn,
utils_str_equal(no_btn, GTK_STOCK_CANCEL) ? GTK_RESPONSE_CANCEL : GTK_RESPONSE_NO);
+ /* we don't want a default, but we need to override the apply button as default */
+ gtk_widget_grab_default(btn);
gtk_dialog_add_button(GTK_DIALOG(dialog), yes_btn, GTK_RESPONSE_YES);
- if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_YES)
- ret = TRUE;
+ ret = gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
-#endif
+
+ if (ret == GTK_RESPONSE_CANCEL)
+ ret = GTK_RESPONSE_NO;
return ret;
}
@@ -1402,7 +1425,6 @@
**/
gboolean dialogs_show_question(const gchar *text, ...)
{
- gboolean ret = FALSE;
gchar string[512];
va_list args;
GtkWidget *parent = (main_status.main_window_realized) ? main_widgets.window : NULL;
@@ -1410,8 +1432,7 @@
va_start(args, text);
g_vsnprintf(string, 511, text, args);
va_end(args);
- ret = show_question(parent, GTK_STOCK_YES, GTK_STOCK_NO, string, NULL);
- return ret;
+ return show_prompt(parent, GTK_STOCK_YES, GTK_STOCK_NO, NULL, string, NULL) == GTK_RESPONSE_YES;
}
@@ -1421,20 +1442,31 @@
gboolean dialogs_show_question_full(GtkWidget *parent, const gchar *yes_btn, const gchar *no_btn,
const gchar *extra_text, const gchar *main_text, ...)
{
- gboolean ret = FALSE;
gchar string[512];
va_list args;
- if (!yes_btn)
- yes_btn = GTK_STOCK_YES;
- if (!no_btn)
- no_btn = GTK_STOCK_NO;
+ va_start(args, main_text);
+ g_vsnprintf(string, 511, main_text, args);
+ va_end(args);
+ return show_prompt(parent, yes_btn, no_btn, NULL, string, extra_text) == GTK_RESPONSE_YES;
+}
+
+/* extra_text can be NULL; otherwise it is displayed below main_text.
+ * if parent is NULL, main_widgets.window will be used
+ * yes_btn, no_btn, apply_btn can be NULL.
+ * returns GTK_RESPONSE_YES, GTK_RESPONSE_NO, GTK_RESPONSE_APPLY */
+gint dialogs_show_prompt(GtkWidget *parent,
+ const gchar *yes_btn, const gchar *no_btn, const gchar *apply_btn,
+ const gchar *extra_text, const gchar *main_text, ...)
+{
+ gchar string[512];
+ va_list args;
+
va_start(args, main_text);
g_vsnprintf(string, 511, main_text, args);
va_end(args);
- ret = show_question(parent, yes_btn, no_btn, string, extra_text);
- return ret;
+ return show_prompt(parent, yes_btn, no_btn, apply_btn, string, extra_text);
}
Modified: trunk/src/dialogs.h
===================================================================
--- trunk/src/dialogs.h 2009-09-14 14:48:24 UTC (rev 4187)
+++ trunk/src/dialogs.h 2009-09-14 17:10:22 UTC (rev 4188)
@@ -58,6 +58,10 @@
gboolean dialogs_show_question_full(GtkWidget *parent, const gchar *yes_btn, const gchar *no_btn,
const gchar *extra_text, const gchar *main_text, ...) G_GNUC_PRINTF (5, 6);
+gint dialogs_show_prompt(GtkWidget *parent,
+ const gchar *yes_btn, const gchar *no_btn, const gchar *apply_btn,
+ const gchar *extra_text, const gchar *main_text, ...) G_GNUC_PRINTF (6, 7);
+
void dialogs_show_msgbox(GtkMessageType type, const gchar *text, ...) G_GNUC_PRINTF (2, 3);
void dialogs_show_msgbox_with_secondary(GtkMessageType type, const gchar *text, const gchar *secondary);
Modified: trunk/src/prefs.c
===================================================================
--- trunk/src/prefs.c 2009-09-14 14:48:24 UTC (rev 4187)
+++ trunk/src/prefs.c 2009-09-14 17:10:22 UTC (rev 4188)
@@ -1371,7 +1371,8 @@
}
-/* test if the entered key combination is already used */
+/* test if the entered key combination is already used
+ * returns true if cancelling duplicate */
static gboolean kb_find_duplicate(GeanyKeyBinding *search_kb,
guint key, GdkModifierType mods, const gchar *action)
{
@@ -1395,16 +1396,20 @@
if (kb->key == key && kb->mods == mods
&& ! (kb->key == search_kb->key && kb->mods == search_kb->mods))
{
- if (dialogs_show_question_full(main_widgets.window, _("_Override"), GTK_STOCK_CANCEL,
+ gint ret = dialogs_show_prompt(main_widgets.window,
+ _("_Override"), GTK_STOCK_CANCEL, _("_Allow"),
_("Override that keybinding?"),
_("The combination '%s' is already used for \"%s\"."),
- action, kb->label))
+ action, kb->label);
+
+ if (ret == GTK_RESPONSE_YES)
{
keybindings_update_combo(kb, 0, 0);
kb_clear_tree_shortcut(g, i);
+ /* carry on looking for other duplicates if overriding */
continue;
}
- return TRUE;
+ return ret == GTK_RESPONSE_NO;
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list