[shotwell: 1/2] Support adding hierarchical tags with /




commit 7adc40687cf48350ad8e7473439863a488da5f01
Author: Jens Georg <mail jensge org>
Date:   Sat Oct 8 06:49:25 2022 +0000

    Support adding hierarchical tags with /

 help/C/organize-tag.page | 21 ++++++++++++++++++--
 src/Commands.vala        |  2 --
 src/Dialogs.vala         | 51 ++++++++++++++++++++++++++++++++++++++----------
 src/Tag.vala             |  6 ++++--
 4 files changed, 64 insertions(+), 16 deletions(-)
---
diff --git a/help/C/organize-tag.page b/help/C/organize-tag.page
index a3f81492..4f1a6eaf 100644
--- a/help/C/organize-tag.page
+++ b/help/C/organize-tag.page
@@ -33,7 +33,9 @@
     <p>
                When you use <keyseq><key>Ctrl</key><key>T</key></keyseq> or 
                <guiseq><gui>Tags</gui><gui>Add Tags...</gui></guiseq> you can type
-               in the names of one or more tags, separated by commas.
+               in the names of one or more tags, separated by commas. You can also
+               add tag hierarchies on the fly using <input>/</input> as if they
+               were paths in the file system.
                Once you have created a tag, you can rename it by selecting that 
                tag in the sidebar and choosing 
                <guiseq><gui>Tags</gui><gui>Rename Tag "[name]"...</gui></guiseq>,
@@ -77,7 +79,22 @@
                                To create a new subtag right-click on a tag and select 
                                <gui>New</gui>.
                        </p>
-            
+                       <p>
+                               In all places where textual tag input is supported, tags
+                               can also be created using <input>/</input>. For example,
+                               using <input>/World/Africa/Togo/Lomé</input> will create
+                               or extend the tag tree
+                       </p>
+                       <tree>
+                               <item>World
+                                       <item>Africa
+                                               <item>Togo
+                                                       <item>Lomé</item>
+                                               </item>
+                                       </item>
+                               </item>
+                       </tree>
+               
             <p>
                                Hierarchical tags can help you to sort your tag list in 
                                ways that better match how you work or think; for example,
diff --git a/src/Commands.vala b/src/Commands.vala
index 9825b6de..c2b01cca 100644
--- a/src/Commands.vala
+++ b/src/Commands.vala
@@ -2165,8 +2165,6 @@ public class ModifyTagsCommand : SingleDataSourceCommand {
         }
         
         foreach (string path in new_paths) {
-            assert(Tag.global.exists(path));
-
             SourceProxy proxy = Tag.for_path(path).get_proxy();
             to_add.add(proxy);
             proxy.broken.connect(on_proxy_broken);
diff --git a/src/Dialogs.vala b/src/Dialogs.vala
index d123ca37..01f24f96 100644
--- a/src/Dialogs.vala
+++ b/src/Dialogs.vala
@@ -821,8 +821,10 @@ public void multiple_object_error_dialog(Gee.ArrayList<DataObject> objects, stri
 
 public abstract class TagsDialog : TextEntryDialogMediator {
     protected TagsDialog(string title, string label, string? initial_text = null) {
-        base (title, label, initial_text, HierarchicalTagIndex.get_global_index().get_all_tags(),
-            ",");
+        var all = new Gee.ArrayList<string>();
+        all.add_all(HierarchicalTagIndex.get_global_index().get_all_tags());
+        all.add_all(HierarchicalTagIndex.get_global_index().get_all_paths());
+        base (title, label, initial_text, all, ",");
     }
 }
 
@@ -844,14 +846,24 @@ public class AddTagsDialog : TagsDialog {
     }
 
     protected override bool on_modify_validate(string text) {
-        if (text.contains(Tag.PATH_SEPARATOR_STRING))
-            return false;
-            
-        // Can't simply call Tag.prep_tag_names().length because of this bug:
-        // https://bugzilla.gnome.org/show_bug.cgi?id=602208
         string[] names = Tag.prep_tag_names(text.split(","));
-        
-        return names.length > 0;
+        if (names.length == 0)
+            return false;
+
+        // If allowing hierarchies, they have to start with a "/"
+        for (int i = 0; i < names.length; i++) {
+            if (names[i].contains(Tag.PATH_SEPARATOR_STRING) && 
!names[i].strip().has_prefix(Tag.PATH_SEPARATOR_STRING))
+                return false;
+
+            if (names[i].strip().has_prefix(Tag.PATH_SEPARATOR_STRING) && names[i].strip().length == 1)
+                return false;
+
+            if (names[i].strip().contains(Tag.PATH_SEPARATOR_STRING + Tag.PATH_SEPARATOR_STRING)) {
+                return false;
+            }
+        }
+
+        return true;
     }
 }
 
@@ -908,7 +920,26 @@ public class ModifyTagsDialog : TagsDialog {
     }
     
     protected override bool on_modify_validate(string text) {
-        return (!text.contains(Tag.PATH_SEPARATOR_STRING));
+        string[] names = Tag.prep_tag_names(text.split(","));
+        if (names.length == 0)
+            return false;
+
+        // If allowing hierarchies, they have to start with a "/"
+        for (int i = 0; i < names.length; i++) {
+            if (names[i].contains(Tag.PATH_SEPARATOR_STRING) && 
!names[i].strip().has_prefix(Tag.PATH_SEPARATOR_STRING)) {
+                return false;
+            }
+
+            if (names[i].strip().has_prefix(Tag.PATH_SEPARATOR_STRING) && names[i].strip().length == 1)
+                return false;
+
+            if (names[i].strip().contains(Tag.PATH_SEPARATOR_STRING + Tag.PATH_SEPARATOR_STRING)) {
+                return false;
+            }
+        }
+
+        return true;
+
     }
     
 }
diff --git a/src/Tag.vala b/src/Tag.vala
index 46cbfaa2..baf56940 100644
--- a/src/Tag.vala
+++ b/src/Tag.vala
@@ -552,11 +552,13 @@ public class Tag : DataSource, ContainerSource, Proxyable, Indexable {
     // path should have already been prepared by prep_tag_name.
     public static Tag for_path(string name) {
         Tag? tag = global.fetch_by_name(name, true);
-        if (tag == null)
+        if (tag == null) {
             tag = global.restore_tag_from_holding_tank(name);
+        }
         
-        if (tag != null)
+        if (tag != null) {
             return tag;
+        }
         
         // create a new Tag for this name
         try {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]