Added field selection to search

This commit is contained in:
Markus Koch 2017-02-04 12:17:41 +01:00
parent 5686bdb834
commit 9bac55c4ce
3 changed files with 126 additions and 9 deletions

View File

@ -41,6 +41,82 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="searchInBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">search in: </property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="checkSearchTitle">
<property name="label" translatable="yes">Title</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="checkSearchTags">
<property name="label" translatable="yes">Tags</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="checkSearchText">
<property name="label" translatable="yes">Text</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkBox" id="boxDateEntry">
<property name="visible">True</property>
@ -88,7 +164,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">3</property>
</packing>
</child>
</object>

View File

@ -194,21 +194,29 @@ static gboolean mainWindow_list_entry_visible(GtkTreeModel *model, GtkTreeIter *
/* Check text search */
searchString = (gchar *)gtk_entry_get_text(GTK_ENTRY(mainWindow->searchEntry));
if (searchString[0] != 0) {
if (searchString[0] != 0 && (
mainWindow->filterSettings.search_title ||
mainWindow->filterSettings.search_tags ||
mainWindow->filterSettings.search_text)) {
regex = g_regex_new(searchString, G_REGEX_CASELESS, 0, NULL);
gtk_tree_model_get(model, iter, COL_TITLE, &temp, -1);
if (g_regex_match(regex, temp, 0, &match_info) && g_match_info_matches(match_info))
search_matched = 1;
g_free(temp);
gtk_tree_model_get(model, iter, COL_TEXT, &temp, -1);
if (!search_matched && g_regex_match(regex, temp, 0, &match_info) && g_match_info_matches(match_info))
if (mainWindow->filterSettings.search_title &&
g_regex_match(regex, temp, 0, &match_info) && g_match_info_matches(match_info))
search_matched = 1;
g_free(temp);
gtk_tree_model_get(model, iter, COL_TAGS_TEXT, &temp, -1);
if (!search_matched && g_regex_match(regex, temp, 0, &match_info) && g_match_info_matches(match_info))
if (!search_matched &&
mainWindow->filterSettings.search_tags &&
g_regex_match(regex, temp, 0, &match_info) && g_match_info_matches(match_info))
search_matched = 1;
g_free(temp);
gtk_tree_model_get(model, iter, COL_TEXT, &temp, -1);
if (!search_matched &&
mainWindow->filterSettings.search_text &&
g_regex_match(regex, temp, 0, &match_info) && g_match_info_matches(match_info))
search_matched = 1;
g_free(temp);
@ -390,6 +398,19 @@ static void mainWindow_connect_signals(struct mainWindow *mainWindow)
"changed",
(GCallback) mainWindow_filterChanged,
mainWindow);
g_signal_connect(mainWindow->checkSearchTitle,
"toggled",
(GCallback) mainWindow_filterChanged,
mainWindow);
g_signal_connect(mainWindow->checkSearchTags,
"toggled",
(GCallback) mainWindow_filterChanged,
mainWindow);
g_signal_connect(mainWindow->checkSearchText,
"toggled",
(GCallback) mainWindow_filterChanged,
mainWindow);
}
/**
@ -412,6 +433,9 @@ struct mainWindow *mainWindow_new()
mainWindow->entryText = GTK_WIDGET(gtk_builder_get_object(builder, "entryText"));
mainWindow->popoverDate = GTK_WIDGET(gtk_builder_get_object(builder, "popoverDate"));
mainWindow->calendarRange = GTK_WIDGET(gtk_builder_get_object(builder, "calendarRange"));
mainWindow->checkSearchTitle = GTK_WIDGET(gtk_builder_get_object(builder, "checkSearchTitle"));
mainWindow->checkSearchTags = GTK_WIDGET(gtk_builder_get_object(builder, "checkSearchTags"));
mainWindow->checkSearchText = GTK_WIDGET(gtk_builder_get_object(builder, "checkSearchText"));
mainWindow->entryListView = GTK_TREE_VIEW(gtk_builder_get_object(builder, "entryListView"));
mainWindow->entryListSelection = GTK_TREE_SELECTION(gtk_builder_get_object(builder, "entryListSelection"));
mainWindow->textBuffer = GTK_TEXT_BUFFER(gtk_builder_get_object(builder, "entryTextBuffer"));
@ -426,6 +450,10 @@ struct mainWindow *mainWindow_new()
mainWindow_configure_treeView(mainWindow);
mainWindow_connect_signals(mainWindow);
gtk_toggle_button_set_active(mainWindow->checkSearchTitle, 1);
gtk_toggle_button_set_active(mainWindow->checkSearchTags, 1);
gtk_toggle_button_set_active(mainWindow->checkSearchText, 0);
/**
* These need to be set to oldest and newest after indexing date
*/
@ -548,6 +576,13 @@ void mainWindow_filterChanged(GtkWidget *widget, gpointer user_data)
}
}
mainWindow->filterSettings.search_title = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
mainWindow->checkSearchTitle));
mainWindow->filterSettings.search_tags = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
mainWindow->checkSearchTags));
mainWindow->filterSettings.search_text = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
mainWindow->checkSearchText));
gtk_tree_model_filter_refilter(mainWindow->entryListFiltered);
}

View File

@ -13,6 +13,9 @@ struct mainWindow {
GtkWidget *entryText;
GtkWidget *popoverDate;
GtkWidget *calendarRange;
GtkWidget *checkSearchTitle;
GtkWidget *checkSearchTags;
GtkWidget *checkSearchText;
GtkTreeView *entryListView;
GtkTreeSelection *entryListSelection;
GtkTextBuffer *textBuffer;
@ -24,6 +27,9 @@ struct mainWindow {
struct filterSettings {
guint time_start;
guint time_end;
gboolean search_title;
gboolean search_tags;
gboolean search_text;
} filterSettings;
};