ide: workspace: (#882) save workspace file (.ews) in json format.
[sdk] / ide / src / dialogs / NewProjectDialog.ec
index 661a4bd..0918314 100644 (file)
@@ -40,7 +40,7 @@ class NewProjectDialog : Window
       parent = this, isDefault = true, disabled = true, position = { 170, 130 }, size = { 60 }, text = $"OK";
       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
       {
-         char * prjName = projectName.contents;
+         const char * prjName = projectName.contents;
          char filePath[MAX_LOCATION];
          char extension[MAX_EXTENSION];
          ProjectConfig debug, release;
@@ -146,9 +146,10 @@ class NewProjectDialog : Window
          char workspaceFile[MAX_LOCATION];
          strcpy(workspaceFile, prj.filePath);
          ChangeExtension(workspaceFile, WorkspaceExtension, workspaceFile);
-         workspace = Workspace { compiler = ideSettings.defaultCompiler, workspaceFile = workspaceFile };
+         workspace = Workspace { activeCompiler = ideSettings.defaultCompiler, workspaceFile = workspaceFile };
+         workspace.Init();
       }
-      workspace.projects.Add(prj);
+      workspace.AddProject(prj, null);
       ide.findInFilesDialog.AddProjectItem(prj);
       ide.findInFilesDialog.mode = FindInFilesMode::project;
       ide.findInFilesDialog.currentDirectory = prj.topNode.path;
@@ -171,6 +172,7 @@ class NewProjectDialog : Window
          StripLastDirectory(newWorkingDir, newWorkingDir);
          ide.ChangeProjectFileDialogDirectory(newWorkingDir);
       }
+      ide.toolBox.visible = true;
 
       if(createFormOption)
       {
@@ -209,7 +211,7 @@ class NewProjectDialog : Window
 
       if(prj && projectWindow)
       {
-         CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
+         CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.activeCompiler);
          ProjectConfig config = prj.config;
          projectWindow.ShowOutputBuildLog(true);
          projectWindow.DisplayCompiler(compiler, false);
@@ -231,7 +233,7 @@ class NewProjectDialog : Window
       parent = this, text = $"Create Form", hotKey = altF, position = { 200, 30 };
       isCheckbox = true, checked = true;
    };
-   
+
    EditBox projectName
    {
       parent = this, textHorzScroll = true, position = { 10, 30 }, size = { 160 };
@@ -243,7 +245,7 @@ class NewProjectDialog : Window
          char name[MAX_FILENAME];
          char tmp[MAX_FILENAME];
          char lastPart[MAX_LOCATION];
-         char * text = editBox.contents;
+         const char * text = editBox.contents;
 
          // drop leading path stuff that has no business here
          GetLastDirectory(text, tmp);
@@ -293,7 +295,7 @@ class NewProjectDialog : Window
       //replacing this: NotifyUpdate = EditBoxUpdate;
       okBtn.disabled = !(text[0] && projectName.contents[0]);
 
-      GetWorkingDir(location, sizeof(location) - 1);
+      strcpy(location, ideSettings.ideProjectFileDialogLocation);
       PathCatSlash(location, text);
 
       GetLastDirectory(path, lastPart);
@@ -316,10 +318,7 @@ class NewProjectDialog : Window
    {
       char location[MAX_LOCATION];
 
-      if(ideSettings.ideProjectFileDialogLocation)
-         strcpy(location, ideSettings.ideProjectFileDialogLocation);
-      else
-         GetWorkingDir(location, sizeof(location) - 1);
+      strcpy(location, ideSettings.ideProjectFileDialogLocation);
 
       locationEditBox.path = location;
       strcpy(path, location);
@@ -395,7 +394,7 @@ class QuickProjectDialog : Window
             MessageBox { type = ok, master = this, text = tempDir, contents = $"Temporary directory does not exist." }.Modal();
             return true;
          }
-         
+
          ide.tmpPrjDir = tempDir;
 
          strcpy(filePath, tempDir);
@@ -408,7 +407,7 @@ class QuickProjectDialog : Window
          debug = ProjectConfig
          {
             name = CopyString("Debug");
-            options = 
+            options =
             {
                optimization = none;
                fastMath = false;
@@ -458,10 +457,10 @@ class QuickProjectDialog : Window
             char workspaceFile[MAX_LOCATION];
             strcpy(workspaceFile, filePath);
             ChangeExtension(workspaceFile, WorkspaceExtension, workspaceFile);
-            workspace = Workspace { compiler = ideSettings.defaultCompiler, workspaceFile = workspaceFile };
-         } 
+            workspace = Workspace { activeCompiler = ideSettings.defaultCompiler, workspaceFile = workspaceFile };
+         }
 
-         workspace.projects.Add(project);
+         workspace.AddProject(project, null);
          ide.findInFilesDialog.AddProjectItem(project);
          ide.findInFilesDialog.mode = FindInFilesMode::project;
          ide.findInFilesDialog.currentDirectory = project.topNode.path;
@@ -483,13 +482,12 @@ class QuickProjectDialog : Window
          projectWindow = ide.CreateProjectView(workspace, filePath);
 
          {
-            char extension[MAX_EXTENSION];
             Window document = null;
             for(document = ide.firstChild; document; document = document.next)
             {
                if(document.created && document.isDocument && document._class == class(CodeEditor))
                {
-                  char * fileName = document.fileName;
+                  const char * fileName = document.fileName;
                   if(strstr(fileName, "http://") == fileName)
                   {
                      char name[MAX_LOCATION];
@@ -515,12 +513,14 @@ class QuickProjectDialog : Window
                   {
                      CodeEditor codeEditor = (CodeEditor)document;
                      ide.projectView.AddFile(project.topNode, fileName, false, false);
-                     codeEditor.AdjustDebugMenus(ide.areDebugMenusUnavailable, ide.isBreakpointTogglingUnavailable, ide.isDebuggerExecuting, ide.isDebuggerStopped);
+                     codeEditor.AdjustDebugMenus();
                   }
                }
             }
          }
 
+         ide.toolBox.visible = true;
+
          if(project.topNode.modified)
          {
             project.Save(filePath);
@@ -560,7 +560,7 @@ class QuickProjectDialog : Window
 
          if(project && projectWindow)
          {
-            CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
+            CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.activeCompiler);
             ProjectConfig config = project.config;
             projectWindow.ShowOutputBuildLog(true);
             projectWindow.DisplayCompiler(compiler, false);
@@ -575,13 +575,13 @@ class QuickProjectDialog : Window
          return true;
       }
    };
-   
+
    Button
    {
       parent = this, position = { 240, 70 }, size = { 60 }, hotKey = escape, text = $"Cancel";
       NotifyClicked = ButtonCloseDialog;
    };
-   
+
    QuickProjectDialog()
    {
       DataRow row;
@@ -608,14 +608,14 @@ class QuickProjectDialog : Window
    }
 }
 
-void ValidProjectNameBufCopy(char *output, char *input)
+void ValidProjectNameBufCopy(char *output, const char *input)
 {
    strcpy(output, input);
    TrimLSpaces(output, output);
    TrimRSpaces(output, output);
    {
       // todo: support '&', '.' and ' ' in project name on windows so that it may be used by all platforms.
-      char * chars = "*|:\",<>?\\/&. ";
+      const char * chars = "*|:\",<>?\\/&. ";
       char ch, * s = output, * o = output;
       while((ch = *s++)) { if(!strchr(chars, ch)) *o++ = ch; }
       *o = '\0';