Added search and processing for the recent workspace selector
This commit is contained in:
parent
f8d3bb8730
commit
54a7814e0b
128
src/mainwindow.c
128
src/mainwindow.c
@ -1,6 +1,45 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "mdiary.h"
|
#include "mdiary.h"
|
||||||
|
|
||||||
|
enum {
|
||||||
|
WSCOL_LABEL = 0,
|
||||||
|
WSCOL_PATH,
|
||||||
|
WSCOL_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
static gboolean mainWindow_workspace_entry_visible(GtkTreeModel *model,
|
||||||
|
GtkTreeIter *iter,
|
||||||
|
struct mainWindow *mainWindow)
|
||||||
|
{
|
||||||
|
GRegex *regex;
|
||||||
|
GMatchInfo *match_info;
|
||||||
|
gchar *searchString;
|
||||||
|
gchar *temp;
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
|
||||||
|
searchString = gtk_entry_get_text(GTK_ENTRY(mainWindow->workspaceSearch));
|
||||||
|
|
||||||
|
if (g_strcmp0(searchString, "")) {
|
||||||
|
regex = g_regex_new(searchString, G_REGEX_CASELESS, 0, NULL);
|
||||||
|
gtk_tree_model_get(model, iter, WSCOL_PATH, &temp, -1);
|
||||||
|
if (g_regex_match(regex, temp, 0, &match_info) && g_match_info_matches(match_info))
|
||||||
|
ret = TRUE;
|
||||||
|
g_free(temp);
|
||||||
|
} else {
|
||||||
|
ret = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mainWindow_workspace_search_changed(GtkWidget *widget, gpointer user_data)
|
||||||
|
{
|
||||||
|
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
|
||||||
|
|
||||||
|
gtk_tree_model_filter_refilter(mainWindow->workspaceListFiltered);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief mainWindow_list_entry_visible checks whether the entry should be displayed.
|
* @brief mainWindow_list_entry_visible checks whether the entry should be displayed.
|
||||||
* @param model N/A
|
* @param model N/A
|
||||||
@ -8,7 +47,9 @@
|
|||||||
* @param mainWindow struct mainWindow *
|
* @param mainWindow struct mainWindow *
|
||||||
* @return True when it should displayed, else false.
|
* @return True when it should displayed, else false.
|
||||||
*/
|
*/
|
||||||
static gboolean mainWindow_list_entry_visible(GtkTreeModel *model, GtkTreeIter *iter, struct mainWindow *mainWindow)
|
static gboolean mainWindow_list_entry_visible(GtkTreeModel *model,
|
||||||
|
GtkTreeIter *iter,
|
||||||
|
struct mainWindow *mainWindow)
|
||||||
{
|
{
|
||||||
GRegex *regex;
|
GRegex *regex;
|
||||||
GMatchInfo *match_info;
|
GMatchInfo *match_info;
|
||||||
@ -102,6 +143,33 @@ static gint mainWindow_sort_date_compare_func(GtkTreeModel *model,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void mainWindow_add_recent_workspace(struct mainWindow *mainWindow, gchar *path)
|
||||||
|
{
|
||||||
|
GtkTreeIter iter;
|
||||||
|
GRegex *regex;
|
||||||
|
GMatchInfo *match_info;
|
||||||
|
gchar *temp;
|
||||||
|
|
||||||
|
regex = g_regex_new("(.*)\\/(.*)", G_REGEX_RAW, 0, NULL);
|
||||||
|
if (g_regex_match(regex, path, 0, &match_info) &&
|
||||||
|
g_regex_get_capture_count(regex) > 1 &&
|
||||||
|
g_match_info_matches(match_info)) {
|
||||||
|
g_match_info_fetch(match_info, 1);
|
||||||
|
|
||||||
|
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, 1));
|
||||||
|
gtk_list_store_append(mainWindow->workspaceListStore, &iter);
|
||||||
|
gtk_list_store_set(mainWindow->workspaceListStore, &iter,
|
||||||
|
WSCOL_LABEL, temp,
|
||||||
|
WSCOL_PATH, path,
|
||||||
|
-1);
|
||||||
|
g_free(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_regex_unref(regex);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief mainWindow_wschooser_configure_treeView configures the GtkTreeView for workspace selection
|
* @brief mainWindow_wschooser_configure_treeView configures the GtkTreeView for workspace selection
|
||||||
* @param mainWindow
|
* @param mainWindow
|
||||||
@ -111,34 +179,28 @@ static void mainWindow_configure_workspaceTreeView(struct mainWindow *mainWindow
|
|||||||
GtkCellRenderer *renderer;
|
GtkCellRenderer *renderer;
|
||||||
GtkTreeViewColumn *col;
|
GtkTreeViewColumn *col;
|
||||||
|
|
||||||
mainWindow->workspaceListStore = gtk_list_store_new(1, G_TYPE_STRING);
|
mainWindow->workspaceListStore = gtk_list_store_new(WSCOL_COUNT,
|
||||||
|
G_TYPE_STRING,
|
||||||
|
G_TYPE_STRING);
|
||||||
|
|
||||||
/*
|
mainWindow->workspaceListFiltered = GTK_TREE_MODEL_FILTER(
|
||||||
* TODO:
|
gtk_tree_model_filter_new(
|
||||||
* gtk_tree_model_filter_set_visible_func(mainWindow->workspaceListStore,
|
GTK_TREE_MODEL(mainWindow->workspaceListStore),
|
||||||
* (GtkTreeModelFilterVisibleFunc) mainWindow_list_entry_visible,
|
NULL));
|
||||||
* mainWindow, NULL);
|
|
||||||
*/
|
|
||||||
|
|
||||||
gtk_tree_view_set_model(mainWindow->workspaceListView, GTK_TREE_MODEL(mainWindow->workspaceListStore));
|
gtk_tree_model_filter_set_visible_func(mainWindow->workspaceListFiltered,
|
||||||
|
(GtkTreeModelFilterVisibleFunc) mainWindow_workspace_entry_visible,
|
||||||
|
mainWindow, NULL);
|
||||||
|
|
||||||
|
gtk_tree_view_set_model(mainWindow->workspaceListView, GTK_TREE_MODEL(mainWindow->workspaceListFiltered));
|
||||||
|
|
||||||
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", 0, NULL);
|
"markup", WSCOL_LABEL, NULL);
|
||||||
|
|
||||||
/* Test entry for debugging */
|
|
||||||
|
|
||||||
GtkTreeIter iter;
|
|
||||||
|
|
||||||
gtk_list_store_append(mainWindow->workspaceListStore, &iter);
|
|
||||||
gtk_list_store_set(mainWindow->workspaceListStore, &iter,
|
|
||||||
0, "<b>testworkspace</b>\n\n<span weight=\"ultralight\">/home/user/Documents</span>",
|
|
||||||
-1);
|
|
||||||
gtk_list_store_append(mainWindow->workspaceListStore, &iter);
|
|
||||||
gtk_list_store_set(mainWindow->workspaceListStore, &iter,
|
|
||||||
0, "<b>testworkspace</b>\n\n<span weight=\"ultralight\">/home/user/Documents</span>",
|
|
||||||
-1);
|
|
||||||
|
|
||||||
|
/* Test only */
|
||||||
|
mainWindow_add_recent_workspace(mainWindow, "/home/user/Document/diary");
|
||||||
|
mainWindow_add_recent_workspace(mainWindow, "/home/user/Document/workfoo");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -293,6 +355,10 @@ static void mainWindow_connect_signals(struct mainWindow *mainWindow)
|
|||||||
"row-activated",
|
"row-activated",
|
||||||
(GCallback) mainWindow_workspaceListClicked,
|
(GCallback) mainWindow_workspaceListClicked,
|
||||||
mainWindow);
|
mainWindow);
|
||||||
|
g_signal_connect(mainWindow->workspaceSearch,
|
||||||
|
"changed",
|
||||||
|
(GCallback) mainWindow_workspace_search_changed,
|
||||||
|
mainWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -337,7 +403,7 @@ struct mainWindow *mainWindow_new()
|
|||||||
mainWindow->textBuffer = GTK_TEXT_BUFFER(gtk_builder_get_object(builder, "entryTextBuffer"));
|
mainWindow->textBuffer = GTK_TEXT_BUFFER(gtk_builder_get_object(builder, "entryTextBuffer"));
|
||||||
|
|
||||||
mainWindow->buttonOtherWorkspace = GTK_WIDGET(gtk_builder_get_object(builder, "buttonOtherWorkspace"));
|
mainWindow->buttonOtherWorkspace = GTK_WIDGET(gtk_builder_get_object(builder, "buttonOtherWorkspace"));
|
||||||
mainWindow->searchWorkspace = GTK_WIDGET(gtk_builder_get_object(builder, "searchWorkspace"));
|
mainWindow->workspaceSearch = GTK_WIDGET(gtk_builder_get_object(builder, "searchWorkspace"));
|
||||||
mainWindow->popoverWorkspace = GTK_WIDGET(gtk_builder_get_object(builder, "popoverWorkspace"));
|
mainWindow->popoverWorkspace = GTK_WIDGET(gtk_builder_get_object(builder, "popoverWorkspace"));
|
||||||
mainWindow->workspaceListView = GTK_TREE_VIEW(gtk_builder_get_object(builder, "treeWorkspace"));
|
mainWindow->workspaceListView = GTK_TREE_VIEW(gtk_builder_get_object(builder, "treeWorkspace"));
|
||||||
mainWindow->workspaceListSelection = GTK_TREE_SELECTION(gtk_builder_get_object(builder,
|
mainWindow->workspaceListSelection = GTK_TREE_SELECTION(gtk_builder_get_object(builder,
|
||||||
@ -585,12 +651,22 @@ void mainWindow_dateIconPress(GtkWidget *widget, gint icon_pos, gint event, gpoi
|
|||||||
}
|
}
|
||||||
|
|
||||||
void mainWindow_workspaceListClicked(GtkWidget *widget,
|
void mainWindow_workspaceListClicked(GtkWidget *widget,
|
||||||
GtkTreePath *path,
|
GtkTreePath *tree_path,
|
||||||
GtkTreeViewColumn *column,
|
GtkTreeViewColumn *column,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
|
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
|
||||||
|
GtkTreeModel *model;
|
||||||
|
GtkTreeIter iter;
|
||||||
|
GtkTreeSelection *selection;
|
||||||
|
gchar *path;
|
||||||
|
|
||||||
gtk_popover_popdown(GTK_POPOVER(mainWindow->popoverWorkspace));
|
gtk_popover_popdown(GTK_POPOVER(mainWindow->popoverWorkspace));
|
||||||
g_print("TODO: Workspace list clicked.\n");
|
|
||||||
|
selection = gtk_tree_view_get_selection(mainWindow->workspaceListView);
|
||||||
|
if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
|
||||||
|
gtk_tree_model_get(model, &iter, WSCOL_PATH, &path, -1);
|
||||||
|
g_print("TODO: Switch workspace to %s\n", path);
|
||||||
|
g_free(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,11 +41,12 @@ struct mainWindow {
|
|||||||
} filterSettings;
|
} filterSettings;
|
||||||
|
|
||||||
GtkWidget *buttonOtherWorkspace;
|
GtkWidget *buttonOtherWorkspace;
|
||||||
GtkWidget *searchWorkspace;
|
GtkWidget *workspaceSearch;
|
||||||
GtkWidget *popoverWorkspace;
|
GtkWidget *popoverWorkspace;
|
||||||
GtkTreeView *workspaceListView;
|
GtkTreeView *workspaceListView;
|
||||||
GtkTreeSelection *workspaceListSelection;
|
GtkTreeSelection *workspaceListSelection;
|
||||||
GtkListStore *workspaceListStore;
|
GtkListStore *workspaceListStore;
|
||||||
|
GtkTreeModelFilter *workspaceListFiltered;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mainWindow *mainWindow_new();
|
struct mainWindow *mainWindow_new();
|
||||||
@ -55,13 +56,14 @@ void mainWindow_set_meta_information(struct mainWindow *mainWindow, guint time_e
|
|||||||
void mainWindow_showPopover(GtkWidget *widget, GdkEvent *event, gpointer user_data);
|
void mainWindow_showPopover(GtkWidget *widget, GdkEvent *event, gpointer user_data);
|
||||||
void mainWindow_otherWorkspaceClicked(GtkWidget *widget, gint event, gpointer user_data);
|
void mainWindow_otherWorkspaceClicked(GtkWidget *widget, gint event, gpointer user_data);
|
||||||
void mainWindow_workspaceListClicked(GtkWidget *widget,
|
void mainWindow_workspaceListClicked(GtkWidget *widget,
|
||||||
GtkTreePath *path,
|
GtkTreePath *tree_path,
|
||||||
GtkTreeViewColumn *column,
|
GtkTreeViewColumn *column,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
void mainWindow_clearSearch(GtkWidget *widget, gpointer user_data);
|
void mainWindow_clearSearch(GtkWidget *widget, gpointer user_data);
|
||||||
void mainWindow_calendarSelected(GtkWidget *widget, gpointer user_data);
|
void mainWindow_calendarSelected(GtkWidget *widget, gpointer user_data);
|
||||||
void mainWindow_entrySelected(GtkWidget *widget, gpointer user_data);
|
void mainWindow_entrySelected(GtkWidget *widget, gpointer user_data);
|
||||||
void mainWindow_filterChanged(GtkWidget *widget, gpointer user_data);
|
void mainWindow_filterChanged(GtkWidget *widget, gpointer user_data);
|
||||||
|
void mainWindow_workspace_search_changed(GtkWidget *widget, gpointer user_data);
|
||||||
void mainWindow_checkDate(GtkWidget *widget, gint event, gpointer user_data);
|
void mainWindow_checkDate(GtkWidget *widget, gint event, gpointer user_data);
|
||||||
void mainWindow_dateIconPress(GtkWidget *widget, gint icon_pos, gint event, gpointer user_data);
|
void mainWindow_dateIconPress(GtkWidget *widget, gint icon_pos, gint event, gpointer user_data);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user