This repository has been archived by the owner on Mar 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Main.cs
362 lines (314 loc) · 15.2 KB
/
Main.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
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
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using IBMiCmd.Forms;
using IBMiCmd.IBMiTools;
using IBMiCmd.LanguageTools;
using NppPluginNET;
using System.Threading;
namespace IBMiCmd
{
class Main
{
#region " Fields "
internal const string PluginName = "IBMiCmd";
internal const string PluginDescription = "IBMiCmd v1.3.2.0 github.com/WorksOfBarry/IBMiCmd";
public static commandEntry CommandWindow { get; set; }
public static errorListing ErrorWindow { get; set; }
public static libraryList LiblWindow { get; set; }
public static cmdBindings BindsWindow { get; set; }
public static selectMember MemberListWindow { get; set; }
public static string ConfigDirectory { get; set; }
public static string SystemsDirectory { get; set; }
public static string FileCacheDirectory { get; set; }
private static int idMyDlg = -1;
private static Bitmap tbBmp = Properties.Resources.star;
private static Bitmap tbBmp_tbTab = Properties.Resources.star_bmp;
private static Icon tbIcon = null;
#endregion
#region " StartUp/CleanUp "
internal static void CommandMenuInit()
{
StringBuilder pluginsConfigDir = new StringBuilder(Win32.MAX_PATH);
Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETPLUGINSCONFIGDIR, Win32.MAX_PATH, pluginsConfigDir);
ConfigDirectory = $"{ pluginsConfigDir.ToString() }\\{ PluginName }\\";
SystemsDirectory = $"{ConfigDirectory}systems\\";
FileCacheDirectory = $"{ConfigDirectory}cache\\";
if (!Directory.Exists(ConfigDirectory)) Directory.CreateDirectory(ConfigDirectory);
if (!Directory.Exists(SystemsDirectory)) Directory.CreateDirectory(SystemsDirectory);
if (!Directory.Exists(FileCacheDirectory)) Directory.CreateDirectory(FileCacheDirectory);
IBMiUtilities.CreateLog(ConfigDirectory + PluginName);
RPGParser.LoadFileCache();
CLParser.LoadFileCache();
if (File.Exists(ConfigDirectory + "dftcfg"))
{
Config.SwitchToConfig(File.ReadAllText(ConfigDirectory + "dftcfg"));
}
else
{
LoadConfigSelect();
if (Config.GetConfigs().Length == 0) return;
if (IBMi._ConfigFile == "" || IBMi._ConfigFile == null)
{
string UseConfig = Config.GetConfigs()[0];
MessageBox.Show("No config selected. Defaulted to " + UseConfig + ".");
Config.SwitchToConfig(UseConfig);
}
}
//if (IBMi.GetConfig("localDefintionsInstalled") == "false")
//{
// IBMiNPPInstaller.InstallLocalDefinitions();
//}
bool ExperimentalFeatures = (IBMi.GetConfig("experimental") == "true");
int ItemOrder = 0;
PluginBase.SetCommand(ItemOrder++, "About IBMiCmd", About, new ShortcutKey(false, false, false, Keys.None));
PluginBase.SetCommand(ItemOrder++, "-SEPARATOR-", null);
PluginBase.SetCommand(ItemOrder++, "Select Remote System", LoadConfigSelect);
PluginBase.SetCommand(ItemOrder++, "Remote System Setup", RemoteSetup);
PluginBase.SetCommand(ItemOrder++, "Library List", LiblDialog, new ShortcutKey(true, false, false, Keys.F7));
if (ExperimentalFeatures) PluginBase.SetCommand(ItemOrder++, "Remote Install Plugin Server", RemoteInstall);
PluginBase.SetCommand(ItemOrder++, "-SEPARATOR-", null);
PluginBase.SetCommand(ItemOrder++, "Command Entry", CommandDialog);
PluginBase.SetCommand(ItemOrder++, "Error Listing", ErrorDialog);
PluginBase.SetCommand(ItemOrder++, "Command Bindings", BindsDialog);
PluginBase.SetCommand(ItemOrder++, "-SEPARATOR-", null);
PluginBase.SetCommand(ItemOrder++, "Member Listing", MemberListing);
PluginBase.SetCommand(ItemOrder++, "Open Source Member", OpenMember, new ShortcutKey(true, false, true, Keys.A));
//PluginBase.SetCommand(ItemOrder++, "Upload Source Member", UploadMember, new ShortcutKey(true, false, true, Keys.X));
PluginBase.SetCommand(ItemOrder++, "Open Include/Copy", OpenInclude, new ShortcutKey(true, false, false, Keys.F12));
PluginBase.SetCommand(ItemOrder++, "-SEPARATOR-", null);
PluginBase.SetCommand(ItemOrder++, "Format CL file", ManageCL, new ShortcutKey(true, false, false, Keys.F4));
PluginBase.SetCommand(ItemOrder++, "RPG Line Conversion", LaunchConversion, new ShortcutKey(true, false, false, Keys.F5));
PluginBase.SetCommand(ItemOrder++, "RPG File Conversion", LaunchFileConversion, new ShortcutKey(true, false, false, Keys.F6));
PluginBase.SetCommand(ItemOrder++, "-SEPARATOR-", null);
PluginBase.SetCommand(ItemOrder++, "Open Log File", OpenLogFile);
if (ExperimentalFeatures) PluginBase.SetCommand(ItemOrder++, "Refresh Extname Definitions", BuildSourceContext);
if (ExperimentalFeatures) PluginBase.SetCommand(ItemOrder++, "Prompt CL Command", PromptCommand, new ShortcutKey(true, false, false, Keys.F4));
idMyDlg = 1;
}
internal static void SetToolBarIcon()
{
}
internal static void PluginCleanUp()
{
}
#endregion
#region " Menu functions "
internal static void About()
{
MessageBox.Show($"IBMiCmd, created by Works Of Barry. { Environment.NewLine} github.com/WorksOfBarry/IBMiCmd");
}
internal static void OpenLogFile()
{
NppFunctions.OpenFile(IBMiUtilities.GetLogPath(), true);
}
internal static void ManageCL()
{
CLFile.CorrectLines(NppFunctions.GetCurrentFileName(), Convert.ToInt32(IBMi.GetConfig("clrcdlen")));
NppFunctions.RefreshWindow(NppFunctions.GetCurrentFileName());
}
internal static void LoadConfigSelect()
{
new selectConfig().ShowDialog();
}
internal static void OpenInclude()
{
Thread gothread = new Thread((ThreadStart)delegate {
string LineNum = NppFunctions.GetLine(NppFunctions.GetLineNumber());
OpenMember Member = Include.HandleInclude(LineNum);
if (Member != null)
{
string FileLoc = "";
FileLoc = IBMiUtilities.DownloadMember(Member.GetLibrary(), Member.GetObject(), Member.GetMember());
if (FileLoc != "")
{
NppFunctions.OpenFile(FileLoc, true);
}
else
{
MessageBox.Show("Unable to download member " + Member.GetLibrary() + "/" + Member.GetObject() + "." + Member.GetMember() + ". Please check it exists and that you have access to the remote system.");
}
}
else
{
MessageBox.Show("Unable to parse out member.");
}
});
gothread.Start();
}
internal static void MemberListing()
{
if (MemberListWindow == null)
{
MemberListWindow = new selectMember();
using (Bitmap newBmp = new Bitmap(16, 16))
{
Graphics g = Graphics.FromImage(newBmp);
ColorMap[] colorMap = new ColorMap[1];
colorMap[0] = new ColorMap();
colorMap[0].OldColor = Color.Fuchsia;
colorMap[0].NewColor = Color.FromKnownColor(KnownColor.Blue);
ImageAttributes attr = new ImageAttributes();
attr.SetRemapTable(colorMap);
g.DrawImage(tbBmp_tbTab, new Rectangle(0, 0, 16, 16), 0, 0, 16, 16, GraphicsUnit.Pixel, attr);
tbIcon = Icon.FromHandle(newBmp.GetHicon());
}
NppTbData _nppTbData = new NppTbData();
_nppTbData.hClient = MemberListWindow.Handle;
_nppTbData.pszName = "Member Listing";
_nppTbData.dlgID = idMyDlg;
_nppTbData.uMask = NppTbMsg.DWS_DF_CONT_RIGHT | NppTbMsg.DWS_ICONTAB | NppTbMsg.DWS_ICONBAR;
_nppTbData.hIconTab = (uint)tbIcon.Handle;
_nppTbData.pszModuleName = PluginName;
IntPtr _ptrNppTbData = Marshal.AllocHGlobal(Marshal.SizeOf(_nppTbData));
Marshal.StructureToPtr(_nppTbData, _ptrNppTbData, false);
Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_DMMREGASDCKDLG, 0, _ptrNppTbData);
}
else
{
Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_DMMSHOW, 0, MemberListWindow.Handle);
}
}
internal static void OpenMember()
{
new openMember().ShowDialog();
}
internal static void UploadMember()
{
new uploadMember().ShowDialog();
}
internal static void LaunchConversion()
{
new rpgForm().ShowDialog();
}
internal static void LaunchFileConversion()
{
new rpgFileConvert().ShowDialog();
}
internal static void RemoteSetup()
{
new userSettings().ShowDialog();
}
internal static void RemoteInstall()
{
new installRemote().ShowDialog();
}
internal static void LiblDialog()
{
new libraryList().ShowDialog();
}
internal static void BuildSourceContext()
{
RPGParser.LaunchFFDCollection();
}
internal static void PromptCommand()
{
CLCommandPrompter.PromptCommand();
}
internal static void CommandDialog()
{
if (CommandWindow == null)
{
CommandWindow = new commandEntry();
using (Bitmap newBmp = new Bitmap(16, 16))
{
Graphics g = Graphics.FromImage(newBmp);
ColorMap[] colorMap = new ColorMap[1];
colorMap[0] = new ColorMap();
colorMap[0].OldColor = Color.Fuchsia;
colorMap[0].NewColor = Color.FromKnownColor(KnownColor.Blue);
ImageAttributes attr = new ImageAttributes();
attr.SetRemapTable(colorMap);
g.DrawImage(tbBmp_tbTab, new Rectangle(0, 0, 16, 16), 0, 0, 16, 16, GraphicsUnit.Pixel, attr);
tbIcon = Icon.FromHandle(newBmp.GetHicon());
}
NppTbData _nppTbData = new NppTbData();
_nppTbData.hClient = CommandWindow.Handle;
_nppTbData.pszName = "Command Entry";
_nppTbData.dlgID = idMyDlg;
_nppTbData.uMask = NppTbMsg.DWS_DF_CONT_RIGHT | NppTbMsg.DWS_ICONTAB | NppTbMsg.DWS_ICONBAR;
_nppTbData.hIconTab = (uint)tbIcon.Handle;
_nppTbData.pszModuleName = PluginName;
IntPtr _ptrNppTbData = Marshal.AllocHGlobal(Marshal.SizeOf(_nppTbData));
Marshal.StructureToPtr(_nppTbData, _ptrNppTbData, false);
Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_DMMREGASDCKDLG, 0, _ptrNppTbData);
}
else
{
Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_DMMSHOW, 0, CommandWindow.Handle);
}
}
internal static void ErrorDialog()
{
if (ErrorWindow == null)
{
ErrorWindow = new errorListing();
using (Bitmap newBmp = new Bitmap(16, 16))
{
Graphics g = Graphics.FromImage(newBmp);
ColorMap[] colorMap = new ColorMap[1];
colorMap[0] = new ColorMap();
colorMap[0].OldColor = Color.Fuchsia;
colorMap[0].NewColor = Color.FromKnownColor(KnownColor.Orange);
ImageAttributes attr = new ImageAttributes();
attr.SetRemapTable(colorMap);
g.DrawImage(tbBmp_tbTab, new Rectangle(0, 0, 16, 16), 0, 0, 16, 16, GraphicsUnit.Pixel, attr);
tbIcon = Icon.FromHandle(newBmp.GetHicon());
}
NppTbData _nppTbData = new NppTbData();
_nppTbData.hClient = ErrorWindow.Handle;
_nppTbData.pszName = "Error Listing";
_nppTbData.dlgID = idMyDlg;
_nppTbData.uMask = NppTbMsg.DWS_DF_CONT_RIGHT | NppTbMsg.DWS_ICONTAB | NppTbMsg.DWS_ICONBAR;
_nppTbData.hIconTab = (uint)tbIcon.Handle;
_nppTbData.pszModuleName = PluginName;
IntPtr _ptrNppTbData = Marshal.AllocHGlobal(Marshal.SizeOf(_nppTbData));
Marshal.StructureToPtr(_nppTbData, _ptrNppTbData, false);
Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_DMMREGASDCKDLG, 0, _ptrNppTbData);
}
else
{
Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_DMMSHOW, 0, ErrorWindow.Handle);
}
}
internal static void BindsDialog()
{
if (BindsWindow == null)
{
BindsWindow = new cmdBindings();
using (Bitmap newBmp = new Bitmap(16, 16))
{
Graphics g = Graphics.FromImage(newBmp);
ColorMap[] colorMap = new ColorMap[1];
colorMap[0] = new ColorMap();
colorMap[0].OldColor = Color.Fuchsia;
colorMap[0].NewColor = Color.FromKnownColor(KnownColor.Green);
ImageAttributes attr = new ImageAttributes();
attr.SetRemapTable(colorMap);
g.DrawImage(tbBmp_tbTab, new Rectangle(0, 0, 16, 16), 0, 0, 16, 16, GraphicsUnit.Pixel, attr);
tbIcon = Icon.FromHandle(newBmp.GetHicon());
}
NppTbData _nppTbData = new NppTbData();
_nppTbData.hClient = BindsWindow.Handle;
_nppTbData.pszName = "Command Bindings";
_nppTbData.dlgID = idMyDlg;
_nppTbData.uMask = NppTbMsg.DWS_DF_CONT_RIGHT | NppTbMsg.DWS_ICONTAB | NppTbMsg.DWS_ICONBAR;
_nppTbData.hIconTab = (uint)tbIcon.Handle;
_nppTbData.pszModuleName = PluginName;
IntPtr _ptrNppTbData = Marshal.AllocHGlobal(Marshal.SizeOf(_nppTbData));
Marshal.StructureToPtr(_nppTbData, _ptrNppTbData, false);
Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_DMMREGASDCKDLG, 0, _ptrNppTbData);
BindsWindow.cmdBindings_Load();
}
else
{
Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_DMMSHOW, 0, BindsWindow.Handle);
}
}
#endregion
}
}