From 902379738b598992d4cb2358dd1fef24ba44314a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Tue, 25 Jul 2006 12:46:08 +0000 Subject: [PATCH] Removed some unneeded functions to avoid duplicate code. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@629 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 6 ++++ src/callbacks.c | 4 ++- src/dialogs.c | 95 +++++++------------------------------------------ src/dialogs.h | 8 +---- src/document.c | 14 +++++--- src/main.c | 16 ++++++--- 6 files changed, 44 insertions(+), 99 deletions(-) diff --git a/ChangeLog b/ChangeLog index 56229219..9bcc4212 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,12 @@ * src/encodings.c, src/document.c, src/keyfile.c, src/main.c: Save default encoding for new files as charset string. * src/filetypes.c: Reordered the filetypes (just a cosmetic change). + * src/win32.c, src/utils.c: + Removed title argument from win32_message_dialog because it is + defined by the dialog type. + Added simple wrapper function win32_open_browser(). + * src/dialogs.c, src/main.c, src/document.c, src/callbacks.c: + Removed some unneeded functions to avoid duplicate code. 2006-07-24 Enrico Tröger diff --git a/src/callbacks.c b/src/callbacks.c index 8c58ea29..ceae99a9 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -848,7 +848,9 @@ on_file_open_dialog_response (GtkDialog *dialog, } else { - dialogs_show_file_open_error(); + dialogs_show_error( + _("You have opened too many files. There is a limit of %d concurrent open files."), + GEANY_MAX_OPEN_FILES); g_slist_foreach(flist, (GFunc)g_free, NULL); break; } diff --git a/src/dialogs.c b/src/dialogs.c index 1dcafae2..fb7010b7 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -42,9 +42,7 @@ #include "win32.h" #include "sciwrappers.h" #include "support.h" -//#include "interface.h" #include "utils.h" -#include "prefs.h" #include "keybindings.h" @@ -148,7 +146,9 @@ void dialogs_show_open_file () } else { - dialogs_show_file_open_error(); + dialogs_show_error( + _("You have opened too many files. There is a limit of %d concurrent open files."), + GEANY_MAX_OPEN_FILES); } } @@ -157,7 +157,7 @@ void dialogs_show_open_file () void dialogs_show_save_as () { #ifdef GEANY_WIN32 - win32_show_file_dialog(FALSE); + win32_show_file_dialog(FALSE); #else gint idx = document_get_cur_idx(); @@ -212,53 +212,6 @@ void dialogs_show_save_as () } - -void dialogs_show_file_open_error(void) -{ - /// TODO rewrite the messages - gchar *pri = g_strdup_printf(_("There is a limit of %d concurrent open tabs."), GEANY_MAX_OPEN_FILES); - gchar *sec = _("error: too many open files"); -#ifdef GEANY_WIN32 - win32_message_dialog(GTK_MESSAGE_INFO, sec, pri); -#else - GtkWidget *dialog; - - dialog = gtk_message_dialog_new(GTK_WINDOW(app->window), GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, sec); - gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), pri); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); -#endif - g_free(pri); -} - - -/// TODO replace by dialogs_show_question -gboolean dialogs_show_not_found(const gchar *text) -{ - GtkWidget *dialog; - gchar *string; - gint ret; - - string = g_strdup_printf(_("The match \"%s\" was not found. Wrap search around the document?"), text); -#ifdef GEANY_WIN32 - dialog = NULL; - ret = MessageBox(NULL, string, _("Question"), MB_YESNO | MB_ICONWARNING); - g_free(string); - if (ret == IDYES) return TRUE; - else return FALSE; -#else - dialog = gtk_message_dialog_new(GTK_WINDOW(app->window), GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "%s", string); - g_free(string); - ret = gtk_dialog_run(GTK_DIALOG (dialog)); - gtk_widget_destroy(dialog); - if (ret == GTK_RESPONSE_YES) return TRUE; - else return FALSE; -#endif -} - - void dialogs_show_info(const gchar *text, ...) { #ifndef GEANY_WIN32 @@ -272,11 +225,11 @@ void dialogs_show_info(const gchar *text, ...) va_end(args); #ifdef GEANY_WIN32 - win32_message_dialog(GTK_MESSAGE_INFO, _("Information"), string); + win32_message_dialog(GTK_MESSAGE_INFO, string); #else dialog = gtk_message_dialog_new(GTK_WINDOW(app->window), GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_INFO, GTK_BUTTONS_OK, string); + GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "%s", string); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); #endif @@ -297,10 +250,10 @@ void dialogs_show_error(const gchar *text, ...) va_end(args); #ifdef GEANY_WIN32 - win32_message_dialog(GTK_MESSAGE_ERROR, _("Error"), string); + win32_message_dialog(GTK_MESSAGE_ERROR, string); #else dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, string); + GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", string); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); #endif @@ -329,10 +282,10 @@ gboolean dialogs_show_unsaved_file(gint idx) msg = g_strdup(_("The file is not saved.\nDo you want to save it before closing?")); } #ifdef GEANY_WIN32 - ret = win32_message_dialog_unsaved(_("Error"), msg); + ret = win32_message_dialog_unsaved(msg); #else dialog = gtk_message_dialog_new(GTK_WINDOW(app->window), GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, msg); + GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, "%s", msg); gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); @@ -1378,30 +1331,6 @@ GtkWidget *dialogs_add_file_open_extra_widget(void) } -/// TODO remove this function and use dialogs_show_question instead -gboolean dialogs_show_mkcfgdir_error(gint error_nr) -{ -#ifndef GEANY_WIN32 - GtkWidget *dialog; -#endif - gchar string[255]; - gint ret; - - snprintf(string, 255, _("Configuration directory could not be created (%s).\nThere could be some problems using %s without a configuration directory.\nStart %s anyway?"), - g_strerror(error_nr), PACKAGE, PACKAGE); -#ifdef GEANY_WIN32 - ret = win32_message_dialog(GTK_MESSAGE_ERROR, _("Error"), string); -#else - dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, GTK_BUTTONS_YES_NO, string); - ret = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - if (ret == GTK_RESPONSE_YES) return TRUE; - else return FALSE; -#endif -} - - void dialogs_show_file_properties(gint idx) { GtkWidget *dialog, *label, *table, *hbox, *image, *perm_table, *check; @@ -1779,10 +1708,10 @@ gboolean dialogs_show_question(const gchar *text, ...) va_end(args); #ifdef GEANY_WIN32 - ret = win32_message_dialog(GTK_MESSAGE_QUESTION, _("Question"), string); + ret = win32_message_dialog(GTK_MESSAGE_QUESTION, string); #else dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, string); + GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "%s", string); if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_YES) ret = TRUE; gtk_widget_destroy(dialog); diff --git a/src/dialogs.h b/src/dialogs.h index f38dba47..a9d55a05 100644 --- a/src/dialogs.h +++ b/src/dialogs.h @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * $Id$ */ @@ -30,10 +30,6 @@ void dialogs_show_open_file(void); /* This shows the file selection dialog to save a file. */ void dialogs_show_save_as(); -void dialogs_show_file_open_error(void); - -gboolean dialogs_show_not_found(const gchar *text); - void dialogs_show_info(const gchar *text, ...); void dialogs_show_error(const gchar *text, ...); @@ -69,8 +65,6 @@ void dialogs_create_recent_menu(void); GtkWidget *dialogs_add_file_open_extra_widget(void); -gboolean dialogs_show_mkcfgdir_error(gint error_nr); - void dialogs_show_file_properties(gint idx); gboolean dialogs_show_question(const gchar *text, ...); diff --git a/src/document.c b/src/document.c index eb4b9a4d..f996d5cb 100644 --- a/src/document.c +++ b/src/document.c @@ -348,7 +348,9 @@ void document_new_file(filetype *ft) if (idx == -1) { - dialogs_show_file_open_error(); + dialogs_show_error( + _("You have opened too many files. There is a limit of %d concurrent open files."), + GEANY_MAX_OPEN_FILES); return; } @@ -377,7 +379,9 @@ void document_new_file(filetype *ft) } else { - dialogs_show_file_open_error(); + dialogs_show_error( + _("You have opened too many files. There is a limit of %d concurrent open files."), + GEANY_MAX_OPEN_FILES); } } @@ -799,6 +803,8 @@ void document_save_file(gint idx) } +#define SEARCH_NOT_FOUND_TXT _("The match \"%s\" was not found. Wrap search around the document?") + /* special search function, used from the find entry in the toolbar */ void document_find_next(gint idx, const gchar *text, gint flags, gboolean find_button, gboolean inc) { @@ -823,7 +829,7 @@ void document_find_next(gint idx, const gchar *text, gint flags, gboolean find_b { if (find_button) { - if (dialogs_show_not_found(text)) + if (dialogs_show_question(SEARCH_NOT_FOUND_TXT, text)) { sci_goto_pos(doc_list[idx].sci, 0, FALSE); document_find_next(idx, text, flags, TRUE, inc); @@ -872,7 +878,7 @@ gint document_find_text(gint idx, const gchar *text, gint flags, gboolean search } else { - if (dialogs_show_not_found(text)) + if (dialogs_show_question(SEARCH_NOT_FOUND_TXT, text)) { sci_goto_pos(doc_list[idx].sci, (search_backwards) ? sci_get_length(doc_list[idx].sci) : 0, TRUE); return document_find_text(idx, text, flags, search_backwards); diff --git a/src/main.c b/src/main.c index a6f7f548..548f45cf 100644 --- a/src/main.c +++ b/src/main.c @@ -491,10 +491,16 @@ gint main(gint argc, gchar **argv) else config_dir = g_strconcat(GEANY_HOME_DIR, G_DIR_SEPARATOR_S, ".", PACKAGE, NULL); mkdir_result = utils_make_settings_dir(config_dir); - if (mkdir_result != 0 && ! dialogs_show_mkcfgdir_error(mkdir_result)) + if (mkdir_result != 0) { - g_free(config_dir); - return (0); + if (! dialogs_show_question( + _("Configuration directory could not be created (%s).\nThere could be some problems " + "using %s without a configuration directory.\nStart %s anyway?"), + g_strerror(mkdir_result), PACKAGE, PACKAGE)) + { + g_free(config_dir); + return (0); + } } #ifdef HAVE_FIFO @@ -573,7 +579,9 @@ gint main(gint argc, gchar **argv) } else { - dialogs_show_file_open_error(); + dialogs_show_error( + _("You have opened too many files. There is a limit of %d concurrent open files."), + GEANY_MAX_OPEN_FILES); break; } }