forked from yuryfdr/pbtk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpbfilechooser.h
108 lines (99 loc) · 2.79 KB
/
pbfilechooser.h
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
/* Copyright (C) 2011-2012 Yury P. Fedorchenko (yuryfdr at users.sf.net) */
/*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PBFILECHOOSER_H
#define PBFILECHOOSER_H
#include "pbwidget.h"
#include "pblistbox.h"
#include "pbbutton.h"
#include "pbdialog.h"
#include "pbinput.h"
#include "pbcombobox.h"
#ifdef __EMU__
#define KBDOPTS KBD_SCREENTOP
#else
#define KBDOPTS 0
#endif
#include <iostream>
/**
*/
class PBDirList : public PBListBox{
void load(const std::string&);
void select(const std::string&);
int handle(int type, int par1, int par2);
std::string fname;
std::string dname;
bool select_files;
public:
PBDirList(const std::string nm,PBWidget*p):PBListBox(nm,p),select_files(true){}
void selectFiles(bool b){select_files=b;}
/**
change dirrectory and select file
*/
void setPath(const std::string&);
/**
return selected path
*/
std::string getPath() const {
if(!fname.empty())return dname+"/"+fname;
return dname;
}
/**
return current directory
*/
std::string getDir() const {
return dname;
}
/**
return relative file name
*/
std::string getFname() const {
return fname;
}
};
class PBFileChooser : public PBDialog {
PBDirList fileList;
public:
PBButton bt_ok;
private:
PBButton bt_cancel;
PBComboBox cbx_pattern;
PBInput lb_path;
void placeWidgets();
void on_pattern_changed(PBComboBox*);
public:
void onButton(PBWidget*);
enum OpenMode {PBFC_OPEN=0,PBFC_SAVE=1,PBFC_ODIR=2} omode;
PBFileChooser(const char* title,OpenMode mode = PBFC_OPEN);
std::string getPath()const{
return fileList.getPath();
}
void setPath(const std::string& s){
fileList.setPath(s);
update();
}
void setMode(OpenMode mode){
omode = mode;
lb_path.setCanBeFocused(omode==PBFC_SAVE);
fileList.selectFiles(omode!=PBFC_ODIR);
}
void setPattern(const char*);
const char* getPattern(){return cbx_pattern.getText().c_str();}
void setInitialName(const char*);
void update(bool relayuot=false);
};
void OpenFileChooser(const char* title,const char* path,const char* pattern,int mode,pb_dialoghandler hproc);
#endif //PBFILECHOOSER_H