Skip to content

Commit

Permalink
refactor: [workspace] show workspace file list
Browse files Browse the repository at this point in the history
reimpl workspace in qml, and set base workspace into mainwindow.

Log: refactor workspace
  • Loading branch information
Lighto-Ku committed Jul 1, 2024
1 parent a591bdf commit de5bc35
Show file tree
Hide file tree
Showing 32 changed files with 852 additions and 186 deletions.
2 changes: 2 additions & 0 deletions include/dfm-gui/appletfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class AppletFactory
bool regCreator(const QString &id, CreateFunc creator, QString *errorString = nullptr);
Applet *create(const QString &id, Containment *parent = nullptr, QString *errorString = nullptr);

QUrl pluginComponent(const QString &plugin, const QString &qmlFile, QString *errorString = nullptr) const;

private:
explicit AppletFactory();
QScopedPointer<AppletFactoryData> d;
Expand Down
54 changes: 31 additions & 23 deletions src/dfm-gui/appletfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,32 @@ Applet *AppletFactory::create(const QString &id, Containment *parent, QString *e
return info;
}

QUrl AppletFactory::pluginComponent(const QString &plugin, const QString &qmlFile, QString *errorString) const
{
QString error;
dfmbase::FinallyUtil finally([&]() {
if (errorString)
*errorString = error;
});

// 根据插件路径 + 文件名查找
dpf::PluginMetaObjectPointer info = dpf::LifeCycle::pluginMetaObj(plugin);
if (!info) {
error = QStringLiteral("Plugin not found");
return QUrl();
}

QString pluginPath = QFileInfo(info->fileName()).absolutePath();
QString fullPath = pluginPath + QDir::separator() + info->name() + QDir::separator() + qmlFile;
if (!QFile::exists(fullPath)) {
error = QStringLiteral("Qml file not exists");
return QUrl();
}

finally.dismiss();
return QUrl::fromLocalFile(fullPath);
}

