ide: fix ide old config reloading messing up new config elements. fix safeWriteFileOpen.
authorRejean Loyer <redj@ecere.com>
Fri, 29 Jul 2016 11:45:09 +0000 (07:45 -0400)
committerJerome St-Louis <jerome@ecere.com>
Mon, 1 Aug 2016 22:05:27 +0000 (18:05 -0400)
ide/src/IDESettings.ec
ide/src/dialogs/GlobalSettingsDialog.ec
ide/src/ide.ec

index 03e37d3..e3e518b 100644 (file)
@@ -25,6 +25,8 @@ import "ide"
 import "process"
 #endif
 
+IDEConfigHolder ideConfig { };
+
 IDESettings ideSettings;
 
 IDESettingsContainer settingsContainer
@@ -252,6 +254,24 @@ define settingsDir = ".ecereIDE";
 define ideSettingsName = "ecereIDE";
 #endif
 
+class IDEConfigHolder
+{
+   CompilerConfigs compilers { };
+   RecentFiles recentFiles { };
+   RecentWorkspaces recentWorkspaces { };
+
+   void forcePathSeparatorStyle(bool unixStyle)
+   {
+      char from, to;
+      if(unixStyle)
+         from = '\\', to = '/';
+      else
+         from = '/', to = '\\';
+      recentFiles.changeChar(from, to);
+      recentWorkspaces.changeChar(from, to);
+   }
+}
+
 class IDESettingsContainer : GlobalSettings
 {
    property bool useNewConfigurationFiles
@@ -418,9 +438,33 @@ private:
          }
       }
 
+      if(oldConfig)
+      {
+         if(data.compilerConfigs && data.compilerConfigs.count)
+         {
+            for(c : data.compilerConfigs)
+               ideConfig.compilers.Add(c);
+            data.compilerConfigs.RemoveAll();
+         }
+         if(data.recentFiles && data.recentFiles.count)
+         {
+            for(s : data.recentFiles)
+               ideConfig.recentFiles.Add(s);
+            data.recentFiles.RemoveAll();
+         }
+         if(data.recentProjects && data.recentProjects.count)
+         {
+            for(s : data.recentProjects)
+               ideConfig.recentWorkspaces.Add(s);
+            data.recentProjects.RemoveAll();
+         }
+         ideConfig.forcePathSeparatorStyle(true);
+      }
+
       CloseAndMonitor();
       FileGetSize(settingsFilePath, &settingsFileSize);
-      CompilerConfigs::fix();
+      if(oldConfig)
+         CompilerConfigs::fix();
       if(portable && moduleLocation[0] && FileExists(moduleLocation).isDirectory)
          data.ManagePortablePaths(moduleLocation, true);
       data.ForcePathSeparatorStyle(true);
@@ -676,7 +720,7 @@ class IDESettings : GlobalSettingsData
 public:
    property CompilerConfigs compilerConfigs
    {
-      set { if(compilerConfigs) compilerConfigs.Free(); delete compilerConfigs; if(value) compilerConfigs = value; }
+      set { if(settingsContainer.oldConfig) { if(compilerConfigs) compilerConfigs.Free(); delete compilerConfigs; if(value) compilerConfigs = value; } }
       get { return compilerConfigs; }
       isset { return false; }
    }
