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

Revision 2043, 2.8 KB checked in by lowjoel, 5 years ago (diff)

Rename all the Settings classes to Configurer since it implements IConfigurer.

  • 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 Eraser.Manager;
32using Eraser.Util;
33
34namespace Eraser.DefaultPlugins
35{
36    public partial class FolderErasureTargetConfigurer : UserControl, IErasureTargetConfigurer
37    {
38        public FolderErasureTargetConfigurer()
39        {
40            InitializeComponent();
41        }
42
43        #region IErasureTargetConfigurer Members
44
45        public void LoadFrom(ErasureTarget target)
46        {
47            FolderErasureTarget folder = target as FolderErasureTarget;
48            if (folder == null)
49                throw new ArgumentException("The provided erasure target type is not " +
50                    "supported by this configurer.");
51
52            folderPath.Text = folder.Path;
53            folderInclude.Text = folder.IncludeMask;
54            folderExclude.Text = folder.ExcludeMask;
55            folderDelete.Checked = folder.DeleteIfEmpty;
56        }
57
58        public bool SaveTo(ErasureTarget target)
59        {
60            FolderErasureTarget folder = target as FolderErasureTarget;
61            if (folder == null)
62                throw new ArgumentException("The provided erasure target type is not " +
63                    "supported by this configurer.");
64
65            if (folderPath.Text.Length == 0)
66            {
67                errorProvider.SetError(folderPath, S._("Invalid folder path"));
68                return false;
69            }
70
71            folder.Path = folderPath.Text;
72            folder.IncludeMask = folderInclude.Text;
73            folder.ExcludeMask = folderExclude.Text;
74            folder.DeleteIfEmpty = folderDelete.Checked;
75            return true;
76        }
77
78        #endregion
79
80        private void folderBrowse_Click(object sender, EventArgs e)
81        {
82            try
83            {
84                folderDialog.SelectedPath = folderPath.Text;
85                if (folderDialog.ShowDialog() == DialogResult.OK)
86                    folderPath.Text = folderDialog.SelectedPath;
87            }
88            catch (NotSupportedException)
89            {
90                MessageBox.Show(this, S._("The path you selected is invalid."), S._("Eraser"),
91                    MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
92                    Localisation.IsRightToLeft(this) ?
93                        MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign : 0);
94            }
95        }
96    }
97}
Note: See TracBrowser for help on using the repository browser.