Пример #1
0
        public Tag Execute(TagType type, Tag [] selection)
        {
            Category default_category = null;

            if (selection.Length > 0)
            {
                if (selection [0] is Category)
                {
                    default_category = (Category)selection [0];
                }
                else
                {
                    default_category = selection [0].Category;
                }
            }
            else
            {
                default_category = tag_store.RootCategory;
            }

            this.DefaultResponse = ResponseType.Ok;

            this.Title        = Catalog.GetString("Create New Tag");
            prompt_label.Text = Catalog.GetString("Name of New Tag:");
            this.auto_icon_checkbutton.Active = Preferences.Get <bool> (Preferences.TAG_ICON_AUTOMATIC);

            PopulateCategoryOptionMenu();
            this.Category = default_category;
            Update();
            tag_name_entry.GrabFocus();

            ResponseType response = (ResponseType)this.Run();


            Tag new_tag = null;

            if (response == ResponseType.Ok)
            {
                bool autoicon = this.auto_icon_checkbutton.Active;
                Preferences.Set(Preferences.TAG_ICON_AUTOMATIC, autoicon);
                try {
                    Category parent_category = Category;

                    if (type == TagType.Category)
                    {
                        new_tag = tag_store.CreateCategory(parent_category, tag_name_entry.Text, autoicon);
                    }
                    else
                    {
                        new_tag = tag_store.CreateTag(parent_category, tag_name_entry.Text, autoicon);
                    }
                } catch (Exception ex) {
                    // FIXME error dialog.
                    Log.Exception(ex);
                }
            }

            this.Destroy();
            return(new_tag);
        }
Пример #2
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);
            }
        }
Пример #3
0
        public Tag Execute(TagType type, Tag [] selection)
        {
            this.CreateDialog("create_tag_dialog");

            Category default_category = null;

            if (selection.Length > 0)
            {
                if (selection [0] is Category)
                {
                    default_category = (Category)selection [0];
                }
                else
                {
                    default_category = selection [0].Category;
                }
            }

            this.Dialog.DefaultResponse = ResponseType.Ok;

            this.Dialog.Title = Catalog.GetString("Create New Tag");
            prompt_label.Text = Catalog.GetString("Name of New Tag:");

            PopulateCategoryOptionMenu();
            this.Category = default_category;
            Update();
            tag_name_entry.GrabFocus();

            ResponseType response = (ResponseType)this.Dialog.Run();

            Tag new_tag = null;

            if (response == ResponseType.Ok)
            {
                try {
                    Category parent_category = Category;

                    if (type == TagType.Category)
                    {
                        new_tag = tag_store.CreateCategory(parent_category, tag_name_entry.Text) as Tag;
                    }
                    else
                    {
                        new_tag = tag_store.CreateTag(parent_category, tag_name_entry.Text);
                    }
                } catch (Exception ex) {
                    // FIXME error dialog.
                    Console.WriteLine("error {0}", ex);
                }
            }

            this.Dialog.Destroy();
            return(new_tag);
        }