Skip to content

Commit

Permalink
Merge pull request #68 from Deledrius/new_object
Browse files Browse the repository at this point in the history
Add New Object option to folder context menus.
  • Loading branch information
zrax committed Oct 20, 2022
2 parents 85062cd + 0656449 commit 715ba56
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/PrpShop/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion src/PrpShop/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
7 changes: 7 additions & 0 deletions src/PrpShop/QPlasmaUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* along with PlasmaShop. If not, see <http://www.gnu.org/licenses/>.
*/

#include <algorithm>
#include "QPlasmaUtils.h"
#include <ResManager/pdUnifiedTypeMap.h>
#include <PRP/Object/plSceneObject.h>
Expand Down Expand Up @@ -606,6 +607,12 @@ std::vector<short> pqGetValidKOTypes()
return std::vector<short>(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();
Expand Down
1 change: 1 addition & 0 deletions src/PrpShop/QPlasmaUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ QIcon pqGetTypeIcon(int);
QString pqGetFriendlyClassName(int);

std::vector<short> pqGetValidKOTypes();
bool pqIsValidKOType(short);
bool pqCanPreviewType(plCreatable* pCre);
bool pqHasTargets(plCreatable* c);

Expand Down

0 comments on commit 715ba56

Please sign in to comment.