3 /*static void ParseListValue(List<String> list, char * equal)
7 string = CopyString(equal);
11 comma = strstr(start, ",");
14 list.Add(CopyString(start));
24 enum OpenedFileState { unknown, opened, closed };
25 enum ValgrindLeakCheck
27 no, summary, yes, full;
31 get { return OnGetString(null, null, null); }
34 char * OnGetString(char * tempString, void * fieldData, bool * needClass)
36 if(this >= no && this <= full)
39 strcpy(tempString, valgrindLeakCheckNames[this]);
40 return valgrindLeakCheckNames[this];
42 if(tempString && tempString[0])
47 static const char * valgrindLeakCheckNames[ValgrindLeakCheck] = { "no", "summary", "yes", "full" };
55 OpenedFileState state;
56 int lineNumber, position;
60 property bool trackingAllowed
62 get { return !holdTracking && ide && ide.workspace && !ide.workspace.holdTracking; }
65 void CaretMove(int line, int charPos)
67 if(trackingAllowed && (line != lineNumber || position != charPos))
71 ide.workspace.modified = true;
75 void ScrollChange(Point scroll)
79 this.scroll.x = scroll.x;
80 this.scroll.y = scroll.y;
81 ide.workspace.modified = true;
89 List<OpenedFileInfo> files = ide.workspace.openedFiles;
90 Iterator<OpenedFileInfo> it { files };
91 if(it.Find(this) && it.pointer != files.GetLast())
93 files.Move(it.pointer, files.GetPrev(files.GetLast()));
94 ide.workspace.modified = true;
108 char * workspaceFile;
110 char * commandLineArgs;
111 property char * commandLineArgs { set { delete commandLineArgs; if(value) commandLineArgs = CopyString(value); } }
113 property char * debugDir { set { delete debugDir; if(value) debugDir = CopyString(value); } }
117 property char * compiler
119 set { delete compiler; if(value && value[0]) compiler = CopyString(value); }
120 get { return compiler && compiler[0] ? compiler : null; }
123 List<String> sourceDirs { };
124 Array<NamedString> environmentVars { };
125 List<Breakpoint> breakpoints { };
126 List<Watch> watches { };
127 List<OpenedFileInfo> openedFiles { };
128 List<Project> projects { };
137 userData = this, delay = 2.5;
146 property char * workspaceFile
150 char dir[MAX_DIRECTORY];
151 if(workspaceFile) delete workspaceFile;
152 if(workspaceDir) delete workspaceDir;
153 workspaceFile = CopyString(value);
154 StripLastDirectory(workspaceFile, dir);
155 workspaceDir = CopyUnixPath(dir);
157 get { return workspaceFile; }
160 property char * projectDir
166 Project prj = projects.firstIterator.data;
167 return prj.topNode ? prj.topNode.path : null;
174 /*property Project project
184 projectDir = CopyString(project.topNode.path);
186 if(!project.config && activeConfig && activeConfig[0])
189 for(cfg = project.configurations.first; cfg; cfg = cfg.next)
190 if(!strcmp(cfg.name, activeConfig))
192 project.config = cfg;
195 project.config = project.configurations.first;
198 get { return project; }
204 // TODO: save these new settings when json format is ready
206 ValgrindLeakCheck vgLeakCheck;
211 vgLeakCheck = summary;
219 file = FileOpen(workspaceFile, write);
223 for(bp : breakpoints)
228 file.Printf("Breakpoint=1,%d,%s,%s\n", bp.line, bp.absoluteFilePath, bp.relativeFilePath);
230 file.Printf("Breakpoint=0,%d,%s,%s\n", bp.line, bp.absoluteFilePath, bp.relativeFilePath);
235 file.Printf("Watch=%s\n", wh.expression);
237 for(dir : sourceDirs)
238 file.Printf("SourceDir=%s\n", dir);
240 if(debugDir && debugDir[0])
241 file.Printf("DebugDir=%s\n", debugDir);
243 if(commandLineArgs && commandLineArgs[0])
244 file.Printf("CommandLineArgs=%s\n", commandLineArgs);
248 char indentation[128*3];
249 char path[MAX_LOCATION];
251 file.Printf("\nECERE Workspace File\n");
252 file.Printf("\nVersion 0.02\n");
253 file.Printf("\nWorkspace\n");
254 file.Printf("\n Active Compiler = %s\n", compiler ? compiler : defaultCompilerName);
255 file.Printf("\n Active Bit Depth = %d\n", bitDepth);
259 file.Printf("\n Projects\n\n");
262 char location[MAX_LOCATION];
263 MakePathRelative(prj.topNode.path, workspaceDir, location);
264 MakeSlashPath(location);
265 PathCatSlash(location, prj.topNode.name);
266 //strcat(location, ".epj");
268 file.Printf(" %s %s\n", "-", location);
271 file.Printf(" Active Configuration = %s\n", prj.config.name);
272 for(cfg : prj.configurations)
274 if(cfg.compilingModified)
275 file.Printf(" Modified Compiler Config = %s\n", cfg.name);
276 else if(cfg.linkingModified)
277 file.Printf(" Modified Linker Config = %s\n", cfg.name);
282 file.Printf("\n Execution Data\n");
283 if(commandLineArgs && commandLineArgs[0])
285 file.Printf("\n Command Line Arguments = ");
286 file.Puts(commandLineArgs);
290 if(environmentVars.count)
292 file.Printf("\n Environment Variables\n\n");
293 for(v : environmentVars)
303 file.Printf("\n Debugger Data\n");
304 // This really belonged in Execution Data...
305 if(debugDir && debugDir[0])
306 file.Printf("\n Debug Working Directory = %s\n", debugDir);
309 file.Printf("\n Source Directories\n");
310 for(dir : sourceDirs)
311 file.Printf(" = %s\n", dir);
314 for(bp : breakpoints)
321 file.Printf("\n Breakpoints\n\n");
329 file.Printf("\n Watches\n\n");
334 if(openedFiles.count)
336 file.Printf("\n Opened Files\n\n");
337 for(ofi : openedFiles)
341 char relativePath[MAX_LOCATION];
342 if(IsPathInsideOf(ofi.path, workspaceDir))
344 MakePathRelative(ofi.path, workspaceDir, relativePath);
345 MakeSlashPath(relativePath);
346 location = relativePath;
352 file.Printf(" %s %s:%d:%d:%d:%d:%s\n", chr, ofi.state == closed ? "C" : "O", ofi.lineNumber, ofi.position, ofi.scroll.x, ofi.scroll.y, location);
361 char * GetAbsolutePathFromRelative(char * relative)
363 char name[MAX_LOCATION];
364 char absolute[MAX_LOCATION];
366 ProjectNode node = null;
368 GetLastDirectory(relative, name);
371 if(node = p.topNode.Find(name, false))
379 node.GetFullFilePath(absolute);
380 return CopyString(absolute);
386 strcpy(absolute, p.topNode.path);
387 PathCatSlash(absolute, relative);
388 if(FileExists(absolute))
395 return CopyString(absolute);
397 strcpy(absolute, workspaceDir); //projectDir // CHECK?
398 PathCatSlash(absolute, relative);
399 if(FileExists(absolute))
400 return CopyString(absolute);
403 for(dir : sourceDirs)
405 strcpy(absolute, dir);
406 PathCatSlash(absolute, relative);
407 if(FileExists(absolute))
408 return CopyString(absolute);
415 char * GetPathWorkspaceRelativeOrAbsolute(char * path)
417 if(IsPathInsideOf(path, workspaceDir))
419 char relativePath[MAX_LOCATION];
420 MakePathRelative(path, workspaceDir, relativePath);
421 return CopyUnixPath(relativePath);
424 return CopyUnixPath(path);
427 Array<ProjectNode> GetAllProjectNodes(char *fullPath, bool skipExcluded)
429 Array<ProjectNode> nodes = null;
430 for(project : projects)
433 if((node = project.topNode.FindByFullPath(fullPath, false)))
435 if(!skipExcluded || !node.GetIsExcluded(project.config))
437 if(!nodes) nodes = { };
445 OpenedFileInfo UpdateOpenedFileInfo(char * fileName, OpenedFileState state)
447 char filePath[MAX_LOCATION];
448 OpenedFileInfo ofi = null;
449 GetSlashPathBuffer(filePath, fileName);
450 for(item : openedFiles)
452 if(!fstrcmp(item.path, filePath))
462 ofi = OpenedFileInfo { path = CopyString(filePath) };
463 openedFiles.Add(ofi);
471 Iterator<OpenedFileInfo> it { openedFiles };
473 openedFiles.Delete(it.pointer);
480 void UpdateSourceDirsArray(Array<String> dirs)
488 sourceDirs.Add(CopyString(s));
490 DropInvalidBreakpoints(null);
495 void RemoveProject(Project project)
497 Iterator<Project> it { projects };
501 for(bp : breakpoints)
502 DropInvalidBreakpoints(project);
504 ide.findInFilesDialog.RemoveProjectItem(project);
505 ide.UpdateToolBarActiveConfigs(false);
511 void SelectActiveConfig(char * configName)
514 for(prj : ide.workspace.projects)
516 for(cfg : prj.configurations)
518 if(cfg.name && !strcmp(cfg.name, configName))
529 ide.UpdateToolBarActiveConfigs(true);
530 ide.projectView.Update(null);
535 bool FindPath(ProjectNode node, char * path)
537 if(node.type == file)
539 // TODO: Should this code be moved into a ProjectNode::absolutePath property? Taken from NodeProperties.ec
540 char filePath[MAX_LOCATION];
541 GetSlashPathBuffer(filePath, node.project.topNode.path);
542 PathCatSlash(filePath, node.path);
543 PathCatSlash(filePath, node.name);
545 if(!fstrcmp(filePath, path))
552 if(FindPath(n, path))
559 void ChangeBreakpoint(DataRow row, char * location)
561 Breakpoint bp = (Breakpoint)row.tag;
564 char * currentLoc = bp.CopyUserLocationString();
565 if(strcmp(location, currentLoc))
568 bp.location = location;
570 newLoc = bp.CopyUserLocationString();
571 if(strcmp(newLoc, currentLoc))
573 ide.breakpointsView.UpdateBreakpoint(row);
581 // adding a breakpoint by typing it in the breakpoints view
582 // todo, parse location
583 // if good, make add breakpoint, make sure possibly previously entered ignore and level are reflected in breakpoint
586 //bp = Breakpoint { };
587 //row.tag = (int64)bp;
588 //breakpoints.Add(bp);
594 void ChangeBreakpointIgnore(DataRow row, int ignore)
596 Breakpoint bp = (Breakpoint)row.tag;
604 void ChangeBreakpointLevel(DataRow row, int level)
606 Breakpoint bp = (Breakpoint)row.tag;
614 void ChangeBreakpointCondition(DataRow row, char * condition)
616 Breakpoint bp = (Breakpoint)row.tag;
617 if(bp && !(!bp.condition && !(condition && condition[0])))
621 bp.condition = Watch { };
622 bp.condition.expression = CopyString(condition);
625 else if(!(condition && condition[0]))
631 else if(strcmp(condition, bp.condition.expression))
634 bp.condition = Watch { };
635 bp.condition.expression = CopyString(condition);
641 void RemoveBreakpoint(Breakpoint bp)
644 ide.breakpointsView.RemoveBreakpoint(bp);
645 ide.debugger.UpdateRemovedBreakpoint(bp);
647 Iterator<Breakpoint> it { breakpoints };
649 breakpoints.Remove(it.pointer);
653 for(document = ide.firstChild; document; document = document.next)
655 char * fileName = document.fileName;
656 if(document.isDocument && fileName && document.created)
658 char winFilePath[MAX_LOCATION];
659 char * slashPath = GetSlashPathBuffer(winFilePath, fileName);
661 if(!fstrcmp(slashPath, bp.absoluteFilePath))
663 CodeEditor codeEditor = (CodeEditor)document;
664 int boxH = codeEditor.editBox.clientSize.h;
665 Box box { 0, 0, 19, boxH - 1 };
666 document.Update(box);
676 void ParseLoadedBreakpoints()
678 for(bp : breakpoints; bp.location)
681 ide.breakpointsView.UpdateBreakpoint(bp.row);
685 void DropInvalidBreakpoints(Project removedProject)
688 for(bpLink = breakpoints.first; bpLink; bpLink = next)
690 Breakpoint bp = (Breakpoint)bpLink.data;
697 if(bp.project == removedProject)
699 ide.breakpointsView.RemoveBreakpoint(bp);
700 RemoveBreakpoint(bp);
705 Project project = bp.project;
710 if(FindPath(p.topNode, bp.absoluteFilePath))
715 // Handle symbol loader modules:
717 char moduleName[MAX_FILENAME];
719 GetLastDirectory(bp.absoluteFilePath, moduleName);
720 // Tweak for automatically resolving symbol loader modules
721 sl = strstr(moduleName, ".main.ec");
722 if(sl && (*sl = 0, !strcmpi(moduleName, p.name)))
733 for(dir : sourceDirs)
735 if(IsPathInsideOf(bp.absoluteFilePath, dir))
743 ide.breakpointsView.RemoveBreakpoint(bp);
744 RemoveBreakpoint(bp);
750 ide.breakpointsView.Update(null);
755 delete workspaceFile;
757 delete commandLineArgs;
769 ide.outputView.buildBox.Clear();
770 ide.outputView.debugBox.Clear();
771 ide.callStackView.Clear();
772 ide.watchesView.Clear();
773 ide.threadsView.Clear();
774 ide.breakpointsView.Clear();
776 property::debugDir = "";
778 SetSourceDirs(sourceDirs);
787 environmentVars.Free();
796 Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
799 Workspace workspace = null;
801 file = FileOpen(filePath, read);
804 OldList openedFilesNotFound { };
807 char subSection[128];
809 workspace = Workspace { compiler = ideSettings.defaultCompiler, workspaceFile = filePath };
821 file.GetLine(buffer, 65536 - 1);
822 TrimLSpaces(buffer, buffer);
823 TrimRSpaces(buffer, buffer);
830 TrimLSpaces(equal, equal);
831 if(!strcmpi(section, "Debugger Data") && !strcmpi(subSection, "Watches"))
834 workspace.watches.Add(wh);
835 wh.expression = CopyString(equal);
837 else if(!strcmpi(section, "Debugger Data") && !strcmpi(subSection, "Breakpoints"))
842 wh.expression = CopyString(equal);
846 else if(!strcmpi(section, "Execution Data") && !strcmpi(subSection, "Environment Variables"))
848 String value = strchr(equal, '=');
853 TrimRSpaces(equal, equal);
854 TrimLSpaces(value, value);
855 workspace.environmentVars.Add({ equal, value });
859 else if(buffer[0] == '*')
863 TrimLSpaces(equal, equal);
864 if(!strcmpi(section, "Debugger Data") && !strcmpi(subSection, "Breakpoints"))
866 char * strEnabled = null;
867 char * strIgnore = null;
868 char * strLevel = null;
869 char * strLine = null;
870 char * strFile = null;
873 if(strEnabled && strEnabled[0])
875 strIgnore = strstr(strEnabled, ",");
879 if(strIgnore && strIgnore[0])
881 strLevel = strstr(strIgnore, ",");
885 if(strLevel && strLevel[0])
887 strLine = strstr(strLevel, ",");
891 if(strLine && strLine[0])
893 strFile = strstr(strLine, ",");
897 if(strEnabled && strEnabled[0] && strIgnore && strIgnore[0] &&
898 strLevel && strLevel[0] && strLine && strLine[0] && strFile && strFile[0])
905 TrimLSpaces(strEnabled, strEnabled);
906 TrimRSpaces(strEnabled, strEnabled);
907 TrimLSpaces(strIgnore, strIgnore);
908 TrimRSpaces(strIgnore, strIgnore);
909 TrimLSpaces(strLevel, strLevel);
910 TrimRSpaces(strLevel, strLevel);
911 TrimLSpaces(strLevel, strLevel);
912 TrimRSpaces(strLevel, strLevel);
913 TrimLSpaces(strFile, strFile);
914 TrimRSpaces(strFile, strFile);
916 enabled = (strEnabled[0] == '1');
917 ignore = atoi(strIgnore);
918 level = atoi(strLevel);
919 line = atoi(strLine);
921 bp = { type = user, enabled = enabled, ignore = ignore, level = level, line = line };
922 workspace.breakpoints.Add(bp);
923 bp.location = strFile;
927 else if(buffer[0] == '=' || buffer[0] == '-')
931 TrimLSpaces(equal, equal);
932 if(!strcmpi(section, "Debugger Data") && !strcmpi(subSection, "Source Directories"))
933 workspace.sourceDirs.Add(CopyString(equal));
934 else if(!strcmpi(section, "Opened Files"))
936 OpenedFileState state = opened;
940 char absolutePath[MAX_LOCATION];
941 strcpy(absolutePath, workspace.workspaceDir);
944 char * comma = strchr(equal, ',');
948 lineNumber = atoi(equal);
952 else if(version >= 0.02)
954 char * column = strchr(equal, ':');
958 if(strcmpi(equal, "O"))
962 column = strchr(equal, ':');
966 lineNumber = atoi(equal);
969 column = strchr(equal, ':');
973 position = atoi(equal);
976 column = strchr(equal, ':');
980 scroll.x = atoi(equal);
983 column = strchr(equal, ':');
987 scroll.y = atoi(equal);
996 PathCatSlash(absolutePath, equal);
998 if(state == closed || FileExists(absolutePath))
999 workspace.openedFiles.Add(OpenedFileInfo { path = CopyString(absolutePath), state = state, lineNumber = lineNumber, position = position, scroll = scroll });
1001 openedFilesNotFound.Add(NamedItem { name = CopyString(equal) });
1003 else if(!strcmpi(section, "Projects"))
1005 char projectFilePath[MAX_LOCATION];
1007 strcpy(projectFilePath, workspace.workspaceDir);
1008 PathCatSlash(projectFilePath, equal);
1009 newProject = LoadProject(projectFilePath, null);
1012 workspace.projects.Add(newProject);
1013 newProject.StartMonitoring();
1015 else if(workspace.projects.count == 0)
1022 // TODO: show message or something when added project fails to load
1023 // http://ecere.com/mantis/view.php?id=524
1027 else if(!strcmpi(buffer, "ECERE Workspace File"));
1028 else if(!strcmpi(buffer, "Version 0a"))
1030 else if(!strncmp(buffer, "Version ", 8))
1031 version = atof(&buffer[8]);
1032 else if(!strcmpi(buffer, "Workspace"))
1033 strcpy(section, buffer);
1034 else if(!strcmpi(buffer, "Projects"))
1035 strcpy(section, buffer);
1036 else if(!strcmpi(buffer, "Execution Data"))
1037 strcpy(section, buffer);
1038 else if(!strcmpi(buffer, "Debugger Data"))
1039 strcpy(section, buffer);
1040 else if(!strcmpi(buffer, "Source Directories"))
1041 strcpy(subSection, buffer);
1042 else if(!strcmpi(buffer, "Breakpoints"))
1043 strcpy(subSection, buffer);
1044 else if(!strcmpi(buffer, "Watches"))
1045 strcpy(subSection, buffer);
1046 else if(!strcmpi(buffer, "Environment Variables"))
1047 strcpy(subSection, buffer);
1048 else if(!strcmpi(buffer, "Opened Files"))
1049 strcpy(section, buffer);
1050 else if(!strcmpi(buffer, "")) // | These two lines were commented out
1051 strcpy(subSection, buffer); // | Do they serve a purpose? They were there for copy paste when adding a new subsection
1054 equal = strstr(buffer, "=");
1057 if(!strcmpi(section, "Workspace"))
1060 TrimRSpaces(buffer, buffer);
1062 TrimLSpaces(equal, equal);
1063 if(!strcmpi(buffer, "Active Compiler"))
1065 CompilerConfig compiler = ideSettings.GetCompilerConfig(equal);
1067 workspace.compiler = defaultCompilerName;
1069 workspace.compiler = equal;
1072 if(!strcmpi(buffer, "Active Bit Depth"))
1074 int bitDepth = atoi(equal);
1075 if(!(bitDepth == 32 || bitDepth == 64))
1077 workspace.bitDepth = bitDepth;
1078 ide.toolBar.activeBitDepth.SelectRow(ide.toolBar.activeBitDepth.FindRow(bitDepth));
1081 else if(!strcmpi(section, "Execution Data"))
1084 TrimRSpaces(buffer, buffer);
1086 TrimLSpaces(equal, equal);
1087 if(!strcmpi(buffer, "Command Line Arguments"))
1088 workspace.commandLineArgs = equal;
1090 if(!strcmpi(buffer, "Environment Variables"))
1092 workspace.environmentVars.Free();
1093 delete workspace.environmentVars;
1094 workspace.environmentVars = { };
1098 else if(!strcmpi(section, "Debugger Data"))
1101 TrimRSpaces(buffer, buffer);
1103 TrimLSpaces(equal, equal);
1104 if(!strcmpi(buffer, "Debug Working Directory"))
1105 workspace.debugDir = equal;
1110 TrimRSpaces(buffer, buffer);
1112 TrimLSpaces(equal, equal);
1113 if(!strcmpi(buffer, "Active Configuration"))
1116 if(workspace.projects.last)
1118 prj = workspace.projects.lastIterator.data;
1119 for(cfg : prj.configurations)
1121 if(!strcmp(cfg.name, equal))
1129 else if(!strcmpi(buffer, "Modified Compiler Config") || !strcmpi(buffer, "Modified Linker Config"))
1132 if(workspace.projects.last)
1134 prj = workspace.projects.lastIterator.data;
1135 for(cfg : prj.configurations)
1137 if(!strcmp(cfg.name, equal))
1139 if(strstr(buffer, "Compiler"))
1140 cfg.compilingModified = true;
1142 cfg.linkingModified = true;
1148 else if(!strcmpi(buffer, "CommandLineArgs"))
1149 workspace.commandLineArgs = equal;
1150 else if(!strcmpi(buffer, "Breakpoint"))
1153 char * lineNum = strstr(equal, ",");
1164 char * absPath = strstr(lineNum, ",");
1171 char * relPath = strstr(absPath, ",");
1178 bp = { type = user, enabled = enabled, level = -1 };
1179 workspace.breakpoints.Add(bp);
1180 bp.line = atoi(lineNum);
1181 bp.location = relPath;
1189 else if(!strcmpi(buffer, "Watch"))
1192 workspace.watches.Add(wh);
1193 wh.expression = CopyString(equal);
1195 else if(!strcmpi(buffer, "SourceDir"))
1197 workspace.sourceDirs.Add(CopyString(equal));
1199 else if(!strcmpi(buffer, "DebugDir"))
1201 workspace.debugDir = equal;
1213 if(!workspace.projects.first)
1217 project = LoadProject(fromProjectFile /*projectFilePath*/, null);
1220 char projectFilePath[MAX_LOCATION];
1221 strcpy(projectFilePath, workspace.workspaceFile);
1222 ChangeExtension(projectFilePath, ProjectExtension, projectFilePath);
1223 project = LoadProject(projectFilePath, null);
1227 project.StartMonitoring();
1228 workspace.projects.Add(project);
1229 workspace.name = CopyString(project.name);
1233 MessageBox { type = ok, master = ide, contents = $"Workspace load file failed", text = $"Workspace Load File Error" }.Modal();
1239 if(openedFilesNotFound.first)
1243 String files = new char[MAX_LOCATION * 16];
1245 String msg = new char[MAX_LOCATION * 16 + 2048];
1249 item = openedFilesNotFound.first;
1253 for(item = openedFilesNotFound.first; item; item = item.next)
1258 strcat(files, "\n...");
1261 strcat(files, "\n");
1262 strcat(files, item.name);
1265 sprintf(title, $"File%s not found", s);
1266 sprintf(msg, $"The following file%s could not be re-opened.%s", s, files);
1268 MessageBox { type = ok, master = ide, contents = msg, text = title }.Modal();
1273 openedFilesNotFound.Free(OldLink::Free);
1276 openedFilesNotFound.Free(OldLink::Free);
1278 else if(fromProjectFile)
1280 //MessageBox { type = Ok, master = ide, contents = "Worspace load file failed", text = "Worspace Load File Error" }.Modal();
1282 char projectFile[MAX_LOCATION];
1285 //strcpy(projectFile, filePath);
1286 //ChangeExtension(projectFile, ProjectExtension, projectFile);
1287 newProject = LoadProject(fromProjectFile /*projectFile*/, null);
1291 newProject.StartMonitoring();
1292 workspace = Workspace { workspaceFile = filePath };
1294 workspace.projects.Add(newProject);
1301 ide.ChangeFileDialogsDirectory(workspace.workspaceDir, false);
1303 if(!workspace.compiler || !workspace.compiler[0])
1304 workspace.compiler = defaultCompilerName;