Exemplo n.º 1
0
        void MergeTags(Tag tag_to_merge)
        {
            TagStore from_store = from_db.Tags;
            TagStore to_store   = to_db.Tags;

            if (tag_to_merge != from_store.RootCategory)               //Do not merge RootCategory
            {
                Tag dest_tag = to_store.GetTagByName(tag_to_merge.Name);
                if (dest_tag == null)
                {
                    Category parent = (tag_to_merge.Category == from_store.RootCategory) ?
                                      to_store.RootCategory :
                                      to_store.GetTagByName(tag_to_merge.Category.Name) as Category;
                    dest_tag = to_store.CreateTag(parent, tag_to_merge.Name, false);
                    //FIXME: copy the tag icon and commit
                }
                tag_map [tag_to_merge.Id] = dest_tag;
            }

            if (!(tag_to_merge is Category))
            {
                return;
            }

            foreach (Tag t in (tag_to_merge as Category).Children)
            {
                MergeTags(t);
            }
        }
Exemplo n.º 2
0
        //Activated means the user pressed 'Enter'
        protected override void OnActivated()
        {
            string [] tagnames = GetTypedTagNames();

            if (tagnames == null)
            {
                return;
            }

            // Add any new tags to the selected photos
            var new_tags = new List <string> ();

            for (int i = 0; i < tagnames.Length; i++)
            {
                if (tagnames [i].Length == 0)
                {
                    continue;
                }

                if (selected_photos_tagnames.Contains(tagnames [i]))
                {
                    continue;
                }

                var t = _tagStore.GetTagByName(tagnames [i]);

                if (t != null)                 // Correct for capitalization differences
                {
                    tagnames [i] = t.Name;
                }

                new_tags.Add(tagnames [i]);
            }

            //Send event
            if (new_tags.Count != 0 && TagsAttached != null)
            {
                TagsAttached(this, new_tags.ToArray());
            }

            // Remove any removed tags from the selected photos
            var remove_tags = new List <Tag> ();

            foreach (string tagname in selected_photos_tagnames)
            {
                if (!IsTagInList(tagnames, tagname))
                {
                    var tag = _tagStore.GetTagByName(tagname);
                    remove_tags.Add(tag);
                }
            }

            //Send event
            if (remove_tags.Count != 0 && TagsRemoved != null)
            {
                TagsRemoved(this, remove_tags.ToArray());
            }
        }
Exemplo n.º 3
0
        public IDictionary <string, object> GetTagByName(string name)
        {
            Tag t = tag_store.GetTagByName(name);

            if (t == null)
            {
                throw new DBusException("Tag with name {0} does not exist.", name);
            }

            return(CreateDictFromTag(t));
        }
Exemplo n.º 4
0
        // Set the tags that will be added on import.
        public void AttachTags(IEnumerable <string> tags)
        {
            App.Instance.Database.BeginTransaction();
            var import_category = GetImportedTagsCategory();

            foreach (var tagname in tags)
            {
                var tag = tag_store.GetTagByName(tagname);
                if (tag == null)
                {
                    tag = tag_store.CreateCategory(import_category, tagname, false);
                    tag_store.Commit(tag);
                }
                attach_tags.Add(tag);
            }
            App.Instance.Database.CommitTransaction();
        }
Exemplo n.º 5
0
        private Tag EnsureTag(TagInfo info, Category parent)
        {
            Tag tag = tag_store.GetTagByName(info.TagName);

            if (tag != null)
            {
                return(tag);
            }

            tag = tag_store.CreateCategory(parent,
                                           info.TagName);

            if (info.HasIcon)
            {
                tag.StockIconName = info.IconName;
                tag_store.Commit(tag);
            }

            tags_created.Push(tag);
            return(tag);
        }
Exemplo n.º 6
0
        //Activated means the user pressed 'Enter'
        protected override void OnActivated()
        {
            string [] tagnames = GetTypedTagNames();

            if (tagnames == null)
            {
                return;
            }

            int sel_start, sel_end;

            if (GetSelectionBounds(out sel_start, out sel_end) && tag_completion_index != -1)
            {
                InsertText(", ", ref sel_end);
                SelectRegion(-1, -1);
                Position = sel_end + 2;
                ClearTagCompletions();
                return;
            }

            // Add any new tags to the selected photos
            ArrayList new_tags = new ArrayList();

            for (int i = 0; i < tagnames.Length; i++)
            {
                if (tagnames [i].Length == 0)
                {
                    continue;
                }

                if (selected_photos_tagnames.Contains(tagnames [i]))
                {
                    continue;
                }

                Tag t = tag_store.GetTagByName(tagnames [i]);

                if (t != null)                 // Correct for capitalization differences
                {
                    tagnames [i] = t.Name;
                }

                new_tags.Add(tagnames [i]);
            }

            //Send event
            if (new_tags.Count != 0 && TagsAttached != null)
            {
                TagsAttached(this, (string [])new_tags.ToArray(typeof(string)));
            }

            // Remove any removed tags from the selected photos
            ArrayList remove_tags = new ArrayList();

            foreach (string tagname in selected_photos_tagnames)
            {
                if (!IsTagInList(tagnames, tagname))
                {
                    Tag tag = tag_store.GetTagByName(tagname);
                    remove_tags.Add(tag);
                }
            }

            //Send event
            if (remove_tags.Count != 0 && TagsRemoved != null)
            {
                TagsRemoved(this, (Tag [])remove_tags.ToArray(typeof(Tag)));
            }
        }