source: trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/FolderErasureTargetConfigurer.cs @ 2070

Revision 2070, 4.2 KB checked in by lowjoel, 5 years ago (diff)

Apply themes for the target configurers.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1/*
2 * $Id$
3 * Copyright 2008-2010 The Eraser Project
4 * Original Author: Joel Low <lowjoel@users.sourceforge.net>
5 * Modified By:
6 *
7 * This file is part of Eraser.
8 *
9 * Eraser is free software: you can redistribute it and/or modify it under the
10 * terms of the GNU General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option) any later
12 * version.
13 *
14 * Eraser is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 *
18 * A copy of the GNU General Public License can be found at
19 * <http://www.gnu.org/licenses/>.
20 */
21
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30
31using System.Text.RegularExpressions;
32
33using Eraser.Manager;
34using Eraser.Util;
35
36namespace Eraser.DefaultPlugins
37{
38    public partial class FolderErasureTargetConfigurer : UserControl, IErasureTargetConfigurer
39    {
40        public FolderErasureTargetConfigurer()
41        {
42            InitializeComponent();
43            Theming.ApplyTheme(this);
44        }
45
46        #region IConfigurer<ErasureTarget> Members
47
48        public void LoadFrom(ErasureTarget target)
49        {
50            FolderErasureTarget folder = target as FolderErasureTarget;
51            if (folder == null)
52                throw new ArgumentException("The provided erasure target type is not " +
53                    "supported by this configurer.");
54
55            folderPath.Text = folder.Path;
56            folderInclude.Text = folder.IncludeMask;
57            folderExclude.Text = folder.ExcludeMask;
58            folderDelete.Checked = folder.DeleteIfEmpty;
59        }
60
61        public bool SaveTo(ErasureTarget target)
62        {
63            FolderErasureTarget folder = target as FolderErasureTarget;
64            if (folder == null)
65                throw new ArgumentException("The provided erasure target type is not " +
66                    "supported by this configurer.");
67
68            if (folderPath.Text.Length == 0)
69            {
70                errorProvider.SetError(folderPath, S._("Invalid folder path"));
71                return false;
72            }
73
74            folder.Path = folderPath.Text;
75            folder.IncludeMask = folderInclude.Text;
76            folder.ExcludeMask = folderExclude.Text;
77            folder.DeleteIfEmpty = folderDelete.Checked;
78            return true;
79        }
80
81        #endregion
82
83        #region ICliConfigurer<ErasureTarget> Members
84
85        public void Help()
86        {
87            throw new NotImplementedException();
88        }
89
90        public bool ProcessArgument(string argument)
91        {
92            //The directory target, taking a list of + and - wildcard expressions.
93            Regex regex = new Regex("dir=(?<directoryName>.*)(?<directoryParams>(?<directoryExcludeMask>,-[^,]+)|(?<directoryIncludeMask>,\\+[^,]+)|(?<directoryDeleteIfEmpty>,deleteIfEmpty(=(?<directoryDeleteIfEmptyValue>true|false))?))*",
94                RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.RightToLeft);
95            Match match = regex.Match(argument);
96
97            string[] trueValues = new string[] { "yes", "true" };
98            if (match.Groups["directoryName"].Success)
99            {
100                folderPath.Text = match.Groups["directoryName"].Value;
101                if (!match.Groups["directoryDeleteIfEmpty"].Success)
102                    folderDelete.Checked = false;
103                else if (!match.Groups["directoryDeleteIfEmptyValue"].Success)
104                    folderDelete.Checked = true;
105                else
106                    folderDelete.Checked =
107                        trueValues.Contains(match.Groups["directoryDeleteIfEmptyValue"].Value);
108
109                if (match.Groups["directoryExcludeMask"].Success)
110                    folderExclude.Text += match.Groups["directoryExcludeMask"].Value.Remove(0, 2) + ' ';
111                if (match.Groups["directoryIncludeMask"].Success)
112                    folderInclude.Text += match.Groups["directoryIncludeMask"].Value.Remove(0, 2) + ' ';
113            }
114
115            return false;
116        }
117
118        #endregion
119
120        private void folderBrowse_Click(object sender, EventArgs e)
121        {
122            try
123            {
124                folderDialog.SelectedPath = folderPath.Text;
125                if (folderDialog.ShowDialog() == DialogResult.OK)
126                    folderPath.Text = folderDialog.SelectedPath;
127            }
128            catch (NotSupportedException)
129            {
130                MessageBox.Show(this, S._("The path you selected is invalid."), S._("Eraser"),
131                    MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
132                    Localisation.IsRightToLeft(this) ?
133                        MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign : 0);
134            }
135        }
136    }
137}
Note: See TracBrowser for help on using the repository browser.