1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "filebrowser.h"
6#include "mainframe/treeviewkeeper.h"
7#include "base/abstractaction.h"
8#include "base/abstractcentral.h"
9#include "base/abstractwidget.h"
10#include "services/window/windowservice.h"
11
12#include <QLabel>
13#include <QSplitter>
14#include <QWidget>
15#include <QTextEdit>
16#include <QTreeView>
17#include <QGridLayout>
18#include <QTabWidget>
19
20using namespace dpfservice;
21
22namespace {
23const int treeWidgtMinWidth = 70;
24const int treeWidgetMinHeight = 400;
25const QString FileBrowser_TEXT = QWidget::tr("File Browser");
26}
27
28void FileBrowser::initialize()
29{
30
31}
32
33bool FileBrowser::start()
34{
35 auto &ctx = dpfInstance.serviceContext();
36 WindowService *windowService = ctx.service<WindowService>(WindowService::name());
37 if (windowService && windowService->addWidgetWorkspace) {
38 windowService->addWidgetWorkspace(FileBrowser_TEXT, createTreeWidget());
39 }
40 return true;
41}
42
43dpf::Plugin::ShutdownFlag FileBrowser::stop()
44{
45 return Sync;
46}
47
48AbstractWidget *FileBrowser::createTreeWidget()
49{
50 QWidget *treeWidget = new QWidget();
51 treeWidget->setMinimumSize({treeWidgtMinWidth, treeWidgetMinHeight});
52
53 QGridLayout* gridLayout = new QGridLayout();
54 gridLayout->setSpacing(0);
55 gridLayout->setMargin(0);
56
57 auto treeView = TreeViewKeeper::instance()->treeView();
58 treeView->setMinimumSize({treeWidgtMinWidth, treeWidgetMinHeight});
59
60 auto folderLabel = new QLabel();
61 QObject::connect(treeView, &TreeView::rootPathChanged,
62 folderLabel, &QLabel::setText,
63 Qt::UniqueConnection);
64
65 gridLayout->addWidget(folderLabel);
66 gridLayout->addWidget(treeView);
67 treeWidget->setLayout(gridLayout);
68
69 return new AbstractWidget(treeWidget);
70}
71
72
73