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