コード例 #1
0
ファイル: ConfigFileLoader.cs プロジェクト: jluchiji/RenEx
        public static RenamingRule ReadRule(XmlNode ruleNode)
        {
            if (ruleNode.Name != "Rule") throw new ArgumentException();

            RenamingRule rule = new RenamingRule();
            rule.Name = ruleNode.Attributes["name"].InnerText;
            rule.DeleteFile = Boolean.Parse(ruleNode.Attributes["delete"].InnerText);
            rule.RegularExpression = ruleNode.SelectSingleNode("RegExp").InnerText;
            rule.ReplacementExpression = ruleNode.SelectSingleNode("RepExp").InnerText;
            rule.Type = (RenamingRule.RuleType) Int32.Parse(ruleNode.Attributes["type"].InnerText);

            return rule;
        }
コード例 #2
0
ファイル: OptionsDialog.cs プロジェクト: jluchiji/RenEx
        public void AttachRuleTemplateHandlers()
        {
            // Item Selection
            lbRlt.SelectedValueChanged += (@s, e) =>
                {
                    if (lbRlt.SelectedItem != null)
                        ShowRule((RenamingRule) lbRlt.SelectedItem);
                    else
                    {
                        txtRltName.Clear();
                        txtRltRegex.Clear();
                        txtRltRep.Clear();
                        radRltName.Checked = true;
                    }

                    gbRltOptions.Enabled = lbRlt.SelectedItem != null;
                };

            // Apply changes
            txtRltName.Leave += (@s, e) => ApplyRltChanges();
            radRltDir.Leave += (@s, e) => ApplyRltChanges();
            radRltExt.Leave += (@s, e) => ApplyRltChanges();
            radRltName.Leave += (@s, e) => ApplyRltChanges();
            txtRltRegex.Leave += (@s, e) => ApplyRltChanges();
            txtRltRep.Leave += (@s, e) => ApplyRltChanges();
            chbRltDelete.CheckedChanged += (@s, e) =>
                {
                    txtRltRep.Enabled = !chbRltDelete.Checked;
                    ApplyRltChanges();
                };

            // Add/Remove
            btnRltAdd.Click += (@s, e) =>
                {
                    String nname = "New Rule #" +
                            libWyvernzora.Core.DirectIntConv.ToHexString(Configuration.Random.Next(), 8)
                            .Substring(2);

                    RenamingRule rule = new RenamingRule() {Name = nname, Type = RenamingRule.RuleType.Name, RegularExpression = "", ReplacementExpression = ""};
                    Configuration.Instance.Rules.Add(nname, rule);
                    UpdateRuleTemplateList(nname);
                    txtRltName.Select();
                    txtRltName.SelectAll();
                };
            btnRltRemove.Click += (@s, e) =>
            {
                RenamingRule rule = lbRlt.SelectedItem as RenamingRule;
                if (rule == null) return;

                Configuration.Instance.Rules.Remove(rule.Name);
                UpdateRuleTemplateList();
            };
        }
コード例 #3
0
ファイル: OptionsDialog.cs プロジェクト: jluchiji/RenEx
        private void ShowRule(RenamingRule rule)
        {
            txtRltName.Text = rule.Name;
            switch (rule.Type)
            {
                case RenamingRule.RuleType.Name:
                    radRltName.Checked = true;
                    break;
                case RenamingRule.RuleType.Extension:
                    radRltExt.Checked = true;
                    break;
                default:
                    radRltDir.Checked = true;
                    break;
            }

            txtRltRegex.Text = rule.RegularExpression;
            txtRltRep.Text = rule.ReplacementExpression;

            chbRltDelete.Checked = rule.DeleteFile;
        }
