Пример #1
0
        /// <summary>
        /// Removes the indicated macro.
        /// </summary>
        /// <param name="macro"></param>
        private void RemoveMacro(Macro macro, bool save = true)
        {
            if (macro != null && tagService.AllTags.Tags != null)
            {
                foreach (Tag tag in tagService.AllTags.Tags)
                {
                    if (tag.Macros.Any(m => m.Equals(macro)))
                    {
                        tag.Macros.Remove(macro);
                        break;
                    }
                }
            }

            if (macro == null)
            {
                Messages.ShowWarningMessage($"The macro '{macro.Name}' was not found", "Not found");
            }
            else if (tagService.AllTags.Tags == null)
            {
                Messages.ShowWarningMessage($"The tag from the macro '{macro}' was not found", "Tag not found");
            }

            if (save)
            {
                JSONUtilities.Write(tagService.AllTags);
                RefreshMacrosHandler?.Invoke(macro.Name, null);
            }
        }
Пример #2
0
        /// <summary>
        /// Creates a macro inside the given tag.
        /// </summary>
        /// <param name="tagName"></param>
        /// <param name="macro"></param>
        /// <param name="save"></param>
        private void CreateMacro(string tagName, Macro macro, bool save = true)
        {
            if (GetMacro(tagName, macro.Name) != null)
            {
                Messages.ShowWarningMessage($"The macro '{macro.Name}' already exists", "Already exists");
            }
            else if (tagService.AllTags.Tags == null)
            {
                Messages.ShowWarningMessage($"The tag '{tagName}' was not found", "Tag not found");
            }
            else
            {
                if (tagService.AllTags.Tags != null)
                {
                    foreach (Tag tag in tagService.AllTags.Tags)
                    {
                        if (tag.Name.Equals(tagName))
                        {
                            if (tag.Macros == null)
                            {
                                tag.Macros = new List <Macro>();
                            }
                            tag.Macros.Add(macro);
                            break;
                        }
                    }
                }

                if (save)
                {
                    JSONUtilities.Write(tagService.AllTags);
                    RefreshMacrosHandler?.Invoke(null, null);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Removes the original tag and creates the new one.
        /// </summary>
        /// <param name="originalTag"></param>
        /// <param name="tag"></param>
        /// <param name="save"></param>
        private void EditTag(Tag originalTag, Tag tag, bool save = true)
        {
            RemoveTag(originalTag, false);
            CreateTag(tag, false);

            if (save)
            {
                JSONUtilities.Write(AllTags);
                refreshTagsHandler?.Invoke(null, null);
            }
        }
Пример #4
0
        /// <summary>
        /// Removes the original macro and creates the new one inside the given tag.
        /// </summary>
        /// <param name="originalMacroName"></param>
        /// <param name="tagNameForNewMacro"></param>
        /// <param name="newMacro"></param>
        /// <param name="save"></param>
        private void EditMacro(Macro originalMacro, string tagNameForNewMacro, Macro newMacro, bool save = true)
        {
            RemoveMacro(originalMacro, false);
            CreateMacro(tagNameForNewMacro, newMacro, false);

            if (save)
            {
                JSONUtilities.Write(tagService.AllTags);
                RefreshMacrosHandler?.Invoke(null, null);
            }
        }
Пример #5
0
        /// <summary>
        /// Removes the indicated tag.
        /// </summary>
        /// <param name="tag"></param>
        private void RemoveTag(Tag tag, bool save)
        {
            if (tag == null)
            {
                Messages.ShowWarningMessage($"The tag '{tag.Name}' was not found", "Not found");
            }
            else
            {
                AllTags.Tags.Remove(tag);

                if (save)
                {
                    JSONUtilities.Write(AllTags);
                    refreshTagsHandler?.Invoke(tag.Name, null);
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Creates an empty tag.
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="save"></param>
        private void CreateTag(Tag tag, bool save = true)
        {
            if (GetTag(tag.Name) == null)
            {
                if (AllTags.Tags == null)
                {
                    AllTags.Tags = new List <Tag>();
                }
                AllTags.Tags.Add(tag);

                if (save)
                {
                    JSONUtilities.Write(AllTags);
                    refreshTagsHandler?.Invoke(null, null);
                }
            }
            else
            {
                Messages.ShowWarningMessage($"The tag '{tag.Name}' already exists", "Already exists");
            }
        }