epj2make: fix call to GenerateMakefile not following argument type change from ide...
[sdk] / ide / src / dialogs / NodeProperties.ec
1 import "ide"
2
3 enum NodePropertiesMode { normal, newFile, newFolder };
4
5 class NodeProperties : Window
6 {
7    tabCycle = true;
8    background = formColor;
9    hasClose = true;
10    borderStyle = sizable;
11    isModal = true;
12    text = $"Properties";
13    //size = { 280, 260 };
14
15    ProjectNode node, topNode;
16    NodePropertiesMode mode;
17
18    Label pathLabel { parent = this, position = { 10, 60 }, labeledWindow = path };
19    EditBox path
20    {
21       this, textHorzScroll = true, position = { 10, 80 }, size = { 260 }, text = $"Path";
22       anchor = { left = 10, top = 80, right = 10 };
23       NotifyModified = PathNotifyModified;
24    };
25
26    Label absolutePathLabel { parent = this, position = { 10, 110 }, labeledWindow = absolutePath };
27    EditBox absolutePath
28    {
29       this, background = formColor, textHorzScroll = true, readOnly = true;
30       position = { 10, 130 }, size = { 260 }, text = $"Absolute Path";
31       anchor = { left = 10, top = 130, right = 10 };
32    };
33
34    Label nameLabel { parent = this, position = { 10, 10 }, labeledWindow = name };
35    EditBox name
36    {
37       this, textHorzScroll = true, position = { 10, 30 }, size = { 260 }, text = $"Name";
38       anchor = { left = 10, top = 30, right = 10 };
39       NotifyModified = NameNotifyModified;
40    };
41
42    bool NameNotifyModified(EditBox editBox)
43    {
44       char filePath[MAX_LOCATION];
45       char * oldName = node.name;
46
47       node.name = null;
48       GetLastDirectory(name.contents, filePath);
49       if(topNode.Find(filePath, false))
50       {
51          MessageBox { type = ok, master = this, text = filePath, contents = $"File with same name already in project." }.Modal();
52          node.name = oldName;
53          return false;
54       }
55       delete oldName;
56       node.name = CopyString(filePath);
57       if(node.type == file)
58          node.icon = NodeIcons::SelectFileIcon(filePath);
59       {
60          char * s;
61          text = (s = PrintString(node.name, $" Properties"));
62          delete s;
63       }
64       if(node.type == folder)
65       {
66          strcpy(filePath, (node.parent.type == project) ? "" : node.parent.path);
67          PathCatSlash(filePath, node.name);
68          delete node.path;
69          node.path = CopyString(filePath);
70          MakeSystemPath(filePath);
71          path.contents = filePath;
72       }
73
74       UpdateFileName();
75       return true;
76    }
77
78    bool PathNotifyModified(EditBox editBox)
79    {
80       delete node.path;
81       node.path = CopyUnixPath(path.contents);
82
83       if(node.type == resources)
84       {
85          master.modifiedDocument = true;
86          node.project.topNode.modified = true;
87          ide.projectView.Update(null);
88       }
89       else
90          UpdateFileName();
91       return true;
92    }
93
94    property ProjectNode node
95    {
96       set
97       {
98          Size minSize = { 280, 260 };
99
100          // name              { 10,  10 }    { 10,  30 }
101          // path              { 10,  60 }    { 10,  80 }
102          // absolutePath      { 10, 110 }    { 10, 130 }
103
104          node = value;
105          if(node)
106          {
107             for(topNode = node; topNode && topNode.parent; topNode = topNode.parent);
108
109             switch(node.type)
110             {
111                case project:
112                {
113                   minSize.h = 160;
114                   QuickReadOnly(path);
115                   break;
116                }
117                case file:
118                {
119                   minSize.h = 160;
120                   break;
121                }
122                case folder:
123                case resources:
124                {
125                   minSize.h = 110;
126                   absolutePath.visible = false;
127                   absolutePathLabel.visible = false;
128                   if(node.type == resources) QuickReadOnly(name);
129                   break;
130                }
131             }
132
133             // project:    - name path absolute -
134             // file
135             //   in res:   - name path absolute -
136             //   not:      - name path absolute -
137             // folder:     - name               -
138             // resources:  - name path          -
139
140             {
141                char * s;
142                text = (s = PrintString(node.name, $" Properties"));
143                delete s;
144             }
145             name.contents = node.name;
146             {
147                char temp[MAX_LOCATION];
148                path.contents = node.path ? GetSystemPathBuffer(temp, node.path) : "";
149             }
150             if(node.type != folder && node.type != resources)
151             {
152                char filePath[MAX_LOCATION];
153                GetSystemPathBuffer(filePath, topNode.path);
154                if(node.path) PathCat(filePath, node.path);
155                PathCat(filePath, node.name);
156                if(node.type == project)
157                   ChangeExtension(filePath, ProjectExtension, filePath);
158                absolutePath.contents = filePath;
159             }
160          }
161          minClientSize = minSize;
162       }
163    }
164
165    void QuickReadOnly(EditBox editBox)
166    {
167       editBox.textHorzScroll = true;
168       editBox.readOnly = true;
169       editBox.background = formColor;
170    }
171
172    bool OnKeyDown(Key key, unichar ch)
173    {
174       if(key == escape || key.code == enter || key.code == keyPadEnter)
175       {
176          StopEditing();
177          if(key.code == enter || key.code == keyPadEnter)
178          {
179             if(mode == newFile)
180             {
181                char filePath[MAX_LOCATION];
182                Window document;
183                node.GetFullFilePath(filePath);
184                if(FileExists(filePath))
185                   ide.projectView.OpenNode(node, key.ctrl && key.shift);
186                else
187                {
188                   document = (Window)NewCodeEditor(ide, normal, false);
189                   document.NotifySaved = ide.DocumentSaved;
190                   MakeSystemPath(filePath);
191                   document.fileName = filePath;
192                }
193             }
194             if(mode == newFile || mode == newFolder)
195             {
196                ide.projectView.modifiedDocument = true;
197                node.project.topNode.modified = true;
198                if(mode == newFile)
199                   node.project.ModifiedAllConfigs(true, false, true, true);
200             }
201          }
202          else if(mode == newFile || mode == newFolder)
203          {
204             ide.projectView.DeleteNode(node);
205             node = null;
206          }
207          Destroy(0);
208          return false;
209       }
210       return true;
211    }
212
213    bool OnClose(bool parentClosing)
214    {
215       StopEditing();
216       return true;
217    }
218
219    void StopEditing()
220    {
221       // tocheck: do we have a better way of doing this?
222       bool b;
223       name.OnActivate(false, null, &b, false);
224       path.OnActivate(false, null, &b, false);
225    }
226
227    void UpdateFileName()
228    {
229       char filePath[MAX_LOCATION];
230       Project prj = node.project;
231
232       GetSystemPathBuffer(filePath, topNode.path);
233       PathCat(filePath, node.path);
234       PathCat(filePath, node.name);
235       if(node.type == project)
236       {
237          ChangeExtension(filePath, ProjectExtension, filePath);
238          absolutePath.contents = filePath;
239          master.fileName = filePath;
240       }
241       else
242          absolutePath.contents = filePath;
243
244       name.modifiedDocument = false;
245       if(path)
246          path.modifiedDocument = false;
247       if(absolutePath)
248          absolutePath.modifiedDocument = false;
249
250       if(prj && mode == normal)
251       {
252          ide.projectView.modifiedDocument = true;
253          prj.topNode.modified = true;
254          ide.projectView.Update(null);
255          if(node.type == file)
256             prj.ModifiedAllConfigs(true, false, false, true);
257       }
258    }
259 }