From f375a6be68d556bc97a44e12c1b0a789d2c00f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Wed, 21 Jun 2006 18:54:07 +0000 Subject: [PATCH] Added missing shortcut for "Close". Added option in the preferences dialog to replace tabs by spaces when saving a file. Added option for default encoding for new files. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@470 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 10 ++++++ geany.glade | 83 +++++++++++++++++++++++++++++++++++++++++++---- src/dialogs.c | 14 ++++++++ src/document.c | 13 ++++++-- src/encodings.c | 11 +++---- src/encodings.h | 5 ++- src/geany.h | 2 ++ src/interface.c | 38 ++++++++++++++++++++-- src/keybindings.c | 9 +++++ src/keybindings.h | 1 + src/keyfile.c | 7 +++- src/prefs.c | 13 ++++++++ 12 files changed, 186 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 04fa065a..30744062 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2006-06-21 Enrico Troeger + + * src/keybindings.c: Added missing shortcut for "Close". + * geany.glade, src/interface.c, src/prefs.c, src/keyfile.c, + src/document.c, src/dialogs.c, src/encodings.h: + Added option in the preferences dialog to replace tabs by spaces + when saving a file. + Added option for default encoding for new files. + + 2006-06-20 Nick Treleaven * src/utils.c, src/utils.h, src/callbacks.c, src/document.c, diff --git a/geany.glade b/geany.glade index aa004188..e44af1a2 100644 --- a/geany.glade +++ b/geany.glade @@ -3136,14 +3136,66 @@ True False - 0 + 3 - - + + True + False + 12 - - + + + True + Default encoding: + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + Sets the default encoding for newly created files. + True + False + + + + True + False + True + + + + + 0 + False + False + + + + + 0 + False + True + @@ -3208,7 +3260,7 @@ 0 - False + True True @@ -3309,6 +3361,25 @@ False + + + + True + Replaces all tabs in document by spaces. + Replace tabs by space + True + GTK_RELIEF_NORMAL + False + False + False + True + + + 0 + False + False + + diff --git a/src/dialogs.c b/src/dialogs.c index 19a8dce6..0f828274 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -46,6 +46,7 @@ #include "utils.h" #include "prefs.h" #include "keybindings.h" +#include "encodings.h" @@ -1647,10 +1648,23 @@ void dialogs_show_prefs_dialog(void) GtkTooltips *tooltips; GtkObject *spin_scrollback_adj; #endif + GtkWidget *combo; + guint i; + gchar *encoding_string; app->prefs_dialog = create_prefs_dialog(); gtk_window_set_transient_for(GTK_WINDOW(app->prefs_dialog), GTK_WINDOW(app->window)); + // init the default file encoding combo box + combo = lookup_widget(app->prefs_dialog, "combo_encoding"); + gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(combo), 3); + for (i = 0; i < GEANY_ENCODINGS_MAX; i++) + { + encoding_string = encodings_to_string(&encodings[i]); + gtk_combo_box_append_text(GTK_COMBO_BOX(combo), encoding_string); + g_free(encoding_string); + } + #ifdef HAVE_VTE if (app->have_vte) { diff --git a/src/document.c b/src/document.c index 313cda7a..bf7f9ab8 100644 --- a/src/document.c +++ b/src/document.c @@ -52,6 +52,7 @@ #include "templates.h" #include "treeviews.h" #include "utils.h" +#include "encodings.h" @@ -372,7 +373,8 @@ void document_new_file(filetype *ft) sci_set_text(doc_list[idx].sci, template); g_free(template); - doc_list[idx].encoding = g_strdup("UTF-8"); + doc_list[idx].encoding = g_strdup( + encodings_get_charset(&encodings[app->pref_editor_default_encoding])); document_set_filetype(idx, ft); utils_set_window_title(idx); utils_build_show_hide(idx); @@ -619,6 +621,8 @@ void document_save_file(gint idx) return; } + // replaces tabs by spaces + if (app->pref_editor_replace_tabs) utils_replace_tabs(idx); // strip trailing spaces if (app->pref_editor_trail_space) utils_strip_trailing_spaces(idx); // ensure the file has a newline at the end @@ -642,8 +646,13 @@ void document_save_file(gint idx) if (conv_error != NULL) { - g_error_free(conv_error); geany_debug("error while converting the file to its orinial encoding"); + geany_debug("encoding: %s error message: %s)", + doc_list[idx].encoding, conv_error->message); + g_free(doc_list[idx].encoding); + doc_list[idx].encoding = g_strdup("UTF-8"); + msgwin_status_add(_("Error while converting file (%s)."), conv_error->message); + g_error_free(conv_error); } else { diff --git a/src/encodings.c b/src/encodings.c index 051077ac..5d8a8d88 100644 --- a/src/encodings.c +++ b/src/encodings.c @@ -57,7 +57,6 @@ static void init_encodings(void) fill(GEANY_ENCODING_ISO_8859_15, "ISO-8859-15", "Western"); fill(GEANY_ENCODING_ISO_8859_16, "ISO-8859-16", "Romanian"); - fill(GEANY_ENCODING_UTF_7, "UTF-7", "Unicode"); fill(GEANY_ENCODING_UTF_8, "UTF-8", "Unicode"); fill(GEANY_ENCODING_UTF_16, "UTF-16", "Unicode"); fill(GEANY_ENCODING_UCS_2, "UCS-2", "Unicode"); @@ -118,10 +117,10 @@ static void encodings_lazy_init(void) if (initialized) return; - g_return_if_fail(G_N_ELEMENTS(encodings) == GEANY_ENCODING_LAST); + g_return_if_fail(G_N_ELEMENTS(encodings) == GEANY_ENCODINGS_MAX); i = 0; - while (i < GEANY_ENCODING_LAST) + while (i < GEANY_ENCODINGS_MAX) { g_return_if_fail(encodings[i].idx == i); @@ -142,7 +141,7 @@ const GeanyEncoding *encodings_get_from_charset(const gchar *charset) encodings_lazy_init (); i = 0; - while (i < GEANY_ENCODING_LAST) + while (i < GEANY_ENCODINGS_MAX) { if (strcmp(charset, encodings[i].charset) == 0) return &encodings[i]; @@ -158,7 +157,7 @@ const GeanyEncoding *encodings_get_from_index(gint index) { g_return_val_if_fail(index >= 0, NULL); - if (index >= GEANY_ENCODING_LAST) + if (index >= GEANY_ENCODINGS_MAX) return NULL; encodings_lazy_init(); @@ -236,7 +235,7 @@ void encodings_init(void) // create encodings submenu in document menu menu = lookup_widget(app->window, "set_encoding1_menu"); - while (i < GEANY_ENCODING_LAST) + while (i < GEANY_ENCODINGS_MAX) { if (encodings[i].idx != i) break; diff --git a/src/encodings.h b/src/encodings.h index 4f8c361d..04db09b9 100644 --- a/src/encodings.h +++ b/src/encodings.h @@ -78,7 +78,6 @@ typedef enum GEANY_ENCODING_ISO_8859_15, GEANY_ENCODING_ISO_8859_16, - GEANY_ENCODING_UTF_7, GEANY_ENCODING_UTF_8, GEANY_ENCODING_UTF_16, GEANY_ENCODING_UCS_2, @@ -129,11 +128,11 @@ typedef enum GEANY_ENCODING_WINDOWS_1257, GEANY_ENCODING_WINDOWS_1258, - GEANY_ENCODING_LAST + GEANY_ENCODINGS_MAX } GeanyEncodingIndex; -GeanyEncoding encodings[GEANY_ENCODING_LAST]; +GeanyEncoding encodings[GEANY_ENCODINGS_MAX]; #endif diff --git a/src/geany.h b/src/geany.h index 0e1ca6e4..918d8036 100644 --- a/src/geany.h +++ b/src/geany.h @@ -147,7 +147,9 @@ typedef struct MyApp gboolean pref_editor_auto_complete_constructs; gboolean pref_editor_folding; gint pref_editor_tab_width; + gint pref_editor_default_encoding; gboolean pref_editor_new_line; + gboolean pref_editor_replace_tabs; gboolean pref_editor_trail_space; gboolean pref_main_load_session; gboolean pref_main_save_winpos; diff --git a/src/interface.c b/src/interface.c index 4f733c34..633c876f 100644 --- a/src/interface.c +++ b/src/interface.c @@ -1830,6 +1830,10 @@ create_prefs_dialog (void) GtkWidget *frame6; GtkWidget *alignment7; GtkWidget *vbox8; + GtkWidget *hbox4; + GtkWidget *label153; + GtkWidget *eventbox1; + GtkWidget *combo_encoding; GtkWidget *table5; GtkWidget *label116; GtkObject *spin_tab_width_adj; @@ -1840,6 +1844,7 @@ create_prefs_dialog (void) GtkWidget *vbox6; GtkWidget *check_trailing_spaces; GtkWidget *check_new_line; + GtkWidget *check_replace_tabs; GtkWidget *label19; GtkWidget *frame5; GtkWidget *alignment6; @@ -2174,13 +2179,30 @@ create_prefs_dialog (void) gtk_container_add (GTK_CONTAINER (frame6), alignment7); gtk_alignment_set_padding (GTK_ALIGNMENT (alignment7), 0, 0, 12, 0); - vbox8 = gtk_vbox_new (FALSE, 0); + vbox8 = gtk_vbox_new (FALSE, 3); gtk_widget_show (vbox8); gtk_container_add (GTK_CONTAINER (alignment7), vbox8); + hbox4 = gtk_hbox_new (FALSE, 12); + gtk_widget_show (hbox4); + gtk_box_pack_start (GTK_BOX (vbox8), hbox4, FALSE, TRUE, 0); + + label153 = gtk_label_new (_("Default encoding:")); + gtk_widget_show (label153); + gtk_box_pack_start (GTK_BOX (hbox4), label153, FALSE, FALSE, 0); + + eventbox1 = gtk_event_box_new (); + gtk_widget_show (eventbox1); + gtk_box_pack_start (GTK_BOX (hbox4), eventbox1, FALSE, FALSE, 0); + gtk_tooltips_set_tip (tooltips, eventbox1, _("Sets the default encoding for newly created files."), NULL); + + combo_encoding = gtk_combo_box_new_text (); + gtk_widget_show (combo_encoding); + gtk_container_add (GTK_CONTAINER (eventbox1), combo_encoding); + table5 = gtk_table_new (1, 2, FALSE); gtk_widget_show (table5); - gtk_box_pack_start (GTK_BOX (vbox8), table5, FALSE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox8), table5, TRUE, TRUE, 0); gtk_table_set_row_spacings (GTK_TABLE (table5), 3); gtk_table_set_col_spacings (GTK_TABLE (table5), 25); @@ -2235,6 +2257,13 @@ create_prefs_dialog (void) gtk_tooltips_set_tip (tooltips, check_new_line, _("Ensures that at the end of the file is a new line"), NULL); gtk_button_set_focus_on_click (GTK_BUTTON (check_new_line), FALSE); + check_replace_tabs = gtk_check_button_new_with_mnemonic (_("Replace tabs by space")); + gtk_widget_show (check_replace_tabs); + gtk_box_pack_start (GTK_BOX (vbox6), check_replace_tabs, FALSE, FALSE, 0); + GTK_WIDGET_UNSET_FLAGS (check_replace_tabs, GTK_CAN_FOCUS); + gtk_tooltips_set_tip (tooltips, check_replace_tabs, _("Replaces all tabs in document by spaces."), NULL); + gtk_button_set_focus_on_click (GTK_BUTTON (check_replace_tabs), FALSE); + label19 = gtk_label_new (_("Saving files")); gtk_widget_show (label19); gtk_frame_set_label_widget (GTK_FRAME (frame2), label19); @@ -2645,6 +2674,10 @@ create_prefs_dialog (void) GLADE_HOOKUP_OBJECT (prefs_dialog, frame6, "frame6"); GLADE_HOOKUP_OBJECT (prefs_dialog, alignment7, "alignment7"); GLADE_HOOKUP_OBJECT (prefs_dialog, vbox8, "vbox8"); + GLADE_HOOKUP_OBJECT (prefs_dialog, hbox4, "hbox4"); + GLADE_HOOKUP_OBJECT (prefs_dialog, label153, "label153"); + GLADE_HOOKUP_OBJECT (prefs_dialog, eventbox1, "eventbox1"); + GLADE_HOOKUP_OBJECT (prefs_dialog, combo_encoding, "combo_encoding"); GLADE_HOOKUP_OBJECT (prefs_dialog, table5, "table5"); GLADE_HOOKUP_OBJECT (prefs_dialog, label116, "label116"); GLADE_HOOKUP_OBJECT (prefs_dialog, spin_tab_width, "spin_tab_width"); @@ -2654,6 +2687,7 @@ create_prefs_dialog (void) GLADE_HOOKUP_OBJECT (prefs_dialog, vbox6, "vbox6"); GLADE_HOOKUP_OBJECT (prefs_dialog, check_trailing_spaces, "check_trailing_spaces"); GLADE_HOOKUP_OBJECT (prefs_dialog, check_new_line, "check_new_line"); + GLADE_HOOKUP_OBJECT (prefs_dialog, check_replace_tabs, "check_replace_tabs"); GLADE_HOOKUP_OBJECT (prefs_dialog, label19, "label19"); GLADE_HOOKUP_OBJECT (prefs_dialog, frame5, "frame5"); GLADE_HOOKUP_OBJECT (prefs_dialog, alignment6, "alignment6"); diff --git a/src/keybindings.c b/src/keybindings.c index b085923e..851d2303 100644 --- a/src/keybindings.c +++ b/src/keybindings.c @@ -47,6 +47,7 @@ static void cb_func_menu_new(void); static void cb_func_menu_open(void); static void cb_func_menu_save(void); static void cb_func_menu_saveall(void); +static void cb_func_menu_close(void); static void cb_func_menu_closeall(void); static void cb_func_menu_reloadfile(void); static void cb_func_menu_undo(void); @@ -110,6 +111,8 @@ void keybindings_init(void) GDK_s, GDK_CONTROL_MASK, "menu_save", _("Save")); keys[GEANY_KEYS_MENU_SAVEALL] = fill(cb_func_menu_saveall, GDK_S, GDK_SHIFT_MASK | GDK_CONTROL_MASK, "menu_saveall", _("Save all")); + keys[GEANY_KEYS_MENU_CLOSE] = fill(cb_func_menu_close, + GDK_w, GDK_CONTROL_MASK, "menu_close", _("Close")); keys[GEANY_KEYS_MENU_CLOSEALL] = fill(cb_func_menu_closeall, GDK_d, GDK_MOD1_MASK, "menu_closeall", _("Close all")); keys[GEANY_KEYS_MENU_RELOADFILE] = fill(cb_func_menu_reloadfile, @@ -234,6 +237,7 @@ static void keybindings_add_accels() // apply the settings GEANY_ADD_ACCEL(GEANY_KEYS_MENU_SAVEALL, menu_save_all1); + GEANY_ADD_ACCEL(GEANY_KEYS_MENU_CLOSE, menu_close1); GEANY_ADD_ACCEL(GEANY_KEYS_MENU_CLOSEALL, menu_close_all1); GEANY_ADD_ACCEL(GEANY_KEYS_MENU_RELOADFILE, revert1); GEANY_ADD_ACCEL(GEANY_KEYS_MENU_UNDO, menu_undo2); @@ -378,6 +382,11 @@ static void cb_func_menu_saveall(void) on_save_all1_activate(NULL, NULL); } +static void cb_func_menu_close(void) +{ + on_close1_activate(NULL, NULL); +} + static void cb_func_menu_closeall(void) { on_close_all1_activate(NULL, NULL); diff --git a/src/keybindings.h b/src/keybindings.h index 85d93ea3..0d6d0da3 100644 --- a/src/keybindings.h +++ b/src/keybindings.h @@ -45,6 +45,7 @@ enum GEANY_KEYS_MENU_OPEN, GEANY_KEYS_MENU_SAVE, GEANY_KEYS_MENU_SAVEALL, + GEANY_KEYS_MENU_CLOSE, GEANY_KEYS_MENU_CLOSEALL, GEANY_KEYS_MENU_RELOADFILE, GEANY_KEYS_MENU_UNDO, diff --git a/src/keyfile.c b/src/keyfile.c index 519e4b1e..97f7232e 100644 --- a/src/keyfile.c +++ b/src/keyfile.c @@ -116,12 +116,14 @@ void configuration_save(void) g_key_file_set_integer_list(config, PACKAGE, "geometry", app->geometry, 4); } g_key_file_set_integer(config, PACKAGE, "pref_editor_tab_width", app->pref_editor_tab_width); + g_key_file_set_integer(config, PACKAGE, "pref_editor_default_encoding", app->pref_editor_default_encoding); g_key_file_set_boolean(config, PACKAGE, "pref_main_confirm_exit", app->pref_main_confirm_exit); g_key_file_set_boolean(config, PACKAGE, "pref_main_load_session", app->pref_main_load_session); g_key_file_set_boolean(config, PACKAGE, "pref_main_save_winpos", app->pref_main_save_winpos); g_key_file_set_boolean(config, PACKAGE, "pref_main_show_search", app->pref_main_show_search); g_key_file_set_boolean(config, PACKAGE, "pref_main_show_goto", app->pref_main_show_goto); g_key_file_set_boolean(config, PACKAGE, "pref_editor_new_line", app->pref_editor_new_line); + g_key_file_set_boolean(config, PACKAGE, "pref_editor_replace_tabs", app->pref_editor_replace_tabs); g_key_file_set_boolean(config, PACKAGE, "pref_editor_trail_space", app->pref_editor_trail_space); g_key_file_set_string(config, PACKAGE, "pref_template_developer", app->pref_template_developer); g_key_file_set_string(config, PACKAGE, "pref_template_company", app->pref_template_company); @@ -221,7 +223,7 @@ gboolean configuration_load(void) app->fullscreen = utils_get_setting_boolean(config, PACKAGE, "fullscreen", FALSE); app->tab_order_ltr = utils_get_setting_boolean(config, PACKAGE, "tab_order_ltr", FALSE); app->brace_match_ltgt = utils_get_setting_boolean(config, PACKAGE, "brace_match_ltgt", FALSE); - app->switch_msgwin_pages = utils_get_setting_boolean(config, PACKAGE, "switch_msgwin_pages", TRUE); + app->switch_msgwin_pages = utils_get_setting_boolean(config, PACKAGE, "switch_msgwin_pages", FALSE); app->pref_editor_auto_close_xml_tags = utils_get_setting_boolean(config, PACKAGE, "auto_close_xml_tags", TRUE); app->pref_editor_auto_complete_constructs = utils_get_setting_boolean(config, PACKAGE, "auto_complete_constructs", TRUE); app->editor_font = utils_get_setting_string(config, PACKAGE, "editor_font", "Courier New 9"); @@ -251,6 +253,8 @@ gboolean configuration_load(void) app->pref_editor_tab_width = utils_get_setting_integer(config, PACKAGE, "pref_editor_tab_width", 4); + // set default encoding to UTF8 (Unicode) - index 15 + app->pref_editor_default_encoding = utils_get_setting_integer(config, PACKAGE, "pref_editor_default_encoding", 15); app->pref_main_confirm_exit = utils_get_setting_boolean(config, PACKAGE, "pref_main_confirm_exit", TRUE); app->pref_main_load_session = utils_get_setting_boolean(config, PACKAGE, "pref_main_load_session", TRUE); app->pref_main_save_winpos = utils_get_setting_boolean(config, PACKAGE, "pref_main_save_winpos", TRUE); @@ -274,6 +278,7 @@ gboolean configuration_load(void) g_free(tmp_string); g_free(tmp_string2); + app->pref_editor_replace_tabs = utils_get_setting_boolean(config, PACKAGE, "pref_editor_replace_tabs", FALSE); app->pref_editor_new_line = utils_get_setting_boolean(config, PACKAGE, "pref_editor_new_line", TRUE); app->pref_editor_trail_space = utils_get_setting_boolean(config, PACKAGE, "pref_editor_trail_space", TRUE); diff --git a/src/prefs.c b/src/prefs.c index 78e010e1..8e165523 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -115,12 +115,19 @@ void prefs_init_dialog(void) gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), app->pref_editor_tab_width); old_tab_width = app->pref_editor_tab_width; + widget = lookup_widget(app->prefs_dialog, "combo_encoding"); + // luckily the index of the combo box items match the index of the encodings array + gtk_combo_box_set_active(GTK_COMBO_BOX(widget), app->pref_editor_default_encoding); + widget = lookup_widget(app->prefs_dialog, "check_trailing_spaces"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_editor_trail_space); widget = lookup_widget(app->prefs_dialog, "check_new_line"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_editor_new_line); + widget = lookup_widget(app->prefs_dialog, "check_replace_tabs"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_editor_replace_tabs); + widget = lookup_widget(app->prefs_dialog, "check_indent"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_editor_show_indent_guide); @@ -323,12 +330,18 @@ void on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_dat widget = lookup_widget(app->prefs_dialog, "spin_tab_width"); app->pref_editor_tab_width = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); + widget = lookup_widget(app->prefs_dialog, "combo_encoding"); + app->pref_editor_default_encoding = gtk_combo_box_get_active(GTK_COMBO_BOX(widget)); + widget = lookup_widget(app->prefs_dialog, "check_trailing_spaces"); app->pref_editor_trail_space = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); widget = lookup_widget(app->prefs_dialog, "check_new_line"); app->pref_editor_new_line = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); + widget = lookup_widget(app->prefs_dialog, "check_replace_tabs"); + app->pref_editor_replace_tabs = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); + widget = lookup_widget(app->prefs_dialog, "spin_long_line"); app->long_line_column = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));