/
ForceNewInstance_extended.js
125 lines (114 loc) · 3.8 KB
/
ForceNewInstance_extended.js
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
// http://tc-image.3dn.ru/forum/9-258-848-16-1332958870
// http://akelpad.sourceforge.net/forum/viewtopic.php?p=4222#4222
// Version: 1.4
// Author: Shengalts Aleksander aka Instructor / texter
//
/// Extended version from ForceNewInstance.js
//
// Description(1033): Force create new program instance.
// Description(1049): Ôîðñèðîâàòü ñîçäàíèå íîâîãî ýêçåìïëÿðà ïðîãðàììû.
//
// Arguments:
// -CmdLine="/Command(4155)" -Command line than will be appended to CmdLineBegin parameter of the second instance.
// -MDI=1 -By default 1 MDI mode, 0 is SDI, 2 is PMDI
//
// Usage:
// Call("Scripts::Main", 1, "ForceNewInstance_extended.js", `-CmdLine="/Command(4155)"`)
// Call("Scripts::Main", 1, "ForceNewInstance_extended.js", '-MDI=2')
//Arguments
var pCmdLine=AkelPad.GetArgValue("CmdLine", "");
var pMDI=AkelPad.GetArgValue("MDI", 1);
ForceNewInstance(pCmdLine, pMDI);
function ForceNewInstance(pCmdLine, pMDI)
{
var hMainWnd=AkelPad.GetMainWnd();
var oSet=AkelPad.ScriptSettings();
var hNewMainWnd=0;
var lpPluginFunction;
var lpCmdLineBegin;
var nCmdLineBeginLen;
var pCmdLineCurrent="";
var bOpenOnStartEnable=false;
//Plugin running?
if (lpPluginFunction=AkelPad.SendMessage(hMainWnd, 1329 /*AKD_DLLFIND*/, "Sessions::Main", 0))
{
//Plugin autoloading?
if (AkelPad.MemRead(_PtrAdd(lpPluginFunction, _X64?812:800) /*offsetof(PLUGINFUNCTION, bAutoLoad)*/, 3 /*DT_DWORD*/))
{
//Plugin opens session on start?
if (oSet.Begin("Sessions", 0x21 /*POB_READ|POB_PLUGS*/))
{
bOpenOnStartEnable=oSet.Read("OpenOnStartEnable", 1 /*PO_DWORD*/);
oSet.End();
}
//Turn off open session on start
if (bOpenOnStartEnable)
{
if (oSet.Begin("Sessions", 0x22 /*POB_SAVE|POB_PLUGS*/))
{
oSet.Write("OpenOnStartEnable", 1 /*PO_DWORD*/, false);
oSet.End();
}
}
}
}
if (pCmdLine)
{
if (oSet.Begin("", 0x42 /*POB_SAVE|POB_PROGRAM*/))
{
if (nCmdLineBeginLen=AkelPad.SendMessage(hMainWnd, 1222 /*AKD_GETMAININFO*/, 105 /*MI_CMDLINEBEGIN*/, 0))
{
if (lpCmdLineBegin=AkelPad.MemAlloc(nCmdLineBeginLen * 2 /*sizeof(wchar_t)*/))
{
if (AkelPad.SendMessage(hMainWnd, 1222 /*AKD_GETMAININFO*/, 105 /*MI_CMDLINEBEGIN*/, lpCmdLineBegin))
pCmdLineCurrent=AkelPad.MemRead(lpCmdLineBegin, 1 /*DT_UNICODE*/);
AkelPad.MemFree(lpCmdLineBegin);
}
}
oSet.Write("CmdLineBegin", 3 /*PO_STRING*/, pCmdLineCurrent + " " + pCmdLine);
oSet.End();
}
}
if (pMDI)
{
if (oSet.Begin("", 0x42 /*POB_SAVE|POB_PROGRAM*/))
{
oSet.Write("MDI", 1 /*PO_DWORD*/, pMDI);
oSet.End();
}
}
if (AkelPad.SendMessage(hMainWnd, 1222 /*AKD_GETMAININFO*/, 153 /*MI_SINGLEOPENPROGRAM*/, 0))
{
AkelPad.Command(4256 /*IDM_OPTIONS_SINGLEOPEN_PROGRAM*/);
hNewMainWnd=AkelPad.Command(4102 /*IDM_FILE_CREATENEW*/);
AkelPad.Command(4256 /*IDM_OPTIONS_SINGLEOPEN_PROGRAM*/);
AkelPad.SendMessage(hNewMainWnd, 273 /*WM_COMMAND*/, 4256 /*IDM_OPTIONS_SINGLEOPEN_PROGRAM*/, 0);
}
else hNewMainWnd=AkelPad.Command(4102 /*IDM_FILE_CREATENEW*/);
//Turn on open session on start
if (bOpenOnStartEnable)
{
if (oSet.Begin("Sessions", 0x22 /*POB_SAVE|POB_PLUGS*/))
{
oSet.Write("OpenOnStartEnable", 1 /*PO_DWORD*/, true);
oSet.End();
}
}
if (pCmdLine)
{
if (oSet.Begin("", 0x42 /*POB_SAVE|POB_PROGRAM*/))
{
oSet.Write("CmdLineBegin", 3 /*PO_STRING*/, pCmdLineCurrent);
oSet.End();
}
}
if (pMDI)
{
if (oSet.Begin("", 0x42 /*POB_SAVE|POB_PROGRAM*/))
{
oSet.Write("MDI", 1 /*PO_DWORD*/, 1);
oSet.End();
}
}
return hNewMainWnd;
}