From b89a1bd6f2ca16055a68fb2b262b4d231297e16e Mon Sep 17 00:00:00 2001 From: Moritz Bruder Date: Tue, 18 Apr 2017 04:52:36 +0200 Subject: Run dialog: Fix wrong history len with max size 1 In a special case where the history size was 1, the actual history saved had length 2. In addition history is always written with new entries. One could also connect a signal to the max size property to force writing history (i.e., to shorten it). --- mate-panel/panel-run-dialog.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/mate-panel/panel-run-dialog.c b/mate-panel/panel-run-dialog.c index d867ed58..fc95d256 100644 --- a/mate-panel/panel-run-dialog.c +++ b/mate-panel/panel-run-dialog.c @@ -155,31 +155,30 @@ _panel_run_save_recent_programs_list (PanelRunDialog *dialog, history_max_size = g_settings_get_uint (dialog->settings, PANEL_RUN_HISTORY_MAX_SIZE_KEY); + items = g_array_new (TRUE, TRUE, sizeof (gchar *)); if (history_max_size > 0) { - items = g_array_new (TRUE, TRUE, sizeof (gchar *)); g_array_append_val (items, lastcommand); i++; model = gtk_combo_box_get_model (GTK_COMBO_BOX (entry)); - if (gtk_tree_model_get_iter_first (model, &iter)) { - char *command; - do { - gtk_tree_model_get (model, &iter, 0, &command, -1); - if (g_strcmp0 (command, lastcommand) == 0) - continue; - g_array_append_val (items, command); - i++; - } while (gtk_tree_model_iter_next (model, &iter) && - i < history_max_size); + if (history_max_size > 1) { + if (gtk_tree_model_get_iter_first (model, &iter)) { + char *command; + do { + gtk_tree_model_get (model, &iter, 0, &command, -1); + if (g_strcmp0 (command, lastcommand) == 0) + continue; + g_array_append_val (items, command); + i++; + } while (gtk_tree_model_iter_next (model, &iter) && + i < history_max_size); + } } - - g_settings_set_strv (dialog->settings, PANEL_RUN_HISTORY_KEY, - (const gchar **) items->data); - - g_array_free (items, TRUE); - } + g_settings_set_strv (dialog->settings, PANEL_RUN_HISTORY_KEY, + (const gchar **) items->data); + g_array_free (items, TRUE); } static void -- cgit v1.2.1