ide, documentor, epj2make: settings, compiler configs: move ide config to new ~/...
[sdk] / ide / src / ide.ec
index 4845e0d..3c34331 100644 (file)
@@ -303,11 +303,11 @@ class IDEToolbar : ToolBar
       this, toolTip = $"Active Compiler", size = { 160 }, disabled = true;
       bool NotifySelect(DropBox dropBox, DataRow row, Modifiers mods)
       {
-         if(ide.workspace && ide.projectView && row && strcmp(row.string, ide.workspace.compiler))
+         if(ide.workspace && ide.projectView && row && strcmp(row.string, ide.workspace.activeCompiler))
          {
             bool silent = ide.projectView.buildInProgress == none ? false : true;
             CompilerConfig compiler = ideSettings.GetCompilerConfig(row.string);
-            ide.workspace.compiler = row.string;
+            ide.workspace.activeCompiler = row.string;
             ide.projectView.ShowOutputBuildLog(!silent);
             if(!silent)
                ide.projectView.DisplayCompiler(compiler, false);
@@ -328,7 +328,7 @@ class IDEToolbar : ToolBar
          if(ide.workspace && ide.projectView && row)
          {
             bool silent = ide.projectView.buildInProgress == none ? false : true;
-            CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
+            CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.activeCompiler);
             ide.workspace.bitDepth = (int)row.tag;
             ide.projectView.ShowOutputBuildLog(!silent);
             if(!silent)
@@ -441,16 +441,18 @@ class IDEWorkSpace : Window
 
       void OnGotoError(const char * line, bool noParsing)
       {
-         CompilerConfig compiler = ide.workspace ? ideSettings.GetCompilerConfig(ide.workspace.compiler) : null;
+         CompilerConfig compiler = ide.workspace ? ideSettings.GetCompilerConfig(ide.workspace.activeCompiler) : null;
          const char * objectFileExt = compiler ? compiler.objectFileExt : objectDefaultFileExt;
          ide.GoToError(line, noParsing, objectFileExt);
+         delete compiler;
       }
 
       void OnCodeLocationParseAndGoTo(const char * line)
       {
-         CompilerConfig compiler = ide.workspace ? ideSettings.GetCompilerConfig(ide.workspace.compiler) : null;
+         CompilerConfig compiler = ide.workspace ? ideSettings.GetCompilerConfig(ide.workspace.activeCompiler) : null;
          const char * objectFileExt = compiler ? compiler.objectFileExt : objectDefaultFileExt;
          ide.CodeLocationParseAndGoTo(line, ide.findInFilesDialog.findProject, ide.findInFilesDialog.findDir, objectFileExt);
+         delete compiler;
       }
 
       bool OnKeyDown(Key key, unichar ch)
@@ -725,8 +727,8 @@ class IDEWorkSpace : Window
          bool NotifySelect(MenuItem selection, Modifiers mods)
          {
             globalSettingsDialog.master = this;
-            if(ide.workspace && ide.workspace.compiler)
-               globalSettingsDialog.workspaceActiveCompiler = ide.workspace.compiler;
+            if(ide.workspace && ide.workspace.activeCompiler)
+               globalSettingsDialog.workspaceActiveCompiler = ide.workspace.activeCompiler;
             else if(ideSettings.defaultCompiler)
                globalSettingsDialog.workspaceActiveCompiler = ideSettings.defaultCompiler;
             globalSettingsDialog.Modal();
@@ -734,8 +736,8 @@ class IDEWorkSpace : Window
          }
       };
       MenuDivider { fileMenu };
-      Menu recentFiles { fileMenu, $"Recent Files", r };
-      Menu recentProjects { fileMenu, $"Recent Projects", p };
+      Menu recentFilesMenu { fileMenu, $"Recent Files", r };
+      Menu recentProjectsMenu { fileMenu, $"Recent Projects", p };
       MenuDivider { fileMenu };
       MenuItem exitItem
       {
@@ -751,7 +753,8 @@ class IDEWorkSpace : Window
       bool FileRecentFile(MenuItem selection, Modifiers mods)
       {
          int id = 0;
-         for(file : ideSettings.recentFiles)
+         RecentPaths recentFiles = workspace ? workspace.recentFiles : ideSettings.recentFiles;
+         for(file : recentFiles)
          {
             if(id == selection.id)
             {
@@ -759,7 +762,7 @@ class IDEWorkSpace : Window
                char extension[MAX_EXTENSION] = "";
                GetExtension(file, extension);
                isProjectFile = (!strcmpi(extension, "epj") || !strcmpi(extension, "ews"));
-               if(mods.ctrl)
+               if(mods.ctrl && !mods.shift)
                {
                   char * command = PrintString("ecere-ide ", isProjectFile ? "-t " : "", file);
                   Execute(command);
@@ -784,14 +787,14 @@ class IDEWorkSpace : Window
          {
             if(id == selection.id)
             {
-               if(mods.ctrl)
+               if(mods.ctrl && !mods.shift)
                {
                   char * command = PrintString("ecere-ide ", file);
                   Execute(command);
                   delete command;
                }
                else
-                  OpenFile(file, false, true, null, no, normal, mods.ctrl && mods.shift);
+                  OpenFile(file, false, true, (mods.ctrl && mods.shift) ? "txt" : null, no, normal, mods.ctrl && mods.shift);
                break;
             }
             id++;
@@ -821,9 +824,8 @@ class IDEWorkSpace : Window
                      newProjectDialog.CreateNewProject();
                      if(projectView)
                      {
-                        ideSettings.AddRecentProject(projectView.fileName);
-                        ide.UpdateRecentMenus();
-                        settingsContainer.Save();
+                        ideSettings.recentProjects.addRecent(CopyString(projectView.fileName));
+                        ide.updateRecentProjectsMenu();
                      }
                   }
                }
@@ -1723,6 +1725,7 @@ class IDEWorkSpace : Window
       ideMainFrame.SetText("%s - %s", project.topNode.name, titleECEREIDE);
 
       AdjustMenus();
+      updateRecentMenus();
 
       ide.breakpointsView.LoadFromWorkspace();
       ide.watchesView.LoadFromWorkspace();
@@ -1754,6 +1757,7 @@ class IDEWorkSpace : Window
          outputView.visible = false;
          ideMainFrame.text = titleECEREIDE;
          ide.AdjustMenus();
+         ide.updateRecentMenus();
          return true;
       }
       return false;
@@ -1820,10 +1824,9 @@ class IDEWorkSpace : Window
 
    void DocumentSaved(Window document, const char * fileName)
    {
-      ideSettings.AddRecentFile(fileName);
-      ide.UpdateRecentMenus();
+      ideSettings.recentFiles.addRecent(CopyString(fileName));
+      ide.updateRecentFilesMenu();
       ide.AdjustFileMenus();
-      settingsContainer.Save();
    }
 
    bool Window::OnFileModified(FileChange fileChange, const char * param)
@@ -1859,7 +1862,7 @@ class IDEWorkSpace : Window
    {
       if(workspace)
       {
-         CompilerConfig compiler = ideSettings.GetCompilerConfig(workspace.compiler);
+         CompilerConfig compiler = ideSettings.GetCompilerConfig(workspace.activeCompiler);
          for(prj : workspace.projects)
             projectView.ProjectUpdateMakefileForAllConfigs(prj);
          delete compiler;
@@ -1872,7 +1875,7 @@ class IDEWorkSpace : Window
       if(workspace)
       {
          bool silent = mute || (ide.projectView.buildInProgress == none ? false : true);
-         CompilerConfig compiler = ideSettings.GetCompilerConfig(workspace.compiler);
+         CompilerConfig compiler = ideSettings.GetCompilerConfig(workspace.activeCompiler);
          if(!silent)
          {
             projectView.ShowOutputBuildLog(true);
@@ -1890,7 +1893,7 @@ class IDEWorkSpace : Window
       for(compiler : ideSettings.compilerConfigs)
       {
          DataRow row = toolBar.activeCompiler.AddString(compiler.name);
-         if(workspace && workspace.compiler && !strcmp(compiler.name, workspace.compiler))
+         if(workspace && workspace.activeCompiler && !strcmp(compiler.name, workspace.activeCompiler))
             toolBar.activeCompiler.currentRow = row;
       }
       if(!toolBar.activeCompiler.currentRow && toolBar.activeCompiler.firstRow)
@@ -2329,7 +2332,7 @@ class IDEWorkSpace : Window
 
                         ide.projectView.ShowOutputBuildLog(true);
                         {
-                           CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
+                           CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.activeCompiler);
                            ide.projectView.DisplayCompiler(compiler, false);
                            delete compiler;
                         }
@@ -2348,23 +2351,8 @@ class IDEWorkSpace : Window
                         // this crashes on starting ide with epj file, solution please?
                         // app.UpdateDisplay();
 
+                        workspace.OpenPreviouslyOpenedFiles(noParsing);
                         workspace.holdTracking = true;
-                        for(ofi : workspace.openedFiles)
-                        {
-                           if(ofi.state != closed)
-                           {
-                              Window file = OpenFile(ofi.path, false, true, null, no, normal, noParsing);
-                              if(file)
-                              {
-                                 char fileName[MAX_LOCATION];
-                                 ProjectNode node;
-                                 GetLastDirectory(ofi.path, fileName);
-                                 node = projectView.project.topNode.Find(fileName, true);
-                                 if(node)
-                                    node.EnsureVisible();
-                              }
-                           }
-                        }
                         ide.RepositionWindows(false);
                         workspace.holdTracking = false;
 
@@ -2447,9 +2435,9 @@ class IDEWorkSpace : Window
                   if(prj)
                   {
                      const char * activeConfigName = null;
-                     CompilerConfig compiler = ideSettings.GetCompilerConfig(workspace.compiler);
+                     CompilerConfig compiler = ideSettings.GetCompilerConfig(workspace.activeCompiler);
                      prj.StartMonitoring();
-                     workspace.projects.Add(prj);
+                     workspace.AddProject(prj, null);
                      if(toolBar.activeConfig.currentRow && toolBar.activeConfig.currentRow != toolBar.activeConfig.firstRow &&
                            toolBar.activeConfig.currentRow.string && toolBar.activeConfig.currentRow.string[0])
                         activeConfigName = toolBar.activeConfig.currentRow.string;
@@ -2552,7 +2540,7 @@ class IDEWorkSpace : Window
          {
             document.fileName = filePath;
             if(workspace && !workspace.holdTracking)
-               workspace.UpdateOpenedFileInfo(filePath, opened);
+               workspace.UpdateOpenedFileInfo(filePath, opened, true);
          }
       }
 
@@ -2572,21 +2560,7 @@ class IDEWorkSpace : Window
       if(document)
       {
          if(projectView && document._class == class(CodeEditor) && workspace)
-         {
-            int lineNumber, position;
-            Point scroll;
-            CodeEditor editor = (CodeEditor)document;
-            editor.openedFileInfo = workspace.UpdateOpenedFileInfo(filePath, opened);
-            editor.openedFileInfo.holdTracking = true;
-            lineNumber = Max(editor.openedFileInfo.lineNumber - 1, 0);
-            position = Max(editor.openedFileInfo.position - 1, 0);
-            if(editor.editBox.GoToLineNum(lineNumber))
-               editor.editBox.GoToPosition(editor.editBox.line, lineNumber, position);
-            scroll.x = Max(editor.openedFileInfo.scroll.x, 0);
-            scroll.y = Max(editor.openedFileInfo.scroll.y, 0);
-            editor.editBox.scroll = scroll;
-            editor.openedFileInfo.holdTracking = false;
-         }
+            workspace.RestorePreviouslyOpenedFileState((CodeEditor)document);
 
          if(needFileModified)
             document.OnFileModified = OnFileModified;
@@ -2595,12 +2569,11 @@ class IDEWorkSpace : Window
             document.state = maximized;
 
          if(isProject)
-            ideSettings.AddRecentProject(document.fileName);
-         else
-            ideSettings.AddRecentFile(document.fileName);
-         ide.UpdateRecentMenus();
+            ideSettings.recentProjects.addRecent(CopyString(document.fileName));
+         else if(!workspace)
+            ideSettings.recentFiles.addRecent(CopyString(document.fileName));
          ide.AdjustFileMenus();
-         settingsContainer.Save();
+         ide.updateRecentFilesMenu();
 
          return document;
       }
@@ -2612,19 +2585,19 @@ class IDEWorkSpace : Window
    /*bool Window::GenericDocumentOnClose(bool parentClosing)
    {
       if(!parentClosing && ide.workspace)
-         ide.workspace.UpdateOpenedFileInfo(fileName, unknown);
+         ide.workspace.UpdateOpenedFileInfo(fileName, unknown, false);
       return true;
    }*/
    bool ModelView::ModelViewOnClose(bool parentClosing)
    {
       if(!parentClosing && ide.workspace)
-         ide.workspace.UpdateOpenedFileInfo(fileName, unknown);
+         ide.workspace.UpdateOpenedFileInfo(fileName, unknown, false);
       return true;
    }
    bool PictureEdit::PictureEditOnClose(bool parentClosing)
    {
       if(!parentClosing && ide.workspace)
-         ide.workspace.UpdateOpenedFileInfo(fileName, unknown);
+         ide.workspace.UpdateOpenedFileInfo(fileName, unknown, false);
       return true;
    }
 
@@ -3195,9 +3168,8 @@ class IDEWorkSpace : Window
                   newProjectDialog.Modal();
                   if(projectView)
                   {
-                     ideSettings.AddRecentProject(projectView.fileName);
-                     ide.UpdateRecentMenus();
-                     settingsContainer.Save();
+                     ideSettings.recentProjects.addRecent(CopyString(projectView.fileName));
+                     ide.updateRecentMenus();
                   }
                   delete newProjectDialog;
                   // Open only one project
@@ -3488,38 +3460,46 @@ class IDEWorkSpace : Window
       return true;
    }
 
-   void UpdateRecentMenus()
+   void updateRecentMenus()
    {
-      int c;
-      Menu fileMenu = menu.FindMenu($"File");
-      Menu recentFiles = fileMenu.FindMenu($"Recent Files");
-      Menu recentProjects = fileMenu.FindMenu($"Recent Projects");
+      updateRecentFilesMenu();
+      updateRecentProjectsMenu();
+   }
+
+   void updateRecentFilesMenu()
+   {
+      int c = 0;
       char * itemPath = new char[MAX_LOCATION];
       char * itemName = new char[MAX_LOCATION+4];
-
-      recentFiles.Clear();
-      c = 0;
-
-      for(recent : ideSettings.recentFiles)
+      Workspace ws = workspace;
+      RecentPaths recentFiles = ws ? ws.recentFiles : ideSettings.recentFiles;
+      recentFilesMenu.Clear();
+      for(recent : recentFiles)
       {
          strncpy(itemPath, recent, MAX_LOCATION); itemPath[MAX_LOCATION-1] = '\0';
          MakeSystemPath(itemPath);
          snprintf(itemName, MAX_LOCATION+4, "%d %s", 1 + c, itemPath); itemName[MAX_LOCATION+4-1] = '\0';
-         recentFiles.AddDynamic(MenuItem { copyText = true, text = itemName, (Key)k1 + c, id = c, NotifySelect = ide.FileRecentFile }, ide, true);
+         recentFilesMenu.AddDynamic(MenuItem { copyText = true, text = itemName, (Key)k1 + c, id = c, NotifySelect = ide.FileRecentFile }, ide, true);
          c++;
       }
+      delete itemPath;
+      delete itemName;
+   }
 
-      recentProjects.Clear();
-      c = 0;
+   void updateRecentProjectsMenu()
+   {
+      int c = 0;
+      char * itemPath = new char[MAX_LOCATION];
+      char * itemName = new char[MAX_LOCATION+4];
+      recentProjectsMenu.Clear();
       for(recent : ideSettings.recentProjects)
       {
          strncpy(itemPath, recent, MAX_LOCATION); itemPath[MAX_LOCATION-1] = '\0';
          MakeSystemPath(itemPath);
          snprintf(itemName, MAX_LOCATION+4, "%d %s", 1 + c, itemPath); itemName[MAX_LOCATION+4-1] = '\0';
-         recentProjects.AddDynamic(MenuItem { copyText = true, text = itemName, (Key)k1 + c, id = c, NotifySelect = ide.FileRecentProject }, ide, true);
+         recentProjectsMenu.AddDynamic(MenuItem { copyText = true, text = itemName, (Key)k1 + c, id = c, NotifySelect = ide.FileRecentProject }, ide, true);
          c++;
       }
-
       delete itemPath;
       delete itemName;
    }
@@ -3684,6 +3664,10 @@ class IDEApp : GuiApplication
          }
       }
 
+      ideSettings.compilerConfigs.read();
+      ideSettings.recentFiles.read();
+      ideSettings.recentProjects.read();
+
       // First count files arg to decide whether to maximize
       {
          bool passThrough = false, debugWorkDir = false;
@@ -3746,6 +3730,8 @@ class IDEApp : GuiApplication
       }
       */
 
+      globalSettingsDialog.settingsContainer = settingsContainer;
+
       // Default to language specified by environment if no language selected
       if(!ideSettings.language)
       {