Skip to content

Commit b825fc8

Browse files
committed
* Fixed window parameter in all window methods
+ Added Developer Console scaffold
1 parent 148c2f8 commit b825fc8

4 files changed

Lines changed: 132 additions & 22 deletions

File tree

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
namespace EmptyFlow.SciterAPI.Client.DeveloperConsole {
2+
3+
public class DeveloperConsole {
4+
5+
private DeveloperConsoleWindowHandler m_windowHandler;
6+
7+
private nint m_consolePointer = nint.Zero;
8+
9+
public DeveloperConsole ( SciterAPIHost host, nint windowPointer ) {
10+
m_windowHandler = new DeveloperConsoleWindowHandler ( windowPointer, host );
11+
host.AddWindowEventHandler ( m_windowHandler, windowPointer );
12+
m_consolePointer = host.CreateWindow ( parent: windowPointer, width: 500, height: 400 );
13+
host.Callbacks.AddAttachBehaviourFactory (
14+
"developerconsolehub",
15+
( element ) => {
16+
return new DeveloperConsoleHubHandler ( element, host, this );
17+
}
18+
);
19+
host.LoadHtml ( DeveloperConsoleHtml.Content, m_consolePointer );
20+
host.ShowWindow ( m_consolePointer );
21+
host.MoveWindow ( m_consolePointer, new SciterWindowPosition ( 100, 100 ) );
22+
}
23+
24+
public void ReloadPage () {
25+
var path = m_windowHandler.Host.GetLatestLoadedFilePath ( m_windowHandler.SubscribedElement );
26+
if ( string.IsNullOrEmpty ( path ) ) return;
27+
28+
m_windowHandler.Host.LoadFile ( path, m_windowHandler.SubscribedElement );
29+
}
30+
31+
}
32+
33+
internal class DeveloperConsoleHubHandler : ElementEventHandler {
34+
35+
private DeveloperConsole m_developerConsole;
36+
37+
public DeveloperConsoleHubHandler ( nint relatedThing, SciterAPIHost host, DeveloperConsole developerConsole ) : base ( relatedThing, host ) {
38+
m_developerConsole = developerConsole;
39+
}
40+
41+
public override EventBehaviourGroups BeforeRegisterEvent () =>
42+
EventBehaviourGroups.HANDLE_METHOD_CALL |
43+
EventBehaviourGroups.HANDLE_SCRIPTING_METHOD_CALL;
44+
45+
public override (SciterValue? value, bool handled) ScriptMethodCall ( string name, IEnumerable<SciterValue> arguments ) {
46+
if ( name == "reloadpage" ) {
47+
m_developerConsole.ReloadPage ();
48+
var resultValue = Host.CreateValue ( true );
49+
return (resultValue, true);
50+
}
51+
52+
return (null, false);
53+
}
54+
55+
}
56+
57+
internal static class DeveloperConsoleHtml {
58+
59+
public static string Content =
60+
""""
61+
<html>
62+
<head>
63+
<style>
64+
body {
65+
margin: 0;
66+
padding: 0;
67+
}
68+
</style>
69+
<script>
70+
const reloadPageButton = document.getElementById('reloadpage');
71+
const hub = document.getElementById('hub');
72+
reloadPageButton.addEventListener(
73+
"click",
74+
function() {
75+
const pizda = document.getElementById('hub');
76+
pizda.xcall('reloadpage');
77+
}
78+
);
79+
</script>
80+
</head>
81+
<body>
82+
<div id="hub" style="behavior: developerconsolehub;"></div>
83+
<button id="reloadpage">Reload page</button>
84+
</body>
85+
</html>
86+
"""";
87+
88+
}
89+
90+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace EmptyFlow.SciterAPI.Client.DeveloperConsole {
2+
3+
internal class DeveloperConsoleWindowHandler : WindowEventHandler {
4+
5+
public DeveloperConsoleWindowHandler ( nint window, SciterAPIHost host ) : base ( window, host ) {
6+
7+
}
8+
9+
}
10+
11+
}

src/EmptyFlow.SciterAPI/Client/HostWindowsAPI.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void ShowWindow(nint windowPointer) {
8989
_ => ""
9090
};
9191
var script = $"Window.this.box(\"xywh\",\"{boxOf}\", \"{relTo}\", {( inPhisicalDevicePixels ? "true" : "false" )})";
92-
if ( m_basicApi.SciterEval ( m_mainWindow, script, (uint) script.Length, out var result ) ) {
92+
if ( m_basicApi.SciterEval ( window, script, (uint) script.Length, out var result ) ) {
9393
if ( !result.IsArray && !result.IsArrayLike ) {
9494
Console.WriteLine ( "GetMainWindowSizeAndPosition: box() return not array!" );
9595
return null;
@@ -113,7 +113,7 @@ public void ShowWindow(nint windowPointer) {
113113

114114
public bool GetWindowActive ( nint window ) {
115115
var script = $"Window.this.isActive";
116-
if ( m_basicApi.SciterEval ( m_mainWindow, script, (uint) script.Length, out var result ) ) {
116+
if ( m_basicApi.SciterEval ( window, script, (uint) script.Length, out var result ) ) {
117117
if ( !result.IsBoolean ) {
118118
Console.WriteLine ( "GetWindowActive: isActive return not boolean!" );
119119
return false;
@@ -127,7 +127,7 @@ public bool GetWindowActive ( nint window ) {
127127

128128
public bool MoveWindow ( nint window, SciterWindowPosition position ) {
129129
var script = $"Window.this.move({position.X}, {position.Y})";
130-
if ( m_basicApi.SciterEval ( m_mainWindow, script, (uint) script.Length, out var result ) ) {
130+
if ( m_basicApi.SciterEval ( window, script, (uint) script.Length, out var result ) ) {
131131
if ( result.IsErrorString || result.IsObjectError ) {
132132
Console.WriteLine ( "MoveWindow: window not moved!" );
133133
return false;
@@ -141,7 +141,7 @@ public bool MoveWindow ( nint window, SciterWindowPosition position ) {
141141

142142
public bool GetWindowTopMost ( nint window ) {
143143
var script = $"Window.this.isTopmost";
144-
if ( m_basicApi.SciterEval ( m_mainWindow, script, (uint) script.Length, out var result ) ) {
144+
if ( m_basicApi.SciterEval ( window, script, (uint) script.Length, out var result ) ) {
145145
if ( !result.IsBoolean ) {
146146
Console.WriteLine ( "GetWindowTopMost: isTopmost return not boolean!" );
147147
return false;
@@ -155,7 +155,7 @@ public bool GetWindowTopMost ( nint window ) {
155155

156156
public bool SetWindowTopMost ( nint window, bool state ) {
157157
var script = $"Window.this.isTopmost = {( state == true ? "true" : "false" )}";
158-
if ( m_basicApi.SciterEval ( m_mainWindow, script, (uint) script.Length, out var result ) ) {
158+
if ( m_basicApi.SciterEval ( window, script, (uint) script.Length, out var result ) ) {
159159
if ( result.IsErrorString || result.IsObjectError ) {
160160
Console.WriteLine ( "SetWindowTopMost: value not changed! " );
161161
return false;
@@ -169,7 +169,7 @@ public bool SetWindowTopMost ( nint window, bool state ) {
169169

170170
public bool GetWindowMaximizable ( nint window ) {
171171
var script = $"Window.this.isMaximizable";
172-
if ( m_basicApi.SciterEval ( m_mainWindow, script, (uint) script.Length, out var result ) ) {
172+
if ( m_basicApi.SciterEval ( window, script, (uint) script.Length, out var result ) ) {
173173
if ( !result.IsBoolean ) {
174174
Console.WriteLine ( "GetWindowMaximizable: isMaximizable return not boolean!" );
175175
return false;
@@ -183,7 +183,7 @@ public bool GetWindowMaximizable ( nint window ) {
183183

184184
public bool SetWindowMaximizable ( nint window, bool state ) {
185185
var script = $"Window.this.isMaximizable = {( state == true ? "true" : "false" )}";
186-
if ( m_basicApi.SciterEval ( m_mainWindow, script, (uint) script.Length, out var result ) ) {
186+
if ( m_basicApi.SciterEval ( window, script, (uint) script.Length, out var result ) ) {
187187
if ( result.IsErrorString || result.IsObjectError ) {
188188
Console.WriteLine ( "SetWindowMaximizable: value not changed! " );
189189
return false;
@@ -197,7 +197,7 @@ public bool SetWindowMaximizable ( nint window, bool state ) {
197197

198198
public bool GetWindowMinimizable ( nint window ) {
199199
var script = $"Window.this.isMinimizable";
200-
if ( m_basicApi.SciterEval ( m_mainWindow, script, (uint) script.Length, out var result ) ) {
200+
if ( m_basicApi.SciterEval ( window, script, (uint) script.Length, out var result ) ) {
201201
if ( !result.IsBoolean ) {
202202
Console.WriteLine ( "GetWindowMinimizable: isMinimizable return not boolean!" );
203203
return false;
@@ -211,7 +211,7 @@ public bool GetWindowMinimizable ( nint window ) {
211211

212212
public bool SetWindowMinimizable ( nint window, bool state ) {
213213
var script = $"Window.this.isMinimizable = {( state == true ? "true" : "false" )}";
214-
if ( m_basicApi.SciterEval ( m_mainWindow, script, (uint) script.Length, out var result ) ) {
214+
if ( m_basicApi.SciterEval ( window, script, (uint) script.Length, out var result ) ) {
215215
if ( result.IsErrorString || result.IsObjectError ) {
216216
Console.WriteLine ( "SetWindowMinimizable: value not changed! " );
217217
return false;
@@ -225,7 +225,7 @@ public bool SetWindowMinimizable ( nint window, bool state ) {
225225

226226
public bool GetWindowEnabled ( nint window ) {
227227
var script = $"Window.this.isEnabled";
228-
if ( m_basicApi.SciterEval ( m_mainWindow, script, (uint) script.Length, out var result ) ) {
228+
if ( m_basicApi.SciterEval ( window, script, (uint) script.Length, out var result ) ) {
229229
if ( !result.IsBoolean ) {
230230
Console.WriteLine ( "GetWindowEnabled: isEnabled return not boolean!" );
231231
return false;
@@ -239,7 +239,7 @@ public bool GetWindowEnabled ( nint window ) {
239239

240240
public bool SetWindowEnabled ( nint window, bool state ) {
241241
var script = $"Window.this.isEnabled = {( state == true ? "true" : "false" )}";
242-
if ( m_basicApi.SciterEval ( m_mainWindow, script, (uint) script.Length, out var result ) ) {
242+
if ( m_basicApi.SciterEval ( window, script, (uint) script.Length, out var result ) ) {
243243
if ( result.IsErrorString || result.IsObjectError ) {
244244
Console.WriteLine ( "SetWindowEnabled: value not changed! " );
245245
return false;
@@ -253,7 +253,7 @@ public bool SetWindowEnabled ( nint window, bool state ) {
253253

254254
public double? GetWindowAspectRatio ( nint window ) {
255255
var script = $"Window.this.aspectRatio";
256-
if ( m_basicApi.SciterEval ( m_mainWindow, script, (uint) script.Length, out var result ) ) {
256+
if ( m_basicApi.SciterEval ( window, script, (uint) script.Length, out var result ) ) {
257257
if ( !result.IsFloat ) {
258258
Console.WriteLine ( "GetWindowAspectRatio: aspectRatio return not boolean!" );
259259
return null;
@@ -267,7 +267,7 @@ public bool SetWindowEnabled ( nint window, bool state ) {
267267

268268
public bool SetWindowAspectRatio ( nint window, double value ) {
269269
var script = $"Window.this.aspectRatio = {value}";
270-
if ( m_basicApi.SciterEval ( m_mainWindow, script, (uint) script.Length, out var result ) ) {
270+
if ( m_basicApi.SciterEval ( window, script, (uint) script.Length, out var result ) ) {
271271
if ( result.IsErrorString || result.IsObjectError ) {
272272
Console.WriteLine ( "SetWindowAspectRatio: value not changed! " );
273273
return false;
@@ -281,7 +281,7 @@ public bool SetWindowAspectRatio ( nint window, double value ) {
281281

282282
public string GetWindowCaption ( nint window ) {
283283
var script = $"Window.this.caption";
284-
if ( m_basicApi.SciterEval ( m_mainWindow, script, (uint) script.Length, out var result ) ) {
284+
if ( m_basicApi.SciterEval ( window, script, (uint) script.Length, out var result ) ) {
285285
if ( !result.IsString ) {
286286
Console.WriteLine ( "GetWindowCaption: caption return not string!" );
287287
return "";
@@ -295,7 +295,7 @@ public string GetWindowCaption ( nint window ) {
295295

296296
public bool SetWindowCaption ( nint window, string value ) {
297297
var script = $"Window.this.caption = \"{value}\"";
298-
if ( m_basicApi.SciterEval ( m_mainWindow, script, (uint) script.Length, out var result ) ) {
298+
if ( m_basicApi.SciterEval ( window, script, (uint) script.Length, out var result ) ) {
299299
if ( result.IsErrorString || result.IsObjectError ) {
300300
Console.WriteLine ( "SetWindowCaption: value not changed! " );
301301
return false;
@@ -309,7 +309,7 @@ public bool SetWindowCaption ( nint window, string value ) {
309309

310310
public SciterWindowFrameType GetWindowFrameType ( nint window ) {
311311
var script = $"Window.this.frameType";
312-
if ( m_basicApi.SciterEval ( m_mainWindow, script, (uint) script.Length, out var result ) ) {
312+
if ( m_basicApi.SciterEval ( window, script, (uint) script.Length, out var result ) ) {
313313
if ( !result.IsString ) {
314314
Console.WriteLine ( "GetWindowFrameType: caption return not string!" );
315315
return SciterWindowFrameType.Unknown;
@@ -342,7 +342,7 @@ public bool SetWindowFrameType ( nint window, SciterWindowFrameType value ) {
342342
};
343343

344344
var script = $"Window.this.frameType = \"{stringValue}\"";
345-
if ( m_basicApi.SciterEval ( m_mainWindow, script, (uint) script.Length, out var result ) ) {
345+
if ( m_basicApi.SciterEval ( window, script, (uint) script.Length, out var result ) ) {
346346
if ( result.IsErrorString || result.IsObjectError ) {
347347
Console.WriteLine ( "SetWindowFrameType: value not changed! " );
348348
return false;
@@ -356,7 +356,7 @@ public bool SetWindowFrameType ( nint window, SciterWindowFrameType value ) {
356356

357357
public bool GetWindowResizable ( nint window ) {
358358
var script = $"Window.this.isResizable";
359-
if ( m_basicApi.SciterEval ( m_mainWindow, script, (uint) script.Length, out var result ) ) {
359+
if ( m_basicApi.SciterEval ( window, script, (uint) script.Length, out var result ) ) {
360360
if ( !result.IsBoolean ) {
361361
Console.WriteLine ( "GetWindowResizable: isResizable return not boolean!" );
362362
return false;
@@ -370,7 +370,7 @@ public bool GetWindowResizable ( nint window ) {
370370

371371
public bool SetWindowResizable ( nint window, bool state ) {
372372
var script = $"Window.this.isResizable = {( state == true ? "true" : "false" )}";
373-
if ( m_basicApi.SciterEval ( m_mainWindow, script, (uint) script.Length, out var result ) ) {
373+
if ( m_basicApi.SciterEval ( window, script, (uint) script.Length, out var result ) ) {
374374
if ( result.IsErrorString || result.IsObjectError ) {
375375
Console.WriteLine ( "SetWindowResizable: value not changed! " );
376376
return false;
@@ -405,7 +405,7 @@ public bool SetWindowResizable ( nint window, bool state ) {
405405
var properties = "{" + string.Join ( ",", keys.Select ( a => a.Key + ": \"" + a.Value + "\"" ) ) + "}";
406406

407407
var script = $"Window.this.selectFile({properties})";
408-
if ( m_basicApi.SciterEval ( m_mainWindow, script, (uint) script.Length, out var result ) ) {
408+
if ( m_basicApi.SciterEval ( window, script, (uint) script.Length, out var result ) ) {
409409
if ( result.IsErrorString || result.IsObjectError ) {
410410
Console.WriteLine ( "ShowWindowSelectFileDialog: error occurs when calling! " );
411411
return null;

src/EmptyFlow.SciterAPI/Client/SciterAPIHost.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ public SciterAPIHost () {
5050
InnerLoadAPI ();
5151
}
5252

53-
private void AdjustVersion() {
53+
private void AdjustVersion () {
5454
var version = typeof ( SciterAPIHost ).Assembly.GetName ()?.Version;
5555
if ( version != null ) VersionOfLibrary = $"{version.Major}.{version.Minor}.{version.Build}";
5656
}
5757

5858
private void InnerLoadAPI () {
59-
Console.WriteLine ("Start load Sciter API....");
59+
Console.WriteLine ( "Start load Sciter API...." );
6060

6161
m_apiPointer = SciterAPI ();
6262
if ( m_apiPointer == IntPtr.Zero ) return;
@@ -148,11 +148,20 @@ public static IntPtr WindowsDelegateImplementaion ( IntPtr hwnd, uint msg, IntPt
148148
m_callbacks.RegisterCallback ();
149149
}
150150

151+
private readonly Dictionary<nint, string> m_latestLoadedFile = new Dictionary<nint, string> ();
152+
151153
public void LoadFile ( string htmlPath, nint windowPointer = default ) {
152154
var window = windowPointer == default ? m_mainWindow : windowPointer;
153155
if ( window == IntPtr.Zero ) return;
154156

155157
m_basicApi.SciterLoadFile ( window, htmlPath );
158+
m_latestLoadedFile[window] = htmlPath;
159+
}
160+
161+
public string GetLatestLoadedFilePath ( nint windowPointer ) {
162+
if ( m_latestLoadedFile.ContainsKey ( windowPointer ) ) return m_latestLoadedFile[windowPointer];
163+
164+
return "";
156165
}
157166

158167
public void LoadHtml ( string html, nint windowPointer = default ) {

0 commit comments

Comments
 (0)