105 lines
3.1 KiB
C++
105 lines
3.1 KiB
C++
#include "project_view.h"
|
|
#include "command_list.h"
|
|
|
|
#include <QInputDialog>
|
|
#include <QMenu>
|
|
#include <QVBoxLayout>
|
|
|
|
using namespace Components;
|
|
using namespace CommandList;
|
|
using namespace Schedule;
|
|
using namespace Core;
|
|
|
|
ProjectView::ProjectView(QWidget *parent, CommandsDispatcher *core, Core::DocumentsManager *mgr)
|
|
: QWidget(parent), project_manager(mgr), source(core), view_present(new QTreeView(this)), menu_root(new QMenu("项目管理")) {
|
|
auto layout = new QVBoxLayout(this);
|
|
layout->addWidget(view_present);
|
|
layout->setMargin(1);
|
|
|
|
this->menGenerate(menu_root);
|
|
|
|
view_present->setModel(mgr->projectManager()->model());
|
|
view_present->setHeaderHidden(true);
|
|
|
|
view_present->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
connect(view_present, &QTreeView::customContextMenuRequested, this, &ProjectView::menu_popup);
|
|
connect(view_present, &QTreeView::doubleClicked, this, &ProjectView::open_target);
|
|
connect(view_present->selectionModel(), &QItemSelectionModel::currentChanged, this, &ProjectView::currentIndexChanged);
|
|
}
|
|
|
|
QMenu *ProjectView::menGenerate(QMenu *m)
|
|
{
|
|
if(!m)
|
|
return menu_root;
|
|
|
|
m->addAction("新建路径", [this](){
|
|
auto path_string = QInputDialog::getText(this, "输入路径定义/packa/packb/packc", "路径定义:");
|
|
if(path_string.isEmpty())
|
|
return;
|
|
|
|
source->postCommand(NewPackage(path_string));
|
|
});
|
|
|
|
auto index = this->view_present->currentIndex();
|
|
if(index.isValid()){
|
|
auto mgr = source->get<DocumentsManager>(NAME(DocumentsManager));
|
|
auto menu = m->addMenu("新建文件");
|
|
auto views = mgr->fileTypes();
|
|
for (auto &it : views) {
|
|
menu->addAction(it, [this, it, &index, mgr]() {
|
|
auto name = QInputDialog::getText(this, "输入文件名称", "文件名称");
|
|
auto path = mgr->convertPath(index);
|
|
source->postCommand(NewFile(path, name, it));
|
|
});
|
|
}
|
|
|
|
m->addSeparator();
|
|
m->addAction("移除节点", [&index, this]() { source->postCommand(DeleteTarget(index)); });
|
|
}
|
|
return m;
|
|
}
|
|
|
|
ProjectView::ProjectView() : project_manager(nullptr), source(nullptr), view_present(nullptr), menu_root(nullptr) {}
|
|
|
|
ExtendView *ProjectView::newInst(QWidget *parent, XApp *core)
|
|
{
|
|
return new ProjectView(parent, core->cmdsPort(), core->docsPort());
|
|
}
|
|
|
|
QMenu *ProjectView::bindMenu() const
|
|
{
|
|
return menu_root;
|
|
}
|
|
|
|
QString ProjectView::typeName() const
|
|
{
|
|
return "项目管理";
|
|
}
|
|
|
|
ExtendType ProjectView::type() const
|
|
{
|
|
return ExtendType::FEATURE_PRESENT;
|
|
}
|
|
|
|
QWidget *ProjectView::presentWidget() const
|
|
{
|
|
return const_cast<ProjectView*>(this);
|
|
}
|
|
|
|
void ProjectView::saveProcess() { project_manager->save(); }
|
|
|
|
void ProjectView::menu_popup(const QPoint &p)
|
|
{
|
|
auto m = menGenerate();
|
|
m->exec(mapToGlobal(p));
|
|
}
|
|
|
|
void ProjectView::open_target(const QModelIndex &t)
|
|
{
|
|
auto mgr = source->get<DocumentsManager>(NAME(DocumentsManager));
|
|
auto path = mgr->convertPath(t);
|
|
source->postCommand(OpenFile(path));
|
|
}
|
|
|
|
void ProjectView::closeProcess() { project_manager->save(); }
|