From 9fe6b716f74708a2ede5ff41b38b6efccc82f747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Mon, 12 Dec 2005 02:23:51 +0000 Subject: [PATCH] made length of MRU list changeable git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@49 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- src/callbacks.c | 6 +++--- src/dialogs.c | 2 +- src/document.c | 4 ++-- src/geany.h | 5 +++-- src/interface.c | 23 +++++++++++++++++++++++ src/keyfile.c | 43 ++++++++++++++++++++++++++++--------------- src/prefs.c | 10 +++++++--- 7 files changed, 67 insertions(+), 26 deletions(-) diff --git a/src/callbacks.c b/src/callbacks.c index 3901d29d..23dcfeee 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -867,7 +867,7 @@ on_file_save_save_button_clicked (GtkButton *button, if (g_queue_find_custom(app->recent_queue, doc_list[idx].file_name, (GCompareFunc) strcmp) == NULL) { g_queue_push_head(app->recent_queue, g_strdup(doc_list[idx].file_name)); - if (g_queue_get_length(app->recent_queue) > GEANY_RECENT_MRU_LENGTH) + if (g_queue_get_length(app->recent_queue) > app->mru_length) { g_free(g_queue_pop_tail(app->recent_queue)); } @@ -1168,7 +1168,7 @@ on_editor_key_press_event (GtkWidget *widget, } /* following code is unusable unless I get a signal for a line changed, don't want to do this with * updateUI() - case GDK_End: +*/ case GDK_End: { // extending HOME and END default behaviour, for details look at the start of this function if (cursor_pos_end == -1 || current_line != sci_get_current_line(doc_list[idx].sci, -1)) { @@ -1183,7 +1183,7 @@ on_editor_key_press_event (GtkWidget *widget, } break; } - case GDK_Home: +/* case GDK_Home: { if (cursor_pos_home_state == 0 || current_line != sci_get_current_line(doc_list[idx].sci, -1)) { diff --git a/src/dialogs.c b/src/dialogs.c index 227eb485..f60469ed 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -551,7 +551,7 @@ void dialogs_create_recent_menu(void) gint i; gchar *filename; - for (i = (MIN(GEANY_RECENT_MRU_LENGTH, g_queue_get_length(app->recent_queue)) - 1); i >= 0; i--) + for (i = (MIN(app->mru_length, g_queue_get_length(app->recent_queue)) - 1); i >= 0; i--) { filename = g_queue_peek_nth(app->recent_queue, i); tmp = gtk_menu_item_new_with_label(filename); diff --git a/src/document.c b/src/document.c index a2a98622..71d099b0 100644 --- a/src/document.c +++ b/src/document.c @@ -176,7 +176,7 @@ gint document_create_new_sci(const gchar *filename) sci_use_popup(sci, FALSE); sci_set_codepage(sci, 1); sci_clear_cmdkey(sci, SCK_END); // disable to act on our own in callbacks.c - sci_clear_cmdkey(sci, SCK_HOME); + //sci_clear_cmdkey(sci, SCK_HOME); sci_set_mark_long_lines(sci, app->long_line_column, app->long_line_color); sci_set_symbol_margin(sci, app->show_markers_margin); //sci_set_lines_wrapped(sci, app->line_breaking); @@ -456,7 +456,7 @@ void document_open_file(gint idx, const gchar *filename, gint pos, gboolean read if (g_queue_find_custom(app->recent_queue, filename, (GCompareFunc) strcmp) == NULL) { g_queue_push_head(app->recent_queue, g_strdup(filename)); - if (g_queue_get_length(app->recent_queue) > GEANY_RECENT_MRU_LENGTH) + if (g_queue_get_length(app->recent_queue) > app->mru_length) { g_free(g_queue_pop_tail(app->recent_queue)); } diff --git a/src/geany.h b/src/geany.h index 381d407d..8c2a411d 100644 --- a/src/geany.h +++ b/src/geany.h @@ -57,8 +57,8 @@ #define GEANY_CODENAME "Tarkin" #define GEANY_HOMEPAGE "http://geany.uvena.de/" #define GEANY_MAX_OPEN_FILES 25 -#define GEANY_MRU_LENGTH 15 -#define GEANY_RECENT_MRU_LENGTH 10 +#define GEANY_SESSION_FILES 15 +//#define GEANY_RECENT_MRU_LENGTH 10 #define GEANY_MAX_TAGS_COUNT 1000 #define GEANY_WORDCHARS "_#&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" #define GEANY_MAX_AUTOCOMPLETE_WORDS 30 @@ -127,6 +127,7 @@ typedef struct MyApp gboolean pref_main_save_winpos; gboolean pref_main_confirm_exit; gboolean pref_main_show_search; + gint mru_length; gint long_line_column; gchar *long_line_color; gchar *pref_template_developer; diff --git a/src/interface.c b/src/interface.c index 1ea35baf..bcd9848e 100644 --- a/src/interface.c +++ b/src/interface.c @@ -1896,6 +1896,10 @@ create_prefs_dialog (void) GtkWidget *frame1; GtkWidget *alignment2; GtkWidget *vbox4; + GtkWidget *hbox2; + GtkWidget *label147; + GtkObject *spin_mru_adj; + GtkWidget *spin_mru; GtkWidget *check_load_session; GtkWidget *check_save_win_pos; GtkWidget *check_switch_pages; @@ -2060,6 +2064,22 @@ create_prefs_dialog (void) gtk_widget_show (vbox4); gtk_container_add (GTK_CONTAINER (alignment2), vbox4); + hbox2 = gtk_hbox_new (FALSE, 19); + gtk_widget_show (hbox2); + gtk_box_pack_start (GTK_BOX (vbox4), hbox2, FALSE, FALSE, 0); + + label147 = gtk_label_new (_("MRU list length")); + gtk_widget_show (label147); + gtk_box_pack_start (GTK_BOX (hbox2), label147, FALSE, FALSE, 0); + + spin_mru_adj = gtk_adjustment_new (4, 1, 50, 1, 10, 10); + spin_mru = gtk_spin_button_new (GTK_ADJUSTMENT (spin_mru_adj), 1, 0); + gtk_widget_show (spin_mru); + gtk_box_pack_start (GTK_BOX (hbox2), spin_mru, FALSE, TRUE, 0); + gtk_tooltips_set_tip (tooltips, spin_mru, _("Specifies the number of files which are stored in the Recent files list."), NULL); + gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spin_mru), TRUE); + gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spin_mru), TRUE); + check_load_session = gtk_check_button_new_with_mnemonic (_("Load files from the last session")); gtk_widget_show (check_load_session); gtk_box_pack_start (GTK_BOX (vbox4), check_load_session, FALSE, FALSE, 0); @@ -2821,6 +2841,9 @@ create_prefs_dialog (void) GLADE_HOOKUP_OBJECT (prefs_dialog, frame1, "frame1"); GLADE_HOOKUP_OBJECT (prefs_dialog, alignment2, "alignment2"); GLADE_HOOKUP_OBJECT (prefs_dialog, vbox4, "vbox4"); + GLADE_HOOKUP_OBJECT (prefs_dialog, hbox2, "hbox2"); + GLADE_HOOKUP_OBJECT (prefs_dialog, label147, "label147"); + GLADE_HOOKUP_OBJECT (prefs_dialog, spin_mru, "spin_mru"); GLADE_HOOKUP_OBJECT (prefs_dialog, check_load_session, "check_load_session"); GLADE_HOOKUP_OBJECT (prefs_dialog, check_save_win_pos, "check_save_win_pos"); GLADE_HOOKUP_OBJECT (prefs_dialog, check_switch_pages, "check_switch_pages"); diff --git a/src/keyfile.c b/src/keyfile.c index 5a297278..deb2abf1 100644 --- a/src/keyfile.c +++ b/src/keyfile.c @@ -31,7 +31,7 @@ static gchar *scribble_text = NULL; -static gchar *session_files[GEANY_MRU_LENGTH]; +static gchar *session_files[GEANY_SESSION_FILES]; static gint hpan_position; static gint vpan_position; @@ -44,7 +44,7 @@ void configuration_save(void) gchar *configfile = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, "geany.conf", NULL); gchar *entry = g_malloc(14); gchar *fname = g_malloc0(256); - gchar *recent_files[GEANY_RECENT_MRU_LENGTH] = { NULL }; + gchar **recent_files = g_new(gchar*, app->mru_length); GtkTextBuffer *buffer; GtkTextIter start, end; @@ -74,6 +74,7 @@ void configuration_save(void) gtk_paned_get_position(GTK_PANED(lookup_widget(app->window, "vpaned1")))); } + g_key_file_set_integer(config, PACKAGE, "mru_length", app->mru_length); g_key_file_set_integer(config, PACKAGE, "long_line_column", app->long_line_column); g_key_file_set_string(config, PACKAGE, "long_line_color", app->long_line_color); g_key_file_set_boolean(config, PACKAGE, "treeview_symbol_visible", app->treeview_symbol_visible); @@ -89,6 +90,8 @@ void configuration_save(void) g_key_file_set_boolean(config, PACKAGE, "switch_msgwin_pages", app->switch_msgwin_pages); g_key_file_set_boolean(config, PACKAGE, "auto_close_xml_tags", app->auto_close_xml_tags); g_key_file_set_boolean(config, PACKAGE, "auto_complete_constructs", app->auto_complete_constructs); + g_key_file_set_comment(config, PACKAGE, "terminal_settings", + _(" VTE settings: FONT;FOREGROUND;BACKGROUND;scrollback;type;scroll on keystroke;scroll on output"), NULL); g_key_file_set_string(config, PACKAGE, "terminal_settings", app->terminal_settings); g_key_file_set_string(config, PACKAGE, "editor_font", app->editor_font); g_key_file_set_string(config, PACKAGE, "tagbar_font", app->tagbar_font); @@ -118,19 +121,24 @@ void configuration_save(void) g_key_file_set_string(config, "build", "build_term_cmd", app->build_term_cmd ? app->build_term_cmd : ""); g_key_file_set_string(config, "build", "build_browser_cmd", app->build_browser_cmd ? app->build_browser_cmd : ""); - for (i = 0; i < GEANY_RECENT_MRU_LENGTH; i++) + for (i = 0; i < app->mru_length; i++) { if (! g_queue_is_empty(app->recent_queue)) { recent_files[i] = g_queue_pop_head(app->recent_queue); } + else + { + recent_files[i] = NULL; + } + } g_key_file_set_string_list(config, "files", "recent_files", - (const gchar**)recent_files, GEANY_RECENT_MRU_LENGTH); + (const gchar**)recent_files, app->mru_length); - // store the last 10(or what ever MRU_LENGTH is set to) filenames, to reopen the next time + // store the last 15(or what ever GEANY_SESSION_FILES is set to) filenames, to reopen the next time max = gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)); - for(i = 0; (i < max) && (j < GEANY_MRU_LENGTH); i++) + for(i = 0; (i < max) && (j < GEANY_SESSION_FILES); i++) { idx = document_get_n_idx(i); if (idx >= 0 && doc_list[idx].file_name) @@ -141,10 +149,10 @@ void configuration_save(void) j++; } } - // if open tabs less than MRU_LENGTH, delete existing saved entries in the list - if (max < GEANY_MRU_LENGTH) + // if open tabs less than GEANY_SESSION_FILES, delete existing saved entries in the list + if (max < GEANY_SESSION_FILES) { - for(i = max; i < GEANY_MRU_LENGTH; i++) + for(i = max; i < GEANY_SESSION_FILES; i++) { g_snprintf(entry, 13, "FILE_NAME_%d", i); g_key_file_set_string(config, "files", entry, ""); @@ -154,7 +162,8 @@ void configuration_save(void) // write the file utils_write_file(configfile, g_key_file_to_data(config, NULL, NULL)); - utils_free_ptr_array(recent_files, GEANY_RECENT_MRU_LENGTH); + utils_free_ptr_array(recent_files, app->mru_length); + g_free(recent_files); g_key_file_free(config); g_free(configfile); g_free(entry); @@ -168,7 +177,7 @@ gboolean configuration_load(void) gboolean config_exists; guint i, geo_len; gint *geo = g_malloc(sizeof(gint) * 4); - gsize len; + gsize len = 0; gchar *configfile = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, "geany.conf", NULL); gchar *entry = g_malloc(14); gchar *tmp_string, *tmp_string2; @@ -178,6 +187,7 @@ gboolean configuration_load(void) config_exists = g_key_file_load_from_file(config, configfile, G_KEY_FILE_KEEP_COMMENTS, NULL); app->toolbar_visible = utils_get_setting_boolean(config, PACKAGE, "toolbar_visible", TRUE); + app->mru_length = utils_get_setting_integer(config, PACKAGE, "mru_length", 10); app->toolbar_icon_style = utils_get_setting_integer(config, PACKAGE, "toolbar_icon_style", GTK_TOOLBAR_ICONS); app->toolbar_icon_size = utils_get_setting_integer(config, PACKAGE, "toolbar_icon_size", 2); app->long_line_color = utils_get_setting_string(config, PACKAGE, "long_line_color", "#C2EBC2"); @@ -227,7 +237,7 @@ gboolean configuration_load(void) app->pref_main_show_search = utils_get_setting_boolean(config, PACKAGE, "pref_main_show_search", TRUE); app->pref_template_developer = utils_get_setting_string(config, PACKAGE, "pref_template_developer", g_get_real_name()); app->pref_template_company = utils_get_setting_string(config, PACKAGE, "pref_template_company", ""); - app->terminal_settings = utils_get_setting_string(config, PACKAGE, "terminal_settings", "Monospace 10;;;500;xterm;true;true"); + app->terminal_settings = utils_get_setting_string(config, PACKAGE, "terminal_settings", ""); tmp_string = utils_get_initials(app->pref_template_developer); app->pref_template_initial = utils_get_setting_string(config, PACKAGE, "pref_template_initial", tmp_string); @@ -285,13 +295,15 @@ gboolean configuration_load(void) app->recent_files = g_key_file_get_string_list(config, "files", "recent_files", &len, NULL); if (app->recent_files != NULL) { - for (i = 0; (i < len) && (i < GEANY_RECENT_MRU_LENGTH); i++) + for (i = 0; (i < len) && (i < app->mru_length); i++) { g_queue_push_head(app->recent_queue, app->recent_files[i]); + app->recent_files[i] = NULL; } } + //geany_debug("%d", g_strv_length(app->recent_files)); - for(i = 0; i < GEANY_MRU_LENGTH; i++) + for(i = 0; i < GEANY_SESSION_FILES; i++) { g_snprintf(entry, 13, "FILE_NAME_%d", i); session_files[i] = g_key_file_get_string(config, "files", entry, &error); @@ -303,6 +315,7 @@ gboolean configuration_load(void) } } + utils_free_ptr_array(app->recent_files, len); g_key_file_free(config); g_free(configfile); g_free(entry); @@ -318,7 +331,7 @@ gboolean configuration_open_files(void) gchar *file, spos[7]; gboolean ret = FALSE; - for(i = GEANY_MRU_LENGTH - 1; i >= 0 ; i--) + for(i = GEANY_SESSION_FILES - 1; i >= 0 ; i--) { if (session_files[i] && strlen(session_files[i])) { diff --git a/src/prefs.c b/src/prefs.c index 57df37c1..03d8ff3b 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -44,6 +44,9 @@ void prefs_init_dialog(void) GdkColor *color; // General settings + widget = lookup_widget(app->prefs_dialog, "spin_mru"); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), app->mru_length); + widget = lookup_widget(app->prefs_dialog, "check_load_session"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_main_load_session); @@ -188,6 +191,9 @@ void on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_dat GtkWidget *widget; // General settings + widget = lookup_widget(app->prefs_dialog, "spin_mru"); + app->mru_length = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); + widget = lookup_widget(app->prefs_dialog, "check_load_session"); app->pref_main_load_session = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); @@ -301,9 +307,7 @@ void on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_dat hex_color_fore = utils_get_hex_from_color(vc->color_fore); hex_color_back = utils_get_hex_from_color(vc->color_back); app->terminal_settings = g_strdup_printf("%s;%s;%s;%d;%s;%s;%s", vc->font, - //(vc->color_fore->red | (vc->color_fore->green << 8) | (vc->color_fore->blue << 16)), - //(vc->color_back->red | (vc->color_back->green << 8) | (vc->color_back->blue << 16)), - hex_color_back, hex_color_fore, + hex_color_fore, hex_color_back, vc->scrollback_lines, vc->emulation, utils_btoa(vc->scroll_on_key), utils_btoa(vc->scroll_on_out));