src/Application.vala
[app.Builder.js] / src / Application.vala
1
2  
3         public class AppSettings : Object
4         {
5
6                 // options - used when builder is run as a compiler
7                 // we have to spawn ourself as a compiler as just running libvala
8                 // as a task to check syntax causes memory leakage..
9                 // 
10                 const OptionEntry[] options = {
11                 
12                         
13                         { "project", 0, 0, OptionArg.STRING, ref opt_compile_project, "Compile a project", null },
14                         { "target", 0, 0, OptionArg.STRING, ref opt_compile_target, "Target to build", null },
15                         { "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 },
16                         { "add-file", 0, 0, OptionArg.STRING, ref opt_compile_add, "Add this file to compile list", null },
17                         { null }
18                 };
19                 string opt_compile_project;
20                 string opt_compile_target;
21                 string opt_compile_skip;
22                 string opt_compile_add;
23                 
24                 
25                 // what are we going to have as settings?
26                 public string roo_html_dir { get; set; }
27
28                 public AppSettings()
29                 {
30                         this.notify.connect(() => {
31                                 this.save();
32                         });
33                 }
34
35                 public static AppSettings factory()
36                 {
37                          
38                         var setting_file = BuilderApplication.configDirectory() + "/builder.settings";
39                         
40                         if (!FileUtils.test(setting_file, FileTest.EXISTS)) {
41                                  return new AppSettings();
42                         }
43                         string data; 
44                         FileUtils.get_contents(setting_file, out data);
45                         return Json.gobject_from_data (typeof (AppSettings), data) as AppSettings;
46                 }
47                 public void save()
48                 {
49                         var dirname = GLib.Environment.get_home_dir() + "/.Builder";
50                         var setting_file = dirname + "/builder.settings";
51                         string data = Json.gobject_to_data (this, null);
52                         print("saving application settings\n");
53                         FileUtils.set_contents(setting_file,   data);
54                 }
55
56                 
57         }
58         
59         
60         public static BuilderApplication application = null;
61         
62         public class BuilderApplication : Gtk.Application
63         {
64                 enum Target {
65                     INT32,
66                     STRING,
67                     ROOTWIN
68                 }
69
70
71                 public const Gtk.TargetEntry[] targetList = {
72                     { "INTEGER",    0, Target.INT32 },
73                     { "STRING",     0, Target.STRING },
74                     { "application/json",     0, Target.STRING },                       
75                     { "text/plain", 0, Target.STRING },
76                     { "application/x-rootwindow-drop", 0, Target.ROOTWIN }
77                 };
78                 public AppSettings settings = null;
79
80         
81                 public BuilderApplication ()
82                 {
83                         Object(
84                                application_id: "org.roojs.app-builder",
85                                 flags: ApplicationFlags.FLAGS_NONE
86                         );
87                                          
88                         configDirectory();
89                         this.settings = AppSettings.factory();  
90  
91
92                 }
93
94
95                 
96                 public static BuilderApplication  singleton()
97                 {
98                         if (application==null) {
99                                 application = new BuilderApplication();
100  
101                         
102                         }
103                         return application;
104                 }
105
106                 
107                 public static string configDirectory()
108                 {
109                         var dirname = GLib.Environment.get_home_dir() + "/.Builder";
110                 
111                         if (!FileUtils.test(dirname,FileTest.IS_DIR)) {
112                                 var dir = File.new_for_path(dirname);
113                                 dir.make_directory();    
114                         }
115                         if (!FileUtils.test(dirname + "/resources",FileTest.IS_DIR)) {
116                                 var dir = File.new_for_path(dirname + "/resources");
117                                 dir.make_directory();    
118                         }
119
120                 
121                         return dirname;
122                 }
123           
124         } 
125
126
127         
128         
129
130