Пример #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 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);
            }
        }