From 3bc1a4a06730640baee2f17f0fae152af6bd4a3d Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Mon, 20 Jan 2020 19:33:20 -0500 Subject: createDirectoryItem() and createFileItem() --- src/filetreemodel.cpp | 76 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 31 deletions(-) (limited to 'src/filetreemodel.cpp') diff --git a/src/filetreemodel.cpp b/src/filetreemodel.cpp index 493a432e..87de1d45 100644 --- a/src/filetreemodel.cpp +++ b/src/filetreemodel.cpp @@ -444,17 +444,7 @@ void FileTreeModel::addNewDirectories( // this is a new directory trace([&]{ log::debug("new dir {}", QString::fromStdWString(d->getName())); }); - auto item = std::make_unique( - &parentItem, 0, parentPath, L"", FileTreeItem::Directory, - d->getName(), L""); - - if (d->isEmpty()) { - // if this directory is empty, mark the item as loaded so the expand - // arrow doesn't show - item->setLoaded(true); - } - - toAdd.push_back(std::move(item)); + toAdd.push_back(createDirectoryItem(parentItem, parentPath, *d)); range.includeCurrent(); } @@ -568,26 +558,7 @@ void FileTreeModel::addNewFiles( // this is a new file trace([&]{ log::debug("new file {}", QString::fromStdWString(file->getName())); }); - bool isArchive = false; - int originID = file->getOrigin(isArchive); - - FileTreeItem::Flags flags = FileTreeItem::NoFlags; - - if (isArchive) { - flags |= FileTreeItem::FromArchive; - } - - if (!file->getAlternatives().empty()) { - flags |= FileTreeItem::Conflicted; - } - - auto item = std::make_unique( - &parentItem, originID, parentPath, file->getFullPath(), flags, - file->getName(), makeModName(*file, originID)); - - item->setLoaded(true); - - toAdd.push_back(std::move(item)); + toAdd.push_back(createFileItem(parentItem, parentPath, *file)); range.includeCurrent(); } @@ -600,6 +571,49 @@ void FileTreeModel::addNewFiles( range.add(std::move(toAdd)); } +std::unique_ptr FileTreeModel::createDirectoryItem( + FileTreeItem& parentItem, const std::wstring& parentPath, + const DirectoryEntry& d) +{ + auto item = std::make_unique( + &parentItem, 0, parentPath, L"", FileTreeItem::Directory, + d.getName(), L""); + + if (d.isEmpty()) { + // if this directory is empty, mark the item as loaded so the expand + // arrow doesn't show + item->setLoaded(true); + } + + return item; +} + +std::unique_ptr FileTreeModel::createFileItem( + FileTreeItem& parentItem, const std::wstring& parentPath, + const FileEntry& file) +{ + bool isArchive = false; + int originID = file.getOrigin(isArchive); + + FileTreeItem::Flags flags = FileTreeItem::NoFlags; + + if (isArchive) { + flags |= FileTreeItem::FromArchive; + } + + if (!file.getAlternatives().empty()) { + flags |= FileTreeItem::Conflicted; + } + + auto item = std::make_unique( + &parentItem, originID, parentPath, file.getFullPath(), flags, + file.getName(), makeModName(file, originID)); + + item->setLoaded(true); + + return item; +} + std::wstring FileTreeModel::makeModName( const MOShared::FileEntry& file, int originID) const { -- cgit v1.3.1