class ViewAppletFacotryData
{
public:
Expand Down Expand Up @@ -125,36 +151,18 @@ ViewAppletFactory *ViewAppletFactory::instance()
bool ViewAppletFactory::regCreator(const QString &plugin, const QString &qmlFile, const QString &scheme,
CreateFunc creator, QString *errorString)
{
QString error;
dfmbase::FinallyUtil finally([&]() {
if (errorString)
*errorString = error;
});

// 根据插件路径 + 文件名查找
dpf::PluginMetaObjectPointer info = dpf::LifeCycle::pluginMetaObj(plugin);
if (!info) {
error = QStringLiteral("Plugin not found");
return false;
}

QString pluginPath = QFileInfo(info->fileName()).absolutePath();
QString fullPath = pluginPath + QDir::separator() + info->name() + QDir::separator() + qmlFile;
if (!QFile::exists(fullPath)) {
error = QStringLiteral("Qml file not exists");
QUrl qmlUrl = AppletFactory::instance()->pluginComponent(plugin, qmlFile, errorString);
if (!qmlUrl.isValid())
return false;
}

QUrl qmlUrl = QUrl::fromLocalFile(fullPath);

if (d->constructList.contains(scheme)) {
error = "The current url has registered "
"the associated construction class";
if (errorString)
*errorString = "The current url has registered "
"the associated construction class";
return false;
}

d->constructList.insert(scheme, { qmlUrl, creator });
finally.dismiss();
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/dfm-gui/windowmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ WindowManager::Handle WindowManager::createWindow(const QUrl &url, const QString
Handle handle = d->createQuickWindow(pluginName, quickId, var);
if (handle) {
handle->loadState();
handle->setCurrentUrl(url);
handle->setCurrentUrl(showedUrl);
d->connectWindowHandle(handle);

if (1 == d->windows.size()) {
Expand Down
11 changes: 2 additions & 9 deletions src/plugins/filemanager/core/dfmplugin-core/FileWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ ApplicationWindow {
DWindow.enabled: true
flags: Qt.Window | Qt.WindowMinMaxButtonsHint | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
height: 600
minimumHeight: 380
minimumWidth: 600
minimumHeight: 600
minimumWidth: 800
width: 800

// TODO: 待评估方案
Expand Down Expand Up @@ -51,15 +51,13 @@ ApplicationWindow {
// For local module test
ActionMenu {
}

Connections {
function onWidthChanged(width) {
}

enabled: Window.window !== null
target: Window.window
}

RowLayout {
anchors.fill: parent

Expand All @@ -81,14 +79,12 @@ ApplicationWindow {
Layout.preferredWidth: parent.width
color: "lightyellow"
}

LayoutItemProxy {
id: sidebar

Layout.fillHeight: true
}
}

AnimationHSpliter {
id: spliter

Expand All @@ -107,7 +103,6 @@ ApplicationWindow {
}
}
}

ColumnLayout {
Layout.fillHeight: true
Layout.fillWidth: true
Expand All @@ -117,7 +112,6 @@ ApplicationWindow {

onTargetChanged: target => {}
}

RowLayout {
Layout.fillHeight: true
Layout.fillWidth: true
Expand All @@ -127,7 +121,6 @@ ApplicationWindow {
id: workspace

}

LayoutItemProxy {
id: detailspace

Expand Down
10 changes: 5 additions & 5 deletions src/plugins/filemanager/core/dfmplugin-sidebar/Sidebar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ AppletItem {
showDirsFirst: true
}
}
Text {
color: "lightgray"
font.pointSize: 36
text: "sidebar"
}
// Text {
// color: "lightgray"
// font.pointSize: 36
// text: "sidebar"
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ target_include_directories(${PROJECT_NAME}

target_link_libraries(${PROJECT_NAME}
DFM::base
DFM::gui
DFM::framework
${DtkWidget_LIBRARIES}
)
Expand Down
41 changes: 0 additions & 41 deletions src/plugins/filemanager/core/dfmplugin-workspace/Workspace.qml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ enum class DirOpenMode : uint8_t {
kOpenInCurrentWindow,
kOpenNewWindow,
kAwaysInCurrentWindow,
//kForceOpenNewWindow // Todo(yanghao): ???
// kForceOpenNewWindow // Todo(yanghao): ???
};

// view defines
Expand Down Expand Up @@ -89,6 +89,8 @@ inline constexpr int kMaxTabCount { 8 };
// view select box
inline constexpr int kSelectBoxLineWidth { 2 };

inline char kWorkspaceUri[] { "org.deepin.filemanager.workspace" };

namespace PropertyKey {
inline constexpr char kScheme[] { "Property_Key_Scheme" };
inline constexpr char kKeepShow[] { "Property_Key_KeepShow" };
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "fileviewcontainment.h"

#include <dfm-gui/panel.h>
#include <dfm-gui/applet.h>
#include <dfm-gui/appletitem.h>
#include <dfm-gui/appletfactory.h>

#include <dfm-framework/dpf.h>
#include <dfm-base/dfm_event_defines.h>

using namespace dfmgui;
using namespace dfmplugin_workspace;

FileViewContainment::FileViewContainment(QObject *parent)
: Containment(parent)
{
}

quint64 FileViewContainment::getWinId()
{
return this->panel()->windId();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef FILEVIEWCONTAINMENT_H
#define FILEVIEWCONTAINMENT_H

#include <dfm-gui/containment.h>

#include <QObject>

DFMGUI_BEGIN_NAMESPACE
class AppletItem;
DFMGUI_END_NAMESPACE

namespace dfmplugin_workspace {

class FileViewContainment : public dfmgui::Containment
{
Q_OBJECT
public:
explicit FileViewContainment(QObject *parent = nullptr);

Q_INVOKABLE quint64 getWinId();
};

} // namespace dfmplugin_workspace

#endif // FILEVIEWCONTAINMENT_H
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ FileItemData::FileItemData(const SortInfoPointer &info, FileItemData *parent)
url(info->fileUrl()),
sortInfo(info)
{
const_cast<FileItemData *>(this)->info = InfoFactory::create<FileInfo>(url);
}

void FileItemData::setParentData(FileItemData *p)
Expand Down Expand Up @@ -111,7 +112,12 @@ QVariant FileItemData::data(int role) const
return "-";
}
case kItemIconRole:
return fileIcon();
// return fileIcon();
if (info->isFile())
// return "file:///usr/share/icons/bloom/mimetypes/32/application-json.svg";
return "application-json";
// return "file:///usr/share/icons/bloom/places/32/folder.svg";
return "folder";
case kItemFileSizeRole:
if (info)
return info->displayOf(DisPlayInfoType::kSizeDisplayName);
Expand Down
Loading

0 comments on commit de5bc35

Please sign in to comment.