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