resources/RooUsage.txt
[app.Builder.js] / src / Application.vala
1
2  
3         public class AppSettings : Object
4         {
5
6                 
7                 
8                 // what are we going to have as settings?
9                 public string roo_html_dir { get; set; }
10
11                 public AppSettings()
12                 {
13                         this.notify.connect(() => {
14                                 this.save();
15                         });
16                 }
17
18                 public static AppSettings factory()
19                 {
20                          
21                         var setting_file = BuilderApplication.configDirectory() + "/builder.settings";
22                         
23                         if (!FileUtils.test(setting_file, FileTest.EXISTS)) {
24                                  return new AppSettings();
25                         }
26                         string data; 
27                         FileUtils.get_contents(setting_file, out data);
28                         return Json.gobject_from_data (typeof (AppSettings), data) as AppSettings;
29                 }
30                 public void save()
31                 {
32                         var dirname = GLib.Environment.get_home_dir() + "/.Builder";
33                         var setting_file = dirname + "/builder.settings";
34                         string data = Json.gobject_to_data (this, null);
35                         print("saving application settings\n");
36                         FileUtils.set_contents(setting_file,   data);
37                 }
38
39                 
40         }
41         
42         
43         public static BuilderApplication application = null;
44         
45         public class BuilderApplication : Gtk.Application
46         {
47                 
48                 // options - used when builder is run as a compiler
49                 // we have to spawn ourself as a compiler as just running libvala
50                 // as a task to check syntax causes memory leakage..
51                 // 
52                 const OptionEntry[] options = {
53                 
54                         
55                         { "project", 0, 0, OptionArg.STRING, ref opt_compile_project, "Compile a project", null },
56                         { "target", 0, 0, OptionArg.STRING, ref opt_compile_target, "Target to build", null },
57                         { "skip-file", 0, 0, OptionArg.STRING, ref opt_compile_skip ,"For test compiles do not add this (usually used in conjunction with add-file ", null },
58                         { "add-file", 0, 0, OptionArg.STRING, ref opt_compile_add, "Add this file to compile list", null },
59                         { "output", 0, 0, OptionArg.STRING, ref opt_compile_output, "output binary file path", null },
60                         { "debug", 0, 0, OptionArg.NONE, ref opt_debug, "Show debug messages", null },
61             
62             // some testing code.
63             { "list-projects", 0, 0,  OptionArg.NONE, ref opt_list_projects, "List Projects", null },
64             { "list-files", 0, 0,  OptionArg.NONE, ref  opt_list_files, "List Files (in a project", null},
65             { "bjs", 0, 0, OptionArg.STRING, ref opt_bjs_compile, "convert bjs file", null },
66             { "bjs-target", 0, 0, OptionArg.STRING, ref opt_bjs_compile_target, "convert bjs file to tareet  : vala / js", null },
67             
68             
69                         { null }
70                 };
71                 public static string opt_compile_project;
72                 public static string opt_compile_target;
73                 public static string opt_compile_skip;
74                 public static string opt_compile_add;
75                 public static string opt_compile_output;
76         public static string opt_bjs_compile;
77         public static string opt_bjs_compile_target;
78                 public static bool opt_debug = false;
79                 public static bool opt_list_projects = false;
80                 public static bool opt_list_files = false;
81                 
82                 public static string _self;
83                 
84                 enum Target {
85                     INT32,
86                     STRING,
87                     ROOTWIN
88                 }
89
90
91                 public const Gtk.TargetEntry[] targetList = {
92                     { "INTEGER",    0, Target.INT32 },
93                     { "STRING",     0, Target.STRING },
94                     { "application/json",     0, Target.STRING },                       
95                     { "text/plain", 0, Target.STRING },
96                     { "application/x-rootwindow-drop", 0, Target.ROOTWIN }
97                 };
98                 public AppSettings settings = null;
99
100         
101                 public BuilderApplication (  string[] args)
102                 {
103                         
104                         _self = FileUtils.read_link("/proc/self/exe");
105                         GLib.debug("SELF = %s", _self);
106                         
107                         Object(
108                                application_id: "org.roojs.app-builder",
109                                 flags: ApplicationFlags.FLAGS_NONE
110                         );
111                                          
112                         configDirectory();
113                         this.settings = AppSettings.factory();  
114                         var opt_context = new OptionContext ("Application Builder");
115                         
116                         try {
117                                 opt_context.set_help_enabled (true);
118                                 opt_context.add_main_entries (options, null);
119                                 opt_context.parse (ref args);
120                                  
121                                 
122                         } catch (OptionError e) {
123                                 stdout.printf ("error: %s\n", e.message);
124                                 stdout.printf ("Run '%s --help' to see a full list of available command line options.\n %s", 
125                                                          args[0], opt_context.get_help(true,null));
126                                 GLib.Process.exit(Posix.EXIT_FAILURE);
127                                  
128                         }
129
130                 }
131
132
133                 
134                 public static BuilderApplication  singleton(  string[] args)
135                 {
136                         if (application==null) {
137                                 application = new BuilderApplication(  args);
138  
139                         
140                         }
141                         return application;
142                 }
143
144                 
145                 public static string configDirectory()
146                 {
147                         var dirname = GLib.Environment.get_home_dir() + "/.Builder";
148                 
149                         if (!FileUtils.test(dirname,FileTest.IS_DIR)) {
150                                 var dir = File.new_for_path(dirname);
151                                 dir.make_directory();    
152                         }
153                         if (!FileUtils.test(dirname + "/resources",FileTest.IS_DIR)) {
154                                 var dir = File.new_for_path(dirname + "/resources");
155                                 dir.make_directory();    
156                         }
157
158                 
159                         return dirname;
160                 }
161                 
162         } 
163
164  
165
166