changeset 2819:dbe1524ba009

Fix #629: Keywords are not adding properly to selected files https://github.com/BestImageViewer/geeqie/issues/629 The right-click menu of the left-hand keywords pane of the info sidebar now uses only the selected keywords. Any partially selected keywords will be expanded to the full keyword. Select none == select all
author Colin Clark <colin.clark@cclark.uk>
date Fri, 17 Aug 2018 18:12:04 +0100
parents f1c975235feb
children a58a176761eb
files doc/docbook/GuideSidebarsInfo.xml src/bar_keywords.c src/ui_misc.c src/ui_misc.h web/help/GuideSidebarsInfo.html
diffstat 5 files changed, 59 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/doc/docbook/GuideSidebarsInfo.xml	Thu Aug 16 19:48:59 2018 +0100
+++ b/doc/docbook/GuideSidebarsInfo.xml	Fri Aug 17 18:12:04 2018 +0100
@@ -114,7 +114,12 @@
       <para>This action cannot be undone.</para>
     </warning>
     <para>Irrespective of their position in a hierarchy in the right-hand box, all keywords are written as individual entries into metadata. When metadata for an image is read in, Geeqie will attempt to recreate any hierarchies within the data, and display it accordingly in the right-hand box.</para>
-    <para>Right-click on the left-hand box allows the keywords to be written to the currently selected files - the keywords may be either added to the existing contents, or entirely replace the existing content.</para>
+    <para>
+      Right-click on the left-hand box allows the selected keywords to be written to the currently selected files - the keywords may be either added to the existing contents, or entirely replace the existing content.
+      <warning>
+        <para>Keyword completion is used when selecting keywords. If the selected area includes part of a keyword, the selection will autmatically be expanded to cover the whole keyword. If no text is selected, all keywords will be used.</para>
+      </warning>
+    </para>
     <para>
       Right-click on the right-hand box allows a connection to be made between a keyword and a mark. The
       <link linkend="GuideImageMarks" endterm="titleGuideImageMarks" />
--- a/src/bar_keywords.c	Thu Aug 16 19:48:59 2018 +0100
+++ b/src/bar_keywords.c	Fri Aug 17 18:12:04 2018 +0100
@@ -62,6 +62,19 @@
 	return list;
 }
 
+static GList *keyword_list_pull_selected(GtkWidget *text_widget)
+{
+	GList *list;
+	gchar *text;
+
+	text = text_widget_text_pull_selected(text_widget);
+	list = string_to_keywords_list(text);
+
+	g_free(text);
+
+	return list;
+}
+
 /* the "changed" signal should be blocked before calling this */
 static void keyword_list_push(GtkWidget *textview, GList *list)
 {
@@ -416,7 +429,7 @@
 	GList *list = NULL;
 	GList *work;
 
-	keywords = keyword_list_pull(pkd->keyword_view);
+	keywords = keyword_list_pull_selected(pkd->keyword_view);
 
 	list = layout_selection_list(pkd->pane.lw);
 	list = file_data_process_groups_in_selection(list, FALSE, NULL);
@@ -460,8 +473,8 @@
 	PaneKeywordsData *pkd = data;
 
 	menu_item_add_divider(GTK_WIDGET(menu));
-	menu_item_add_stock(GTK_WIDGET(menu), _("Add keywords to selected files"), GTK_STOCK_ADD, G_CALLBACK(bar_pane_keywords_sel_add_cb), pkd);
-	menu_item_add_stock(GTK_WIDGET(menu), _("Replace existing keywords in selected files"), GTK_STOCK_CONVERT, G_CALLBACK(bar_pane_keywords_sel_replace_cb), pkd);
+	menu_item_add_stock(GTK_WIDGET(menu), _("Add selected keywords to selected files"), GTK_STOCK_ADD, G_CALLBACK(bar_pane_keywords_sel_add_cb), pkd);
+	menu_item_add_stock(GTK_WIDGET(menu), _("Replace existing keywords in selected files with selected keywords"), GTK_STOCK_CONVERT, G_CALLBACK(bar_pane_keywords_sel_replace_cb), pkd);
 }
 
 
--- a/src/ui_misc.c	Thu Aug 16 19:48:59 2018 +0100
+++ b/src/ui_misc.c	Fri Aug 17 18:12:04 2018 +0100
@@ -1732,4 +1732,34 @@
 
 }
 
+gchar *text_widget_text_pull_selected(GtkWidget *text_widget)
+{
+	if (GTK_IS_TEXT_VIEW(text_widget))
+		{
+		GtkTextBuffer *buffer;
+		GtkTextIter start, end;
+		GtkTextIter selection_start, selection_end;
+
+		buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_widget));
+		gtk_text_buffer_get_bounds(buffer, &start, &end);
+
+		if (gtk_text_buffer_get_selection_bounds(buffer, &start, &end))
+			{
+			gtk_text_iter_set_line_offset(&start, 0);
+			gtk_text_iter_forward_to_line_end(&end);
+			}
+
+		return gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
+		}
+	else if (GTK_IS_ENTRY(text_widget))
+		{
+		return g_strdup(gtk_entry_get_text(GTK_ENTRY(text_widget)));
+		}
+	else
+		{
+		return NULL;
+		}
+
+}
+
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/ui_misc.h	Thu Aug 16 19:48:59 2018 +0100
+++ b/src/ui_misc.h	Fri Aug 17 18:12:04 2018 +0100
@@ -199,6 +199,7 @@
 				 GCallback func, gpointer data);
 
 gchar *text_widget_text_pull(GtkWidget *text_widget);
+gchar *text_widget_text_pull_selected(GtkWidget *text_widget);
 
 #endif
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/web/help/GuideSidebarsInfo.html	Thu Aug 16 19:48:59 2018 +0100
+++ b/web/help/GuideSidebarsInfo.html	Fri Aug 17 18:12:04 2018 +0100
@@ -572,7 +572,12 @@
       <p class="para block block-first">This action cannot be undone.</p>
     </div></div>
 <p class="para block">Irrespective of their position in a hierarchy in the right-hand box, all keywords are written as individual entries into metadata. When metadata for an image is read in, Geeqie will attempt to recreate any hierarchies within the data, and display it accordingly in the right-hand box.</p>
-<p class="para block">Right-click on the left-hand box allows the keywords to be written to the currently selected files - the keywords may be either added to the existing contents, or entirely replace the existing content.</p>
+<p class="para block">
+      Right-click on the left-hand box allows the selected keywords to be written to the currently selected files - the keywords may be either added to the existing contents, or entirely replace the existing content.
+      <div class="admonition block warning block-first block-indent"><div class="warning-inner">
+        <p class="para block block-first">Keyword completion is used when selecting keywords. If the selected area includes part of a keyword, the selection will autmatically be expanded to cover the whole keyword. If no text is selected, all keywords will be used.</p>
+      </div></div>
+    </p>
 <p class="para block">
       Right-click on the right-hand box allows a connection to be made between a keyword and a mark. The
       <a class="link" href="GuideImageMarks.html" title="Marking Images">Marking Images</a>