コード例 #4
0
ファイル: OptionsDialog.cs プロジェクト: jluchiji/RenEx
        private RenamingRule GetRuleFromUi()
        {
            RenamingRule rule = new RenamingRule
                {
                    Name = txtRltName.Text,
                    RegularExpression = txtRltRegex.Text,
                    ReplacementExpression = txtRltRep.Text,
                    DeleteFile = chbRltDelete.Checked,
                    Type = radRltName.Checked
                               ? RenamingRule.RuleType.Name
                               : radRltExt.Checked
                                     ? RenamingRule.RuleType.Extension
                                     : RenamingRule.RuleType.Directory
                };

            return rule;
        }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: jluchiji/RenEx
        private void UIEventHandlers()
        {
            // Drag Drop Files
            lvPreview.DragEnter += (@s, a) =>
                {
                    if (a.Data.GetDataPresent(DataFormats.FileDrop))
                        a.Effect = DragDropEffects.Link;
                };
            lvPreview.DragDrop += (@s, e) =>
                {
                    String[] files = (String[]) e.Data.GetData(DataFormats.FileDrop);
                    Session.AddFile(files);
                    UpdatePreview();
                };

            // Resize
            lvPreview.Resize += (@s, a) =>
            {
                Int32 width = (lvPreview.Width - 48) / 2;
                lvPreview.Columns[0].Width = width;
                lvPreview.Columns[1].Width = width;
            };
            lvPreview.KeyDown += (@s, e) =>
                {
                    if (e.KeyCode == Keys.A && e.Modifiers == Keys.Control)
                    {
                        foreach (ListViewItem i in lvPreview.Items)
                            i.Selected = true;
                    }
                    else if (e.KeyCode == Keys.Delete)
                    {
                        ListViewItem[] items = new ListViewItem[lvPreview.SelectedItems.Count];
                        lvPreview.SelectedItems.CopyTo(items, 0);

                        Session.RemoveFiles(from i in items select (String)i.Tag);
                        UpdatePreview();
                    }
                };

            // Context Menus
            lvPreview.ItemSelectionChanged += (@s, e) =>
                {
                    Int32 count = lvPreview.SelectedItems.Count;

                    tsmiPvRemSelection.Enabled = count > 0;
                    tsmiPvExtractRule.Enabled = count == 1;
                };
            lvRules.ItemSelectionChanged += (@s, e) =>
                {
                    Int32 count = lvRules.SelectedItems.Count;

                    tsmiRemoveRules.Enabled = count > 0;
                    tsmiAddToTemplates.Enabled = count == 1;
                };
            tsmiAddRule.Click += (@s, e) =>
                {
                    RuleEditorDialog dlg = new RuleEditorDialog(this);
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        RenamingRule rule = dlg.Rule;
                        Session.Rules.AddRule(rule);
                    }
                };
            tsmiRemoveRules.Click += (@s, e) =>
                {
                    ListViewItem[] selection = new ListViewItem[lvRules.SelectedItems.Count];
                    lvRules.SelectedItems.CopyTo(selection, 0);

                    foreach (RenamingRule rule in selection.Select(v => v.Tag).OfType<RenamingRule>())
                        Session.Rules.RemoveRule(rule);

                    UpdateUI();
                };
            tsmiAddToTemplates.Click += (@s, e) =>
                {
                    RenamingRule rule = lvRules.SelectedItems[0].Tag as RenamingRule;
                    if (rule == null) throw new Exception();

                    OptionsDialog dlg = new OptionsDialog(1, rule);
                    dlg.ShowDialog();
                    UpdateUI();
                };
            tsmiPvAddFiles.Click += (@s, e) =>
                {
                    OpenFileDialog dlg = new OpenFileDialog() { Multiselect = true };
                    if (dlg.ShowDialog() == DialogResult.OK)
                        Session.AddFile(dlg.FileNames);
                };
            tsmiPvRemSelection.Click += (@s, e) =>
                {
                    ListViewItem[] items = new ListViewItem[lvPreview.SelectedItems.Count];
                    lvPreview.SelectedItems.CopyTo(items, 0);

                    Session.RemoveFiles(from i in items select (String)i.Tag);
                    UpdatePreview();
                };
            tsmiPvExtractRule.Click += (@s, e) =>
                {
                    String fname = lvPreview.SelectedItems[0].Tag as String;
                    if (fname == null) return;

                    var extConfig = Configuration.Instance.GetCurrentExtensionSettings();
                    var fds = new FileNameDescriptor(fname, extConfig.MaximumExtensions, extConfig.Validator);

                    RenamingRule rule = new RenamingRule
                        {
                            Type = RenamingRule.RuleType.Name,
                            RegularExpression = Regex.Escape(fds.FileName).Replace("\\ ", " "),
                            ReplacementExpression =
                                String.Format("{0}{1}", Path.GetFileNameWithoutExtension(fds.Directory), "[${i}]")
                        };

                    RuleEditorDialog dlg = new RuleEditorDialog(this) {Rule = rule};
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        Session.Rules.AddRule(dlg.Rule);
                        UpdateUI();
                    }

                };
            tsmiPvRemApplied.Click += (@s, e) =>
                {
                    Session.RemoveApplied();
                    UpdatePreview();
                };

            // RUN RENAMING
            renBtnRunRename.Click += (@s, a) => ApplyRenaming();
        }
コード例 #6
0
        /// <summary>
        /// Adds a rule to the collection.
        /// </summary>
        /// <param name="rule"></param>
        public void AddRule(RenamingRule rule)
        {
            rule.Active = true;

            switch (rule.Type)
            {
                case RenamingRule.RuleType.Name:
                        NameRules.Add(rule);
                    break;
                case RenamingRule.RuleType.Extension:
                        ExtensionRules.Add(rule);
                    break;
                case RenamingRule.RuleType.Directory:
                        DirectoryRules.Add(rule);
                    break;
            }
        }
コード例 #7
0
 /// <summary>
 /// Removes a rule from the collection.
 /// </summary>
 /// <param name="rule">RenamingRule instance to remove.</param>
 public void RemoveRule(RenamingRule rule)
 {
     switch (rule.Type)
     {
         case RenamingRule.RuleType.Name:
             NameRules.Remove(rule);
             break;
         case RenamingRule.RuleType.Extension:
             ExtensionRules.Remove(rule);
             break;
         case RenamingRule.RuleType.Directory:
             DirectoryRules.Remove(rule);
             break;
     }
 }