-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileCollectionBase.cs
More file actions
225 lines (202 loc) · 6.87 KB
/
Copy pathFileCollectionBase.cs
File metadata and controls
225 lines (202 loc) · 6.87 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace netCommander
{
public abstract class FileCollectionBase : IDisposable
{
protected abstract void internal_dispose();
protected abstract void internal_sort(int criteria_index, bool reverse_order);
protected abstract void internal_refill();
public abstract string[] SortCriteriaAvailable { get; }
public event EventHandler AfterSummaryUpdate;
public event EventHandler AfterSort;
public event EventHandler AfterRefill;
public event ItemUpdateEventHandler ItemUpdate;
public event ItemUpdateEventHandler ItemRemove;
public event ItemUpdateEventHandler ItemInsert;
//public event EventHandler RefillException;
public abstract string GetItemDisplayName(int index);
public abstract string GetItemDisplayNameLong(int index);
public abstract string GetItemDisplaySummaryInfo(int index);
public abstract string GetSummaryInfo();
public abstract string GetSummaryInfo(int[] indices);
public abstract int ItemCount { get; }
public abstract bool GetItemSelectEnable(int index);
public abstract bool GetItemIsContainer(int index);
/// <summary>
/// create child collection
/// </summary>
/// <param name="index">target item index</param>
/// <param name="new_collection">set if new FileCollectionBase needed</param>
/// <param name="use_new">must use new_collection, else use current collection</param>
/// <param name="preferred_focused_text">text to set caret</param>
public abstract void GetChildCollection(int index, ref FileCollectionBase new_collection, ref bool use_new,ref string preferred_focused_text);
public abstract int FindIndexOfName(string name);
public abstract int[] FindItems();
public abstract string GetStatusText();
private List<PanelCommandBase> available_commands = new List<PanelCommandBase>();
public FileCollectionBase(int sort_criteria_index, bool sort_reverse)
{
sort_current = sort_criteria_index;
this.sort_reverse = sort_reverse;
}
public List<PanelCommandBase> AvailableCommands
{
get
{
return available_commands;
}
}
public mainForm MainWindow { get; set; }
private List<ToolStripMenuItem> internal_sort_menu = null;
public List<ToolStripMenuItem> AvailableSortMenu
{
get
{
if (internal_sort_menu == null)
{
internal_sort_menu = new List<ToolStripMenuItem>();
string[] sort_modes = SortCriteriaAvailable;
foreach (string one_mode in sort_modes)
{
ToolStripMenuItem sort_menu_item = new ToolStripMenuItem(one_mode);
sort_menu_item.Click += new EventHandler(sort_menu_item_Click);
internal_sort_menu.Add(sort_menu_item);
}
}
return internal_sort_menu;
}
}
void sort_menu_item_Click(object sender, EventArgs e)
{
try
{
ToolStripMenuItem src_menu = (ToolStripMenuItem)sender;
int ind = internal_sort_menu.IndexOf(src_menu);
if (ind < 0)
{
return;
}
if (ind == SortCriteria)
{
//change sort order
SortReverse = !SortReverse;
}
else
{
SortCriteria = ind;
}
}
catch (Exception ex)
{
Messages.ShowException(ex);
}
}
private int sort_current;
public int SortCriteria
{
get
{
return sort_current;
}
set
{
if (sort_current != value)
{
internal_sort(value, sort_reverse);
sort_current = value;
OnAfterSort();
}
}
}
private bool sort_reverse = false;
public bool SortReverse
{
get
{
return sort_reverse;
}
set
{
if (sort_reverse != value)
{
internal_sort(sort_current, value);
sort_reverse = value;
OnAfterSort();
}
}
}
public void Refill()
{
internal_refill();
OnAfterRefill();
}
protected void OnAfterSummaryUpdate()
{
if (AfterSummaryUpdate != null)
{
AfterSummaryUpdate(this, new EventArgs());
}
}
protected void OnAfterSort()
{
if (AfterSort != null)
{
AfterSort(this, new EventArgs());
}
}
protected void OnAfterRefill()
{
if (AfterRefill != null)
{
AfterRefill(this, new EventArgs());
}
}
protected void OnItemUpdate(int index)
{
if (ItemUpdate != null)
{
ItemUpdate(this, new ItemUpdateEventArgs(index));
}
}
protected void OnItemRemove(int index)
{
if (ItemRemove != null)
{
ItemRemove(this, new ItemUpdateEventArgs(index));
}
}
protected void OnItemInsert(int index)
{
if (ItemInsert != null)
{
ItemInsert(this, new ItemUpdateEventArgs(index));
}
}
protected void OnLongOperaion(string status, bool show_status_window)
{
if (MainWindow == null)
{
return;
}
MainWindow.NotifyLongOperation(status, show_status_window);
}
#region IDisposable Members
public void Dispose()
{
internal_dispose();
}
#endregion
}
public class ItemUpdateEventArgs : EventArgs
{
public int Index { get; private set; }
public ItemUpdateEventArgs(int index)
{
Index = index;
}
}
public delegate void ItemUpdateEventHandler(object sender, ItemUpdateEventArgs e);
}