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