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();
477 void RemoveProject(Project project)
479 Iterator<Project> it { projects };
483 DropInvalidBreakpoints();
485 ide.findInFilesDialog.RemoveProjectItem(project);
486 ide.UpdateToolBarActiveConfigs(false);
492 void SelectActiveConfig(char * configName)
495 for(prj : ide.workspace.projects)
497 for(cfg : prj.configurations)
499 if(cfg.name && !strcmp(cfg.name, configName))
510 ide.UpdateToolBarActiveConfigs(true);
511 ide.projectView.Update(null);
516 bool FindPath(ProjectNode node, char * path)
518 if(node.type == file)
520 // TODO: Should this code be moved into a ProjectNode::absolutePath property? Taken from NodeProperties.ec
521 char filePath[MAX_LOCATION];
522 GetSlashPathBuffer(filePath, node.project.topNode.path);
523 PathCatSlash(filePath, node.path);
524 PathCatSlash(filePath, node.name);
526 if(!fstrcmp(filePath, path))
533 if(FindPath(n, path))
540 void ChangeBreakpoint(DataRow row, char * location)
542 Breakpoint bp = (Breakpoint)row.tag;
545 char * currentLoc = bp.CopyUserLocationString();
546 if(strcmp(location, currentLoc))
548 // todo, parse location
549 // if good, make changes to breakpoint, according to execution state delete and place breakpoint
550 ide.breakpointsView.UpdateBreakpoint(row); // this is the else
557 // adding a breakpoint by typing it in the breakpoints view
558 // todo, parse location
559 // if good, make add breakpoint, make sure possibly previously entered ignore and level are reflected in breakpoint
562 //bp = Breakpoint { };
563 //row.tag = (int64)bp;
564 //breakpoints.Add(bp);
570 void ChangeBreakpointIgnore(DataRow row, int ignore)
572 Breakpoint bp = (Breakpoint)row.tag;
580 void ChangeBreakpointLevel(DataRow row, int level)
582 Breakpoint bp = (Breakpoint)row.tag;
590 void ChangeBreakpointCondition(DataRow row, char * condition)
592 Breakpoint bp = (Breakpoint)row.tag;
593 if(bp && !(!bp.condition && !(condition && condition[0])))
597 bp.condition = Watch { };
598 bp.condition.expression = CopyString(condition);
601 else if(!(condition && condition[0]))
607 else if(strcmp(condition, bp.condition.expression))
610 bp.condition = Watch { };
611 bp.condition.expression = CopyString(condition);
617 void RemoveBreakpoint(Breakpoint bp)
620 ide.breakpointsView.RemoveBreakpoint(bp);
621 ide.debugger.UpdateRemovedBreakpoint(bp);
623 Iterator<Breakpoint> it { breakpoints };
625 breakpoints.Remove(it.pointer);
629 for(document = ide.firstChild; document; document = document.next)
631 char * fileName = document.fileName;
632 if(document.isDocument && fileName && document.created)
634 char winFilePath[MAX_LOCATION];
635 char * slashPath = GetSlashPathBuffer(winFilePath, fileName);
637 if(!fstrcmp(slashPath, bp.absoluteFilePath))
639 CodeEditor codeEditor = (CodeEditor)document;
640 int boxH = codeEditor.editBox.clientSize.h;
641 Box box { 0, 0, 19, boxH - 1 };
642 document.Update(box);
652 void DropInvalidBreakpoints()
655 for(bpLink = breakpoints.first; bpLink; bpLink = next)
657 Breakpoint bp = (Breakpoint)bpLink.data;
662 Project project = null;
665 if(FindPath(p.topNode, bp.absoluteFilePath))
670 // Handle symbol loader modules:
672 char moduleName[MAX_FILENAME];
674 GetLastDirectory(bp.absoluteFilePath, moduleName);
675 // Tweak for automatically resolving symbol loader modules
676 sl = strstr(moduleName, ".main.ec");
677 if(sl && (*sl = 0, !strcmpi(moduleName, p.name)))
687 for(dir : sourceDirs)
689 if(IsPathInsideOf(bp.absoluteFilePath, dir))
697 ide.breakpointsView.RemoveBreakpoint(bp);
698 RemoveBreakpoint(bp);
703 ide.breakpointsView.Update(null);
708 delete workspaceFile;
710 delete commandLineArgs;
722 ide.outputView.buildBox.Clear();
723 ide.outputView.debugBox.Clear();
724 ide.callStackView.Clear();
725 ide.watchesView.Clear();
726 ide.threadsView.Clear();
727 ide.breakpointsView.Clear();
729 property::debugDir = "";
731 SetSourceDirs(sourceDirs);
740 environmentVars.Free();
749 Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
752 Workspace workspace = null;
754 file = FileOpen(filePath, read);
757 OldList openedFilesNotFound { };
760 char subSection[128];
762 workspace = Workspace { compiler = ideSettings.defaultCompiler, workspaceFile = filePath };
774 file.GetLine(buffer, 65536 - 1);
775 TrimLSpaces(buffer, buffer);
776 TrimRSpaces(buffer, buffer);
783 TrimLSpaces(equal, equal);
784 if(!strcmpi(section, "Debugger Data") && !strcmpi(subSection, "Watches"))
787 workspace.watches.Add(wh);
788 wh.expression = CopyString(equal);
790 else if(!strcmpi(section, "Debugger Data") && !strcmpi(subSection, "Breakpoints"))
795 wh.expression = CopyString(equal);
799 else if(!strcmpi(section, "Execution Data") && !strcmpi(subSection, "Environment Variables"))
801 String value = strchr(equal, '=');
806 TrimRSpaces(equal, equal);
807 TrimLSpaces(value, value);
808 workspace.environmentVars.Add({ equal, value });
812 else if(buffer[0] == '*')
816 TrimLSpaces(equal, equal);
817 if(!strcmpi(section, "Debugger Data") && !strcmpi(subSection, "Breakpoints"))
819 char * strEnabled = null;
820 char * strIgnore = null;
821 char * strLevel = null;
822 char * strLine = null;
823 char * strFile = null;
826 if(strEnabled && strEnabled[0])
828 strIgnore = strstr(strEnabled, ",");
832 if(strIgnore && strIgnore[0])
834 strLevel = strstr(strIgnore, ",");
838 if(strLevel && strLevel[0])
840 strLine = strstr(strLevel, ",");
844 if(strLine && strLine[0])
846 strFile = strstr(strLine, ",");
850 if(strEnabled && strEnabled[0] && strIgnore && strIgnore[0] &&
851 strLevel && strLevel[0] && strLine && strLine[0] && strFile && strFile[0])
858 TrimLSpaces(strEnabled, strEnabled);
859 TrimRSpaces(strEnabled, strEnabled);
860 TrimLSpaces(strIgnore, strIgnore);
861 TrimRSpaces(strIgnore, strIgnore);
862 TrimLSpaces(strLevel, strLevel);
863 TrimRSpaces(strLevel, strLevel);
864 TrimLSpaces(strLevel, strLevel);
865 TrimRSpaces(strLevel, strLevel);
866 TrimLSpaces(strFile, strFile);
867 TrimRSpaces(strFile, strFile);
869 enabled = (strEnabled[0] == '1');
870 ignore = atoi(strIgnore);
871 level = atoi(strLevel);
872 line = atoi(strLine);
874 bp = { type = user, enabled = enabled, ignore = ignore, level = level, line = line };
875 workspace.breakpoints.Add(bp);
876 bp.relativeFilePath = strFile;
877 bp.absoluteFilePath = workspace.GetAbsolutePathFromRelative(strFile);
878 if(!bp.absoluteFilePath)
879 bp.absoluteFilePath = CopyString("");
883 else if(buffer[0] == '=' || buffer[0] == '-')
887 TrimLSpaces(equal, equal);
888 if(!strcmpi(section, "Debugger Data") && !strcmpi(subSection, "Source Directories"))
889 workspace.sourceDirs.Add(CopyString(equal));
890 else if(!strcmpi(section, "Opened Files"))
892 OpenedFileState state = opened;
896 char absolutePath[MAX_LOCATION];
897 strcpy(absolutePath, workspace.workspaceDir);
900 char * comma = strchr(equal, ',');
904 lineNumber = atoi(equal);
908 else if(version >= 0.02)
910 char * column = strchr(equal, ':');
914 if(strcmpi(equal, "O"))
918 column = strchr(equal, ':');
922 lineNumber = atoi(equal);
925 column = strchr(equal, ':');
929 position = atoi(equal);
932 column = strchr(equal, ':');
936 scroll.x = atoi(equal);
939 column = strchr(equal, ':');
943 scroll.y = atoi(equal);
952 PathCatSlash(absolutePath, equal);
954 if(state == closed || FileExists(absolutePath))
955 workspace.openedFiles.Add(OpenedFileInfo { path = CopyString(absolutePath), state = state, lineNumber = lineNumber, position = position, scroll = scroll });
957 openedFilesNotFound.Add(NamedItem { name = CopyString(equal) });
959 else if(!strcmpi(section, "Projects"))
961 char projectFilePath[MAX_LOCATION];
963 strcpy(projectFilePath, workspace.workspaceDir);
964 PathCatSlash(projectFilePath, equal);
965 newProject = LoadProject(projectFilePath, null);
968 workspace.projects.Add(newProject);
969 newProject.StartMonitoring();
971 else if(workspace.projects.count == 0)
978 // TODO: show message or something when added project fails to load
979 // http://ecere.com/mantis/view.php?id=524
983 else if(!strcmpi(buffer, "ECERE Workspace File"));
984 else if(!strcmpi(buffer, "Version 0a"))
986 else if(!strncmp(buffer, "Version ", 8))
987 version = atof(&buffer[8]);
988 else if(!strcmpi(buffer, "Workspace"))
989 strcpy(section, buffer);
990 else if(!strcmpi(buffer, "Projects"))
991 strcpy(section, buffer);
992 else if(!strcmpi(buffer, "Execution Data"))
993 strcpy(section, buffer);
994 else if(!strcmpi(buffer, "Debugger Data"))
995 strcpy(section, buffer);
996 else if(!strcmpi(buffer, "Source Directories"))
997 strcpy(subSection, buffer);
998 else if(!strcmpi(buffer, "Breakpoints"))
999 strcpy(subSection, buffer);
1000 else if(!strcmpi(buffer, "Watches"))
1001 strcpy(subSection, buffer);
1002 else if(!strcmpi(buffer, "Environment Variables"))
1003 strcpy(subSection, buffer);
1004 else if(!strcmpi(buffer, "Opened Files"))
1005 strcpy(section, buffer);
1006 else if(!strcmpi(buffer, "")) // | These two lines were commented out
1007 strcpy(subSection, buffer); // | Do they serve a purpose? They were there for copy paste when adding a new subsection
1010 equal = strstr(buffer, "=");
1013 if(!strcmpi(section, "Workspace"))
1016 TrimRSpaces(buffer, buffer);
1018 TrimLSpaces(equal, equal);
1019 if(!strcmpi(buffer, "Active Compiler"))
1021 CompilerConfig compiler = ideSettings.GetCompilerConfig(equal);
1023 workspace.compiler = defaultCompilerName;
1025 workspace.compiler = equal;
1028 if(!strcmpi(buffer, "Active Bit Depth"))
1030 int bitDepth = atoi(equal);
1031 if(!(bitDepth == 32 || bitDepth == 64))
1033 workspace.bitDepth = bitDepth;
1034 ide.toolBar.activeBitDepth.SelectRow(ide.toolBar.activeBitDepth.FindRow(bitDepth));
1037 else if(!strcmpi(section, "Execution Data"))
1040 TrimRSpaces(buffer, buffer);
1042 TrimLSpaces(equal, equal);
1043 if(!strcmpi(buffer, "Command Line Arguments"))
1044 workspace.commandLineArgs = equal;
1046 if(!strcmpi(buffer, "Environment Variables"))
1048 workspace.environmentVars.Free();
1049 delete workspace.environmentVars;
1050 workspace.environmentVars = { };
1054 else if(!strcmpi(section, "Debugger Data"))
1057 TrimRSpaces(buffer, buffer);
1059 TrimLSpaces(equal, equal);
1060 if(!strcmpi(buffer, "Debug Working Directory"))
1061 workspace.debugDir = equal;
1066 TrimRSpaces(buffer, buffer);
1068 TrimLSpaces(equal, equal);
1069 if(!strcmpi(buffer, "Active Configuration"))
1072 if(workspace.projects.last)
1074 prj = workspace.projects.lastIterator.data;
1075 for(cfg : prj.configurations)
1077 if(!strcmp(cfg.name, equal))
1085 else if(!strcmpi(buffer, "Modified Compiler Config") || !strcmpi(buffer, "Modified Linker Config"))
1088 if(workspace.projects.last)
1090 prj = workspace.projects.lastIterator.data;
1091 for(cfg : prj.configurations)
1093 if(!strcmp(cfg.name, equal))
1095 if(strstr(buffer, "Compiler"))
1096 cfg.compilingModified = true;
1098 cfg.linkingModified = true;
1104 else if(!strcmpi(buffer, "CommandLineArgs"))
1105 workspace.commandLineArgs = equal;
1106 else if(!strcmpi(buffer, "Breakpoint"))
1109 char * lineNum = strstr(equal, ",");
1120 char * absPath = strstr(lineNum, ",");
1127 char * relPath = strstr(absPath, ",");
1134 bp = { type = user, enabled = enabled, level = -1 };
1135 workspace.breakpoints.Add(bp);
1136 bp.line = atoi(lineNum);
1137 bp.relativeFilePath = relPath;
1138 bp.absoluteFilePath = workspace.GetAbsolutePathFromRelative(relPath);
1139 if(!bp.absoluteFilePath)
1140 bp.absoluteFilePath = "";
1148 else if(!strcmpi(buffer, "Watch"))
1151 workspace.watches.Add(wh);
1152 wh.expression = CopyString(equal);
1154 else if(!strcmpi(buffer, "SourceDir"))
1156 workspace.sourceDirs.Add(CopyString(equal));
1158 else if(!strcmpi(buffer, "DebugDir"))
1160 workspace.debugDir = equal;
1172 if(!workspace.projects.first)
1176 project = LoadProject(fromProjectFile /*projectFilePath*/, null);
1179 char projectFilePath[MAX_LOCATION];
1180 strcpy(projectFilePath, workspace.workspaceFile);
1181 ChangeExtension(projectFilePath, ProjectExtension, projectFilePath);
1182 project = LoadProject(projectFilePath, null);
1186 project.StartMonitoring();
1187 workspace.projects.Add(project);
1188 workspace.name = CopyString(project.name);
1192 MessageBox { type = ok, master = ide, contents = $"Workspace load file failed", text = $"Workspace Load File Error" }.Modal();
1198 if(openedFilesNotFound.first)
1202 String files = new char[MAX_LOCATION * 16];
1204 String msg = new char[MAX_LOCATION * 16 + 2048];
1208 item = openedFilesNotFound.first;
1212 for(item = openedFilesNotFound.first; item; item = item.next)
1217 strcat(files, "\n...");
1220 strcat(files, "\n");
1221 strcat(files, item.name);
1224 sprintf(title, $"File%s not found", s);
1225 sprintf(msg, $"The following file%s could not be re-opened.%s", s, files);
1227 MessageBox { type = ok, master = ide, contents = msg, text = title }.Modal();
1232 openedFilesNotFound.Free(OldLink::Free);
1235 openedFilesNotFound.Free(OldLink::Free);
1237 else if(fromProjectFile)
1239 //MessageBox { type = Ok, master = ide, contents = "Worspace load file failed", text = "Worspace Load File Error" }.Modal();
1241 char projectFile[MAX_LOCATION];
1244 //strcpy(projectFile, filePath);
1245 //ChangeExtension(projectFile, ProjectExtension, projectFile);
1246 newProject = LoadProject(fromProjectFile /*projectFile*/, null);
1250 newProject.StartMonitoring();
1251 workspace = Workspace { workspaceFile = filePath };
1253 workspace.projects.Add(newProject);
1260 ide.ChangeFileDialogsDirectory(workspace.workspaceDir, false);
1262 if(!workspace.compiler || !workspace.compiler[0])
1263 workspace.compiler = defaultCompilerName;