[shotwell/wip/phako/44: 497/497] Support adding hierarchical tags with /




commit cbd8b9013f9026b517ddbf8465f1833b6245eeed
Author: Jens Georg <mail jensge org>
Date:   Sat Aug 24 13:42:35 2019 +0200

    Support adding hierarchical tags with /
    
    Fixes #44

 src/Commands.vala |  2 --
 src/Dialogs.vala  | 51 +++++++++++++++++++++++++++++++++++++++++----------
 src/Tag.vala      |  7 +++++--
 3 files changed, 46 insertions(+), 14 deletions(-)
---
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..4a319923 100644
--- a/src/Tag.vala
+++ b/src/Tag.vala
@@ -551,12 +551,15 @@ public class Tag : DataSource, ContainerSource, Proxyable, Indexable {
     // Returns a Tag for the path, creating a new empty one if it does not already exist.
     // path should have already been prepared by prep_tag_name.
     public static Tag for_path(string name) {
+        print ("Tag for path: %s\n", 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]