-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPluginMain.cs
257 lines (222 loc) · 7.51 KB
/
PluginMain.cs
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
using PluginCore;
using PluginCore.Helpers;
using PluginCore.Managers;
using PluginCore.Utilities;
using QuickLaunch.Controls;
using QuickLaunch.Documents;
using QuickLaunch.Helpers;
using QuickLaunch.Managers;
using QuickLaunch.Menu;
using QuickLaunch.Types;
using System;
using System.ComponentModel;
using System.IO;
using System.Windows.Forms;
namespace QuickLaunch
{
public class PluginMain : IPlugin
{
private const int API = 1;
private const string NAME = "QuickLaunch";
private const string GUID = "128ACEAB-3A9A-48bf-8FEF-7A06475D02CF";
private const string HELP = "http://www.flashdevelop.org/community/viewtopic.php?f=4&t=9443";
private const string DESCRIPTION = "Adds a quick launch box that provides easy access to commands, files, classes, and more..";
private const string AUTHOR = "Joey Robichaud";
private string _settingFilename = "";
private Settings _settings;
private ToolStripSearchTextBox _quickLaunchBox = null;
private ToolStripMenuItem _activateItem = null;
#region Required Properties
/// <summary>
/// Api level of the plugin
/// </summary>
public int Api
{
get { return 1; }
}
/// <summary>
/// Name of the plugin
/// </summary>
public string Name
{
get { return NAME; }
}
/// <summary>
/// GUID of the plugin
/// </summary>
public string Guid
{
get { return GUID; }
}
/// <summary>
/// Author of the plugin
/// </summary>
public string Author
{
get { return AUTHOR; }
}
/// <summary>
/// Description of the plugin
/// </summary>
public string Description
{
get { return DESCRIPTION; }
}
/// <summary>
/// Web address for help
/// </summary>
public string Help
{
get { return HELP; }
}
/// <summary>
/// Object that contains the settings
/// </summary>
[Browsable(false)]
public object Settings
{
get { return _settings; }
}
#endregion
#region Required Methods
/// <summary>
/// Initializes the plugin
/// </summary>
public void Initialize()
{
InitBasics();
LoadSettings();
AddEventHandlers();
InitializeQuickLaunch();
UpdateLocation();
RegisterProviders();
}
/// <summary>
/// Disposes the plugin
/// </summary>
public void Dispose()
{
SaveSettings();
}
/// <summary>
/// Handles the incoming events
/// </summary>
public void HandleEvent(object sender, NotifyEvent e, HandlingPriority prority)
{
if (e.Type == EventType.ApplyTheme)
{
_quickLaunchBox.ApplyTheme();
}
}
void _settings_OnSettingsChanged()
{
UpdateLocation();
}
private void UpdateLocation()
{
RemoveQuickLaunch();
AddQuickLaunch();
UpdateWatermark();
}
private void AddQuickLaunch()
{
if (_settings.Location == QuickLaunchLocation.MenuStrip)
PluginBase.MainForm.MenuStrip.Items.Add(_quickLaunchBox);
else if (_settings.Location == QuickLaunchLocation.ToolStrip)
PluginBase.MainForm.ToolStrip.Items.Add(_quickLaunchBox);
}
private void RemoveQuickLaunch()
{
if (PluginBase.MainForm.MenuStrip.Items.Contains(_quickLaunchBox))
PluginBase.MainForm.MenuStrip.Items.Remove(_quickLaunchBox);
if (PluginBase.MainForm.ToolStrip.Items.Contains(_quickLaunchBox))
PluginBase.MainForm.ToolStrip.Items.Remove(_quickLaunchBox);
}
private void UpdateWatermark()
{
string watermark = ResourceHelper.GetString("QuickLaunch.Label.QuickLaunch");
_quickLaunchBox.WatermarkText = watermark;
}
#endregion
#region Plugin Methods
private void ActivateQuickLaunch(object sender, EventArgs e)
{
if (_settings.Location != QuickLaunchLocation.None)
_quickLaunchBox.Focus();
}
#endregion
#region Custom Methods
/// <summary>
/// Initializes important variables
/// </summary>
public void InitBasics()
{
string dataPath = Path.Combine(PluginCore.Helpers.PathHelper.DataDir, NAME);
if (!Directory.Exists(dataPath)) Directory.CreateDirectory(dataPath);
_settingFilename = Path.Combine(dataPath, "Settings.fdb");
}
/// <summary>
/// Adds the required event handlers
/// </summary>
public void AddEventHandlers()
{
// Set events you want to listen (combine as flags)
EventManager.AddEventHandler(this, EventType.ApplyTheme);
ToolStripMenuItem menu = (ToolStripMenuItem)PluginBase.MainForm.FindMenuItem("SearchMenu");
_activateItem = new ToolStripMenuItem(ResourceHelper.GetString("QuickLaunch.Label.ActivateQuickLaunch"), null, new EventHandler(ActivateQuickLaunch));
_activateItem.Visible = false;
_activateItem.ShortcutKeys = Keys.Control | Keys.Oemtilde;
PluginBase.MainForm.RegisterShortcutItem("QuickLaunch.ActivateQuickLaunch", _activateItem);
menu.DropDownItems.Add(_activateItem);
_settings.OnSettingsChanged += new SettingsChangesEvent(_settings_OnSettingsChanged);
}
/// <summary>
/// Adds shortcuts for manipulating the navigation bar
/// </summary>
public void InitializeQuickLaunch()
{
_quickLaunchBox = new ToolStripSearchTextBox();
_quickLaunchBox.Name = ResourceHelper.GetString("QuickLaunch.Label.QuickLaunch");
_quickLaunchBox.Renderer = new DockPanelStripRenderer();
_quickLaunchBox.AutoSize = false;
_quickLaunchBox.Width = ScaleHelper.Scale(200);
_quickLaunchBox.Font = PluginBase.Settings.DefaultFont;
_quickLaunchBox.Alignment = ToolStripItemAlignment.Right;
_quickLaunchBox.Search += new EventHandler(quickLaunchBox_Search);
}
void quickLaunchBox_Search(object sender, EventArgs e)
{
ToolStripSearchTextBox quickLaunchBox = (ToolStripSearchTextBox)sender;
quickLaunchBox.Items.Clear();
quickLaunchBox.Items.AddRange(QuickLaunchManager.FindItems(quickLaunchBox.Text));
quickLaunchBox.DroppedDown = true;
}
public void RegisterProviders()
{
QuickLaunchManager.RegisterProvider(new MenuProvider());
QuickLaunchManager.RegisterProvider(new DocumentProvider());
QuickLaunchManager.RegisterProvider(new TypeProvider());
}
/// <summary>
/// Loads the plugin settings
/// </summary>
public void LoadSettings()
{
_settings = new Settings();
if (!File.Exists(_settingFilename)) SaveSettings();
else
{
object obj = ObjectSerializer.Deserialize(_settingFilename, _settings);
_settings = (Settings)obj;
}
}
/// <summary>
/// Saves the plugin settings
/// </summary>
public void SaveSettings()
{
ObjectSerializer.Serialize(_settingFilename, _settings);
}
#endregion
}
}