69 lines
2.1 KiB
C++
69 lines
2.1 KiB
C++
#include "projectpresent.h"
|
|
#include "command_list.h"
|
|
|
|
#include <QInputDialog>
|
|
#include <QMenu>
|
|
#include <QVBoxLayout>
|
|
|
|
using namespace Components;
|
|
using namespace CommandList;
|
|
|
|
ProjectPresent::ProjectPresent(Core::AppCore *core, QWidget *parent)
|
|
: QWidget(parent), source(core), view_present(new QTreeView(this))
|
|
{
|
|
auto layout = new QVBoxLayout(this);
|
|
|
|
layout->addWidget(view_present);
|
|
auto mgr = core->disp_core->get<DocumentsManager>(NAME(DocumentsManager));
|
|
view_present->setModel(mgr->projectManager()->model());
|
|
|
|
connect(view_present, &QTreeView::customContextMenuRequested,
|
|
this, &ProjectPresent::menu_popup);
|
|
connect(view_present, &QTreeView::doubleClicked,
|
|
this, &ProjectPresent::open_target);
|
|
}
|
|
|
|
QString ProjectPresent::name() const
|
|
{
|
|
return NAME(ProjectPresent);
|
|
}
|
|
|
|
void ProjectPresent::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->disp_core->postCommand(NewPackage(path_string));
|
|
});
|
|
|
|
auto index = this->view_present->currentIndex();
|
|
if(index.isValid()){
|
|
auto mgr = source->disp_core->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->converter(index);
|
|
source->disp_core->postCommand(NewFile(path, name, it));
|
|
});
|
|
}
|
|
|
|
m.addSeparator();
|
|
m.addAction("移除节点");
|
|
}
|
|
|
|
|
|
m.exec(mapToGlobal(p));
|
|
}
|
|
|
|
void ProjectPresent::open_target(const QModelIndex &t)
|
|
{
|
|
auto mgr = source->disp_core->get<DocumentsManager>(NAME(DocumentsManager));
|
|
auto path = mgr->converter(t);
|
|
source->disp_core->postCommand(OpenFile(path));
|
|
}
|