This repository was archived by the owner on Aug 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginMain.cs
More file actions
526 lines (406 loc) · 14.8 KB
/
PluginMain.cs
File metadata and controls
526 lines (406 loc) · 14.8 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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
//Abbreviation: create an instance CreateWords that’s the abbreviation itself.
//After insert the text, this function will move the mouse pointer inside the sensible area and between docs.
//CreateWords: it Analyze the text with the arguments and it returns the abbreviation full text.
//Plus it monitor the changes, self-deactivating when something is writing outside the sensible area.
//ControlShortCutDoubleChar: it activate or deactivate the Autoclose’s functions because it is not able to do it alone.
//AutoClose: it check the insert between the brackets and the creation of the parameters.
//Some notices about the style of the code:
//Nomenclature:
//I’ve used ActionScript for a lot of time and I’m used to utilize its style for the nomenclature.
//For this reason some part of the code may be written in ActionScript style – most probably I forgot it.
//Style of the code:
// Aiming to improve the performance:
//- Usually I not create a property that encapsulate a field if this is enabled both in reading and writing with no checks applied on it or if the code that use it, is not based on the properties.
//- I use the For cycle instead of foreach in some cases.
// Others:
//I changed the name of some classes or variables according to their real function/behavior and it’s probably that some wrong name are present.
//ES: Autoclose is the new name of the old DoubleChar.
//Some code choose were done base on my knowledge that I had or have about FlashDevelop and it may appear bizarre at the first look.
//Some parts of the code may appear not necessary, but it was done to keep my aim to execute less instruction to FlashDevelop especially in the monitoring of the writing.
//My scope was to create a plug-in that will not rework any part of the code of FlashDevelop.
//I found myself in certain situations when I could use some functions due their level of visibility or because these functions not used events to hook my code.
//In this case, I had to copy some part of FlashDevelp inside this plug-in.
// In CreateWords I show an example.
/// ----------------------------- ITALIAN -----------------------------
/*
* Abbreviation: Crea una instanza CreateWords che è in altre parole è l'abbreviazione stessa.
* Dopo aver inserito il testo si preoccupa dello spostamento dentro le aree sensibili e fra documenti.
* CreateWords: Analizza il testo con gli argomenti e ne restituisce il testo completo dell'abbreviazione.
* Poi ne monitora i cambiamenti disattivandosi quando viene scritto all'infuori delle aree sensibili.
*
*
* ControlShortCutDoubleChar: si preoccupa di Abilitare o Disabiltare le funzioni di AutoClose perchè questo non può farlo da solo.
* AutoClose: Controlla l'inserimento delle parentesi e la creazione dei parametri.
*
* Alcune note sullo stile del codice:
*
* Nomeclatura:
* Avendo usato ActionScript per un pò di tempo e mi ero abituato ad usare il suo stile di nomenclatura.
* Per questo ci potrebbero essere delle parti scritte in stile ActionScript che mi sono dimenticato di riscrivere.
*
* Stile del codice:
*
*
* Al fine di migliorare le prestazioni:
* - Di solito non creo una proprietà che incapsula un campo se questo è abilitato
* sia alla lettura che alla scrittura senza nessun tipo di controllo applicato ad esso
* o se il codice che ne fà utilizzo non si basa sulle proprietà.
* - Uso il ciclo for al posto del foreach in alcuni casi.
*
*
* Altro:
* Ho cambiato il nome di alcune classi o varibili per rispecchiare il loro attuale comportamento ed è probabile che ci siano ancora
* dei nomi fuorvianti.
* Per es. AutoClose prima era DoubleChar.
*
* Alcune scelte sono state effettuate in base alle conoscenze che avevo o ho su FlashDevelop quindi possono apparire bizzarre.
* Alcuni pezzi di codice appariranno non neccessarie, ma ciò sono state dettate dal mio intento di far eseguire meno istruzioni
* possibili a FlashDevelop sopratutto nel monitoraggio della scrittura.
*
*
* Il mio scopo era quello di creare un plugin che ovviamente non doveva toccare nessuna parte del codice di FLashDevelop.
* Mi sono trovato però in delle situazioni che non potevo riutilizzare alcune funzioni per via del loro livello di visibilità o perchè queste non
* era proviste di eventi a cui potevo agganciarmi.
* In questi casi, ho dovuto allora drasticamente copiare alcune parti di FlashDevlop stesso in questo plugin.
* In CreateWords ne mostro un esempio.
*
*/
using System;
using System.IO;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;
using PluginCore.Utilities;
using PluginCore.Helpers;
using PluginCore;
using ASCompletion.Context;
using QuickGenerator.UI.form;
using QuickGenerator.CustomCompletionList;
using QuickGenerator.Abbreviation;
using QuickGenerator.UI.MenuItem;
using System.Text;
using QuickGenerator.Command;
using QuickGenerator.QuickSettings;
namespace QuickGenerator
{
public class PluginMain : IPlugin
{
private String pluginName = "QuickGenerator";
private String pluginGuid = "21D1087C-998D-4466-A25C-8E6EA42F6F32";
private String pluginHelp = "http://www.youtube.com/user/Alan271078";
private String pluginDesc = "Add functionality for create code quickly";
private String pluginAuth = "Alan Lucchese, update: trzeci";
private int pluginApi = 1;
internal static CustomCompletionScintillaControl custCompletion;
private Dictionary<Keys, IPressKey> dictNotifyPressKey;
private ManagerSettings managerSettings;
ItemShowCreateClass showCreateClass;
ToolStripMenuItem menuCompletition;
ToolStripMenuItem _EnvelopMenu;
IPressKey key;
ManagerResources managerResource;
SettingsLoader settingsLoader;
private Vocabulary.VocabularyArgument vca;
public Settings settingsQuickGenerator
{
get { return settingsLoader.GetQuickSettings(); }
}
#region Required Properties
/// <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>
/// Web address for help
/// </summary>
public int Api
{
get { return this.pluginApi; }
}
/// <summary>
/// Object that contains the settings
/// </summary>
[Browsable(false)]
public Object Settings
{
get { return this.settingsQuickGenerator; }
}
#endregion
#region Required Methods
/// <summary>
/// Initializes the plugin
/// </summary>
public void Initialize()
{
managerResource = new ManagerResources();
settingsLoader = new SettingsLoader();
this.InitBasics();
this.LoadSettings();
this.CreateMenu();
dictNotifyPressKey = new Dictionary<Keys, IPressKey>();
managerSettings = new ManagerSettings(settingsQuickGenerator, dictNotifyPressKey, this, vca);
managerSettings.ShortcutMenuChangeHandler += new ShortcutMenuChange(managerSettings_ShortcutMenuChangeHandler);
custCompletion = new CustomCompletionScintillaControl();
custCompletion.OnSelectItem += new CustomCompletionScintillaControl.ItemSelectedEventHandler(custCompletion_OnSelectItem);
}
void custCompletion_OnSelectItem(ICommandInterface cmd)
{
cmd.Execute();
}
void managerSettings_ShortcutMenuChangeHandler()
{
showCreateClass.ShortcutKeys = settingsQuickGenerator.CreateClassShortCut;
menuCompletition.ShortcutKeys = settingsQuickGenerator.CreateClassFromNameShortCut;
}
/// <summary>
/// Disposes the plugin
/// </summary>
public void Dispose()
{
this.SaveSettings();
if (custCompletion != null)
{
custCompletion.Dispose();
custCompletion = null;
}
managerSettings.Dispose();
managerResource.Dispose();
if (_EnvelopMenu != null)
{
_EnvelopMenu.Dispose();
_EnvelopMenu = null;
}
}
/// <summary>
/// Handles the incoming events
/// </summary>
public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority prority)
{
switch (e.Type)
{
case EventType.Keys:
KeyEvent k = e as KeyEvent;
if (dictNotifyPressKey.TryGetValue(k.Value, out key))
{
key.EventKey(k);
e.Handled = true;
}
break;
}
}
#endregion
#region Custom Methods
/// <summary>
/// Initializes important variables
/// </summary>
public void InitBasics()
{
String dataPath = Path.Combine(PathHelper.DataDir, pluginName);
if (!Directory.Exists(dataPath)) Directory.CreateDirectory(dataPath);
settingsLoader.SetPath(Path.Combine(dataPath, "Settings.fdb"));
// this.pluginImage = PluginBase.MainForm.FindImage("100");
}
/// <summary>
/// Creates a menu item for the plugin and adds a ignored key
/// </summary>
public void CreateMenu()
{
ToolStripMenuItem generator = new ToolStripMenuItem("Generator");
showCreateClass = new ItemShowCreateClass(this);
// showCreateClass.ShortcutKeys = Keys.Alt | Keys.N;
showCreateClass.ShortcutKeys = settingsQuickGenerator.CreateClassShortCut;
menuCompletition = new ToolStripMenuItem("Completition");
menuCompletition.Visible = false;
// menuCompletition.ShortcutKeys = Keys.ControlKey | Keys.Alt | Keys.J;
menuCompletition.ShortcutKeys = settingsQuickGenerator.CreateClassFromNameShortCut;
menuCompletition.Click += new EventHandler(menuCompletiton);
generator.DropDownItems.Add(showCreateClass);
generator.DropDownItems.Add(menuCompletition);
ASContext.MainForm.MenuStrip.Items.Add(generator);
PluginBase.MainForm.EditorMenu.Opening += new CancelEventHandler(EditorMenu_Opening);
}
void menuCompletiton(object sender, EventArgs e)
{
string currentWord = ASContext.CurSciControl.GetWordFromPosition(ASContext.CurSciControl.CurrentPos);
if (currentWord == null || currentWord.Length == 0)
return;
// Project project = (Project)PluginBase.CurrentProject;
List<ICompletionListItem> lcomp = new List<ICompletionListItem>();
ICompletionListItem cmd = null;
if (ASContext.Context.CurrentModel.haXe)
{
cmd = new QuickGenerator.Command.CreateClassCmdHaxe(currentWord, this, ManagerResources.ClassImage);
}
else
{
cmd = new QuickGenerator.Command.CreateClassCmdAS3(currentWord, this, ManagerResources.ClassImage);
}
lcomp.Add(cmd);
custCompletion.Show(lcomp, true);
}
ToolStripMenuItem addAbbrevationMenu;
void EditorMenu_Opening(object sender, CancelEventArgs e)
{
bool hasTextToInsert = (ASContext.CurSciControl.SelText.Trim().Length != 0);
ContextMenuStrip contextMenu = (ContextMenuStrip)sender;
if (_EnvelopMenu == null)
{
_EnvelopMenu = new ToolStripMenuItem("Wrap");
_EnvelopMenu.DropDownItems.Add("in Function", ManagerResources.MethodImage, new EventHandler(this.EnvelopInFunction));
_EnvelopMenu.DropDownItems.Add("in if()", ManagerResources.ImportImage, new EventHandler(this.EnvelopInIF));
}
if (addAbbrevationMenu == null)
{
addAbbrevationMenu = new ToolStripMenuItem("Add to Abbreviation", null, new EventHandler(addAbrevation));
}
if (hasTextToInsert)
{
if (!contextMenu.Items.Contains(_EnvelopMenu))
contextMenu.Items.Add(_EnvelopMenu);
if (!contextMenu.Items.Contains(addAbbrevationMenu))
contextMenu.Items.Add(addAbbrevationMenu);
}
else
{
if (contextMenu.Items.Contains(_EnvelopMenu))
contextMenu.Items.Remove(_EnvelopMenu);
if (contextMenu.Items.Contains(addAbbrevationMenu))
contextMenu.Items.Remove(addAbbrevationMenu);
}
}
private void addAbrevation(object sender, EventArgs e)
{
QuickSettings.settingAbbrevation sta = new QuickGenerator.QuickSettings.settingAbbrevation();
sta.AbbrevationDictionary = settingsQuickGenerator.abbrevationDictList;
sta.CustomList = settingsQuickGenerator.customList;
sta.ColorArgument = settingsQuickGenerator.ColorArgument;
AbbrevationCompletionForm frm = new AbbrevationCompletionForm(sta, vca);
ScintillaNet.ScintillaControl sci = ASContext.CurSciControl;
string text = ASContext.CurSciControl.SelText;
int pos = sci.SelectionStart;
int end = sci.SelectionEnd;
int initLine = sci.LineFromPosition(pos);
int endLine = sci.LineFromPosition(end);
int indent = sci.GetLineIndentation(initLine);
if (initLine != endLine)
{
while (initLine < endLine)
{
initLine++;
int newIdent = sci.GetLineIndentation(initLine);
if (newIdent < indent)
indent = newIdent;
}
}
string tabString = new string('\t', indent / sci.Indent);
StringBuilder sb = new StringBuilder(text.Length);
if (tabString.Length != 0)
{
string[] str = text.Split('\n');
//sb.Append(str[0]);
//sb.Append("\n");
int ind = -1;
int lenght = tabString.Length;
for (int i = 0; i < str.Length; i++)
{
ind = str[i].IndexOf(tabString, 0);
if (ind != -1)
{
//sb.Append(str[i].Replace(tabString, ""));
// string sg = str[i].Substring(ind + lenght);
sb.Append(str[i].Substring(ind + lenght));
}
else
{
//sb.Append(str[i].TrimStart('\t'));
sb.Append(str[i]);
}
sb.Append("\n");
}
sb.Remove(sb.Length - 1, 1);
}
else
sb.Append(text);
frm.getAbbrevationExternal(sb.ToString());
frm.ShowDialog();
sta = frm.getSettingAbbrevation();
settingsQuickGenerator.abbrevationDictList = sta.AbbrevationDictionary;
settingsQuickGenerator.customList = sta.CustomList;
settingsQuickGenerator.ColorArgument = sta.ColorArgument;
}
/// <summary>
/// Invoked when the user selects the "Envelop" command
/// </summary>
private void EnvelopInFunction(object sender, EventArgs e)
{
Wrap.EnvelopInFunction();
}
/// <summary>
/// Invoked when the user selects the "Envelop" command
/// </summary>
private void EnvelopInIF(object sender, EventArgs e)
{
Wrap.EnvelopInIF();
}
/// <summary>
/// The form is closed.The new settings now begin save.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void SaveSettingsFrmCreateClass(object sender, FormClosedEventArgs e)
{
CreateClassfrm frm = (CreateClassfrm)sender;
if (frm.OptionChange)
{
settingsQuickGenerator.createClassSettings = frm.settings;
SaveSettings();
}
}
/// <summary>
/// Loads the plugin settings
/// </summary>
public void LoadSettings()
{
settingsLoader.LoadSettings();
}
/// <summary>
/// Saves the plugin settings
/// </summary>
public void SaveSettings()
{
settingsLoader.SaveSettings();
}
#endregion
}
}