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 OpenedFileInfo UpdateOpenedFileInfo(char * fileName, OpenedFileState state)
429 char filePath[MAX_LOCATION];
430 OpenedFileInfo ofi = null;
431 GetSlashPathBuffer(filePath, fileName);
432 for(item : openedFiles)
434 if(!fstrcmp(item.path, filePath))
444 ofi = OpenedFileInfo { path = CopyString(filePath) };
445 openedFiles.Add(ofi);
453 Iterator<OpenedFileInfo> it { openedFiles };
455 openedFiles.Delete(it.pointer);
462 void UpdateSourceDirsArray(Array<String> dirs)
470 sourceDirs.Add(CopyString(s));
472 DropInvalidBreakpoints(null);
477 void RemoveProject(Project project)
479 Iterator<Project> it { projects };
483 for(bp : breakpoints)
484 DropInvalidBreakpoints(project);
486 ide.findInFilesDialog.RemoveProjectItem(project);
487 ide.UpdateToolBarActiveConfigs(false);
493 void SelectActiveConfig(char * configName)
496 for(prj : ide.workspace.projects)
498 for(cfg : prj.configurations)
500 if(cfg.name && !strcmp(cfg.name, configName))
511 ide.UpdateToolBarActiveConfigs(true);
512 ide.projectView.Update(null);
517 bool FindPath(ProjectNode node, char * path)
519 if(node.type == file)
521 // TODO: Should this code be moved into a ProjectNode::absolutePath property? Taken from NodeProperties.ec
522 char filePath[MAX_LOCATION];
523 GetSlashPathBuffer(filePath, node.project.topNode.path);
524 PathCatSlash(filePath, node.path);
525 PathCatSlash(filePath, node.name);
527 if(!fstrcmp(filePath, path))
534 if(FindPath(n, path))
541 void ChangeBreakpoint(DataRow row, char * location)
543 Breakpoint bp = (Breakpoint)row.tag;
546 char * currentLoc = bp.CopyUserLocationString();
547 if(strcmp(location, currentLoc))
550 bp.location = location;
552 newLoc = bp.CopyUserLocationString();
553 if(strcmp(newLoc, currentLoc))
555 ide.breakpointsView.UpdateBreakpoint(row);
563 // adding a breakpoint by typing it in the breakpoints view
564 // todo, parse location
565 // if good, make add breakpoint, make sure possibly previously entered ignore and level are reflected in breakpoint
568 //bp = Breakpoint { };
569 //row.tag = (int64)bp;
570 //breakpoints.Add(bp);
576 void ChangeBreakpointIgnore(DataRow row, int ignore)
578 Breakpoint bp = (Breakpoint)row.tag;
586 void ChangeBreakpointLevel(DataRow row, int level)
588 Breakpoint bp = (Breakpoint)row.tag;
596 void ChangeBreakpointCondition(DataRow row, char * condition)
598 Breakpoint bp = (Breakpoint)row.tag;
599 if(bp && !(!bp.condition && !(condition && condition[0])))
603 bp.condition = Watch { };
604 bp.condition.expression = CopyString(condition);
607 else if(!(condition && condition[0]))
613 else if(strcmp(condition, bp.condition.expression))
616 bp.condition = Watch { };
617 bp.condition.expression = CopyString(condition);
623 void RemoveBreakpoint(Breakpoint bp)
626 ide.breakpointsView.RemoveBreakpoint(bp);
627 ide.debugger.UpdateRemovedBreakpoint(bp);
629 Iterator<Breakpoint> it { breakpoints };
631 breakpoints.Remove(it.pointer);
635 for(document = ide.firstChild; document; document = document.next)
637 char * fileName = document.fileName;
638 if(document.isDocument && fileName && document.created)
640 char winFilePath[MAX_LOCATION];
641 char * slashPath = GetSlashPathBuffer(winFilePath, fileName);
643 if(!fstrcmp(slashPath, bp.absoluteFilePath))
645 CodeEditor codeEditor = (CodeEditor)document;
646 int boxH = codeEditor.editBox.clientSize.h;
647 Box box { 0, 0, 19, boxH - 1 };
648 document.Update(box);
658 void ParseLoadedBreakpoints()
660 for(bp : breakpoints; bp.location)
663 ide.breakpointsView.UpdateBreakpoint(bp.row);
667 void DropInvalidBreakpoints(Project removedProject)
670 for(bpLink = breakpoints.first; bpLink; bpLink = next)
672 Breakpoint bp = (Breakpoint)bpLink.data;
679 if(bp.project == removedProject)
681 ide.breakpointsView.RemoveBreakpoint(bp);
682 RemoveBreakpoint(bp);
687 Project project = bp.project;
692 if(FindPath(p.topNode, bp.absoluteFilePath))
697 // Handle symbol loader modules:
699 char moduleName[MAX_FILENAME];
701 GetLastDirectory(bp.absoluteFilePath, moduleName);
702 // Tweak for automatically resolving symbol loader modules
703 sl = strstr(moduleName, ".main.ec");
704 if(sl && (*sl = 0, !strcmpi(moduleName, p.name)))
715 for(dir : sourceDirs)
717 if(IsPathInsideOf(bp.absoluteFilePath, dir))
725 ide.breakpointsView.RemoveBreakpoint(bp);
726 RemoveBreakpoint(bp);
732 ide.breakpointsView.Update(null);
737 delete workspaceFile;
739 delete commandLineArgs;
751 ide.outputView.buildBox.Clear();
752 ide.outputView.debugBox.Clear();
753 ide.callStackView.Clear();
754 ide.watchesView.Clear();
755 ide.threadsView.Clear();
756 ide.breakpointsView.Clear();
758 property::debugDir = "";
760 SetSourceDirs(sourceDirs);
769 environmentVars.Free();
778 Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
781 Workspace workspace = null;
783 file = FileOpen(filePath, read);
786 OldList openedFilesNotFound { };
789 char subSection[128];
791 workspace = Workspace { compiler = ideSettings.defaultCompiler, workspaceFile = filePath };
803 file.GetLine(buffer, 65536 - 1);
804 TrimLSpaces(buffer, buffer);
805 TrimRSpaces(buffer, buffer);
812 TrimLSpaces(equal, equal);
813 if(!strcmpi(section, "Debugger Data") && !strcmpi(subSection, "Watches"))
816 workspace.watches.Add(wh);
817 wh.expression = CopyString(equal);
819 else if(!strcmpi(section, "Debugger Data") && !strcmpi(subSection, "Breakpoints"))
824 wh.expression = CopyString(equal);
828 else if(!strcmpi(section, "Execution Data") && !strcmpi(subSection, "Environment Variables"))
830 String value = strchr(equal, '=');
835 TrimRSpaces(equal, equal);
836 TrimLSpaces(value, value);
837 workspace.environmentVars.Add({ equal, value });
841 else if(buffer[0] == '*')
845 TrimLSpaces(equal, equal);
846 if(!strcmpi(section, "Debugger Data") && !strcmpi(subSection, "Breakpoints"))
848 char * strEnabled = null;
849 char * strIgnore = null;
850 char * strLevel = null;
851 char * strLine = null;
852 char * strFile = null;
855 if(strEnabled && strEnabled[0])
857 strIgnore = strstr(strEnabled, ",");
861 if(strIgnore && strIgnore[0])
863 strLevel = strstr(strIgnore, ",");
867 if(strLevel && strLevel[0])
869 strLine = strstr(strLevel, ",");
873 if(strLine && strLine[0])
875 strFile = strstr(strLine, ",");
879 if(strEnabled && strEnabled[0] && strIgnore && strIgnore[0] &&
880 strLevel && strLevel[0] && strLine && strLine[0] && strFile && strFile[0])
887 TrimLSpaces(strEnabled, strEnabled);
888 TrimRSpaces(strEnabled, strEnabled);
889 TrimLSpaces(strIgnore, strIgnore);
890 TrimRSpaces(strIgnore, strIgnore);
891 TrimLSpaces(strLevel, strLevel);
892 TrimRSpaces(strLevel, strLevel);
893 TrimLSpaces(strLevel, strLevel);
894 TrimRSpaces(strLevel, strLevel);
895 TrimLSpaces(strFile, strFile);
896 TrimRSpaces(strFile, strFile);
898 enabled = (strEnabled[0] == '1');
899 ignore = atoi(strIgnore);
900 level = atoi(strLevel);
901 line = atoi(strLine);
903 bp = { type = user, enabled = enabled, ignore = ignore, level = level, line = line };
904 workspace.breakpoints.Add(bp);
905 bp.location = strFile;
909 else if(buffer[0] == '=' || buffer[0] == '-')
913 TrimLSpaces(equal, equal);
914 if(!strcmpi(section, "Debugger Data") && !strcmpi(subSection, "Source Directories"))
915 workspace.sourceDirs.Add(CopyString(equal));
916 else if(!strcmpi(section, "Opened Files"))
918 OpenedFileState state = opened;
922 char absolutePath[MAX_LOCATION];
923 strcpy(absolutePath, workspace.workspaceDir);
926 char * comma = strchr(equal, ',');
930 lineNumber = atoi(equal);
934 else if(version >= 0.02)
936 char * column = strchr(equal, ':');
940 if(strcmpi(equal, "O"))
944 column = strchr(equal, ':');
948 lineNumber = atoi(equal);
951 column = strchr(equal, ':');
955 position = atoi(equal);
958 column = strchr(equal, ':');
962 scroll.x = atoi(equal);
965 column = strchr(equal, ':');
969 scroll.y = atoi(equal);
978 PathCatSlash(absolutePath, equal);
980 if(state == closed || FileExists(absolutePath))
981 workspace.openedFiles.Add(OpenedFileInfo { path = CopyString(absolutePath), state = state, lineNumber = lineNumber, position = position, scroll = scroll });
983 openedFilesNotFound.Add(NamedItem { name = CopyString(equal) });
985 else if(!strcmpi(section, "Projects"))
987 char projectFilePath[MAX_LOCATION];
989 strcpy(projectFilePath, workspace.workspaceDir);
990 PathCatSlash(projectFilePath, equal);
991 newProject = LoadProject(projectFilePath, null);
994 workspace.projects.Add(newProject);
995 newProject.StartMonitoring();
997 else if(workspace.projects.count == 0)
1004 // TODO: show message or something when added project fails to load
1005 // http://ecere.com/mantis/view.php?id=524
1009 else if(!strcmpi(buffer, "ECERE Workspace File"));
1010 else if(!strcmpi(buffer, "Version 0a"))
1012 else if(!strncmp(buffer, "Version ", 8))
1013 version = atof(&buffer[8]);
1014 else if(!strcmpi(buffer, "Workspace"))
1015 strcpy(section, buffer);
1016 else if(!strcmpi(buffer, "Projects"))
1017 strcpy(section, buffer);
1018 else if(!strcmpi(buffer, "Execution Data"))
1019 strcpy(section, buffer);
1020 else if(!strcmpi(buffer, "Debugger Data"))
1021 strcpy(section, buffer);
1022 else if(!strcmpi(buffer, "Source Directories"))
1023 strcpy(subSection, buffer);
1024 else if(!strcmpi(buffer, "Breakpoints"))
1025 strcpy(subSection, buffer);
1026 else if(!strcmpi(buffer, "Watches"))
1027 strcpy(subSection, buffer);
1028 else if(!strcmpi(buffer, "Environment Variables"))
1029 strcpy(subSection, buffer);
1030 else if(!strcmpi(buffer, "Opened Files"))
1031 strcpy(section, buffer);
1032 else if(!strcmpi(buffer, "")) // | These two lines were commented out
1033 strcpy(subSection, buffer); // | Do they serve a purpose? They were there for copy paste when adding a new subsection
1036 equal = strstr(buffer, "=");
1039 if(!strcmpi(section, "Workspace"))
1042 TrimRSpaces(buffer, buffer);
1044 TrimLSpaces(equal, equal);
1045 if(!strcmpi(buffer, "Active Compiler"))
1047 CompilerConfig compiler = ideSettings.GetCompilerConfig(equal);
1049 workspace.compiler = defaultCompilerName;
1051 workspace.compiler = equal;
1054 if(!strcmpi(buffer, "Active Bit Depth"))
1056 int bitDepth = atoi(equal);
1057 if(!(bitDepth == 32 || bitDepth == 64))
1059 workspace.bitDepth = bitDepth;
1060 ide.toolBar.activeBitDepth.SelectRow(ide.toolBar.activeBitDepth.FindRow(bitDepth));
1063 else if(!strcmpi(section, "Execution Data"))
1066 TrimRSpaces(buffer, buffer);
1068 TrimLSpaces(equal, equal);
1069 if(!strcmpi(buffer, "Command Line Arguments"))
1070 workspace.commandLineArgs = equal;
1072 if(!strcmpi(buffer, "Environment Variables"))
1074 workspace.environmentVars.Free();
1075 delete workspace.environmentVars;
1076 workspace.environmentVars = { };
1080 else if(!strcmpi(section, "Debugger Data"))
1083 TrimRSpaces(buffer, buffer);
1085 TrimLSpaces(equal, equal);
1086 if(!strcmpi(buffer, "Debug Working Directory"))
1087 workspace.debugDir = equal;
1092 TrimRSpaces(buffer, buffer);
1094 TrimLSpaces(equal, equal);
1095 if(!strcmpi(buffer, "Active Configuration"))
1098 if(workspace.projects.last)
1100 prj = workspace.projects.lastIterator.data;
1101 for(cfg : prj.configurations)
1103 if(!strcmp(cfg.name, equal))
1111 else if(!strcmpi(buffer, "Modified Compiler Config") || !strcmpi(buffer, "Modified Linker Config"))
1114 if(workspace.projects.last)
1116 prj = workspace.projects.lastIterator.data;
1117 for(cfg : prj.configurations)
1119 if(!strcmp(cfg.name, equal))
1121 if(strstr(buffer, "Compiler"))
1122 cfg.compilingModified = true;
1124 cfg.linkingModified = true;
1130 else if(!strcmpi(buffer, "CommandLineArgs"))
1131 workspace.commandLineArgs = equal;
1132 else if(!strcmpi(buffer, "Breakpoint"))
1135 char * lineNum = strstr(equal, ",");
1146 char * absPath = strstr(lineNum, ",");
1153 char * relPath = strstr(absPath, ",");
1160 bp = { type = user, enabled = enabled, level = -1 };
1161 workspace.breakpoints.Add(bp);
1162 bp.line = atoi(lineNum);
1163 bp.location = relPath;
1171 else if(!strcmpi(buffer, "Watch"))
1174 workspace.watches.Add(wh);
1175 wh.expression = CopyString(equal);
1177 else if(!strcmpi(buffer, "SourceDir"))
1179 workspace.sourceDirs.Add(CopyString(equal));
1181 else if(!strcmpi(buffer, "DebugDir"))
1183 workspace.debugDir = equal;
1195 if(!workspace.projects.first)
1199 project = LoadProject(fromProjectFile /*projectFilePath*/, null);
1202 char projectFilePath[MAX_LOCATION];
1203 strcpy(projectFilePath, workspace.workspaceFile);
1204 ChangeExtension(projectFilePath, ProjectExtension, projectFilePath);
1205 project = LoadProject(projectFilePath, null);
1209 project.StartMonitoring();
1210 workspace.projects.Add(project);
1211 workspace.name = CopyString(project.name);
1215 MessageBox { type = ok, master = ide, contents = $"Workspace load file failed", text = $"Workspace Load File Error" }.Modal();
1221 if(openedFilesNotFound.first)
1225 String files = new char[MAX_LOCATION * 16];
1227 String msg = new char[MAX_LOCATION * 16 + 2048];
1231 item = openedFilesNotFound.first;
1235 for(item = openedFilesNotFound.first; item; item = item.next)
1240 strcat(files, "\n...");
1243 strcat(files, "\n");
1244 strcat(files, item.name);
1247 sprintf(title, $"File%s not found", s);
1248 sprintf(msg, $"The following file%s could not be re-opened.%s", s, files);
1250 MessageBox { type = ok, master = ide, contents = msg, text = title }.Modal();
1255 openedFilesNotFound.Free(OldLink::Free);
1258 openedFilesNotFound.Free(OldLink::Free);
1260 else if(fromProjectFile)
1262 //MessageBox { type = Ok, master = ide, contents = "Worspace load file failed", text = "Worspace Load File Error" }.Modal();
1264 char projectFile[MAX_LOCATION];
1267 //strcpy(projectFile, filePath);
1268 //ChangeExtension(projectFile, ProjectExtension, projectFile);
1269 newProject = LoadProject(fromProjectFile /*projectFile*/, null);
1273 newProject.StartMonitoring();
1274 workspace = Workspace { workspaceFile = filePath };
1276 workspace.projects.Add(newProject);
1283 ide.ChangeFileDialogsDirectory(workspace.workspaceDir, false);
1285 if(!workspace.compiler || !workspace.compiler[0])
1286 workspace.compiler = defaultCompilerName;