forked from fdorg/flashdevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginMain.cs
More file actions
290 lines (255 loc) · 10.1 KB
/
Copy pathPluginMain.cs
File metadata and controls
290 lines (255 loc) · 10.1 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
using System;
using System.IO;
using System.Web;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using WeifenLuo.WinFormsUI.Docking;
using ProjectManager.Projects;
using PluginCore.Localization;
using PluginCore.Utilities;
using PluginCore.Managers;
using PluginCore.Helpers;
using StartPage.Controls;
using PluginCore;
namespace StartPage
{
public class PluginMain : IPlugin
{
private String pluginName = "StartPage";
private String pluginGuid = "e4246322-bc55-4f4a-99c8-aaeeed0a7b9a";
private String pluginHelp = "www.flashdevelop.org/community/";
private String pluginDesc = "Adds a start page to FlashDevelop.";
private String pluginAuth = "FlashDevelop Team";
private Boolean justOpened = true;
private String defaultRssUrl = "";
private String defaultStartPageUrl = "";
private StartPageWebBrowser startPageWebBrowser;
private String settingFilename;
private Settings settingObject;
private DockContent startPage;
private Image pluginImage;
#region Required Properties
/// <summary>
/// Api level of the plugin
/// </summary>
public Int32 Api
{
get { return 1; }
}
/// <summary>
/// Name of the plugin
/// </summary>
public String Name
{
get { return this.pluginName; }
}
/// <summary>
/// GUID of the plugin
/// </summary>
public String Guid
{
get { return this.pluginGuid; }
}
/// <summary>
/// Author of the plugin
/// </summary>
public String Author
{
get { return this.pluginAuth; }
}
/// <summary>
/// Description of the plugin
/// </summary>
public String Description
{
get { return this.pluginDesc; }
}
/// <summary>
/// Web address for help
/// </summary>
public String Help
{
get { return this.pluginHelp; }
}
/// <summary>
/// Object that contains the settings
/// </summary>
public Object Settings
{
get { return this.settingObject; }
}
#endregion
#region Required Methods
/// <summary>
/// Initializes the plugin
/// </summary>
public void Initialize()
{
this.InitBasics();
this.LoadSettings();
this.AddEventHandlers();
this.CreateMenuItem();
}
/// <summary>
/// Disposes the plugin
/// </summary>
public void Dispose()
{
this.SaveSettings();
}
/// <summary>
/// Handles the incoming events
/// </summary>
public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority prority)
{
switch (e.Type)
{
case EventType.Command :
DataEvent de = (DataEvent)e;
switch (de.Action)
{
case ProjectManager.ProjectManagerEvents.Project :
// Close pluginPanel if the user has the setting checked and a project is opened
if (de.Data != null & this.startPage != null)
{
if (this.settingObject.CloseOnProjectOpen) this.startPage.Close();
if (this.startPage != null)
{
// The project manager does not update recent projects until after
// it broadcasts this event so we'll wait a little bit before refreshing
Timer timer = new Timer();
timer.Interval = 100;
timer.Tick += delegate { timer.Stop(); if (!this.startPageWebBrowser.IsDisposed) this.startPageWebBrowser.SendProjectInfo(); };
timer.Start();
}
}
break;
}
break;
case EventType.FileEmpty :
if ((this.justOpened & (this.settingObject.ShowStartPageOnStartup == ShowStartPageOnStartupEnum.Always || this.settingObject.ShowStartPageOnStartup == ShowStartPageOnStartupEnum.NotRestoringSession)) || this.settingObject.ShowStartPageInsteadOfUntitled)
{
this.ShowStartPage();
this.justOpened = false;
e.Handled = true;
}
break;
case EventType.RestoreSession:
ISession session = ((DataEvent)e).Data as ISession;
if (session.Type != SessionType.Startup) return; // handle only startup sessions
if (this.settingObject.ShowStartPageOnStartup == ShowStartPageOnStartupEnum.Always) e.Handled = true;
else if (session.Files.Count > 0) this.justOpened = false;
break;
}
}
#endregion
#region Custom Methods
private String CurrentPageUrl { get { return this.settingObject.UseCustomStartPage ? this.settingObject.CustomStartPage : this.defaultStartPageUrl; } }
private String CurrentRssUrl { get { return this.settingObject.UseCustomRssFeed ? this.settingObject.CustomRssFeed : this.defaultRssUrl; } }
/// <summary>
/// Initializes important variables
/// </summary>
public void InitBasics()
{
String dataDir = Path.Combine(PathHelper.DataDir, "StartPage");
String startPageDir = Path.Combine(PathHelper.AppDir, "StartPage");
String localeName = PluginBase.MainForm.Settings.LocaleVersion.ToString();
String version = Application.ProductName.Substring(13, Application.ProductName.IndexOf(" for") - 13);
String fileWithArgs = "index.html?l=" + localeName + "&v=" + HttpUtility.HtmlEncode(version);
this.defaultStartPageUrl = Path.Combine(startPageDir, fileWithArgs);
this.defaultRssUrl = "http://www.flashdevelop.org/community/rss.php?f=15";
if (!Directory.Exists(dataDir)) Directory.CreateDirectory(dataDir);
this.settingFilename = Path.Combine(dataDir, "Settings.fdb");
this.pluginDesc = TextHelper.GetString("Info.Description");
this.pluginImage = PluginBase.MainForm.FindImage("224");
}
/// <summary>
/// Adds the required event handlers
/// </summary>
public void AddEventHandlers()
{
EventManager.AddEventHandler(this, EventType.Command);
EventManager.AddEventHandler(this, EventType.FileEmpty);
EventManager.AddEventHandler(this, EventType.RestoreSession);
}
/// <summary>
/// Loads the plugin settings
/// </summary>
public void LoadSettings()
{
this.settingObject = new Settings();
if (!File.Exists(this.settingFilename)) this.SaveSettings();
else
{
Object obj = ObjectSerializer.Deserialize(this.settingFilename, this.settingObject);
this.settingObject = (Settings)obj;
}
}
/// <summary>
/// Saves the plugin settings
/// </summary>
public void SaveSettings()
{
ObjectSerializer.Serialize(this.settingFilename, this.settingObject);
}
/// <summary>
/// Creates a menu item for the plugin
/// </summary>
public void CreateMenuItem()
{
String title = TextHelper.GetString("Label.ViewMenuItem");
ToolStripMenuItem viewMenu = (ToolStripMenuItem)PluginBase.MainForm.FindMenuItem("ViewMenu");
ToolStripMenuItem viewItem = new ToolStripMenuItem(title, this.pluginImage, new EventHandler(this.ViewMenuClick));
PluginBase.MainForm.RegisterShortcutItem("ViewMenu.ShowStartPage", viewItem);
viewMenu.DropDownItems.Add(viewItem);
}
/// <summary>
/// Creates the Start Page Tab
/// </summary>
public void CreateStartPage()
{
this.startPageWebBrowser = new StartPageWebBrowser(this.CurrentPageUrl, this.CurrentRssUrl);
this.startPage = PluginBase.MainForm.CreateCustomDocument(this.startPageWebBrowser);
this.startPage.Icon = ImageKonverter.ImageToIcon(this.pluginImage);
this.startPage.Disposed += new EventHandler(this.PluginPanelDisposed);
this.startPage.Closing += new CancelEventHandler(this.PluginPanelClosing);
this.startPage.Text = TextHelper.GetString("Title.StartPage");
}
/// <summary>
/// Shows the Start Page Tab and creates if necessary.
/// </summary>
public void ShowStartPage()
{
if (this.startPage == null) this.CreateStartPage();
else this.startPage.Show();
}
#endregion
#region Event Handlers
/// <summary>
/// Shows the start page.
/// </summary>
private void ViewMenuClick(Object sender, System.EventArgs e)
{
this.ShowStartPage();
}
/// <summary>
/// Some internal event handling for closing.
/// </summary>
private void PluginPanelClosing(Object sender, CancelEventArgs e)
{
if (this.settingObject.ShowStartPageInsteadOfUntitled && PluginBase.MainForm.Documents.Length == 1)
{
e.Cancel = true;
}
}
/// <summary>
/// Reset the start page reference.
/// </summary>
private void PluginPanelDisposed(Object sender, EventArgs e)
{
this.startPage = null;
}
#endregion
}
}