Skip to content

Commit

Permalink
UI|Client|libappfw: Use native file dialog for picking folders
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 1080d52 commit 0081a81
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 34 deletions.
25 changes: 9 additions & 16 deletions doomsday/apps/client/src/ui/home/nogamescolumnwidget.cpp
Expand Up @@ -23,9 +23,7 @@

#include <de/ButtonWidget>
#include <de/Config>
//#include <de/SignalAction>
#include <de/TextValue>
//#include <QFileDialog>
#include <de/FileDialog>

using namespace de;

Expand Down Expand Up @@ -64,27 +62,24 @@ void NoGamesColumnWidget::browseForDataFiles()
{
bool reload = false;

DE_ASSERT_FAIL("Need a file picker");
#if 0
#if !defined (DE_MOBILE)
// Use a native dialog to select the IWAD folder.
ClientApp::app().beginNativeUIMode();
auto &cfg = Config::get();

const auto folders = Config::get().getStringList("resource.packageFolder");
FileDialog dlg;
String lastDir;
if (!folders.isEmpty())
{
lastDir = folders.back();
}
QFileDialog dlg(nullptr, "Select IWAD Folder", lastDir);
dlg.setFileMode(QFileDialog::Directory);
dlg.setReadOnly(true);
//dlg.setNameFilter("*.wad");
dlg.setLabelText(QFileDialog::Accept, tr("Select"));
dlg.setTitle("Select IWAD Folder");
dlg.setInitialLocation(cfg.gets("resource.iwadFolder", ""));
dlg.setBehavior(FileDialog::AcceptDirectories, ReplaceFlags);
dlg.setPrompt("Select");
if (dlg.exec())
{
Variable & var = Config::get("resource.packageFolder");
const TextValue selDir{dlg.selectedFiles().at(0)};
Variable &var = Config::get("resource.packageFolder");
const TextValue selDir{dlg.selectedPath().toString()};
if (is<ArrayValue>(var.value()))
{
auto &array = var.value<ArrayValue>();
Expand All @@ -103,8 +98,6 @@ void NoGamesColumnWidget::browseForDataFiles()
}

ClientApp::app().endNativeUIMode();
#endif
#endif

// Reload packages and recheck for game availability.
if (reload)
Expand Down
8 changes: 3 additions & 5 deletions doomsday/libs/appfw/src/baseguiapp.cpp
Expand Up @@ -189,7 +189,6 @@ VRConfig &BaseGuiApp::vr()

void BaseGuiApp::beginNativeUIMode()
{
#if !defined (DE_MOBILE)
// Switch temporarily to windowed mode. Not needed on macOS because the display mode
// is never changed on that platform.
#if !defined (MACOSX)
Expand All @@ -203,18 +202,17 @@ void BaseGuiApp::beginNativeUIMode()
win.changeAttributes(windowedMode);
}
#endif
#endif
}

void BaseGuiApp::endNativeUIMode()
{
#if !defined (DE_MOBILE)
auto &win = static_cast<BaseWindow &>(GLWindow::main());
# if !defined (MACOSX)
{
static_cast<BaseWindow &>(GLWindow::main()).restoreState();
win.restoreState();
}
# endif
#endif
win.raise();
}

} // namespace de
23 changes: 10 additions & 13 deletions doomsday/libs/appfw/src/widgets/directoryarraywidget.cpp
Expand Up @@ -24,6 +24,7 @@
#include <de/Garbage>
#include <de/NativePath>
#include <de/TextValue>
#include <de/FileDialog>
#include <de/ToggleWidget>

namespace de {
Expand All @@ -40,26 +41,22 @@ DirectoryArrayWidget::DirectoryArrayWidget(Variable &variable, String const &nam
addButton().setText("Add Folder...");
addButton().setActionFn([this] ()
{
// Use a native dialog to select the IWAD folder.
DE_BASE_GUI_APP->beginNativeUIMode();

DE_ASSERT_FAIL("Need a file picker");

#if 0
QFileDialog dlg(nullptr, tr("Select Folder"),
Config::get().gets(CFG_LAST_FOLDER, "."), "");
dlg.setFileMode(QFileDialog::Directory);
dlg.setReadOnly(true);
//dlg.setNameFilter("*.wad");
dlg.setLabelText(QFileDialog::Accept, tr("Select"));
auto &cfg = Config::get();
FileDialog dlg;
dlg.setTitle("Select Folder");
dlg.setInitialLocation(cfg.gets(CFG_LAST_FOLDER, NativePath::homePath()));
dlg.setPrompt("Select");
dlg.setBehavior(FileDialog::AcceptDirectories, ReplaceFlags);
dlg.setFileTypes({"wad"});
if (dlg.exec())
{
String dir = dlg.selectedFiles().at(0);
Config::get().set(CFG_LAST_FOLDER, dir.fileNamePath());
NativePath dir = dlg.selectedPath();
cfg.set(CFG_LAST_FOLDER, dir.endOmitted().toString());
elementsMenu().items() << makeItem(TextValue(dir));
setVariableFromWidget();
}
#endif

DE_BASE_GUI_APP->endNativeUIMode();
});
Expand Down

0 comments on commit 0081a81

Please sign in to comment.