| 1 |
namespace phoenix { |
| 2 |
|
| 3 |
string pBrowserWindow::directory(BrowserWindow::State& state) { |
| 4 |
QString directory = QFileDialog::getExistingDirectory( |
| 5 |
state.parent ? state.parent->p.qtWindow : nullptr, |
| 6 |
state.title ? state.title : "Select Directory", |
| 7 |
QString::fromUtf8(state.path), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks |
| 8 |
); |
| 9 |
string name = directory.toUtf8().constData(); |
| 10 |
if(name && name.endsWith("/") == false) name.append("/"); |
| 11 |
return name; |
| 12 |
} |
| 13 |
|
| 14 |
string pBrowserWindow::open(BrowserWindow::State& state) { |
| 15 |
string filters = state.filters.merge(";;"); |
| 16 |
|
| 17 |
//convert filter list from phoenix to Qt format, example: |
| 18 |
//"Text, XML files (*.txt,*.xml)" -> "Text, XML files (*.txt *.xml)" |
| 19 |
signed parentheses = 0; |
| 20 |
for(auto& n : filters) { |
| 21 |
if(n == '(') parentheses++; |
| 22 |
if(n == ')') parentheses--; |
| 23 |
if(n == ',' && parentheses) n = ' '; |
| 24 |
} |
| 25 |
|
| 26 |
QString filename = QFileDialog::getOpenFileName( |
| 27 |
state.parent ? state.parent->p.qtWindow : nullptr, |
| 28 |
state.title ? state.title : "Open File", |
| 29 |
QString::fromUtf8(state.path), QString::fromUtf8(filters) |
| 30 |
); |
| 31 |
return filename.toUtf8().constData(); |
| 32 |
} |
| 33 |
|
| 34 |
string pBrowserWindow::save(BrowserWindow::State& state) { |
| 35 |
string filters = state.filters.merge(";;"); |
| 36 |
|
| 37 |
//convert filter list from phoenix to Qt format, example: |
| 38 |
//"Text, XML files (*.txt,*.xml)" -> "Text, XML files (*.txt *.xml)" |
| 39 |
signed parentheses = 0; |
| 40 |
for(auto& n : filters) { |
| 41 |
if(n == '(') parentheses++; |
| 42 |
if(n == ')') parentheses--; |
| 43 |
if(n == ',' && parentheses) n = ' '; |
| 44 |
} |
| 45 |
|
| 46 |
QString filename = QFileDialog::getSaveFileName( |
| 47 |
state.parent ? state.parent->p.qtWindow : nullptr, |
| 48 |
state.title ? state.title : "Save File", |
| 49 |
QString::fromUtf8(state.path), QString::fromUtf8(filters) |
| 50 |
); |
| 51 |
return filename.toUtf8().constData(); |
| 52 |
} |
| 53 |
|
| 54 |
} |