index b6c5392..ed5820c 100644 (file)
@@ -89,13 +89,13 @@ class GlobalSettingsDialog : Window
             {
                if(strcmp(compilersTab.compilerConfigsDir.path, ideSettings.compilerConfigsDir))
                   ideSettings.compilerConfigsDir = compilersTab.compilerConfigsDir.path;
-               if(compilersTab.compilerConfigs.OnCompare(ideSettings.compilerConfigs))
+               if(compilersTab.compilerConfigs.OnCompare(ideConfig.compilers))
                {
-                  cfgsToWrite = compilersTab.compilerConfigs.getWriteRequiredList(ideSettings.compilerConfigs);
-                  ideSettings.compilerConfigs.Free();
+                  cfgsToWrite = compilersTab.compilerConfigs.getWriteRequiredList(ideConfig.compilers);
+                  ideConfig.compilers.Free();
                   for(compiler : compilersTab.compilerConfigs)
                   {
-                     ideSettings.compilerConfigs.Add(compiler.Copy());
+                     ideConfig.compilers.Add(compiler.Copy());
                   }
                   compilerSettingsChanged = true;
                }
@@ -129,7 +129,7 @@ class GlobalSettingsDialog : Window
 
             if(compilerSettingsChanged)
             {
-               ideSettings.compilerConfigs.write(cfgsToWrite);
+               ideConfig.compilers.write(cfgsToWrite);
                OnGlobalSettingChange(GlobalSettingsChange::compilerSettings);
                cfgsToWrite.Free();
                delete cfgsToWrite;
@@ -185,7 +185,7 @@ class GlobalSettingsDialog : Window
       // CompilersTab
       if(workspaceActiveCompiler)
       {
-         for(compiler : ideSettings.compilerConfigs)
+         for(compiler : ideConfig.compilers)
          {
             if(!activateCompiler && !strcmp(workspaceActiveCompiler, compiler.name))
                activateCompiler = compiler;
@@ -197,10 +197,10 @@ class GlobalSettingsDialog : Window
       }
       if(!activateCompiler && readonlyCompiler)
          activateCompiler = readonlyCompiler;
-      if(!activateCompiler && ideSettings.compilerConfigs.count)
-         activateCompiler = ideSettings.compilerConfigs[0];
+      if(!activateCompiler && ideConfig.compilers.count)
+         activateCompiler = ideConfig.compilers[0];
 
-      for(compiler : ideSettings.compilerConfigs)
+      for(compiler : ideConfig.compilers)
          compilersTab.AddCompiler(compiler.Copy(), compiler == activateCompiler);
       compilersTab.compilerConfigsDir.path = ideSettings.compilerConfigsDir;
 
@@ -1400,7 +1400,7 @@ class WorkspaceOptionsTab : GlobalSettingsSubTab
       if(dialog && dialog.compilersTab.compilerConfigs && dialog.ideSettings)
       {
          DataRow row;
-         for(compiler : dialog.ideSettings.compilerConfigs)
+         for(compiler : ideConfig.compilers)
          {
             row = defaultCompilerDropBox.AddString(compiler.name);
             if(dialog.ideSettings.defaultCompiler && dialog.ideSettings.defaultCompiler[0] &&
index 3c34331..5be6554 100644 (file)
@@ -753,7 +753,7 @@ class IDEWorkSpace : Window
       bool FileRecentFile(MenuItem selection, Modifiers mods)
       {
          int id = 0;
-         RecentPaths recentFiles = workspace ? workspace.recentFiles : ideSettings.recentFiles;
+         RecentPaths recentFiles = workspace ? workspace.recentFiles : ideConfig.recentFiles;
          for(file : recentFiles)
          {
             if(id == selection.id)
@@ -783,7 +783,7 @@ class IDEWorkSpace : Window
       bool FileRecentProject(MenuItem selection, Modifiers mods)
       {
          int id = 0;
-         for(file : ideSettings.recentProjects)
+         for(file : ideConfig.recentWorkspaces)
          {
             if(id == selection.id)
             {
@@ -824,7 +824,7 @@ class IDEWorkSpace : Window
                      newProjectDialog.CreateNewProject();
                      if(projectView)
                      {
-                        ideSettings.recentProjects.addRecent(CopyString(projectView.fileName));
+                        ideConfig.recentWorkspaces.addRecent(CopyString(projectView.fileName));
                         ide.updateRecentProjectsMenu();
                      }
                   }
@@ -1824,7 +1824,7 @@ class IDEWorkSpace : Window
 
    void DocumentSaved(Window document, const char * fileName)
    {
-      ideSettings.recentFiles.addRecent(CopyString(fileName));
+      ideConfig.recentFiles.addRecent(CopyString(fileName));
       ide.updateRecentFilesMenu();
       ide.AdjustFileMenus();
    }
@@ -1890,7 +1890,7 @@ class IDEWorkSpace : Window
    void UpdateToolBarActiveCompilers()
    {
       toolBar.activeCompiler.Clear();
-      for(compiler : ideSettings.compilerConfigs)
+      for(compiler : ideConfig.compilers)
       {
          DataRow row = toolBar.activeCompiler.AddString(compiler.name);
          if(workspace && workspace.activeCompiler && !strcmp(compiler.name, workspace.activeCompiler))
@@ -2569,9 +2569,9 @@ class IDEWorkSpace : Window
             document.state = maximized;
 
          if(isProject)
-            ideSettings.recentProjects.addRecent(CopyString(document.fileName));
+            ideConfig.recentWorkspaces.addRecent(CopyString(document.fileName));
          else if(!workspace)
-            ideSettings.recentFiles.addRecent(CopyString(document.fileName));
+            ideConfig.recentFiles.addRecent(CopyString(document.fileName));
          ide.AdjustFileMenus();
          ide.updateRecentFilesMenu();
 
@@ -3168,7 +3168,7 @@ class IDEWorkSpace : Window
                   newProjectDialog.Modal();
                   if(projectView)
                   {
-                     ideSettings.recentProjects.addRecent(CopyString(projectView.fileName));
+                     ideConfig.recentWorkspaces.addRecent(CopyString(projectView.fileName));
                      ide.updateRecentMenus();
                   }
                   delete newProjectDialog;
@@ -3472,7 +3472,7 @@ class IDEWorkSpace : Window
       char * itemPath = new char[MAX_LOCATION];
       char * itemName = new char[MAX_LOCATION+4];
       Workspace ws = workspace;
-      RecentPaths recentFiles = ws ? ws.recentFiles : ideSettings.recentFiles;
+      RecentPaths recentFiles = ws ? ws.recentFiles : ideConfig.recentFiles;
       recentFilesMenu.Clear();
       for(recent : recentFiles)
       {
@@ -3492,7 +3492,7 @@ class IDEWorkSpace : Window
       char * itemPath = new char[MAX_LOCATION];
       char * itemName = new char[MAX_LOCATION+4];
       recentProjectsMenu.Clear();
-      for(recent : ideSettings.recentProjects)
+      for(recent : ideConfig.recentWorkspaces)
       {
          strncpy(itemPath, recent, MAX_LOCATION); itemPath[MAX_LOCATION-1] = '\0';
          MakeSystemPath(itemPath);
@@ -3664,9 +3664,9 @@ class IDEApp : GuiApplication
          }
       }
 
-      ideSettings.compilerConfigs.read();
-      ideSettings.recentFiles.read();
-      ideSettings.recentProjects.read();
+      ideConfig.compilers.read();
+      ideConfig.recentFiles.read();
+      ideConfig.recentWorkspaces.read();
 
       // First count files arg to decide whether to maximize
       {