Skip to content

Commit

Permalink
Widgets|UI|libgui: Working on the directory browser
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 14cbee6 commit 76369d5
Show file tree
Hide file tree
Showing 21 changed files with 289 additions and 51 deletions.
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/render/fx/lensflares.cpp
Expand Up @@ -355,7 +355,7 @@ DE_PIMPL(LensFlares)
// The vertex buffer will contain a number of quads.
VBuf::Vertices verts;
VBuf::Indices idx;
VBuf::Type vtx;
// VBuf::Type vtx;

for (PVSet::const_iterator i = pvs.begin(); i != pvs.end(); ++i)
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/ui/home/nogamescolumnwidget.cpp
Expand Up @@ -75,7 +75,7 @@ void NoGamesColumnWidget::browseForDataFiles()
}
dlg.setBehavior(FileDialog::AcceptDirectories, ReplaceFlags);
dlg.setPrompt("Select");
if (dlg.exec())
if (dlg.exec(root()))
{
Variable &var = Config::get("resource.packageFolder");
const TextValue selDir{dlg.selectedPath().toString()};
Expand Down
Expand Up @@ -22,7 +22,6 @@

#include <doomsday/console/var.h>
#include <de/PopupMenuWidget>
#include <de/FileDialog>

using namespace de;

Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/ui/widgets/nativepathwidget.cpp
Expand Up @@ -119,7 +119,7 @@ void NativePathWidget::chooseUsingNativeFileDialog()
dlg.setInitialLocation(NativePath::workPath() / dir);
dlg.setFileTypes(d->filters);
dlg.setPrompt("Select");
if (dlg.exec())
if (dlg.exec(root()))
{
d->path = dlg.selectedPath();
setText(d->labelText());
Expand Down
10 changes: 5 additions & 5 deletions doomsday/apps/client/src/ui/widgets/packageswidget.cpp
Expand Up @@ -465,12 +465,12 @@ DE_GUI_PIMPL(PackagesWidget)

// Search filter:
LineEditWidget *search;
Rule const *searchMinY = nullptr;
ButtonWidget *clearSearch;
Animation searchBackgroundOpacity { 0.f, Animation::Linear };
StringList filterTerms;
const Rule * searchMinY = nullptr;
ButtonWidget * clearSearch;
Animation searchBackgroundOpacity{0.f, Animation::Linear};
StringList filterTerms;
Strings hiddenTagsInEffect;
Timer refilterTimer;
Timer refilterTimer;

ProgressWidget *refreshProgress;

Expand Down
12 changes: 12 additions & 0 deletions doomsday/libs/core/include/de/data/map.h
Expand Up @@ -63,6 +63,18 @@ class Map : public std::map<Key, Value, Compare>
}
return Base::insert(typename Base::value_type(key, value)).first;
}

iterator insert(const Key &key, Value &&value)
{
auto found = Base::find(key);
if (found != Base::end())
{
found->second = std::move(value);
return found;
}
return Base::insert(typename Base::value_type(key, std::move(value))).first;
}

void remove(const Key &key) { Base::erase(key); }
bool contains(const Key &key) const { return Base::find(key) != Base::end(); }
const_iterator constFind(const Key &key) const { return Base::find(key); }
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/include/de/widgets/indirectrule.h
Expand Up @@ -45,7 +45,7 @@ class DE_PUBLIC IndirectRule : public Rule
*
* @param rule Source rule.
*/
void setSource(Rule const &rule);
void setSource(const Rule &rule);

void unsetSource();

Expand Down
2 changes: 2 additions & 0 deletions doomsday/libs/gui/include/de/DirectoryBrowserWidget
@@ -0,0 +1,2 @@
#include "widgets/directorybrowserwidget.h"

4 changes: 3 additions & 1 deletion doomsday/libs/gui/include/de/dialogs/filedialog.h
Expand Up @@ -25,6 +25,8 @@

