diff --git a/ChangeLog b/ChangeLog index 83ed4405..0049355c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,12 @@ 2007-07-04 Enrico Tröger - * geany.glade, src/interface.c, src/keybindings.c, src/keybindings.h: + * geany.glade, doc/geany.docbook, src/interface.c, src/keybindings.c, + src/keybindings.h: Change Help shortcut to F1, use Ctrl-H for Replace. + * src/callbacks.c, src/dialogs.c, src/dialogs.h, src/document.c, + src/document.h, src/editor.c, src/project.c, src/search.c, + src/utils.c, src/win32.c, src/win32.h: + Fix focus problem when using the Find dialog. 2007-07-04 Nick Treleaven diff --git a/doc/geany.docbook b/doc/geany.docbook index bafcad08..bf5ec57e 100644 --- a/doc/geany.docbook +++ b/doc/geany.docbook @@ -1670,6 +1670,10 @@ widget "GeanyPrefsDialog" style "geanyStyle" Preferences Opens preferences dialog. + + Help + Opens the manual. + Find Next Finds next result. diff --git a/src/callbacks.c b/src/callbacks.c index a5916da1..854b1916 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -170,7 +170,7 @@ on_exit_clicked (GtkWidget *widget, gpointer gdata) } else if (! app->pref_main_confirm_exit || - dialogs_show_question_full(GTK_STOCK_QUIT, GTK_STOCK_CANCEL, NULL, + dialogs_show_question_full(NULL, GTK_STOCK_QUIT, GTK_STOCK_CANCEL, NULL, _("Do you really want to quit?"))) { quit_app(); @@ -487,7 +487,7 @@ on_reload_as_activate (GtkMenuItem *menuitem, } basename = g_path_get_basename(doc_list[idx].file_name); - if (dialogs_show_question_full(_("_Reload"), GTK_STOCK_CANCEL, + if (dialogs_show_question_full(NULL, _("_Reload"), GTK_STOCK_CANCEL, _("Any unsaved changes will be lost."), _("Are you sure you want to reload '%s'?"), basename)) { @@ -1322,7 +1322,7 @@ on_find_next1_activate (GtkMenuItem *menuitem, if (search_data.text) { document_find_text(idx, search_data.text, search_data.flags, - search_data.backwards, TRUE); + search_data.backwards, TRUE, NULL); } } @@ -1340,7 +1340,7 @@ on_find_previous1_activate (GtkMenuItem *menuitem, else { document_find_text(idx, search_data.text, search_data.flags, - !search_data.backwards, TRUE); + !search_data.backwards, TRUE, NULL); } } diff --git a/src/dialogs.c b/src/dialogs.c index fb7b4a30..0105e3be 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -370,7 +370,7 @@ void dialogs_show_msgbox(gint type, const gchar *text, ...) va_end(args); #ifdef G_OS_WIN32 - win32_message_dialog(type, string); + win32_message_dialog(NULL, type, string); #else dialog = gtk_message_dialog_new(GTK_WINDOW(app->window), GTK_DIALOG_DESTROY_WITH_PARENT, type, GTK_BUTTONS_OK, "%s", string); @@ -1057,21 +1057,23 @@ void dialogs_show_file_properties(gint idx) } -static gboolean -show_question(const gchar *yes_btn, const gchar *no_btn, const gchar *question_text, - const gchar *extra_text) +static gboolean show_question(GtkWidget *parent, const gchar *yes_btn, const gchar *no_btn, + const gchar *question_text, const gchar *extra_text) { gboolean ret = FALSE; #ifdef G_OS_WIN32 gchar *string = (extra_text == NULL) ? g_strdup(question_text) : g_strconcat(question_text, "\n\n", extra_text, NULL); - ret = win32_message_dialog(GTK_MESSAGE_QUESTION, string); + ret = win32_message_dialog(parent, GTK_MESSAGE_QUESTION, string); g_free(string); #else GtkWidget *dialog; - dialog = gtk_message_dialog_new(GTK_WINDOW(app->window), + if (parent == NULL) + parent = app->window; + + dialog = gtk_message_dialog_new(GTK_WINDOW(parent), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, "%s", question_text); gtk_widget_set_name(dialog, "GeanyDialog"); @@ -1102,14 +1104,15 @@ gboolean dialogs_show_question(const gchar *text, ...) va_start(args, text); g_vsnprintf(string, 511, text, args); va_end(args); - ret = show_question(GTK_STOCK_YES, GTK_STOCK_NO, string, NULL); + ret = show_question(app->window, GTK_STOCK_YES, GTK_STOCK_NO, string, NULL); g_free(string); return ret; } -/* extra_text can be NULL; otherwise it is displayed below main_text. */ -gboolean dialogs_show_question_full(const gchar *yes_btn, const gchar *no_btn, +/* extra_text can be NULL; otherwise it is displayed below main_text. + * if parent is NULL, app->window will be used */ +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; @@ -1119,7 +1122,7 @@ gboolean dialogs_show_question_full(const gchar *yes_btn, const gchar *no_btn, va_start(args, main_text); g_vsnprintf(string, 511, main_text, args); va_end(args); - ret = show_question(yes_btn, no_btn, string, extra_text); + ret = show_question(parent, yes_btn, no_btn, string, extra_text); g_free(string); return ret; } diff --git a/src/dialogs.h b/src/dialogs.h index fa2ca572..f168c10c 100644 --- a/src/dialogs.h +++ b/src/dialogs.h @@ -50,8 +50,8 @@ void dialogs_show_file_properties(gint idx); gboolean dialogs_show_question(const gchar *text, ...) G_GNUC_PRINTF (1, 2); /* extra_text can be NULL; otherwise it is displayed below main_text. */ -gboolean dialogs_show_question_full(const gchar *yes_btn, const gchar *no_btn, - const gchar *extra_text, const gchar *main_text, ...) G_GNUC_PRINTF (4, 5); +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); void dialogs_show_msgbox(gint type, const gchar *text, ...) G_GNUC_PRINTF (2, 3); diff --git a/src/document.c b/src/document.c index 36ba2af9..263fd477 100644 --- a/src/document.c +++ b/src/document.c @@ -924,7 +924,7 @@ gint document_reload_file(gint idx, const gchar *forced_enc) { gint pos = 0; - if (idx < 0 || ! doc_list[idx].is_valid) + if (! DOC_IDX_VALID(idx)) return -1; // try to set the cursor to the position before reloading @@ -1151,7 +1151,7 @@ void document_search_bar_find(gint idx, const gchar *text, gint flags, gboolean * Returns -1 on failure or the start position of the matching text. * Will skip past any selection, ignoring it. */ gint document_find_text(gint idx, const gchar *text, gint flags, gboolean search_backwards, - gboolean scroll) + gboolean scroll, GtkWidget *parent) { gint selection_end, selection_start, search_pos, first_visible_line; @@ -1198,13 +1198,13 @@ gint document_find_text(gint idx, const gchar *text, gint flags, gboolean search // we searched only part of the document, so ask whether to wraparound. if (app->pref_main_suppress_search_dialogs || - dialogs_show_question_full(GTK_STOCK_FIND, GTK_STOCK_CANCEL, + dialogs_show_question_full(parent, GTK_STOCK_FIND, GTK_STOCK_CANCEL, _("Wrap search and find again?"), _("\"%s\" was not found."), text)) { gint ret; sci_set_current_position(doc_list[idx].sci, (search_backwards) ? sci_len : 0, FALSE); - ret = document_find_text(idx, text, flags, search_backwards, scroll); + ret = document_find_text(idx, text, flags, search_backwards, scroll, parent); if (ret == -1) { // return to original cursor position if not found sci_set_current_position(doc_list[idx].sci, selection_start, FALSE); @@ -1234,7 +1234,7 @@ gint document_replace_text(gint idx, const gchar *find_text, const gchar *replac if (selection_end == selection_start) { // no selection so just find the next match - document_find_text(idx, find_text, flags, search_backwards, TRUE); + document_find_text(idx, find_text, flags, search_backwards, TRUE, NULL); return -1; } // there's a selection so go to the start before finding to search through it @@ -1244,7 +1244,7 @@ gint document_replace_text(gint idx, const gchar *find_text, const gchar *replac else sci_goto_pos(doc_list[idx].sci, selection_start, TRUE); - search_pos = document_find_text(idx, find_text, flags, search_backwards, TRUE); + search_pos = document_find_text(idx, find_text, flags, search_backwards, TRUE, NULL); // return if the original selected text did not match (at the start of the selection) if (search_pos != selection_start) return -1; @@ -1782,8 +1782,9 @@ void document_print(gint idx) cmdline = g_strdup(app->tools_print_cmd); cmdline = utils_str_replace(cmdline, "%f", doc_list[idx].file_name); - if (dialogs_show_question(_("The file \"%s\" will be printed with the following command:\n\n%s"), - doc_list[idx].file_name, cmdline)) + if (dialogs_show_question( + _("The file \"%s\" will be printed with the following command:\n\n%s"), + doc_list[idx].file_name, cmdline)) { GError *error = NULL; diff --git a/src/document.h b/src/document.h index 1ee470c5..06a6081e 100644 --- a/src/document.h +++ b/src/document.h @@ -166,7 +166,7 @@ void document_search_bar_find(gint idx, const gchar *text, gint flags, gboolean /* General search function, used from the find dialog. * Returns -1 on failure or the start position of the matching text. */ gint document_find_text(gint idx, const gchar *text, gint flags, gboolean search_backwards, - gboolean scroll); + gboolean scroll, GtkWidget *parent); gint document_replace_text(gint idx, const gchar *find_text, const gchar *replace_text, gint flags, gboolean search_backwards); diff --git a/src/editor.c b/src/editor.c index df07e3d5..aed0c950 100644 --- a/src/editor.c +++ b/src/editor.c @@ -1428,7 +1428,7 @@ static void real_uncomment_multiline(gint idx) if (idx == -1 || ! doc_list[idx].is_valid || doc_list[idx].file_type == NULL) return; // remove comment open chars - pos = document_find_text(idx, doc_list[idx].file_type->comment_open, 0, TRUE, FALSE); + pos = document_find_text(idx, doc_list[idx].file_type->comment_open, 0, TRUE, FALSE, NULL); SSM(doc_list[idx].sci, SCI_DELETEBACK, 0, 0); // check whether the line is empty and can be deleted @@ -1441,7 +1441,7 @@ static void real_uncomment_multiline(gint idx) g_free(linebuf); // remove comment close chars - pos = document_find_text(idx, doc_list[idx].file_type->comment_close, 0, FALSE, FALSE); + pos = document_find_text(idx, doc_list[idx].file_type->comment_close, 0, FALSE, FALSE, NULL); SSM(doc_list[idx].sci, SCI_DELETEBACK, 0, 0); // check whether the line is empty and can be deleted diff --git a/src/project.c b/src/project.c index c072449f..757d0d40 100644 --- a/src/project.c +++ b/src/project.c @@ -497,7 +497,7 @@ static gboolean close_open_project() { if (app->project != NULL) { - if (dialogs_show_question_full(GTK_STOCK_OK, GTK_STOCK_CANCEL, + if (dialogs_show_question_full(NULL, GTK_STOCK_OK, GTK_STOCK_CANCEL, _("Do you want to close it before proceeding?"), _("The '%s' project is already open. "), app->project->name)) { @@ -552,7 +552,7 @@ static gboolean update_config(const PropertyDialogElements *e) gchar *locale_path = utils_get_locale_from_utf8(base_path); if (! g_file_test(locale_path, G_FILE_TEST_IS_DIR)) { - if (dialogs_show_question_full(GTK_STOCK_OK, GTK_STOCK_CANCEL, + if (dialogs_show_question_full(NULL, GTK_STOCK_OK, GTK_STOCK_CANCEL, _("Create the project's base path directory?"), _("The path \"%s\" does not exist."), base_path)) diff --git a/src/search.c b/src/search.c index 8196eb38..8ea39b26 100644 --- a/src/search.c +++ b/src/search.c @@ -269,7 +269,7 @@ void search_find_selection(gint idx, gboolean search_backwards) if (s) { setup_find_next(s); // allow find next/prev - document_find_text(idx, s, 0, search_backwards, TRUE); + document_find_text(idx, s, 0, search_backwards, TRUE, NULL); g_free(s); } } @@ -848,7 +848,7 @@ on_find_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) case GEANY_RESPONSE_FIND: case GEANY_RESPONSE_FIND_PREVIOUS: document_find_text(idx, search_data.text, search_data.flags, - (response == GEANY_RESPONSE_FIND_PREVIOUS), TRUE); + (response == GEANY_RESPONSE_FIND_PREVIOUS), TRUE, GTK_WIDGET(dialog)); check_close = FALSE; if (app->pref_main_suppress_search_dialogs) check_close = TRUE; @@ -954,7 +954,7 @@ on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) search_backwards_re); if (rep != -1) document_find_text(idx, find, search_flags_re, search_backwards_re, - TRUE); + TRUE, NULL); break; } case GEANY_RESPONSE_REPLACE: @@ -965,7 +965,8 @@ on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) } case GEANY_RESPONSE_FIND: { - document_find_text(idx, find, search_flags_re, search_backwards_re, TRUE); + document_find_text(idx, find, search_flags_re, search_backwards_re, TRUE, + GTK_WIDGET(dialog)); break; } case GEANY_RESPONSE_REPLACE_IN_FILE: diff --git a/src/utils.c b/src/utils.c index a9758a90..e3044194 100644 --- a/src/utils.c +++ b/src/utils.c @@ -350,7 +350,7 @@ gboolean utils_check_disk_status(gint idx, gboolean force) { gchar *basename = g_path_get_basename(doc_list[idx].file_name); - if (dialogs_show_question_full(_("_Reload"), GTK_STOCK_CANCEL, + if (dialogs_show_question_full(NULL, _("_Reload"), GTK_STOCK_CANCEL, _("Do you want to reload it?"), _("The file '%s' on the disk is more recent than\n" "the current buffer."), basename)) diff --git a/src/win32.c b/src/win32.c index 548be438..f1994e27 100644 --- a/src/win32.c +++ b/src/win32.c @@ -234,7 +234,7 @@ gchar *win32_show_project_open_dialog(const gchar *title, const gchar *initial_d { gchar *error; error = g_strdup_printf("File dialog box error (%x)", (int)CommDlgExtendedError()); - win32_message_dialog(GTK_MESSAGE_ERROR, error); + win32_message_dialog(NULL, GTK_MESSAGE_ERROR, error); g_free(error); } g_free(fname); @@ -294,7 +294,7 @@ gboolean win32_show_file_dialog(gboolean file_open) { gchar error[100]; snprintf(error, sizeof error, "File dialog box error (%x)", (int)CommDlgExtendedError()); - win32_message_dialog(GTK_MESSAGE_ERROR, error); + win32_message_dialog(NULL, GTK_MESSAGE_ERROR, error); } g_free(fname); return FALSE; @@ -453,7 +453,7 @@ void win32_show_pref_file_dialog(GtkEntry *item) { gchar error[100]; snprintf(error, sizeof error, "File dialog box error (%x)", (int)CommDlgExtendedError()); - win32_message_dialog(GTK_MESSAGE_ERROR, error); + win32_message_dialog(NULL, GTK_MESSAGE_ERROR, error); } g_strfreev(field); g_free(fname); @@ -483,7 +483,7 @@ void win32_show_pref_file_dialog(GtkEntry *item) /* Creates a native Windows message box of the given type and returns always TRUE * or FALSE representing th pressed Yes or No button. * If type is not GTK_MESSAGE_QUESTION, it returns always TRUE. */ -gboolean win32_message_dialog(GtkMessageType type, const gchar *msg) +gboolean win32_message_dialog(GtkWidget *parent, GtkMessageType type, const gchar *msg) { gboolean ret = TRUE; gint rc; @@ -526,7 +526,10 @@ gboolean win32_message_dialog(GtkMessageType type, const gchar *msg) MultiByteToWideChar(CP_UTF8, 0, title, -1, w_title, sizeof(w_title)/sizeof(w_title[0])); // display the message box - rc = MessageBoxW(GDK_WINDOW_HWND(app->window->window), w_msg, w_title, t); + if (parent == NULL) + parent = app->window; + + rc = MessageBoxW(GDK_WINDOW_HWND(parent->window), w_msg, w_title, t); if (type == GTK_MESSAGE_QUESTION && rc != IDYES) ret = FALSE; diff --git a/src/win32.h b/src/win32.h index 3246c2fe..e8430f00 100644 --- a/src/win32.h +++ b/src/win32.h @@ -36,7 +36,7 @@ void win32_show_color_dialog(const gchar *colour); /* Creates a native Windows message box of the given type and returns always TRUE * or FALSE representing th pressed Yes or No button. * If type is not GTK_MESSAGE_QUESTION, it returns always TRUE. */ -gboolean win32_message_dialog(GtkMessageType type, const gchar *msg); +gboolean win32_message_dialog(GtkWidget *parent, GtkMessageType type, const gchar *msg); /* Special dialog to ask for an action when closing an unsaved file */ gint win32_message_dialog_unsaved(const gchar *msg);