root/trunk/src/leds/Leds.d

Revision 274, 21.9 kB (checked in by Alan Knowles, 3 years ago)

fixed to work with gtkd

Line 
1 /*
2  * This file is part of leds.
3  *
4  * leds is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * leds is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with leds; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19
20 module leds.Leds;
21
22 //debug=startup;
23
24 version(linux) private import std.c.linux.linux;
25
26 private import leds.Workspace;
27 private import leds.Language;
28 private import leds.Trash;
29 private import property.Props;
30 private import property.Properties;
31 private import property.PropertiesUI;
32 //private import ext.dconf.DConf;
33
34 private import std.stdio;
35    
36 private import std.c.time;
37 //private import leds.trash;
38    
39 private import dool.String;
40 private import dool.io.Path;
41 private import dool.io.FileException;
42
43 private import gtk.Main;
44
45 private import gthread.Thread;
46
47 public:
48 const int VERSION_MAJOR = 0;
49 const int VERSION_MINOR = 9;
50 const int VERSION_MICRO = 79;
51 const char[] VERSION_QUAL = "beta";
52
53 private:
54 extern(C)
55 {
56      char* getenv(char*);
57 };
58
59 public:
60
61 const char [] leadsHeaderMessage =
62 "#"
63 "\n# leds preferences file"
64 "\n#"
65 "\n"
66 "\n#"
67 "\n# This file was generated automatically by leds"
68 "\n# editing this file is not recomended"
69 "\n#"
70 "\n"
71 "\n"
72 ;
73
74 static const char [] ledsAboutMessage =
75 "leds\n"
76 "Light Editor for D w/ Scintilla\n"
77 " \n"
78 "build with gtkD\n"
79 " \n"
80 "by Antonio Monteiro\n"
81 ;
82
83 static const char[] defaultShortcus =
84 "if if ( $cursor )\\n{\\n\\n}\\n"
85 "\nife if ( $cursor )\\n{\\n\\n}\\nelse\\n{\\n}\\n"
86 "\nfor for ( $cursor;  ;i++)\\n{\\n}\\n"
87 "\nfori for ( ini i=0; i < $cursor ;i++)\\n{\\n}\\n"
88 "\nsw switch ( $cursor )\\n{\\ncase :\\n\\tbreak;\\n\\ndefault:\\n\\tbreak;\\n}\\n"
89 "\nwh while ( $cursor )\\n{\\n}\\n"
90 "\ndo do\\n{\\n\\n$cursor\\n} while ( );\\n"
91 "\ntry try\\n{\\n\\n$cursor\\n}\\n catch (  )\\n{\\n}\\n"
92 "\nca catch (  )\\n{\\n}\\n"
93 ;
94 static const char[] dShortcus =
95 "fore foreach( $cursor ; )\\n{\\n}\\n"
96 "\nmain int main(char[][] args)\\n{\\n$cursor\\n\\nreturn 0;\\n}\\n"
97 ;
98 static const char[] javaShortcus =
99 "main public static void main(String[] args)\\n{\\n}\\n"
100 ;
101
102 private import leds.KeyMap;
103
104 /**
105  * leds
106  */
107 public:
108 class Leds : PropertiesUICaller
109 {  
110     private:
111
112     Properties props;
113
114     /**
115      * all the workspaces. For now only one is supported.
116      */
117     Workspace[] workspaces;
118
119     int exitCode = 0;
120     /** if we are about to exit this will be set to true */
121     bit closing = false;
122
123     /**
124      * When true leds won't open projects at startup
125      * setup by command line "-nop"
126      */
127     bit noProjects = false;
128     //DConf dConf;
129    
130     String ledsHome;// = "~/.leds";
131     String ledsData;// = "~/.leds_data";
132    
133     public String editorType;
134    
135     String projectsDir;
136     String projectExtension;
137
138     static Leds thisLeds;
139    
140     /** A global to hold the last find string */
141     String previousFindString;
142
143     /** if we are working without home directory this will be false */
144     bit homeExists;
145    
146     Trash trash;
147    
148     alias String[String] Shortcuts;
149     Shortcuts[String] contextShortcuts;
150    
151     /**
152      * get a common instance of Leds.
153      * A new Leds will be created if none exists
154      */
155     static public Leds leds()
156     {
157         if ( thisLeds is null )
158         {
159             char[][] args;
160             thisLeds = new Leds();
161             thisLeds.init(args);
162         }
163         return thisLeds;
164     }
165    
166     /**
167      * get a common instance of Leds.
168      * A new Leds will be created if none exists
169      */
170     static public Leds leds(char[][]args)
171     {
172         if ( thisLeds is null )
173         {
174             thisLeds = new Leds();
175             thisLeds.init(args);
176         }
177         return thisLeds;
178     }
179
180     /**
181      * Don't allow external instanciations
182      */
183     private: this()
184     {
185         previousFindString = new String();
186         projectsDir = new String("projects");
187         projectExtension = new String("lpj");
188         ledsHome = new String();
189         ledsData = new String();
190         editorType = new String("scintilla");
191     }
192    
193     //extern(C) static void t(Leds leds)
194     //{
195     //  int count = 0;
196     //  while(true)
197     //  {
198     //      printf("ThreadG %.*s %d\n",leds.getHomeDir(), count++);
199     //      sleep(1);
200     //  }
201     //}
202        
203
204     /**
205      * setup Leds.
206      * - determone the home directories
207      * - creates a workspace
208      */
209     private: void init(char[][]args)
210     {
211         debug(startup) printf("Leds.init 1\n");
212         ledsHome = Path.join(getAppData(),".leds3");
213         ledsData = Path.join(getAppData(),".leds3_data");
214
215         assert(ledsHome !is null);
216         assert(ledsData !is null);
217        
218         //dConf = new DConf();
219         //ThreadG tg = new ThreadG((void*)&t, (void*)this, 0, true, true, ThreadPriority.NORMAL, error);
220
221         //printf("Plugin error before new Plugin %.*s\n",Plugin.error());
222         //Plugin plugin = new Plugin("../Plug.o",PluginFlags.BIND_LAZY);
223         //printf("Plugin error after new Plugin %.*s\n",Plugin.error());
224        
225         String[] filesToOpen;
226         bit exitNow = parseArgs(args, filesToOpen);
227
228         debug(startup) printf("Leds.init 2\n");
229         if ( exitNow )
230         {
231             closing = true;
232         }
233         else
234         {
235             debug(startup) printf("Leds.init 3\n");
236             homeExists = confirmHomeExists();
237             ledsHome.println("Using home = ");
238             ledsData.println("Using data = ");
239             if ( !homeExists )
240             {
241                 printf("No home or data directory exist!\nprojects cannot be created or saved!\n\n");
242             }
243
244             debug(startup) printf("Leds.init 4\n");
245             setProps();
246             debug(startup) printf("Leds.init 5\n");
247             setKeys();
248             debug(startup) printf("Leds.init 6\n");
249             setShortcuts();
250             debug(startup) printf("Leds.init 7\n");
251    
252             Workspace workspace = new Workspace("main", this, !noProjects);
253             debug(startup) printf("Leds.init 8\n");
254             workspaces ~= workspace;
255             workspace.showAll();
256             debug(startup) printf("Leds.init 9\n");
257             if ( filesToOpen is null || filesToOpen.length == 0 )
258             {
259                 debug(startup) printf("Leds.init 10\n");
260                 workspace.openSavedState();
261                 debug(startup) printf("Leds.init 10a\n");
262             }
263             else
264             {
265                 debug(startup) printf("Leds.init 11\n");
266                 workspace.openFiles(filesToOpen);
267             }
268             debug(startup) printf("Leds.init 12\n");
269             workspace.setBGColor();
270             workspace.setFont();
271             debug(startup) printf("Leds.init 13\n");
272         }
273     }
274    
275     /**
276      * \support multiple workspaces
277      */
278     public Workspace getWorkspace()
279     {
280         return workspaces[0];
281     }
282    
283     private bit confirmHomeExists()
284     {
285         bit homeOK = true;
286         bit homeNotDir = false;
287         bit dataNotDir = false;
288         try
289         {
290             if ( !Path.exists(ledsHome) )
291             {
292                 Path.mkdirs(ledsHome);
293             }
294             if ( !Path.isDir(ledsHome) )
295             {
296                 homeNotDir = true;
297             }
298         }
299         catch ( FileException fe)
300         {
301             try
302             {
303                 Path.mkdir(ledsHome);
304             }
305             catch ( FileException mkdirHomeFE )
306             {
307                 homeOK = false;
308             }
309         }
310         try
311         {
312             if ( !Path.exists(ledsData) )
313             {
314                 Path.mkdirs(ledsData);
315                 Path.mkdir(Path.join(ledsData,"projects"));
316             }
317             if ( !Path.isDir(ledsData) )
318             {
319                 dataNotDir = true;
320             }
321         }
322         catch ( FileException fe)
323         {
324             try
325             {
326                 Path.mkdir(ledsData);
327                 Path.mkdir(Path.join(ledsData,"projects"));
328             }
329             catch ( FileException mkdirHomeFE )
330             {
331                 homeOK = false;
332             }
333         }
334         return homeOK;
335     }
336    
337     public:
338    
339     /**
340      * loops through the args to process each one.
341      * @param args the args
342      * @param filesToOpen the files to open from the command line
343      * @return true if we should exit the program
344      */
345     bit parseArgs(char[][] args, inout String[] filesToOpen)
346     {
347         int i = 1;
348         while ( i>0 && i < args.length )
349         {
350             char [] arg = args[i];
351             printf("args[%d] = '%.*s'\n", i, arg);
352             if ( arg[0] == '-' )
353             {
354                 i = processOption(i,args);
355             }
356             else
357             {
358                 filesToOpen ~= new String(arg);
359                 ++i;
360             }
361         }
362        
363         return i<0;
364     }
365
366     /**
367      * processes one option and returns the next offset value.
368      * @return the next offset value or -1 if the program should exit
369      */
370     int processOption(int offset, char[][] args)
371     {
372         switch(args[offset])
373         {
374             case "-home", "--home":
375                 ledsHome = new String(args[++offset]);
376                 break;
377                
378             case "-data", "--data":
379                 ledsData = new String(args[++offset]);
380                 break;
381
382             case "-nop", "--nop":
383                 noProjects = true;
384                 break;
385                
386             case "-h", "--help":
387                 printf((getAppName().toString() ~ "\n\0").ptr);
388                 printf( "usage: leds [options] files -GTK[GTK options]\n\n"
389                         "options:\n"
390                         "  -h, --help     print this help and exit\n"
391                         "  -v, --version  print leds version and exit\n"
392                         " --home          specify leds home directory [default ~/.leds]\n"
393                         " --data          specify leds data directory [default ~/.leds_data]\n"
394                         " --editor        the editor to use\n"
395                         "                 'textView' the internal code editor (obsolete)\n"
396                         "                 'sv' the new GtkSourceView (incomplete)\n"
397                         "                 'sc' the Scintilla editor (default)\n"
398                         " --nop           do not open projects\n"
399                         "\n"
400                         "files            files to open\n"
401                         "-GTK             subsequente areguments will not be process by leds\n"
402                         "                 but will be passed to GTK\n"
403                         );
404                 offset = -2;
405                 break;
406                
407             case "-v", "--version":
408                 printf((getAppName().toString() ~ "\n\0").ptr);
409                 offset = -2;
410                 break;
411            
412             case "--editor":
413                 editorType = new String(args[++offset]);
414                 break;
415            
416             case "-sv":
417                 editorType = new String("sv");
418                 break;
419            
420             default:
421                 printf("Unknown option %.*s ignored\n",args[offset]);
422                 break;
423         }
424         ++offset;
425         return offset;
426     }
427
428     String getPreviousFindString()
429     {
430         return previousFindString;
431     }
432
433     void setPreviousFindString(String previousFindString)
434     {
435         this.previousFindString.set(previousFindString);
436     }
437
438     /**
439      * saves the preferences and exits
440      * @param code the code that generated this exit request
441      * @param force if true the program will exit anyway
442      * @return true it the exit should proced false if the application should not exit
443      */
444     public bit exit(int code, bit force)
445     {
446    
447         exitCode = code;
448         closing = true;
449
450         saveProps();
451        
452         return true;
453     }
454
455     public String getHomeDir()
456     {
457         return ledsHome;
458     }
459    
460     public String getDataDir()
461     {
462         return ledsData;
463     }
464
465     public String getUser()
466     {
467         return String.newz(getenv("USER\0"));
468     }
469
470     public String getAppData()
471     {
472         version(Win32)
473         {
474             return String.newz(getenv("APPDATA\0"));
475         }
476         else
477         {
478             return String.newz(getenv("HOME\0"));
479         }
480     }
481
482     public String getUserHome()
483     {
484         version(Win32)
485         {
486             return String.newz(getenv("HOMEPATH\0"));
487         }
488         else
489         {
490             return String.newz(getenv("HOME\0"));
491         }
492     }
493
494     public String getProjectsDir()
495     {
496         return Path.join(getDataDir(),projectsDir);
497     }
498
499     public String getProjectExtension()
500     {
501         return projectExtension;
502     }
503    
504     public String getProjectFileName(String name)
505     {
506         String filename = Path.join(getProjectsDir(),name);
507         return Path.addExt(filename,projectExtension);
508     }
509
510     public Trash getTrash()
511     {
512         if ( trash is null )
513         {
514             trash = new Trash(Path.join(getHomeDir(),"trash.zip"),
515                                         getPropValue("trashSize",1000000));
516         }
517         return trash;
518     }
519     void setProps()
520     {
521         props = new Properties();
522        
523
524         props.add(PropsTypes.TEXT, "outputScroll", "yes", "Ouput scroll on write","run","Workspace.");
525         props.add(PropsTypes.TEXT, "execCommand", "", "Set 'Execute' command","build","Workspace.");
526         props.add(PropsTypes.TEXT, "stopCommand", "", "Set 'stop' command","","Workspace.");
527         props.add(PropsTypes.YES_NO, "saveOnExit", "yes", "Save on exit","","Workspace.");
528         props.add(PropsTypes.YES_NO, "showProjectView", "yes", "Show project view","","Workspace.");
529         props.add(PropsTypes.YES_NO, "showCodeBrowser", "yes", "Show code browser","","Workspace.");
530         props.add(PropsTypes.YES_NO, "showWideTreeTooltip", "no", "Show wide tree tooltip","","Workspace.");
531         props.add(PropsTypes.YES_NO, "showfileBrowser", "yes", "Show file browser","","Workspace.");
532         props.add(PropsTypes.YES_NO, "closeButtonOnTabs", "yes", "Close on tabs","","Workspace.");
533         props.add(PropsTypes.YES_NO, "wideConsole", "no", "Wide console","","Workspace.layout.");
534         props.add(PropsTypes.FONT,   "fontBrowsers", "", "Browers Font","","Workspace.Fonts.");
535         props.add(PropsTypes.INT,    "fontSizeBrowsers", "", "Browers Font size","","Workspace.Fonts.");
536         props.add(PropsTypes.FONT,   "fontConsoles", "", "Consoles Font","","Workspace.Fonts.");
537         props.add(PropsTypes.INT,    "fontSizeConsoles", "", "Consoles Font size","","Workspace.Fonts.");
538
539         props.add(PropsTypes.YES_NO, "showHidden", "no", "Show hidden files","","Projects.");
540         props.add(PropsTypes.YES_NO, "popupBuildOutput", "yes", "Show Build Window","","Projects.");
541         props.add(PropsTypes.YES_NO, "backgroundBuild", "yes", "Allow background build","","Projects.");
542         props.add(PropsTypes.YES_NO, "hierarquicalView", "no", "Hierarquical view","","Projects.");
543
544         props.add(PropsTypes.YES_NO, "scrollOnWrite", "yes", "Scroll on write","","Console.");
545         props.add(PropsTypes.YES_NO, "newOnRun", "yes", "Open new for every run","","Console.");
546
547         props.add(PropsTypes.INT,    "tabWidth", "4", "Tab width","","Editor.");
548         props.add(PropsTypes.YES_NO, "useTabs", "yes", "Use Tabs","","Editor.");
549        
550         props.add(PropsTypes.YES_NO, "lineNumbers", "no", "Show line numbers","","Editor.");
551         props.add(PropsTypes.YES_NO, "codeFolding", "no", "Code folding","","Editor.");
552         props.add(PropsTypes.YES_NO, "fastSearch", "yes", "Fast search","","Editor.");
553         props.add(PropsTypes.LIST,   "codePage", "*Default*:*Default*:UTF-8:DBCS", "codePage","","Editor.");
554         props.add(PropsTypes.FONT,   "font", "", "Font","","Editor.");
555         props.add(PropsTypes.INT,    "fontSize", "", "Font size","","Editor.");
556         props.add(PropsTypes.YES_NO, "antiAliasing", "no", "Anti-Aliasing","","Editor.");
557         props.add(PropsTypes.YES_NO, "autoIndent", "yes", "Auto-Indent","","Editor.");
558         props.add(PropsTypes.YES_NO, "smartSemiColon", "yes", "Smart Semicolon","","Editor.");
559         props.add(PropsTypes.YES_NO, "smartCurlyBrace", "yes", "Smart Curly Brace","","Editor.");
560
561         props.add(PropsTypes.YES_NO, "autoHelp", "no", "show Definition when clicking in editor","","Editor.");
562         props.add(PropsTypes.YES_NO, "autoComplete", "no", "Auto complete when typing","","Editor.");
563
564         // configurable keys
565        
566         String l = new String("leds");
567         KeyMap.addKeyMap(l, props);
568         KeyMap.setCurrKeyMap(l);
569        
570         // configurable colors
571         props.add(PropsTypes.COLOR, "color.keyWord", "", "Keyword","","Editor.Colors.");
572         props.add(PropsTypes.COLOR, "color.Comment", "", "Comment","","Editor.Colors.");
573         props.add(PropsTypes.COLOR, "color.CommentLine", "", "Comment line","","Editor.Colors.");
574         props.add(PropsTypes.COLOR, "color.CommentDoc", "", "Comment doc","","Editor.Colors.");
575         props.add(PropsTypes.COLOR, "color.string", "", "String","","Editor.Colors.");
576         props.add(PropsTypes.COLOR, "color.stringEOL", "", "String EOL","","Editor.Colors.");
577         props.add(PropsTypes.COLOR, "color.char", "", "Character","","Editor.Colors.");
578         props.add(PropsTypes.COLOR, "color.number", "", "Number","","Editor.Colors.");
579         props.add(PropsTypes.COLOR, "color.braceMath", "", "Brace match","","Editor.Colors.");
580         props.add(PropsTypes.COLOR, "color.braceUnmatched", "", "Brace unmatched","","Editor.Colors.");
581
582         // format code
583         props.add(PropsTypes.YES_NO, "autoDocComments", "yes", "Doc Comments","","Editor.Format.");
584         props.add(PropsTypes.YES_NO, "emptyDocComments", "no", "Empty Doc Comments","","Editor.Format.");
585         props.add(PropsTypes.YES_NO, "ddocComments", "no", "Ddoc Comment style","","Editor.Format.");
586         props.add(PropsTypes.INT, "docCommentsLineLength", "80", "Doc Comments max line length","","Editor.Format.");
587
588         // shortcuts
589         props.add(PropsTypes.MULTY_TEXT, "shortcut", "", "shorcuts","","Editor.shortcuts.");
590
591         //### All language specific Properties ######################################################
592         Language.setPropsForAll(props);
593        
594         //props.add(PropsTypes.YES_NO, "duiGL", "", "use dui openGL","","");
595
596         //### java ########################################################
597        
598        
599         // advanced options
600        
601         props.add(PropsTypes.INT, "trashSize", "", "Trash size","","Advanced.");
602        
603         // non visible props
604
605         props.add(PropsTypes.INT, "main.left", "0", "","",".");
606         props.add(PropsTypes.INT, "main.top", "0", "","",".");
607         props.add(PropsTypes.INT, "main.width", "550", "","",".");
608         props.add(PropsTypes.INT, "main.height", "650", "","",".");
609         props.add(PropsTypes.INT, "main.leftPos", "50", "","",".");
610         props.add(PropsTypes.INT, "main.leftOpen", "yes", "","",".");
611         props.add(PropsTypes.INT, "main.bottomPos", "50", "","",".");
612         props.add(PropsTypes.INT, "main.bottomOpen", "yes", "","",".");
613         props.add(PropsTypes.INT, "main.dummy", "50", "","",".");
614
615         props.add(PropsTypes.MULTY_TEXT, "openedFiles", "", "","",".");
616         props.add(PropsTypes.MULTY_TEXT, "recentFiles", "", "","",".");
617
618         props.add(PropsTypes.TEXT, "key.currKeyMap", "leds", "current key map","",".");
619
620         props.load(Path.join(getHomeDir(),"preferences.leds").toString());
621        
622     }
623
624     /**
625      * Sets the user configurable keys
626      * \todo move this to workspace level?
627      * \todo allow to configure by file type?
628      */
629     void setKeys()
630     {
631         KeyMap.currKeyMap.setKeys(props);
632     }
633
634     KeyMap getCurrKeyMap()
635     {
636         return KeyMap.currKeyMap;
637     }
638    
639     /**
640      * Sets the shortcuts for a specific contexts
641      * @param prop the collection of shortcuts for one context
642      * @return the shortcuts
643      */
644     Shortcuts setShortcuts(char[] prop)
645     {
646         return setShortcuts(new String(prop));
647     }
648
649     Shortcuts setShortcuts(String prop)
650     {
651         Shortcuts shortcuts;
652         int pos;
653         foreach(String line ; prop.splitLines() )
654         {
655             pos = line.find(" ");
656             if ( pos > 0 && pos < (line.length-1) )
657             {
658                 shortcuts[line[0..pos]] = line[pos+1..line.length].dup;
659             }
660         }
661
662         return shortcuts;
663     }
664
665     /**
666      * Set all shortcuts for all contexts
667      */
668     void setShortcuts()
669     {
670         Shortcuts[String] contextShortcuts;
671         contextShortcuts[new String()] = setShortcuts(props.get("shortcut",defaultShortcus));
672         contextShortcuts[new String("d")] = setShortcuts(props.get("shortcut.d",dShortcus));
673         contextShortcuts[new String("java")] = setShortcuts(props.get("shortcut.java",javaShortcus));
674        
675         this.contextShortcuts = contextShortcuts;
676     }
677    
678     /**
679      * Gets one expanded shortcuts for one context or "" if the shortcuts is noe found
680      * @param context the context (for now "", "d", "java")
681      * @param shortcut the user abreviature to be expanded
682      * @return the expanded shortcut or "" if not found
683      */
684     String getShortcut(char[] context, char[] shortcut)
685     {
686         return getShortcut(new String(context), new String(shortcut));
687     }
688     String getShortcut(String context, String shortcut)
689     {
690         String longcut = new String();
691         if ( context in contextShortcuts )
692         {
693             Shortcuts s = contextShortcuts[context];
694             if ( shortcut in s )
695             {
696                 longcut = s[shortcut];
697             }
698         }
699         return longcut;
700     }
701
702     CodeCommand getCommandFromKey(char key)
703     {
704         return KeyMap.currKeyMap.getCommandFromKey(key);
705     }
706
707     void propertiesEditDone(Properties newProperties)
708     {
709         props = newProperties;
710         saveProps();
711         setKeys();
712         setShortcuts();
713         workspaces[0].setBGColor();
714         workspaces[0].setFont();
715        
716     }
717
718     Properties getProps()
719     {
720         if ( props is null )
721         {
722             setProps();
723             setKeys();
724             setShortcuts();
725             workspaces[0].setBGColor();
726         }
727         return props;
728     }
729    
730     bit propertiesValidator(Properties properties)
731     {
732         return true;
733     }
734    
735     public void editPreferences()
736     {
737         (new PropertiesUI(this, getProps(), workspaces[0], "Preferences", true )).show();
738     }
739    
740     String getPropValue(char[] key, char[] defaultValue)
741     {
742         return new String(props.get(key,defaultValue));
743     }
744        
745     int getPropValue(char[] key, int defaultValue)
746     {
747         return props.get(key,defaultValue);
748     }
749    
750     int getPropValueUInt(char[] key, uint defaultValue)
751     {
752         return props.get(key,defaultValue);
753     }
754    
755     bit getPropValue(char[] key, bit defaultValue)
756     {
757         return props.get(key,defaultValue);
758     }
759        
760     void setPropValue(char[] key, char[] defaultValue)
761     {
762         props.set(key,defaultValue);
763     }
764        
765     void setPropValue(char[] key, int defaultValue)
766     {
767         props.set(key,defaultValue);
768     }
769
770     void saveProps()
771     {
772         props.save(Path.join(getHomeDir(),"preferences.leds").toString(),leadsHeaderMessage);
773         //props.dump();
774     }
775        
776 };
777
778 private import dool.String;
779
780 String getVersionString()
781 {
782     return new String(VERSION_MAJOR) ~ "." ~ VERSION_MINOR ~ "." ~ VERSION_MICRO ~ " " ~ VERSION_QUAL;
783 };
784
785 String getAppName()
786 {
787     version(Win32)
788     {
789         return getVersionString().prepend("leds (Light Editor for D (Simple)), version ");
790     }
791     version(linux)
792     {
793         return getVersionString().prepend("leds (Linux Editor for D (Simple)), version ");
794     }
795 };
796
797 private import gtkc.Loader;
798 private import gdk.Threads;
799 version(splash)
800 {
801     private import gtk.Window;
802     private import gtk.Image;
803 }
804
805 int main(char[][] args)
806 {
807
808     Linker.dumpFailedLoads();
809    
810     version(Win32)
811     {
812         // TODO threads are still broken on windows
813         Main.init(args);
814     }
815     else
816     {
817         //Main.initMultiThread(args);
818         Main.init(args);
819     }
820    
821
822     version(splash)
823     {
824         Window w = new Window(false);
825         Image i = new Image("src/resources/ledsSplash.png");
826         w.add(i);
827         w.showAll();
828     }
829
830     debug(startup) writefln("Leds.main 1");
831     Leds leds = Leds.leds(args);
832     debug(startup) writefln("Leds.main 2");
833     if ( !leds.closing )
834     {
835         debug(startup) writefln("Leds.main 3");
836         version(splash) w.destroy();
837         debug(startup) writefln("Leds.main 4");
838         Main.run();
839         //Main.mainThreads();
840         debug(startup) writefln("Leds.main 5");
841     }
842     debug(startup) writefln("Leds.main 6");
843     return leds.exitCode;
844 }
845
846 public static void mainThreads()
847 {
848     gdkThreadsEnter();
849     Main.run();
850     gdkThreadsLeave();
851 }
Note: See TracBrowser for help on using the browser.