1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
#include <precomp.h>
#include "selectfile.h"
#include <api/wnd/popup.h>
#include <api/service/svcs/svc_filesel.h>
SelectFile::SelectFile(ifc_window *parent, const wchar_t *menu_prefix, const wchar_t *menu_suffix)
: parentWnd(parent),
prefix_str(menu_prefix),
suffix_str(menu_suffix)
{
svc = NULL;
ASSERT(parent != NULL);
xpos = ypos = 0;
pos_set = 0;
}
SelectFile::~SelectFile()
{
if (svc) WASABI_API_SVC->service_release(svc);
types.deleteAll();
}
void SelectFile::setDefaultDir(const wchar_t *dir)
{
default_dir = dir;
}
const wchar_t *SelectFile::getDirectory()
{
if (svc) return svc->getDirectory();
return NULL;
}
void SelectFile::setIdent(const wchar_t *id)
{
ident = id;
}
void SelectFile::setPopPosition(int x, int y)
{
xpos = x;
ypos = y;
pos_set = 1;
}
int SelectFile::runSelector(const wchar_t *type, int allow_multiple, const wchar_t *extlist)
{
if (svc) WASABI_API_SVC->service_release(svc); svc = NULL;
types.deleteAll();
if (type == NULL)
{
int pos = 0;
for (;;)
{
waServiceFactory *wasvc = WASABI_API_SVC->service_enumService(WaSvc::FILESELECTOR, pos++);
if (wasvc == NULL) break;
svc_fileSelector *sfs = castService<svc_fileSelector>(wasvc);
const wchar_t *pref = sfs->getPrefix();
if (pref != NULL)
types.addItem(new StringW(pref));
WASABI_API_SVC->service_release(sfs);
}
if (types.getNumItems() <= 0) return 0; // none?!
PopupMenu *pop = new PopupMenu(parentWnd);
for (int i = 0; i < types.getNumItems(); i++)
{
StringW str;
str += prefix_str;
str += types[i]->getValue();
str += suffix_str;
pop->addCommand(str, i);
}
int cmd = pos_set ? pop->popAtXY(xpos, ypos) : pop->popAtMouse();
StringW *s = types[cmd];
if (s == NULL) return 0;
type = *s;
}
ASSERT(type != NULL);
saved_type = type;
svc = FileSelectorEnum(type).getFirst();
ASSERT(svc != NULL); // we just enumed it
if (extlist != NULL) svc->setExtList(extlist);
//FUCKO : need to set open vs. save as
WASABI_API_WND->pushModalWnd();
int r = svc->runSelector(parentWnd, FileSel::OPEN, allow_multiple,
ident.isempty() ? type : ident.getValue(),
default_dir);
WASABI_API_WND->popModalWnd();
ASSERT(svc != NULL); // we just enumed it
return r;
}
const wchar_t *SelectFile::getType()
{
return saved_type;
}
int SelectFile::getNumFiles()
{
return svc ? svc->getNumFilesSelected() : 0;
}
const wchar_t *SelectFile::enumFilename(int n)
{
return svc ? svc->enumFilename(n) : NULL;
}
|