72 lines
2.3 KiB
C++
72 lines
2.3 KiB
C++
#include "projectview.h"
|
|
#include "command_list.h"
|
|
|
|
#include <QInputDialog>
|
|
#include <QMenu>
|
|
#include <QVBoxLayout>
|
|
|
|
using namespace Components;
|
|
using namespace CommandList;
|
|
using namespace Schedule;
|
|
using namespace SplitFrame;
|
|
using namespace Core;
|
|
|
|
ProjectView::ProjectView(ViewPresent *host, CommandsDispatcher *core, Core::DocumentsManager *mgr, QWidget *parent)
|
|
: FnWrap<ProjectView, false>(host, parent), project_manager(mgr), source(core), view_present(new QTreeView(this)) {
|
|
auto layout = new QVBoxLayout(this);
|
|
layout->addWidget(view_present);
|
|
layout->setMargin(1);
|
|
|
|
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);
|
|
}
|
|
|
|
QModelIndex ProjectView::currentIndex() const { return view_present->currentIndex(); }
|
|
|
|
void ProjectView::menu_popup(const QPoint &p)
|
|
{
|
|
QMenu m;
|
|
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("移除节点");
|
|
}
|
|
|
|
|
|
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(); }
|