Improved last_workspace handling
This commit is contained in:
parent
eef1f96a0a
commit
85f8c1e783
@ -149,10 +149,11 @@ static gint mainWindow_sort_date_compare_func(GtkTreeModel *model,
|
|||||||
|
|
||||||
void mainWindow_add_recent_workspace(struct mainWindow *mainWindow, gchar *path)
|
void mainWindow_add_recent_workspace(struct mainWindow *mainWindow, gchar *path)
|
||||||
{
|
{
|
||||||
GtkTreeIter iter, iter2;
|
GtkTreeIter iter, iter_delete;
|
||||||
GRegex *regex;
|
GRegex *regex;
|
||||||
GMatchInfo *match_info;
|
GMatchInfo *match_info;
|
||||||
gchar *temp;
|
gchar *temp;
|
||||||
|
gboolean del_iter = FALSE;
|
||||||
|
|
||||||
regex = g_regex_new("(.*)\\/(.*)", G_REGEX_RAW, 0, NULL);
|
regex = g_regex_new("(.*)\\/(.*)", G_REGEX_RAW, 0, NULL);
|
||||||
if (g_regex_match(regex, path, 0, &match_info) &&
|
if (g_regex_match(regex, path, 0, &match_info) &&
|
||||||
@ -160,6 +161,20 @@ void mainWindow_add_recent_workspace(struct mainWindow *mainWindow, gchar *path)
|
|||||||
g_match_info_matches(match_info)) {
|
g_match_info_matches(match_info)) {
|
||||||
g_match_info_fetch(match_info, 1);
|
g_match_info_fetch(match_info, 1);
|
||||||
|
|
||||||
|
gtk_tree_model_get_iter_first(GTK_TREE_MODEL(mainWindow->workspaceListStore), &iter);
|
||||||
|
while (gtk_tree_model_iter_next(GTK_TREE_MODEL(mainWindow->workspaceListStore), &iter)) {
|
||||||
|
memcpy(&iter_delete, &iter, sizeof(iter)); /* Used for last element in case we need to reduce */
|
||||||
|
gtk_tree_model_get(GTK_TREE_MODEL(mainWindow->workspaceListStore), &iter,
|
||||||
|
WSCOL_PATH, &temp,
|
||||||
|
-1);
|
||||||
|
if (!g_strcmp0(temp, path)) {
|
||||||
|
g_free(temp);
|
||||||
|
del_iter = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
g_free(temp);
|
||||||
|
}
|
||||||
|
|
||||||
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));
|
||||||
@ -170,13 +185,11 @@ void mainWindow_add_recent_workspace(struct mainWindow *mainWindow, gchar *path)
|
|||||||
-1);
|
-1);
|
||||||
g_free(temp);
|
g_free(temp);
|
||||||
|
|
||||||
if (gtk_tree_model_iter_n_children(GTK_TREE_MODEL(mainWindow->workspaceListStore), NULL)
|
if (del_iter)
|
||||||
> FILE_LIST_MAX_LEN) {
|
gtk_list_store_remove(mainWindow->workspaceListStore, &iter_delete);
|
||||||
while (gtk_tree_model_iter_next(GTK_TREE_MODEL(mainWindow->workspaceListStore), &iter)) {
|
else if (gtk_tree_model_iter_n_children(GTK_TREE_MODEL(mainWindow->workspaceListStore), NULL)
|
||||||
memcpy(&iter2, &iter, sizeof(iter)); /* TODO: A bit of a hack if you ask me... */
|
> FILE_LIST_MAX_LEN)
|
||||||
}
|
gtk_list_store_remove(mainWindow->workspaceListStore, &iter_delete);
|
||||||
gtk_list_store_remove(mainWindow->workspaceListStore, &iter2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_regex_unref(regex);
|
g_regex_unref(regex);
|
||||||
@ -703,12 +716,14 @@ static void mainWindow_switch_workspace(struct mainWindow *mainWindow, gchar *pa
|
|||||||
gtk_popover_popdown(GTK_POPOVER(mainWindow->popoverWorkspace));
|
gtk_popover_popdown(GTK_POPOVER(mainWindow->popoverWorkspace));
|
||||||
mainWindow_set_meta_information(mainWindow, 0, 0, TRUE);
|
mainWindow_set_meta_information(mainWindow, 0, 0, TRUE);
|
||||||
mdiary_reset_store(mainWindow->entryListStore, mainWindow->completionListStore);
|
mdiary_reset_store(mainWindow->entryListStore, mainWindow->completionListStore);
|
||||||
if (mdiary_scan_to_store(path, mainWindow->entryListStore, mainWindow->completionListStore))
|
if (mdiary_scan_to_store(path, mainWindow->entryListStore, mainWindow->completionListStore)) {
|
||||||
mainWindow_set_meta_information(mainWindow,
|
mainWindow_set_meta_information(mainWindow,
|
||||||
mdiary_get_time_earliest(), mdiary_get_time_latest(),
|
mdiary_get_time_earliest(), mdiary_get_time_latest(),
|
||||||
FALSE);
|
FALSE);
|
||||||
else
|
mainWindow_add_recent_workspace(mainWindow, path);
|
||||||
|
} else {
|
||||||
mainWindow_show_error(mainWindow, "Could not open workspace or no entries were found in it.");
|
mainWindow_show_error(mainWindow, "Could not open workspace or no entries were found in it.");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user