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