diff --git a/src/PrpShop/Main.cpp b/src/PrpShop/Main.cpp
index 108fbdb..7d47d06 100644
--- a/src/PrpShop/Main.cpp
+++ b/src/PrpShop/Main.cpp
@@ -84,6 +84,7 @@ PrpShopMain::PrpShopMain()
fActions[kTreeDelete] = new QAction(tr("&Delete"), this);
fActions[kTreeImport] = new QAction(tr("&Import..."), this);
fActions[kTreeExport] = new QAction(tr("E&xport..."), this);
+ fActions[kTreeNewObject] = new QAction(tr("&New Object..."), this);
fActions[kFileOpen]->setShortcut(Qt::CTRL + Qt::Key_O);
fActions[kFileSave]->setShortcut(Qt::CTRL + Qt::Key_S);
@@ -205,6 +206,7 @@ PrpShopMain::PrpShopMain()
connect(fActions[kTreeDelete], &QAction::triggered, this, &PrpShopMain::treeDelete);
connect(fActions[kTreeImport], &QAction::triggered, this, &PrpShopMain::treeImport);
connect(fActions[kTreeExport], &QAction::triggered, this, &PrpShopMain::treeExport);
+ connect(fActions[kTreeNewObject], &QAction::triggered, this, &PrpShopMain::createNewObject);
connect(fBrowserTree, &QTreeWidget::currentItemChanged,
this, &PrpShopMain::treeItemChanged);
@@ -448,6 +450,18 @@ void PrpShopMain::treeContextMenu(const QPoint& pos)
fActions[kTreeViewTargets]->setEnabled(pqHasTargets(item->obj()));
} else {
menu.addAction(fActions[kTreeImport]);
+ if (item->childCount() != 0) {
+ QPlasmaTreeItem* child = (QPlasmaTreeItem*)item->child(0);
+ if (child->type() == QPlasmaTreeItem::kTypeKO) {
+ auto obj_type = child->obj()->getKey()->getType();
+
+ menu.addAction(fActions[kTreeNewObject]);
+ fActions[kTreeNewObject]->setText(tr("New %1...").arg(
+ pqGetFriendlyClassName(obj_type))
+ );
+ fActions[kTreeNewObject]->setEnabled(pqIsValidKOType(obj_type));
+ }
+ }
}
menu.exec(fBrowserTree->viewport()->mapToGlobal(pos));
}
diff --git a/src/PrpShop/Main.h b/src/PrpShop/Main.h
index 70f1ec0..1d927d9 100644
--- a/src/PrpShop/Main.h
+++ b/src/PrpShop/Main.h
@@ -78,7 +78,7 @@ class PrpShopMain : public QMainWindow
// Tree Context Menu
kTreeClose, kTreeEdit, kTreeEditPRC, kTreeEditHex, kTreePreview,
- kTreeViewTargets, kTreeDelete, kTreeImport, kTreeExport,
+ kTreeViewTargets, kTreeDelete, kTreeImport, kTreeExport, kTreeNewObject,
kNumActions
};
diff --git a/src/PrpShop/QPlasmaUtils.cpp b/src/PrpShop/QPlasmaUtils.cpp
index 899484e..4835782 100644
--- a/src/PrpShop/QPlasmaUtils.cpp
+++ b/src/PrpShop/QPlasmaUtils.cpp
@@ -14,6 +14,7 @@
* along with PlasmaShop. If not, see .
*/
+#include
#include "QPlasmaUtils.h"
#include
#include
@@ -606,6 +607,12 @@ std::vector pqGetValidKOTypes()
return std::vector(s_typeList, s_typeList + s_numTypes);
}
+bool pqIsValidKOType(short objType)
+{
+ const auto valid_types = pqGetValidKOTypes();
+ return std::find(valid_types.begin(), valid_types.end(), objType) != valid_types.end();
+}
+
bool pqCanPreviewType(plCreatable* pCre)
{
short type = pCre->ClassIndex();
diff --git a/src/PrpShop/QPlasmaUtils.h b/src/PrpShop/QPlasmaUtils.h
index 6ec4e1b..565cea7 100644
--- a/src/PrpShop/QPlasmaUtils.h
+++ b/src/PrpShop/QPlasmaUtils.h
@@ -46,6 +46,7 @@ QIcon pqGetTypeIcon(int);
QString pqGetFriendlyClassName(int);
std::vector pqGetValidKOTypes();
+bool pqIsValidKOType(short);
bool pqCanPreviewType(plCreatable* pCre);
bool pqHasTargets(plCreatable* c);