namespace de {

class GuiRootWidget;

/**
* Native file chooser dialog.
*/
Expand Down Expand Up @@ -60,7 +62,7 @@ class LIBGUI_PUBLIC FileDialog
void setInitialLocation(const NativePath &initialLocation);
void setFileTypes(const FileTypes &fileTypes);

bool exec();
bool exec(GuiRootWidget &);

NativePath selectedPath() const;
List<NativePath> selectedPaths() const;
Expand Down
54 changes: 30 additions & 24 deletions doomsday/libs/gui/include/de/gui/directorytreedata.h
Expand Up @@ -24,32 +24,10 @@

namespace de {

class DirectoryItem;

class LIBGUI_PUBLIC DirectoryTreeData : public ui::TreeData
{
public:
/**
* Item in the directory tree data model (i.e., file or subdirectory).
*/
class LIBGUI_PUBLIC DirectoryItem : public ui::Item
{
public:
DirectoryItem(const String &name, const File::Status &status, const Path &directory)
: ui::Item(DefaultSemantics, name)
, _status(status)
, _directory(directory)
{
setLabel(name);
}

String name() const { return label(); }
File::Status status() const { return _status; }
Path path() const { return _directory / name(); }

private:
File::Status _status;
const Path & _directory;
};

public:
DirectoryTreeData();

Expand All @@ -61,4 +39,32 @@ class LIBGUI_PUBLIC DirectoryTreeData : public ui::TreeData
DE_PRIVATE(d)
};

/**
* Item in the directory tree data model (i.e., file or subdirectory).
*/
class LIBGUI_PUBLIC DirectoryItem : public ui::Item
{
public:
DirectoryItem(const String &name, const File::Status &status, const Path &directory)
: ui::Item(DefaultSemantics, name)
, _status(status)
, _directory(directory)
{
setLabel(name);
}

String name() const { return label(); }
File::Status status() const { return _status; }
Path path() const { return _directory / name(); }

bool isDirectory() const
{
return status().type() == File::Type::Folder;
}

private:
File::Status _status;
const Path & _directory;
};

} // namespace de
8 changes: 7 additions & 1 deletion doomsday/libs/gui/include/de/gui/guiwidgetprivate.h
Expand Up @@ -25,6 +25,7 @@
namespace de {

class Style;
class Font;

/**
* Base class for GuiWidget-derived widgets' private implementation. Provides
Expand Down Expand Up @@ -122,11 +123,16 @@ class GuiWidgetPrivate : public Private<PublicType>,
return Base::self().style();
}

Rule const &rule(DotPath const &path) const
const Rule &rule(const DotPath &path) const
{
return Base::self().rule(path);
}

const Font &font(const DotPath &path) const
{
return style().fonts().font(path);
}

void atlasContentRepositioned(Atlas &atlas)
{
if (_observingAtlas == &atlas)
Expand Down
2 changes: 2 additions & 0 deletions doomsday/libs/gui/include/de/gui/treedata.h
Expand Up @@ -36,6 +36,8 @@ class LIBGUI_PUBLIC TreeData

virtual bool contains(const Path &path) const = 0;
virtual const Data &items(const Path &path) const = 0;

DE_CAST_METHODS()
};

} // namespace ui
Expand Down
10 changes: 9 additions & 1 deletion doomsday/libs/gui/include/de/widgets/browserwidget.h
Expand Up @@ -18,7 +18,8 @@

#pragma once

#include <de/GuiWidget>
#include "../ui/TreeData"
#include "../MenuWidget"

namespace de {

Expand All @@ -32,6 +33,13 @@ class LIBGUI_PUBLIC BrowserWidget : public GuiWidget
public:
BrowserWidget(const String &name = {});

void setData(const ui::TreeData &data, int averageItemHeight);
const ui::TreeData &data() const;

MenuWidget &menu();

void setCurrentPath(const Path &path);

private:
DE_PRIVATE(d)
};
Expand Down
34 changes: 34 additions & 0 deletions doomsday/libs/gui/include/de/widgets/directorybrowserwidget.h
@@ -0,0 +1,34 @@
/** @file directorybrowserwidget.h
*
* @authors Copyright (c) 2019 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* LGPL: http://www.gnu.org/licenses/lgpl.html
*
* <small>This program 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 3 of the License, or (at your
* option) any later version. This program 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 program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#pragma once

#include "../BrowserWidget"

namespace de {

class DirectoryBrowserWidget : public BrowserWidget
{
public:
DirectoryBrowserWidget(const String &name = {});

private:
DE_PRIVATE(d)
};

} // namespace de
2 changes: 1 addition & 1 deletion doomsday/libs/gui/src/dialogs/filedialog_macx.mm
Expand Up @@ -70,7 +70,7 @@
return d->selection;
}

bool FileDialog::exec()
bool FileDialog::exec(GuiRootWidget &)
{
d->selection.clear();

Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/gui/src/dialogs/filedialog_windows.cpp
Expand Up @@ -87,7 +87,7 @@ List<NativePath> FileDialog::selectedPaths() const
return d->selection;
}

bool FileDialog::exec()
bool FileDialog::exec(GuiRootWidget &)
{
d->selection.clear();

Expand Down
23 changes: 22 additions & 1 deletion doomsday/libs/gui/src/dialogs/filedialog_x11.cpp
Expand Up @@ -17,6 +17,8 @@
*/

#include "de/FileDialog"
#include "de/DirectoryBrowserWidget"
#include "de/DialogWidget"

namespace de {

Expand All @@ -29,6 +31,8 @@ DE_PIMPL_NOREF(FileDialog)
NativePath initialLocation;
FileTypes fileTypes; // empty list: eveything allowed

DirectoryBrowserWidget *browser;

// using Filters = List<std::pair<Block, Block>>;

// Filters filters() const
Expand All @@ -42,6 +46,16 @@ DE_PIMPL_NOREF(FileDialog)
// }
// return list;
// }

DialogWidget *makeDialog()
{
auto *dlg = new DialogWidget;
dlg->setDeleteAfterDismissed(true);

browser = new DirectoryBrowserWidget;

return dlg;
}
};

FileDialog::FileDialog() : d(new Impl)
Expand Down Expand Up @@ -82,7 +96,7 @@ List<NativePath> FileDialog::selectedPaths() const
return d->selection;
}

bool FileDialog::exec()
bool FileDialog::exec(GuiRootWidget &root)
{
d->selection.clear();

Expand Down Expand Up @@ -165,6 +179,13 @@ bool FileDialog::exec()
// // Cleanup.
// dlg->Release();

auto *dlg = d->makeDialog();
if (dlg->exec(root))
{
// Get the selected items.

}

return !d->selection.empty();
}

Expand Down
25 changes: 17 additions & 8 deletions doomsday/libs/gui/src/directorytreedata.cpp
Expand Up @@ -26,27 +26,33 @@ namespace de {

DE_PIMPL(DirectoryTreeData)
{
Map<NativePath, ui::ListDataT<DirectoryItem>> pathItems;
using DirList = ui::ListDataT<DirectoryItem>;
Map<NativePath, std::unique_ptr<DirList>> pathItems;

Impl(Public *i) : Base(i)
{}

void populate(const NativePath &path)
{
auto found = pathItems.find(path);
if (found == pathItems.end())
{
found = pathItems.insert(path, std::unique_ptr<DirList>(new DirList));
}
auto &items = *found->second;

// Get rid of the previous contents.
auto &items = pathItems[path];
items.clear();

// Populate a folder with the directory contents.
dir = path;
Folder folder(path.fileName());
folder.attach(new DirectoryFeed(dir));
folder.attach(new DirectoryFeed(path));
folder.populate(Folder::PopulateOnlyThisFolder | Folder::DisableNotification);

// Create corresponding data items.
for (const auto &entry : folder.contents())
{
items << new DirectoryItem(entry.first, entry.second->status(), dir);
items << new DirectoryItem(entry.first, entry.second->status(), found->first);
}

items.sort();
Expand All @@ -64,11 +70,14 @@ bool DirectoryTreeData::contains(const Path &path) const

const ui::Data &DirectoryTreeData::items(const Path &path) const
{
if (NativePath(path) != d->dir)
DE_ASSERT(contains(path));

const NativePath dir(path);
if (!d->pathItems.contains(dir))
{
d->populate(path);
d->populate(dir);
}
return d->items;
return *d->pathItems[dir];
}

} // namespace de

0 comments on commit 76369d5

Please sign in to comment.