Esempio n. 1
0
        /// <summary>
        /// Adds a new replace rule.
        /// </summary>
        public ReplaceRule AddReplace(string inId)
        {
            CheckLocked();

            ReplaceRule rule = FindOrCreateReplaceRule(inId);

            return(rule);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a new replace rule that replaces with the result of the given callback.
        /// </summary>
        public ReplaceRule AddReplace(string inId, TryReplaceDelegate inReplace)
        {
            CheckLocked();

            ReplaceRule rule = FindOrCreateReplaceRule(inId);

            rule.TryReplaceWith(inReplace);
            return(rule);
        }
Esempio n. 3
0
        /// <summary>
        /// Adds a new replace rule that replaces with the result of the given callback.
        /// </summary>
        public ReplaceRule AddReplace(string inId, ReplaceSourceContextDelegate inReplace)
        {
            CheckLocked();

            ReplaceRule rule = FindOrCreateReplaceRule(inId);

            rule.ReplaceWith(inReplace);
            return(rule);
        }
Esempio n. 4
0
        private ReplaceRule FindOrCreateReplaceRule(string inPattern)
        {
            foreach (var rule in m_ReplaceRules)
            {
                if (rule.Id() == inPattern)
                {
                    return(rule);
                }
            }

            ReplaceRule newRule = new ReplaceRule(inPattern);

            m_ReplaceRules.Add(newRule);
            return(newRule);
        }
Esempio n. 5
0
        public bool TryReplace(TagData inData, StringSlice inSource, object inContext, out string outReplace)
        {
            ReplaceRule rule = m_ReplaceRules.FindMatch(inData.Id);

            if (rule != null)
            {
                return(rule.Evaluate(inData, inSource, inContext, out outReplace));
            }

            if (m_ReplaceInheritFrom != null)
            {
                return(m_ReplaceInheritFrom.TryReplace(inData, inSource, inContext, out outReplace));
            }

            outReplace = null;
            return(false);
        }
        void spec_Apply()
        {
            context["normal text"] = () =>
            {
                ReplaceRule rule = new ReplaceRule("<target>", "new text", new string[] { "test" });
                string oldName = "first test 1";
                string newFormat = "<target>";
                rule.Apply(ref oldName, ref newFormat);
                it["remove text from old name"] = () => oldName.should_be("first  1");
                it["copy text to new format"] = () => newFormat.should_be("new text<target>");
            };

            context["regular expression"] = () =>
            {
                ReplaceRule rule = new ReplaceRule("<target>", "new text", new string[] { "* t.st" });
                string oldName = "first test 1";
                string newFormat = "<target>";
                rule.Apply(ref oldName, ref newFormat);
                it["remove text from old name"] = () => oldName.should_be("first  1");
                it["copy text to new format"] = () => newFormat.should_be("new text<target>");
            };

            context["regular expression with capturing"] = () =>
            {
                ReplaceRule rule = new ReplaceRule("<target>", "new text", new string[] { "* (te.t)" });
                string oldName = "first test 1";
                string newFormat = "<target>";
                rule.Apply(ref oldName, ref newFormat);
                it["remove text from old name"] = () => oldName.should_be("first  1");
                it["copy text to new format"] = () => newFormat.should_be("new text<target>");
            };

            context["regular expression with capturing excluding text"] = () =>
            {
                ReplaceRule rule = new ReplaceRule("<target>", "new text", new string[] { "* (te)st" });
                string oldName = "first test 1";
                string newFormat = "<target>";
                rule.Apply(ref oldName, ref newFormat);
                it["remove text from old name"] = () => oldName.should_be("first  1");
                it["copy text to new format"] = () => newFormat.should_be("new text<target>");
            };
        }
Esempio n. 7
0
        private void ConfirmButtonClick(object sender, EventArgs e)
        {
            if (Globals.RenameRules == null)
            {
                Globals.RenameRules = new List <IRenameRule>();
            }
            switch (RuleTypeTabControl.SelectedIndex)
            {
            case 0:
                InsertRule insertRule = new InsertRule(insertText: InsertTextTextBox.Text,
                                                       numberSequence: InsertNumberSeqRadioButton.Checked,
                                                       numberSequenceStart: (int)InsertNumberSeqStartingAtNumericUpDown.Value,
                                                       numberSequenceLeadingZeroes: (int)InsertNumberSeqLeadingZeroesNumericUpDown.Value,
                                                       beforeTextStr: InsertBeforeTextTextBox.Text,
                                                       afterTextStr: InsertAfterTextTextBox.Text,
                                                       prefix: InsertPrefixRadioButton.Checked,
                                                       suffix: InsertSuffixRadioButton.Checked,
                                                       position: InsertAtPositionRadioButton.Checked,
                                                       positionRightToLeft: InsertPositionRightLeftCheckBox.Checked,
                                                       beforeText: InsertBeforeTextRadioButton.Checked,
                                                       afterText: InsertAfterTextRadioButton.Checked,
                                                       replaceFileName: ReplaceCurrentFileNameRadioButton.Checked,
                                                       ignoreExtension: InsertIgnoreExtensionCheckBox.Checked,
                                                       positionIndex: (int)InsertPositionNumericUpDown.Value);

                if (editMode)
                {
                    int oldRuleIndex = Globals.RenameRules.IndexOf(Globals.RenameRules.Find(rule => rule.Id == currentlyEditedRule.Id));
                    Globals.RenameRules[oldRuleIndex] = insertRule;
                }
                else
                {
                    Globals.RenameRules.Add(insertRule);
                }

                DialogResult = DialogResult.OK;
                break;

            case 1:
                DeleteRule deleteRule = new DeleteRule(fromPosition: DeleteFromPositionRadioButton.Checked,
                                                       fromDelimiter: DeleteFromDelimiterRadioButton.Checked,
                                                       toPosition: DeleteToPositionRadioButton.Checked,
                                                       toDelimiter: DeleteToDelimiterRadioButton.Checked,
                                                       deleteToEnd: DeleteToEndRadioButton.Checked,
                                                       deleteEntireFileName: DeleteEntireFileNameCheckBox.Checked,
                                                       ignoreExtension: DeleteIgnoreExtensionCheckBox.Checked,
                                                       keepDelimiters: DeleteKeepDelimitersCheckBox.Checked,
                                                       fromPositionIndex: (int)DeleteFromPositionNumericUpDown.Value,
                                                       toPositionIndex: (int)DeleteToPositionNumericUpDown.Value,
                                                       fromDelimiterStr: DeleteFromDelimiterTextBox.Text,
                                                       toDelimiterStr: DeleteToDelimiterTextBox.Text);

                if (editMode)
                {
                    int oldRuleIndex = Globals.RenameRules.IndexOf(Globals.RenameRules.Find(rule => rule.Id == currentlyEditedRule.Id));
                    Globals.RenameRules[oldRuleIndex] = deleteRule;
                }
                else
                {
                    Globals.RenameRules.Add(deleteRule);
                }

                DialogResult = DialogResult.OK;
                break;

            case 2:
                RemoveRule removeRule = new RemoveRule(removeText: RemoveTextTextBox.Text,
                                                       allOccurrences: RemoveAllOccurrencesRadioButton.Checked,
                                                       firstOccurrence: RemoveFirstOccurrenceRadioButton.Checked,
                                                       lastOccurrence: RemoveLastOccurrenceRadioButton.Checked,
                                                       caseSensitive: RemoveCaseSensitiveCheckBox.Checked,
                                                       ignoreExtension: RemoveIgnoreExtensionCheckBox.Checked
                                                       );

                if (editMode)
                {
                    int oldRuleIndex = Globals.RenameRules.IndexOf(Globals.RenameRules.Find(rule => rule.Id == currentlyEditedRule.Id));
                    Globals.RenameRules[oldRuleIndex] = removeRule;
                }
                else
                {
                    Globals.RenameRules.Add(removeRule);
                }

                DialogResult = DialogResult.OK;
                break;

            case 3:
                ReplaceRule replaceRule = new ReplaceRule(findText: ReplaceFindTextBox.Text,
                                                          replaceText: ReplaceTextTextBox.Text,
                                                          allOccurrences: ReplaceAllOccurrencesRadioButton.Checked,
                                                          firstOccurrence: ReplaceFirstOccurrenceRadioButton.Checked,
                                                          lastOccurrence: ReplaceLastOccurrenceRadioButton.Checked,
                                                          caseSensitive: ReplaceCaseSensitiveCheckBox.Checked,
                                                          ignoreExtension: ReplaceIgnoreExtensionCheckBox.Checked
                                                          );

                if (editMode)
                {
                    int oldRuleIndex = Globals.RenameRules.IndexOf(Globals.RenameRules.Find(rule => rule.Id == currentlyEditedRule.Id));
                    Globals.RenameRules[oldRuleIndex] = replaceRule;
                }
                else
                {
                    Globals.RenameRules.Add(replaceRule);
                }

                DialogResult = DialogResult.OK;
                break;

            case 4:
                CleanRule cleanRule = new CleanRule(cleanLatinAlphabet: CleanLatinAlphabetCheckBox.Checked,
                                                    cleanDigits: CleanDigitsCheckBox.Checked,
                                                    cleanBrackets: CleanBracketsCheckBox.Checked,
                                                    cleanSymbols: CleanSymbolsCheckBox.Checked,
                                                    cleanUserDefined: CleanUserDefinedCheckBox.Checked,
                                                    cleanUserDefinedText: CleanUserDefinedTextBox.Text,
                                                    caseSensitive: CleanCaseSensitiveCheckBox.Checked,
                                                    ignoreExtension: CleanIgnoreExtensionCheckBox.Checked
                                                    );

                if (editMode)
                {
                    int oldRuleIndex = Globals.RenameRules.IndexOf(Globals.RenameRules.Find(rule => rule.Id == currentlyEditedRule.Id));
                    Globals.RenameRules[oldRuleIndex] = cleanRule;
                }
                else
                {
                    Globals.RenameRules.Add(cleanRule);
                }

                DialogResult = DialogResult.OK;
                break;

            case 5:
                RegexRule regexRule = new RegexRule(regexFindText: RegexFindTextTextBox.Text,
                                                    replaceText: RegexReplaceTextTextBox.Text,
                                                    ignoreExtension: CleanIgnoreExtensionCheckBox.Checked
                                                    );

                if (editMode)
                {
                    int oldRuleIndex = Globals.RenameRules.IndexOf(Globals.RenameRules.Find(rule => rule.Id == currentlyEditedRule.Id));
                    Globals.RenameRules[oldRuleIndex] = regexRule;
                }
                else
                {
                    Globals.RenameRules.Add(regexRule);
                }

                DialogResult = DialogResult.OK;
                break;

            default:
                MessageBox.Show("An unknown error has occurred.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
                DialogResult = DialogResult.Cancel;
                break;
            }
        }