ide: define ide's settingsName in a single location and use that definition is settin...
[sdk] / ide / src / OldIDESettings.ec
1 #ifdef ECERE_STATIC
2 import static "ecere"
3 #else
4 import "ecere"
5 #endif
6
7 import "IDESettings"
8
9 define makeCommandSetting = "Make Command";
10 define ecpCommandSetting = "ECP Command";
11 define eccCommandSetting = "ECC Command";
12 define ecsCommandSetting = "ECS Command";
13 define earCommandSetting = "EAR Command";
14 define cPreprocessorCommandSetting = "C Preprocessor Command";
15 define cCompilerCommandSetting = "C Compiler Command";
16 define cxxCompilerCommandSetting = "C++ Compiler Command";
17
18 define projectOptions = "Project Options";
19 define defaultTargetDir = "Default Target Directory";
20 define defaultIntermediateObjDir = "Default Intermediate Objects Directory";
21
22 define makeDefaultCommand = (__runtimePlatform == win32) ? "mingw32-make" :
23 #ifdef __FreeBSD__
24    "gmake";
25 #else
26    "make";
27 #endif
28
29 class OldIDESettings : GlobalAppSettings
30 {
31    settingsName = ideSettingsName;
32
33    List<CompilerConfig> compilerConfigs { };
34    Array<String> recentFiles { };
35    Array<String> recentProjects { };
36    char * docDir;
37    char * ideFileDialogLocation;
38    char * ideProjectFileDialogLocation;
39    bool useFreeCaret;
40    bool showLineNumbers;
41    bool caretFollowsScrolling;
42    //int numJobs;
43    char * displayDriver;
44    useFreeCaret = false; //true;
45    showLineNumbers = true;
46    caretFollowsScrolling = false; //true;
47    //numJobs = 1;
48
49    char * projectDefaultTargetDir;
50    property const char * projectDefaultTargetDir
51    {
52       set { delete projectDefaultTargetDir; if(value && value[0]) projectDefaultTargetDir = CopyString(value); }
53       get { return projectDefaultTargetDir ? projectDefaultTargetDir : ""; }
54    }
55    char * projectDefaultIntermediateObjDir;
56    property const char * projectDefaultIntermediateObjDir
57    {
58       set { delete projectDefaultIntermediateObjDir; if(value && value[0]) projectDefaultIntermediateObjDir = CopyString(value); }
59       get { return projectDefaultIntermediateObjDir ? projectDefaultIntermediateObjDir : ""; }
60    }
61
62    CompilerConfig GetCompilerConfig(const String compilerName)
63    {
64       const char * name = compilerName && compilerName[0] ? compilerName : defaultCompilerName;
65       CompilerConfig compilerConfig = null;
66       for(compiler : compilerConfigs)
67       {
68          if(!strcmp(compiler.name, name))
69          {
70             compilerConfig = compiler;
71             break;
72          }
73       }
74       if(!compilerConfig && compilerConfigs.count)
75          compilerConfig = compilerConfigs.firstIterator.data;
76       if(compilerConfig)
77          incref compilerConfig;
78       return compilerConfig;
79    }
80
81    ~OldIDESettings()
82    {
83       compilerConfigs.Free();
84       recentFiles.Free();
85       recentProjects.Free();
86       delete docDir;
87
88       delete projectDefaultTargetDir;
89       delete projectDefaultIntermediateObjDir;
90
91       delete ideFileDialogLocation;
92       delete ideProjectFileDialogLocation;
93       delete displayDriver;
94    }
95
96    void OnAskReloadSettings()
97    {
98       /*if(MessageBox { type = YesNo, master = this,
99             text = "Global Settings Modified Externally",
100             contents = "The global settings were modified by another instance.\n"
101             "Would you like to reload them?" }.Modal() == Yes)*/
102       {
103          //Load();
104       }
105    }
106
107    SettingsIOResult Load()
108    {
109       SettingsIOResult result = GlobalAppSettings::Load();
110       if(result == success)
111       {
112          Array<String> configNames { };
113          CompilerConfig compiler;
114
115          CompilerConfig defaultCompiler = MakeDefaultCompiler(defaultCompilerName, true);
116          compilerConfigs.Free();
117          compilerConfigs.Add(defaultCompiler);
118
119          // Load new settings
120          GetGlobalValue("Compilers", "Configs", stringList, configNames);
121          // todo manage the ability to modify the Default config, for now it will be hard coded
122
123          GetGlobalValue("Directories", settingsDirectoryNames[includes], stringList, defaultCompiler.includeDirs);
124          GetGlobalValue("Directories", settingsDirectoryNames[libraries], stringList, defaultCompiler.libraryDirs);
125          GetGlobalValue("Directories", settingsDirectoryNames[executables], stringList, defaultCompiler.executableDirs);
126
127          for(configName : configNames)
128          {
129             int len = strlen(configName);
130             if(len)
131             {
132                char * v = null;
133                char * section, * platformName = null;
134                section = new char[len + 17];
135                sprintf(section, "%s Compiler Config", configName);
136                GetGlobalValue(section, "Target Platform", singleString, &platformName);
137                compiler = CompilerConfig { name = configName, targetPlatform = platformName };
138                incref compiler;
139                if(!compiler.targetPlatform)
140                   compiler.targetPlatform = __runtimePlatform;
141                delete platformName;
142                // TOCHECK these must call the property!
143                GetGlobalValue(section, makeCommandSetting, singleString, &v); compiler.makeCommand = v && v[0] ? v : makeDefaultCommand; delete v;
144                GetGlobalValue(section, ecpCommandSetting, singleString, &v); compiler.ecpCommand = v && v[0] ? v : ecpDefaultCommand; delete v;
145                GetGlobalValue(section, eccCommandSetting, singleString, &v); compiler.eccCommand = v && v[0] ? v : eccDefaultCommand; delete v;
146                GetGlobalValue(section, ecsCommandSetting, singleString, &v); compiler.ecsCommand = v && v[0] ? v : ecsDefaultCommand; delete v;
147                GetGlobalValue(section, earCommandSetting, singleString, &v); compiler.earCommand = v && v[0] ? v : earDefaultCommand; delete v;
148                GetGlobalValue(section, cPreprocessorCommandSetting, singleString, &v); compiler.cppCommand = v && v[0] ? v : cppDefaultCommand; delete v;
149                GetGlobalValue(section, cCompilerCommandSetting, singleString, &v); compiler.ccCommand = v && v[0] ? v : ccDefaultCommand; delete v;
150                GetGlobalValue(section, cCompilerCommandSetting, singleString, &v); compiler.cxxCommand = v && v[0] ? v : cxxDefaultCommand; delete v;
151                delete section;
152                section = new char[len + 13];
153                sprintf(section, "%s Directories", configName);
154                GetGlobalValue(section, settingsDirectoryNames[includes], stringList, compiler.includeDirs);
155                GetGlobalValue(section, settingsDirectoryNames[libraries], stringList, compiler.libraryDirs);
156                GetGlobalValue(section, settingsDirectoryNames[executables], stringList, compiler.executableDirs);
157
158                delete section;
159                compilerConfigs.Add(compiler);
160             }
161          }
162          configNames.Free();
163          delete configNames;
164
165          GetGlobalValue("Recent", "Files", stringList, recentFiles);
166
167          GetGlobalValue("Recent", "Projects", stringList, recentProjects);
168
169          {
170             delete ideFileDialogLocation;
171             GetGlobalValue("FileOpenLocations", "Files", singleString, &ideFileDialogLocation);
172
173             delete ideProjectFileDialogLocation;
174             GetGlobalValue("FileOpenLocations", "Projects", singleString, &ideProjectFileDialogLocation);
175          }
176
177          GetGlobalValue("Editing", "UseFreeCaret", integer, &useFreeCaret);
178          GetGlobalValue("Editing", "CaretFollowsScrolling", integer, &caretFollowsScrolling);
179          GetGlobalValue("Editing", "ShowLineNumbers", integer, &showLineNumbers);
180
181          GetGlobalValue("Building", "NumParallelJobs", integer, &defaultCompiler.numJobs);
182          {
183             delete displayDriver;
184             GetGlobalValue("View", "DisplayDriver", singleString, &displayDriver);
185          }
186
187          delete docDir;
188          GetGlobalValue("Documentor", "Files", singleString, &docDir); // get the path to the documentor files from ecereIDE.ini. Note that the path cannot include quotes or it will not work.
189
190          delete projectDefaultTargetDir;
191          GetGlobalValue(projectOptions, defaultTargetDir, singleString, &projectDefaultTargetDir);
192          if(!projectDefaultTargetDir || !projectDefaultTargetDir[0])
193             property::projectDefaultTargetDir = defaultObjDirExpression;
194
195          delete projectDefaultIntermediateObjDir;
196          GetGlobalValue(projectOptions, defaultIntermediateObjDir, singleString, &projectDefaultIntermediateObjDir);
197          if(!projectDefaultIntermediateObjDir || !projectDefaultIntermediateObjDir[0])
198             property::projectDefaultIntermediateObjDir = defaultObjDirExpression;
199
200          CloseAndMonitor();
201       }
202       return result;
203    }
204
205    SettingsIOResult Save()
206    {
207       SettingsIOResult result = GlobalAppSettings::Save();
208       if(result == success)
209       {
210          Array<String> configNames { };
211          CompilerConfig compiler = compilerConfigs.firstIterator.data;
212
213          PutGlobalValue("Directories", settingsDirectoryNames[includes],  stringList, compiler.includeDirs);
214          PutGlobalValue("Directories", settingsDirectoryNames[libraries],  stringList, compiler.libraryDirs);
215          PutGlobalValue("Directories", settingsDirectoryNames[executables],  stringList, compiler.executableDirs);
216          PutGlobalValue("Recent", "Files", stringList, recentFiles);
217          PutGlobalValue("Recent", "Projects", stringList, recentProjects);
218
219          PutGlobalValue("FileOpenLocations", "Files", singleString, ideFileDialogLocation);
220          PutGlobalValue("FileOpenLocations", "Projects", singleString, ideProjectFileDialogLocation);
221
222          PutGlobalValue("Editing", "UseFreeCaret", integer, (void *)(intptr)useFreeCaret);
223          PutGlobalValue("Editing", "CaretFollowsScrolling", integer, (void *)(intptr)caretFollowsScrolling);
224          PutGlobalValue("Editing", "ShowLineNumbers", integer, (void *)(intptr)showLineNumbers);
225
226          PutGlobalValue("Building", "NumParallelJobs", integer, (void *)(intptr)(compiler.numJobs));
227          PutGlobalValue("View", "DisplayDriver", singleString, displayDriver);
228          PutGlobalValue("Documentor", "Files", singleString, docDir);
229
230          PutGlobalValue(projectOptions, defaultTargetDir, singleString, projectDefaultTargetDir);
231          PutGlobalValue(projectOptions, defaultIntermediateObjDir, singleString, projectDefaultIntermediateObjDir);
232
233          for(compiler : compilerConfigs; compiler != compilerConfigs.firstIterator.data)
234             configNames.Add(CopyString(compiler.name));
235
236          PutGlobalValue("Compilers", "Configs", stringList, configNames);
237
238          for(compiler : compilerConfigs; compiler != compilerConfigs.firstIterator.data)
239          {
240             int len = strlen(compiler.name);
241             if(len)
242             {
243                char * section = new char[len + 17];
244                const char * platform;
245                sprintf(section, "%s Compiler Config", compiler.name);
246                platform = compiler.targetPlatform.OnGetString(null, null, null);
247                PutGlobalValue(section, "Target Platform", singleString, platform);
248                PutGlobalValue(section, makeCommandSetting, singleString, compiler.makeCommand);
249                PutGlobalValue(section, ecpCommandSetting, singleString, compiler.ecpCommand);
250                PutGlobalValue(section, eccCommandSetting, singleString, compiler.eccCommand);
251                PutGlobalValue(section, ecsCommandSetting, singleString, compiler.ecsCommand);
252                PutGlobalValue(section, earCommandSetting, singleString, compiler.earCommand);
253                PutGlobalValue(section, cPreprocessorCommandSetting, singleString, compiler.cppCommand);
254                PutGlobalValue(section, cCompilerCommandSetting, singleString, compiler.ccCommand);
255                PutGlobalValue(section, cxxCompilerCommandSetting, singleString, compiler.cxxCommand);
256                delete section;
257                section = new char[len + 13];
258                sprintf(section, "%s Directories", compiler.name);
259                PutGlobalValue(section, settingsDirectoryNames[includes], stringList, compiler.includeDirs);
260                PutGlobalValue(section, settingsDirectoryNames[libraries], stringList, compiler.libraryDirs);
261                PutGlobalValue(section, settingsDirectoryNames[executables], stringList, compiler.executableDirs);
262                delete section;
263             }
264          }
265          configNames.Free();
266          delete configNames;
267
268          CloseAndMonitor();
269       }
270       return result;
271    }
272 }