NavigateBarActionList.cs
9.2 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
/*
* Project : Outlook 2003 Style Navigation Pane
*
* Author : Muhammed ŞAHİN
* eMail : muhammed.sahin@gmail.com
*
* Description : Navigation Pane desinger commands
*
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel.Design;
using System.ComponentModel;
using MT.WindowsUI.NavigationPane;
using System.Windows.Forms;
namespace MT.WindowsUI.NavigationPane.Design
{
enum ColorTables
{
SystemColor,
Office2003Blue,
Office2003Olive,
Office2003Silver,
Office2007Blue,
Office2007Black,
Office2007Silver
}
class NavigateBarActionList : DesignerActionList
{
DesignerActionUIService actionUISvc;
IDesignerHost designerHost;
#region NavigateBar Color Table
ColorTables colorTable = ColorTables.SystemColor;
public ColorTables ColorTable
{
get { return colorTable; }
set
{
switch (value)
{
case ColorTables.SystemColor:
SetProperty("NavigateBarColorTable", NavigateBarColorTable.SystemColor);
break;
case ColorTables.Office2003Blue:
SetProperty("NavigateBarColorTable", NavigateBarColorTable.Office2003Blue);
break;
case ColorTables.Office2003Olive:
SetProperty("NavigateBarColorTable", NavigateBarColorTable.Office2003Olive);
break;
case ColorTables.Office2003Silver:
SetProperty("NavigateBarColorTable", NavigateBarColorTable.Office2003Silver);
break;
case ColorTables.Office2007Black:
SetProperty("NavigateBarColorTable", NavigateBarColorTable.Office2007Black);
break;
case ColorTables.Office2007Blue:
SetProperty("NavigateBarColorTable", NavigateBarColorTable.Office2007Blue);
break;
case ColorTables.Office2007Silver:
SetProperty("NavigateBarColorTable", NavigateBarColorTable.Office2007Silver);
break;
}
colorTable = value;
}
}
private void ResetColorTable()
{
this.ColorTable = ColorTables.SystemColor;
}
#endregion
#region RightToLeft
public RightToLeft RightToLeft
{
get { return ((NavigateBar)this.Component).RightToLeft; }
set { SetProperty("RightToLeft", value); }
}
#endregion
#region Dock
public DockStyle Dock
{
get { return ((NavigateBar)this.Component).Dock; }
set { SetProperty("Dock", value); }
}
#endregion
#region Constructor
public NavigateBarActionList(IComponent component)
: base(component)
{
if (!(component is NavigateBar))
{
throw new System.ArgumentException("The NavigateBarActionList only defines a list of smart tag items for controls of type, or controls that derive from type, NavigateBar.", "component");
}
this.actionUISvc = GetService(typeof(DesignerActionUIService)) as DesignerActionUIService;
this.designerHost = (IDesignerHost)GetService(typeof(IDesignerHost));
// Set Designer Item Collection
SetDesignerActionItemObjects();
}
#endregion
#region DesignerActionItemCollection
const string APPEARANCE = "Appearance";
const string BUTTONS = "Buttons";
DesignerActionItemCollection actionItemCollection;
void SetDesignerActionItemObjects()
{
actionItemCollection = new DesignerActionItemCollection();
// Görünüm
actionItemCollection.Add(new DesignerActionHeaderItem(APPEARANCE));
actionItemCollection.Add(new DesignerActionTextItem("Properties that are related to the controls appearance.", APPEARANCE));
actionItemCollection.Add(new DesignerActionPropertyItem("ColorTable", "Select Color Table", APPEARANCE, "Change color table navigation pane."));
actionItemCollection.Add(new DesignerActionMethodItem(this, "ResetColorTable", "Reset Color Table", APPEARANCE, "Return system colors."));
actionItemCollection.Add(new DesignerActionPropertyItem("RightToLeft", "Right To Left", APPEARANCE, "Change RightToLeft by the control."));
actionItemCollection.Add(new DesignerActionPropertyItem("Dock", "Dock", APPEARANCE, "Change Dock by the control."));
// Buttons
actionItemCollection.Add(new DesignerActionHeaderItem(BUTTONS));
actionItemCollection.Add(new DesignerActionTextItem("Add a new button or remove a exist button from navigation pane.", BUTTONS));
actionItemCollection.Add(new DesignerActionMethodItem(this, "AddButton", "Add Button", BUTTONS, "Add a new button.", true));
actionItemCollection.Add(new DesignerActionMethodItem(this, "RemoveButton", "Remove Button", BUTTONS, "Remove last button.", true));
}
public override DesignerActionItemCollection GetSortedActionItems()
{
return actionItemCollection;
}
#endregion
#region ReFreshUI
void ReFreshUI()
{
if (this.actionUISvc != null)
this.actionUISvc.Refresh(this.Component);
}
#endregion
#region SetProperty
/// <summary>
/// Componentin özelliğini değiştirmek için
/// </summary>
/// <param name="tPropertyName">Özelliğin adı</param>
/// <param name="tPropertyValue">Yeni değeri</param>
void SetProperty(string tPropertyName, object tPropertyValue)
{
PropertyDescriptor propDescriptor = TypeDescriptor.GetProperties(this.Component)[tPropertyName];
propDescriptor.SetValue(this.Component, tPropertyValue);
ReFreshUI();
}
#endregion
#region AddButton
/// <summary>
/// Add a new button
/// </summary>
void AddButton()
{
if (this.designerHost == null)
return;
if (!(this.Component is NavigateBar))
throw new Exception("Component is not NavigateBar or derived");
try
{
NavigateBar navigationPane = (NavigateBar)this.Component;
// Yeni button
NavigateBarButton nvButton = (NavigateBarButton)this.designerHost.CreateComponent(typeof(NavigateBarButton));
if (nvButton == null)
{
System.Windows.Forms.MessageBox.Show("Component is null");
return;
}
nvButton.Caption = nvButton.Name;
navigationPane.NavigateBarButtons.Add(nvButton);
navigationPane.NavigateBarDisplayedButtonCount = navigationPane.NavigateBarButtons.Count;
navigationPane.PerformNavigationPane(); // Panelin görünümünü yenile
ReFreshUI();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message, "AddButton");
}
}
#endregion
#region RemoveButton
/// <summary>
/// Remove button from collection
/// </summary>
void RemoveButton()
{
if (this.designerHost == null)
return;
if (!(this.Component is NavigateBar))
throw new Exception("Component is not NavigateBar or derived");
try
{
NavigateBar navigationPane = (NavigateBar)this.Component;
if (navigationPane.NavigateBarButtons.Count <= 0)
return;
// Get last button in collection
NavigateBarButton nvButton = navigationPane.NavigateBarButtons[navigationPane.NavigateBarButtons.Count - 1];
if (nvButton == null)
return;
navigationPane.NavigateBarButtons.Remove(nvButton);
if (navigationPane.NavigateBarDisplayedButtonCount > 0)
{
navigationPane.NavigateBarDisplayedButtonCount--;
if (navigationPane.DisplayedButtonCount > navigationPane.NavigateBarDisplayedButtonCount)
navigationPane.DisplayedButtonCount = navigationPane.NavigateBarDisplayedButtonCount;
}
if (navigationPane.NavigateBarButtons.Count == 0)
navigationPane.SetCaptionText(null);
navigationPane.PerformNavigationPane(); // Panelin görünümünü yenile
this.designerHost.DestroyComponent(nvButton); // buttonu kaldır
ReFreshUI();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message, "RemoveButton");
}
}
#endregion
}
}