1 module app;
2 
3 import dlangui;
4 import std.stdio;
5 import std.conv;
6 import dlangide.ui.frame;
7 import dlangide.ui.commands;
8 import dlangide.workspace.workspace;
9 import std.experimental.logger;
10 
11 mixin APP_ENTRY_POINT;
12 
13 /// entry point for dlangui based application
14 extern (C) int UIAppMain(string[] args) {
15 
16     //debug(TestDMDTraceParser) {
17     //    import dlangide.tools.d.dmdtrace;
18     //    long start = currentTimeMillis;
19     //    DMDTraceLogParser parser = parseDMDTraceLog("trace.log");
20     //    if (parser) {
21     //        Log.d("trace.log is parsed ok in ", currentTimeMillis - start, " seconds");
22     //    }
23     //}
24     debug(TestParser) {
25         import ddc.lexer.parser;
26         runParserTests();
27     }
28 
29     version(Windows) {
30         debug {
31             sharedLog = new FileLogger("dcd.log");
32         } else {
33             sharedLog = new NullLogger();
34         }
35     } else {
36         debug {
37             //sharedLog = new FileLogger("dcd.log");
38         } else {
39             sharedLog = new NullLogger();
40         }
41     }
42 
43     //version (Windows) {
44     //    import derelict.lldb.lldbtest;
45     //    runLldbTests();
46     //}
47 
48     // embed non-standard resources listed in views/resources.list into executable
49     embeddedResourceList.addResources(embedResourcesFromList!("resources.list")());
50 
51     Platform.instance.uiTheme = "ide_theme_default";
52 
53     // you can override default hinting mode here
54     //FontManager.hintingMode = HintingMode.Light;
55     //FontManager.hintingMode = HintingMode.AutoHint;
56     FontManager.hintingMode = HintingMode.Normal;
57     //FontManager.hintingMode = HintingMode.Disabled;
58     // you can override antialiasing setting here
59     FontManager.minAnitialiasedFontSize = 0;
60     /// set font gamma (1.0 is neutral, < 1.0 makes glyphs lighter, >1.0 makes glyphs bolder)
61     FontManager.fontGamma = 1.0;
62     version (NO_OPENGL) {
63         FontManager.subpixelRenderingMode = SubpixelRenderingMode.BGR;
64     } else {
65         FontManager.subpixelRenderingMode = SubpixelRenderingMode.None;
66     }
67     version (USE_OPENGL) {
68         // you can turn on subpixel font rendering (ClearType) here
69         FontManager.subpixelRenderingMode = SubpixelRenderingMode.None; //
70         FontManager.fontGamma = 0.9;
71         FontManager.hintingMode = HintingMode.AutoHint;
72     } else {
73         version (USE_FREETYPE) {
74             // you can turn on subpixel font rendering (ClearType) here
75             FontManager.fontGamma = 0.8;
76             //FontManager.subpixelRenderingMode = SubpixelRenderingMode.BGR; //SubpixelRenderingMode.None; //
77             FontManager.hintingMode = HintingMode.AutoHint;
78         }
79     }
80 
81     //version(USE_WIN_DEBUG) {
82     //    debuggerTest();
83     //}
84     //version(USE_GDB_DEBUG) {
85     //    debuggerTestGDB();
86     //}
87     version(unittest) {
88         return 0;
89     } else {
90 
91         // create window
92         Window window = Platform.instance.createWindow("Dlang IDE", null, WindowFlag.Resizable, 900, 730);
93         static if (BACKEND_GUI) {
94             // set window icon
95             window.windowIcon = drawableCache.getImage("dlangui-logo1");
96         }
97     
98         //Widget w = new Widget();
99         //pragma(msg, w.click.return_t, "", w.click.params_t);
100 
101         IDEFrame frame = new IDEFrame(window);
102         
103         // Open project, if it specified in command line
104         if (args.length > 1)
105         {
106             Action a = ACTION_FILE_OPEN_WORKSPACE.clone();
107             a.stringParam = args[1].toAbsolutePath;
108             frame.handleAction(a);
109             // Mark that workspace opened to prevent auto open
110             frame.isOpenedWorkspace(true);
111         }
112 
113         // open home screen tab
114         if (!frame.isOpenedWorkspace)
115             frame.showHomeScreen();
116         // for testing: load workspace at startup
117         //frame.openFileOrWorkspace(appendPath(exePath, "../workspaces/sample1/sample1.dlangidews"));
118 
119         // show window
120         window.show();
121         // restore window state, size, position
122         frame.restoreUIStateOnStartup();
123 
124         //jsonTest();
125 
126         // run message loop
127         return Platform.instance.enterMessageLoop();
128     }
129 }
130 
131 /*
132 version(USE_WIN_DEBUG) {
133     void debuggerTest() {
134         import ddebug.windows.windebug;
135         WinDebugger debugger = new WinDebugger("test\\dmledit.exe", "");
136         debugger.start();
137     }
138 }
139 
140 version(USE_GDB_DEBUG) {
141     void debuggerTestGDB() {
142         import ddebug.gdb.gdbinterface;
143         import core.thread;
144         Log.d("Testing GDB debugger");
145         DebuggerBase debugger = new DebuggerBase();
146         debugger.startDebugging("gdb", "test", [], "", delegate(ResponseCode code, string msg) {
147                 Log.d("startDebugging result: ", code, " : ", msg);
148                 //assert(code == ResponseCode.NotImplemented);
149             });
150         debugger.stop();
151         destroy(debugger);
152 
153         // async
154 
155         debugger = new GDBInterface();
156         DebuggerProxy proxy = new DebuggerProxy(debugger, delegate(Runnable runnable) {
157                 runnable();
158             });
159         Log.d("calling debugger.start()");
160         debugger.start();
161         Log.d("calling proxy.startDebugging()");
162         proxy.startDebugging("gdb", "/home/lve/src/d/dlangide/test/gdbtest", ["param1", "param2"], "/home/lve/src/d/dlangide/test", delegate(ResponseCode code, string msg) {
163                 Log.d("startDebugging result: ", code, " : ", msg);
164                 //assert(code == ResponseCode.NotImplemented);
165             });
166         Thread.sleep(dur!"msecs"(200000));
167         debugger.stop();
168         Thread.sleep(dur!"msecs"(200000));
169         destroy(debugger);
170         Log.d("Testing of GDB debugger is finished");
171     }
172 }
173 */
174 
175 unittest {
176     void jsonTest() {
177         import dlangui.core.settings;
178         Setting s = new Setting();
179         s["param1_ulong"] = cast(ulong)1543453u;
180         s["param2_long"] = cast(long)-22934;
181         s["param3_double"] = -39.123e-10;
182         s["param4_string"] = "some string value";
183         s["param5_bool_true"] = true;
184         s["param6_bool_false"] = false;
185         s["param7_null"] = new Setting();
186         Setting a = new Setting();
187         a[0] = cast(ulong)1u;
188         a[1] = cast(long)-2;
189         a[2] = 3.3;
190         a[3] = "some string value";
191         a[4] = true;
192         a[5] = false;
193         a[6] = new Setting();
194         Setting mm = new Setting();
195         mm["n"] = cast(ulong)5u;
196         mm["name"] = "test";
197         a[7] = mm;
198         s["param8_array"] = a;
199         Setting m = new Setting();
200         m["aaa"] = "bbb";
201         m["aaa2"] = cast(ulong)5u;
202         m["aaa3"] = false;
203         s["param9_object"] = m;
204         string json = s.toJSON(true);
205         s.save("test_file.json");
206 
207         Setting loaded = new Setting();
208         loaded.load("test_file.json");
209         string json2 = loaded.toJSON(true);
210         loaded.save("test_file2.json");
211     }
212 
213 }