Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libgui|Widgets: Basic implementation of DirectoryTreeData
- Loading branch information
Showing
8 changed files
with
194 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#include "gui/directorytreedata.h" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** @file directorytreedata.h Native filesystem directory tree. | ||
* | ||
* @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 "../ui/Item" | ||
#include "../ui/TreeData" | ||
#include <de/File> | ||
|
||
namespace de { | ||
|
||
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(); | ||
|
||
// Implements ui::TreeData. | ||
bool contains(const Path &path) const override; | ||
const ui::Data &items(const Path &path) const override; | ||
|
||
private: | ||
DE_PRIVATE(d) | ||
}; | ||
|
||
} // namespace de |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** @file treedata.h Data model for a tree of lists. | ||
* | ||
* @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 "../ui/Data" | ||
#include <de/Path> | ||
|
||
namespace de { | ||
namespace ui { | ||
|
||
/** | ||
* Data model representing a tree of lists. | ||
* | ||
* @ingroup uidata | ||
*/ | ||
class LIBGUI_PUBLIC TreeData | ||
{ | ||
public: | ||
virtual ~TreeData() = default; | ||
|
||
virtual bool contains(const Path &path) const = 0; | ||
virtual const Data &items(const Path &path) const = 0; | ||
}; | ||
|
||
} // namespace ui | ||
} // namespace de |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#include "../gui/treedata.h" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** @file directorytreedata.cpp Native filesystem directory tree. | ||
* | ||
* @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> | ||
*/ | ||
|
||
#include "de/DirectoryTreeData" | ||
#include "de/ui/ListData" | ||
|
||
#include <de/DirectoryFeed> | ||
#include <de/Folder> | ||
|
||
namespace de { | ||
|
||
DE_PIMPL(DirectoryTreeData) | ||
{ | ||
NativePath dir; | ||
ui::ListDataT<DirectoryItem> items; | ||
|
||
Impl(Public *i) : Base(i) | ||
{} | ||
|
||
void populate(const NativePath &path) | ||
{ | ||
// Get rid of the previous contents. | ||
items.clear(); | ||
|
||
// Populate a folder with the directory contents. | ||
dir = path; | ||
Folder folder(path.fileName()); | ||
folder.attach(new DirectoryFeed(dir)); | ||
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.sort(); | ||
} | ||
}; | ||
|
||
DirectoryTreeData::DirectoryTreeData() | ||
: d(new Impl(this)) | ||
{} | ||
|
||
bool DirectoryTreeData::contains(const Path &path) const | ||
{ | ||
return NativePath(path).isDirectory(); | ||
} | ||
|
||
const ui::Data &DirectoryTreeData::items(const Path &path) const | ||
{ | ||
if (NativePath(path) != d->dir) | ||
{ | ||
d->populate(path); | ||
} | ||
return d->items; | ||
} | ||
|
||
} // namespace de |