Skip to content

Commit aab39ff

Browse files
committed
Implement Delete as action
Closes #13
1 parent f0bbf09 commit aab39ff

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed

PatternFileMover/Action/Delete.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.IO;
2+
using System.Windows.Forms;
3+
4+
namespace PatternFileMover.Action
5+
{
6+
internal class Delete : AbstractAction
7+
{
8+
public bool DoDelete()
9+
{
10+
try
11+
{
12+
File.Delete(this.GetSourcePath());
13+
}
14+
catch (IOException)
15+
{
16+
return false;
17+
}
18+
19+
return true;
20+
}
21+
22+
public override bool ExecuteAction()
23+
{
24+
return base.ExecuteAction();
25+
}
26+
27+
public override bool Matches(DataGridViewRow row)
28+
{
29+
if (!base.Matches(row))
30+
{
31+
return false;
32+
}
33+
34+
if (
35+
(
36+
this.GetFileExtension() == "*.*" &&
37+
Path.GetFileNameWithoutExtension(
38+
this.GetCurrent().Cells[(int)NameAssociationCellIndex.Name].Value.ToString()
39+
).Contains(this.GetSearchPattern())
40+
) ||
41+
(
42+
Path.GetFileNameWithoutExtension(
43+
this.GetCurrent().Cells[(int)NameAssociationCellIndex.Name].Value.ToString()
44+
).Contains(this.GetSearchPattern()) &&
45+
this.GetFileExtension() == Path.GetExtension(this.GetCurrent().Cells[(int)NameAssociationCellIndex.Name].Value.ToString())
46+
)
47+
)
48+
{
49+
return true;
50+
}
51+
52+
return false;
53+
}
54+
}
55+
}

PatternFileMover/Actions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public enum AvailableActions
1818
CopyOverwrite = 2,
1919
[Description("grid.Action.MoveOverwrite")]
2020
MoveOverwrite = 3,
21+
[Description("grid.Action.Delete")]
22+
Delete = 4,
2123
}
2224

2325
public class AvailableAction

PatternFileMover/NameAssociationsForm.de.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,7 @@
183183
<data name="grid.Action.MoveOverwrite" xml:space="preserve">
184184
<value>Verschieben (Überschreiben)</value>
185185
</data>
186+
<data name="grid.Action.Delete" xml:space="preserve">
187+
<value>Löschen</value>
188+
</data>
186189
</root>

PatternFileMover/NameAssociationsForm.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,4 +372,7 @@
372372
<data name="grid.Action.MoveOverwrite" xml:space="preserve">
373373
<value>Move (Overwrite)</value>
374374
</data>
375+
<data name="grid.Action.Delete" xml:space="preserve">
376+
<value>Delete</value>
377+
</data>
375378
</root>

PatternFileMover/PatternFileMover.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<Compile Include="Actions.cs" />
5353
<Compile Include="Action\Copy.cs" />
5454
<Compile Include="Action\CopyOverwrite.cs" />
55+
<Compile Include="Action\Delete.cs" />
5556
<Compile Include="Action\IAction.cs" />
5657
<Compile Include="Action\Move.cs" />
5758
<Compile Include="Action\MoveOverwrite.cs" />

0 commit comments

Comments
 (0)