Updated mainWindow_add_recent_workspace + refactoring

This commit is contained in:
Markus Koch 2017-02-11 17:51:04 +01:00
parent d066bdde58
commit eef1f96a0a

View File

@ -147,9 +147,9 @@ static gint mainWindow_sort_date_compare_func(GtkTreeModel *model,
return -1; return -1;
} }
static void mainWindow_add_recent_workspace(struct mainWindow *mainWindow, gchar *path) void mainWindow_add_recent_workspace(struct mainWindow *mainWindow, gchar *path)
{ {
GtkTreeIter iter; GtkTreeIter iter, iter2;
GRegex *regex; GRegex *regex;
GMatchInfo *match_info; GMatchInfo *match_info;
gchar *temp; gchar *temp;
@ -163,12 +163,20 @@ static void mainWindow_add_recent_workspace(struct mainWindow *mainWindow, gchar
temp = g_strdup_printf("<b>%s</b>\n<span weight=\"ultralight\">%s</span>", temp = g_strdup_printf("<b>%s</b>\n<span weight=\"ultralight\">%s</span>",
g_match_info_fetch(match_info, 2), g_match_info_fetch(match_info, 2),
g_match_info_fetch(match_info, 1)); g_match_info_fetch(match_info, 1));
gtk_list_store_append(mainWindow->workspaceListStore, &iter); gtk_list_store_prepend(mainWindow->workspaceListStore, &iter);
gtk_list_store_set(mainWindow->workspaceListStore, &iter, gtk_list_store_set(mainWindow->workspaceListStore, &iter,
WSCOL_LABEL, temp, WSCOL_LABEL, temp,
WSCOL_PATH, path, WSCOL_PATH, path,
-1); -1);
g_free(temp); g_free(temp);
if (gtk_tree_model_iter_n_children(GTK_TREE_MODEL(mainWindow->workspaceListStore), NULL)
> FILE_LIST_MAX_LEN) {
while (gtk_tree_model_iter_next(GTK_TREE_MODEL(mainWindow->workspaceListStore), &iter)) {
memcpy(&iter2, &iter, sizeof(iter)); /* TODO: A bit of a hack if you ask me... */
}
gtk_list_store_remove(mainWindow->workspaceListStore, &iter2);
}
} }
g_regex_unref(regex); g_regex_unref(regex);
@ -201,10 +209,6 @@ static void mainWindow_configure_workspaceTreeView(struct mainWindow *mainWindow
renderer = gtk_cell_renderer_text_new(); renderer = gtk_cell_renderer_text_new();
gtk_tree_view_insert_column_with_attributes(mainWindow->workspaceListView, -1, "", renderer, gtk_tree_view_insert_column_with_attributes(mainWindow->workspaceListView, -1, "", renderer,
"markup", WSCOL_LABEL, NULL); "markup", WSCOL_LABEL, NULL);
/* Test only */
mainWindow_add_recent_workspace(mainWindow, "/home/user/Document/diary");
mainWindow_add_recent_workspace(mainWindow, "/home/user/Document/workfoo");
} }
/** /**
@ -752,9 +756,9 @@ void mainWindow_otherWorkspaceClicked(GtkWidget *widget, gpointer user_data)
if (res == GTK_RESPONSE_ACCEPT) { if (res == GTK_RESPONSE_ACCEPT) {
char *directory; char *directory;
directory = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog)); directory = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
mainWindow_switch_workspace(mainWindow, directory); mainWindow_switch_workspace(mainWindow, directory);
g_free (directory); g_free(directory);
} }
gtk_widget_destroy (dialog); gtk_widget_destroy (dialog);