Skip to content

Commit

Permalink
fix: [workspace]tree view issue
Browse files Browse the repository at this point in the history
support expand file item in my-share view.

Log: fix tree view issue
Bug: https://pms.uniontech.com/bug-view-235073.html
  • Loading branch information
Lighto-Ku committed Jan 4, 2024
1 parent 09eee4e commit 9fe2baf
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ ShareFileInfo::~ShareFileInfo()

QString ShareFileInfo::displayOf(const DisPlayInfoType type) const
{
if (DisPlayInfoType::kFileDisplayName == type)
return d->fileName();
if (DisPlayInfoType::kFileDisplayName == type) {
auto name = d->fileName();
if (name.isEmpty())
name = ProxyFileInfo::displayOf(type);
return name;
}
return ProxyFileInfo::displayOf(type);
}

Expand Down Expand Up @@ -56,12 +60,7 @@ QUrl ShareFileInfo::urlOf(const UrlInfoType type) const

bool ShareFileInfo::isAttributes(const OptInfoType type) const
{
switch (type) {
case FileIsType::kIsDir:
return true;
default:
return ProxyFileInfo::isAttributes(type);
}
return ProxyFileInfo::isAttributes(type);
}

bool ShareFileInfo::canAttributes(const CanableInfoType type) const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include <dfm-base/base/urlroute.h>
#include <dfm-base/base/schemefactory.h>
#include <dfm-base/utils/universalutils.h>
#include <dfm-base/file/local/localdiriterator.h>

#include <dfm-framework/event/event.h>

Expand All @@ -17,8 +19,10 @@ DFMBASE_USE_NAMESPACE

ShareIterator::ShareIterator(const QUrl &url, const QStringList &nameFilters, QDir::Filters filters, QDirIterator::IteratorFlags flags)
: AbstractDirIterator(url, nameFilters, filters, flags),
d(new ShareIteratorPrivate(this))
d(new ShareIteratorPrivate(this, url))
{
if (!UniversalUtils::urlEquals(url, ShareUtils::rootUrl()))
d->proxy = new LocalDirIterator(ShareUtils::convertToLocalUrl(url), nameFilters, filters, flags);
}

ShareIterator::~ShareIterator()
Expand All @@ -27,24 +31,38 @@ ShareIterator::~ShareIterator()

QUrl ShareIterator::next()
{
if (d->proxy)
return ShareUtils::makeShareUrl(d->proxy->next().path());

if (d->shares.isEmpty())
return {};

d->currentInfo = d->shares.takeFirst();

return fileUrl();
}

bool ShareIterator::hasNext() const
{
if (d->proxy)
return d->proxy->hasNext();

return !d->shares.isEmpty();
}

QString ShareIterator::fileName() const
{
if (d->proxy)
return d->proxy->fileName();

return d->currentInfo.value(ShareInfoKeys::kName).toString();
}

QUrl ShareIterator::fileUrl() const
{
if (d->proxy)
return ShareUtils::makeShareUrl(d->proxy->fileUrl().path());

return ShareUtils::makeShareUrl(d->currentInfo.value(ShareInfoKeys::kPath).toString());
}

Expand All @@ -55,13 +73,17 @@ const FileInfoPointer ShareIterator::fileInfo() const

QUrl ShareIterator::url() const
{
if (d->rootUrl.isValid())
return d->rootUrl;

return ShareUtils::rootUrl();
}

ShareIteratorPrivate::ShareIteratorPrivate(ShareIterator *qq)
ShareIteratorPrivate::ShareIteratorPrivate(ShareIterator *qq, const QUrl &url)
: q(qq)
{
shares = dpfSlotChannel->push("dfmplugin_dirshare", "slot_Share_AllShareInfos").value<QList<QVariantMap>>();
rootUrl = url;
}

ShareIteratorPrivate::~ShareIteratorPrivate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "events/shareeventscaller.h"

#include <dfm-base/dfm_menu_defines.h>
#include <dfm-base/base/schemefactory.h>
#include "plugins/common/core/dfmplugin-menu/menu_eventinterface_helper.h"

#include <QMenu>
Expand Down Expand Up @@ -126,18 +127,24 @@ void MyShareMenuScenePrivate::createFileMenu(QMenu *parent)
predicateAction[MySharesActionId::kOpenShareFolder] = act;

if (selectFiles.count() == 1) {
act = parent->addAction(predicateName[MySharesActionId::kOpenShareInNewWin]);
act->setProperty(ActionPropertyKey::kActionID, MySharesActionId::kOpenShareInNewWin);
predicateAction[MySharesActionId::kOpenShareInNewWin] = act;

act = parent->addAction(predicateName[MySharesActionId::kOpenShareInNewTab]);
act->setProperty(ActionPropertyKey::kActionID, MySharesActionId::kOpenShareInNewTab);
predicateAction[MySharesActionId::kOpenShareInNewTab] = act;
parent->addSeparator();

act = parent->addAction(predicateName[MySharesActionId::kCancleSharing]);
act->setProperty(ActionPropertyKey::kActionID, MySharesActionId::kCancleSharing);
predicateAction[MySharesActionId::kCancleSharing] = act;
auto info = InfoFactory::create<FileInfo>(selectFiles.first());
if (info && info->isAttributes(OptInfoType::kIsDir)) {
act = parent->addAction(predicateName[MySharesActionId::kOpenShareInNewWin]);
act->setProperty(ActionPropertyKey::kActionID, MySharesActionId::kOpenShareInNewWin);
predicateAction[MySharesActionId::kOpenShareInNewWin] = act;

act = parent->addAction(predicateName[MySharesActionId::kOpenShareInNewTab]);
act->setProperty(ActionPropertyKey::kActionID, MySharesActionId::kOpenShareInNewTab);
predicateAction[MySharesActionId::kOpenShareInNewTab] = act;
parent->addSeparator();

bool shared = dpfSlotChannel->push("dfmplugin_dirshare", "slot_Share_IsPathShared", info->pathOf(PathInfoType::kAbsoluteFilePath)).toBool();
if (shared) {
act = parent->addAction(predicateName[MySharesActionId::kCancleSharing]);
act->setProperty(ActionPropertyKey::kActionID, MySharesActionId::kCancleSharing);
predicateAction[MySharesActionId::kCancleSharing] = act;
}
}
}
parent->addSeparator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

#include "dfmplugin_myshares_global.h"

#include <QUrl>

namespace dfmbase {
class LocalDirIterator;
}

namespace dfmplugin_myshares {

class ShareIterator;
Expand All @@ -15,13 +21,17 @@ class ShareIteratorPrivate
friend class ShareIterator;

public:
explicit ShareIteratorPrivate(ShareIterator *qq);
explicit ShareIteratorPrivate(ShareIterator *qq, const QUrl &url);
~ShareIteratorPrivate();

private:
dfmbase::LocalDirIterator *proxy { nullptr };

ShareIterator *q { nullptr };
ShareInfoList shares;
ShareInfo currentInfo;

QUrl rootUrl;
};

}
Expand Down

0 comments on commit 9fe2baf

Please sign in to comment.