-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPanelCommandTouchFile.cs
More file actions
160 lines (145 loc) · 5.97 KB
/
Copy pathPanelCommandTouchFile.cs
File metadata and controls
160 lines (145 loc) · 5.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace netCommander
{
class PanelCommandTouchFile : PanelCommandBase
{
public PanelCommandTouchFile()
{
ToolStripMenuItem menu = new ToolStripMenuItem();
menu.ShortcutKeys = Keys.Control | Keys.T;
menu.ShowShortcutKeys = true;
menu.Text = "Touch";
CommandMenu = menu;
}
protected override void internal_command_proc()
{
try
{
QueryPanelInfoEventArgs e = new QueryPanelInfoEventArgs();
OnQueryCurrentPanel(e);
if (e.FocusedIndex == -1)
{
return;
}
string target_file = string.Empty;
DirectoryList dl = (DirectoryList)e.ItemCollection;
int[] sel_indices = e.SelectedIndices;
bool group_mode = (sel_indices.Length > 1);
//we need cache list of selected files
//becouse e.ItemCollection can change while processing (sort!)
List<string> sel_names = new List<string>();
for (int i = 0; i < sel_indices.Length; i++)
{
sel_names.Add(e.ItemCollection.GetItemDisplayNameLong(sel_indices[i]));
}
if (!group_mode)
{
if (sel_indices.Length == 1)
{
target_file = Path.Combine(dl.DirectoryPath, dl.GetItemDisplayNameLong(sel_indices[0]));
}
else
{
target_file = Path.Combine(dl.DirectoryPath, dl.GetItemDisplayNameLong(e.FocusedIndex));
}
}
if (target_file.EndsWith(".."))
{
target_file = dl.DirectoryPath + Path.DirectorySeparatorChar;
}
FileSystemInfo target_fsi = null;
if (!group_mode)
{
target_fsi = IOhelper.GetFileSystemInfo(target_file);
}
TouchFileDialog dialog = new TouchFileDialog();
dialog.Text = "Touch";
if (!group_mode)
{
dialog.textBoxFileName.Text = target_file;
dialog.dateTimePickerAccess.Value = target_fsi.LastAccessTime;
dialog.dateTimePickerCreation.Value = target_fsi.CreationTime;
dialog.dateTimePickerModification.Value = target_fsi.LastWriteTime;
}
else
{
dialog.textBoxFileName.Text = string.Format("Touch {0} entries", sel_indices.Length);
dialog.textBoxFileName.Enabled = false;
}
if (dialog.ShowDialog() != DialogResult.OK)
{
return;
}
if (!group_mode)
{
if (dialog.textBoxFileName.Text != target_file)
{
//try create new file
netCommander.FileSystemEx.Wrapper.CreateNewEmptyFile(dialog.textBoxFileName.Text);
//if success
target_fsi = new FileInfo(dialog.textBoxFileName.Text);
}
}
//set times
if (group_mode)
{
foreach (string one_name in sel_names)
{
try
{
target_file = Path.Combine(dl.DirectoryPath, one_name);
target_fsi = IOhelper.GetFileSystemInfo(target_file);
if (dialog.dateTimePickerAccess.Checked)
{
target_fsi.LastAccessTime = dialog.dateTimePickerAccess.Value;
}
if (dialog.dateTimePickerCreation.Checked)
{
target_fsi.CreationTime = dialog.dateTimePickerCreation.Value;
}
if (dialog.dateTimePickerModification.Checked)
{
target_fsi.LastWriteTime = dialog.dateTimePickerModification.Value;
}
OnItemProcessDone(new ItemEventArs(one_name));
}
catch (Exception ex)
{
Messages.ShowException(ex);
}
}
}
else
{
try
{
if (dialog.dateTimePickerAccess.Checked)
{
target_fsi.LastAccessTime = dialog.dateTimePickerAccess.Value;
}
if (dialog.dateTimePickerCreation.Checked)
{
target_fsi.CreationTime = dialog.dateTimePickerCreation.Value;
}
if (dialog.dateTimePickerModification.Checked)
{
target_fsi.LastWriteTime = dialog.dateTimePickerModification.Value;
}
}
catch (Exception ex)
{
Messages.ShowException(ex);
}
}
}
catch (Exception ex)
{
Messages.ShowException(ex);
}
}// end of proc
}//end of class
}