-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathItemViewModel.cs
More file actions
291 lines (262 loc) · 8.77 KB
/
ItemViewModel.cs
File metadata and controls
291 lines (262 loc) · 8.77 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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
namespace SolutionLib.ViewModels.Browser.Base
{
using InplaceEditBoxLib.Events;
using SolutionLib.ViewModels.Base;
using SolutionLib.Interfaces;
using SolutionLib.Models;
using System;
using System.Windows;
using System.Windows.Media.Imaging;
using UserNotification.Events;
/// <summary>
/// Implements base functions for all treeview items that are NOT concerned
/// about managing Children collections. The functionality in this base class
/// is focussed on the item itself (not on it's children). The design aims
/// at implementing items, such as files, that may not even have
/// children themselves.
/// </summary>
internal abstract class ItemViewModel : BaseViewModel, IItem
{
#region fields
private readonly SolutionItemType _ItemType;
private string _DisplayName;
private string _Description;
private bool _IsItemExpanded;
private bool _IsItemSelected;
private IItem _Parent = null;
private bool _IsReadOnly;
private long _ItemId = -1;
#endregion fields
#region constructors
/// <summary>
/// Class constructor
/// </summary>
protected ItemViewModel(IItem parent, SolutionItemType itemType)
: this()
{
SetParent(parent);
_ItemType = itemType;
}
/// <summary>
/// Class constructor
/// </summary>
protected ItemViewModel()
{
_IsItemExpanded = false;
_IsItemSelected = false;
_IsReadOnly = false;
}
#endregion constructors
#region events
/// <summary>
/// Expose an event that is triggered when the viewmodel tells its view:
/// Here is another notification message please show it to the user.
/// </summary>
public event UserNotification.Events.ShowNotificationEventHandler ShowNotificationMessage;
/// <summary>
/// Expose an event that is triggered when the viewmodel requests its view to
/// start the editing mode for rename this item.
/// </summary>
public event InplaceEditBoxLib.Events.RequestEditEventHandler RequestEdit;
#endregion events
#region properties
/// <summary>
/// Gets the enumerated type of an item in the solution.
/// </summary>
public SolutionItemType ItemType { get { return _ItemType; } }
/// <summary>
/// Gets the name of this item to be displayed in the UI.
/// </summary>
public string DisplayName
{
get { return _DisplayName; }
private set
{
if (_DisplayName != value)
{
_DisplayName = value;
NotifyPropertyChanged(() => DisplayName);
}
}
}
/// <summary>
/// Gets the description of this item to be displayed in the UI.
/// </summary>
public string Description
{
get { return _Description; }
private set
{
if (_Description != value)
{
_Description = value;
NotifyPropertyChanged(() => Description);
}
}
}
/// <summary>
/// Gets/sets whether this treeview item is expanded or not.
/// </summary>
public bool IsItemExpanded
{
get { return _IsItemExpanded; }
set
{
if (_IsItemExpanded != value)
{
_IsItemExpanded = value;
NotifyPropertyChanged(() => IsItemExpanded);
}
}
}
/// <summary>
/// Gets/sets whether this treeview item is selected or not.
/// </summary>
public bool IsItemSelected
{
get { return _IsItemSelected; }
set
{
if (_IsItemSelected != value)
{
_IsItemSelected = value;
NotifyPropertyChanged(() => IsItemSelected);
}
}
}
/// <summary>
/// Gets/sets whether the <see cref="DisplayName"/> of this treeview item
/// can be renamed by the user or not.
///
/// This property is part of the <see cref="InplaceEditBoxLib.Interfaces.IEditBox"/>
/// interface and should, therefore, not be renamed.
/// </summary>
public bool IsReadOnly
{
get { return _IsReadOnly; }
private set
{
if (_IsReadOnly != value)
{
_IsReadOnly = value;
NotifyPropertyChanged(() => IsReadOnly);
}
}
}
/// <summary>
/// Gets whether the item represents a file-like item.
/// </summary>
public bool IsFile
{
get
{
return this.ItemType == Models.SolutionItemType.File;
}
}
/// <summary>
/// Gets the parent object where this object is the child in the treeview.
/// </summary>
public IItem Parent { get { return _Parent; } }
/// <summary>
/// Gets/sets a string that determines the order in which items are displayed.
/// </summary>
public string SortKey { get; set; }
#endregion properties
#region methods
/// <summary>
/// Sets the value of the <seealso cref="DisplayName"/> property.
/// </summary>
/// <param name="displayName"></param>
public void SetDisplayName(string displayName)
{
this.DisplayName = displayName;
}
/// <summary>
/// Sets the value of the <seealso cref="Description"/> property.
/// </summary>
/// <param name="description"></param>
public void SetDescription(string description)
{
this.Description = description;
}
/// <summary>
/// Sets the value of the <seealso cref="IsReadOnly"/> property.
/// </summary>
/// <param name="value"></param>
public void SetIsReadOnly(bool value)
{
IsReadOnly = value;
}
/// <summary>
/// Sets the <see cref="Parent"/> property object
/// where this object is the child in the treeview.
/// </summary>
/// <param name="parent"></param>
public void SetParent(IItem parent)
{
_Parent = parent;
NotifyPropertyChanged(() => Parent);
}
/// <summary>
/// Sets the ID of an item in the collection.
/// </summary>
/// <param name="itemId"></param>
void IItem.SetId(long itemId)
{
_ItemId = itemId;
}
/// <summary>
/// Gets the ID of an item in the collection.
/// </summary>
long IItem.GetId()
{
return _ItemId;
}
#region IEditBox Members
/// <summary>
/// Call this method to request of start editing mode for renaming this item.
/// </summary>
/// <param name="request"></param>
/// <returns>Returns true if event was successfully send (listener is attached), otherwise false</returns>
public bool RequestEditMode(RequestEditEvent request)
{
if (this.RequestEdit != null)
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
this.RequestEdit(this, new RequestEdit(request));
}));
return true;
}
else
{
System.Console.WriteLine("CANNOT Request Edit Mode in ViewModel (No View Attached).");
}
return false;
}
/// <summary>
/// Shows a pop-notification message with the given title and text.
/// </summary>
/// <param name="title"></param>
/// <param name="message"></param>
/// <param name="imageIcon"></param>
/// <returns>true if the event was succesfully fired.</returns>
public bool ShowNotification(string title, string message,
BitmapImage imageIcon = null)
{
if (this.ShowNotificationMessage != null)
{
this.ShowNotificationMessage(this, new ShowNotificationEvent
(
title,
message,
imageIcon
));
return true;
}
return false;
}
#endregion IEditBox Members
#endregion methods
}
}