a13c796b5308c1a793b61887ef0e8c881dce6f2f
[sdk] / ide / src / dialogs / WorkspaceSettings.ec
1 import "Project"
2
3 class WorkspaceTab : Tab
4 {
5    bool firstCreation;
6    firstCreation = true;
7
8    background = formColor;
9    text = $"Workspace";
10
11    Label labelDebugDirectory { this, position = { 8, 8 }, labeledWindow = debugDirectory };
12    PathBox debugDirectory
13    {
14       this, size = { 290, 22 }, position = { 8, 24 }, anchor = { left = 8, top = 24, right = 8 };
15       text = $"Debug Working Directory", hotKey = altU;
16       typeExpected = directory;
17       browseDialog = { };
18
19       bool NotifyModified(PathBox pathBox)
20       {
21          char path[MAX_LOCATION];
22          String debugDir = pathBox.path;
23          strcpy(path, ide.workspace.projectDir);
24          if(debugDir)
25             PathCat(path, debugDir);
26          if(strcmp(path, debugDir))
27             debugDirectory.path = path;
28
29          modifiedDocument = true;
30          return true;
31       }
32    };
33
34    Label labelCommandLineArgs { this, position = { 8, 50 }, labeledWindow = commandLineArgs };
35    EditBox commandLineArgs
36    {
37       this, size = { 290, 22 }, position = { 8, 66 }, anchor = { left = 8, top = 66, right = 8 };
38       text = $"Command Line Arguments", hotKey = altA;
39       NotifyModified = WorkspaceControlModified;
40    };
41    Label labelEnvironmentVars { environmentVars, this, position = { 0, 6 }, labeledWindow = environmentVars };
42    NamedStringsBox environmentVars
43    {
44       this, size = { 290, 100 }, anchor = { left = 8, top = 96, right = 8 };
45       text = $"Environment Variables", hotKey = altV;
46       NotifyModified = WorkspaceControlModified;
47    };
48
49    Label labelSourceDirs { sourceDirs, this, position = { 0, 6 }, labeledWindow = sourceDirs };
50    DirectoriesBox sourceDirs
51    {
52       this, size = { 290, 100 }, anchor = { left = 8, top = 204, right = 8 };
53       text = $"Source Files Directories", hotKey = altI;
54       NotifyModified = WorkspaceControlModified;
55    };
56
57    bool OnCreate()
58    {
59       if(firstCreation)
60       {
61          // This is required to be here because the label is labeling its parent, which otherwise has issues
62          labelSourceDirs.labeledWindow = sourceDirs;
63
64          if(ide.projectView)
65          {
66             Array<String> strings { };
67             char path[MAX_LOCATION];
68             String debugDir = ide.workspace.debugDir;
69             for(dir : ide.workspace.sourceDirs)
70                strings.Add(dir);
71             sourceDirs.strings = strings;
72
73             strcpy(path, ide.workspace.projectDir);
74             if(debugDir)
75                PathCat(path, debugDir);
76             debugDirectory.path = path;
77             commandLineArgs.contents = ide.workspace.commandLineArgs;
78             environmentVars.namedStrings = ide.workspace.environmentVars;
79
80             delete strings;
81          }
82          firstCreation = false;
83       }
84       return true;
85    }
86
87    bool WorkspaceControlModified(CommonControl control)
88    {
89       modifiedDocument = true;
90       return true;
91    }
92
93    void SaveChanges()
94    {
95       if(debugDirectory.modifiedDocument)
96       {
97          char path[MAX_LOCATION];
98          strcpy(path, debugDirectory.slashPath);
99          if(!fstrcmp(path, ide.workspace.projectDir))
100             strcpy(path, "");
101          ide.workspace.debugDir = path;
102       }
103       if(commandLineArgs.modifiedDocument)
104          ide.workspace.commandLineArgs = commandLineArgs.line.text;
105       if(environmentVars.modifiedDocument)
106       {
107          ide.workspace.environmentVars.Free();
108          delete ide.workspace.environmentVars;
109          ide.workspace.environmentVars = environmentVars.namedStrings;
110       }
111       if(sourceDirs.modifiedDocument)
112          ide.workspace.UpdateSourceDirsArray(sourceDirs.strings);
113
114       if(debugDirectory.modifiedDocument || sourceDirs.modifiedDocument || commandLineArgs.modifiedDocument)
115          ide.workspace.modified = true;
116    }
117
118    bool OnClose(bool parentClosing)
119    {
120       if(modifiedDocument)
121       {
122          DialogResult diagRes = MessageBox
123          {
124             type = yesNoCancel, master = rootWindow,
125             text = $"Save changes to workspace options?",
126             contents = $"Would you like to save changes made to the workspace options?"
127          }.Modal();
128          if(diagRes == cancel)
129             return false;
130          if(diagRes == yes)
131             SaveChanges();
132          modifiedDocument = false;
133       }
134       return true;
135    }
136 }