Explorer; libede: Fixes to compile, warnings; fixed single window coming up when...
[ede] / libede / src / CreateNewFileDialog.ec
1 public import "ecere"
2
3 public class CreateNewFileDialog : Window
4 {
5    background = activeBorder;
6    minClientSize = Size { 240, 100 };
7    tabCycle = true;
8    hasClose = true;
9    text = "Create New File";
10
11 public:
12
13    property const char * currentDirectory
14    {
15       set
16       {
17          GetWorkingDir(currentDirectory, MAX_DIRECTORY);  // is this necessary?
18          PathCat(currentDirectory, value);
19          FileFixCase(currentDirectory);
20       }
21       get { return currentDirectory; }
22    };
23
24 private:
25
26    char currentDirectory[MAX_DIRECTORY];
27
28    CreateNewFileDialog()
29    {
30       //FileNameType c;
31
32       GetWorkingDir(currentDirectory, MAX_DIRECTORY);
33       FileFixCase(currentDirectory);
34    }
35
36    ~CreateNewFileDialog()
37    {
38    }
39
40    bool OnPostCreate()
41    {
42       newNewFileName.SelectAll();
43       return true;
44    }
45
46    Button ok
47    {
48       parent = this, isDefault = true, position = { 70, 60 }, size = { 60 }, text = "OK";
49       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
50       {
51          if(newNewFileName.contents && newNewFileName.contents[0])
52          {
53             char newFilePath[MAX_DIRECTORY];
54             strcpy(newFilePath, currentDirectory);
55             PathCat(newFilePath, newNewFileName.contents);
56             if(!FileExists(newFilePath).isFile)
57             {
58                File f = FileOpen(newFilePath, write);
59                if(f)
60                {
61                   f.Flush();
62                }
63                delete f;
64                Destroy(DialogResult::ok);
65             }
66             else
67                MessageBox { master = this, parent = parent, type = ok, text = "Create NewFile Error", contents = "NewFile already exists." }.Modal();
68          }
69          else
70             MessageBox { master = this, parent = parent, type = ok, text = "Create NewFile Error", contents = "Please enter a name." }.Modal();
71          return true;
72       }
73    };
74
75    Button cancel
76    {
77       parent = this, position = { 140, 60 }, size = { 60 }, hotKey = escape, text = "Cancel";
78       NotifyClicked = ButtonCloseDialog;
79    };
80
81    EditBox newNewFileName
82    {
83       this, textHorzScroll = true, anchor = { left = 10, right = 10, top = 30 }, size = { 250 };
84       hotKey = altN, text = "Name";
85       contents = "New NewFile";
86    };
87    Label { this, position = { 10, 10 }, labeledWindow = newNewFileName };
88
89 }