First checkin, AXE release 0.2
[AXE.git] / src / filedialog.h
1
2 #include "button.h"
3 #include "edit.h"
4 #include "table.h"
5 #include "pixmap.h"
6
7 #define OPEN_DLG_OK  100
8 #define OPEN_DLG_CANCEL 101
9
10 #include <sys/stat.h>
11 #include <unistd.h>
12 #include <dirent.h>
13
14 struct file_entry
15 {
16    String        name;
17    struct stat   st;
18 };
19
20 bool operator < (const file_entry &fe1, const file_entry &fe2);
21
22 class directory_view : public table_view
23 {
24    String                   cwd;
25    std::vector<file_entry>  d_list;
26
27    pixmap         dir;
28    pixmap         reg;
29
30    int   scan();
31
32 public:
33
34    directory_view(window &parent);
35
36    void redraw();
37    String changedir(String dir);
38
39    bool selected_a_dir()
40    {
41       return S_ISDIR(d_list[selected()].st.st_mode) != 0;
42    }
43 };
44
45
46 class file_dialog : public managed_window
47 {
48    command_button *OK;
49    command_button *Cancel;
50    edit           *diredit;
51    edit           *fileedit;
52    directory_view *directory_list;
53    int            OK_command;
54
55 public:
56
57    file_dialog(int cmd);
58
59    String PathName()
60    {
61       return *diredit + "/" + *fileedit;
62    }
63
64    virtual int DoCommand(int code);
65
66    virtual void ChildMessage(win_message &msg);
67 };
68