@@ -63,30 +63,38 @@ FileTreeWindow::FileTreeWindow(HashDatabase &database, const QString &gamePath,
6363 auto index = treeWidget->indexAt (pos);
6464
6565 if (index.isValid ()) {
66- auto path = m_searchModel->data (index, Qt::UserRole).toString ();
66+ const auto path = m_searchModel->data (index, FileTreeModel::CustomRoles::PathRole).toString ();
67+ const auto isUnknown = m_searchModel->data (index, FileTreeModel::CustomRoles::IsUnknown).toBool ();
68+ const auto isFolder = m_searchModel->data (index, FileTreeModel::CustomRoles::IsFolder).toBool ();
6769
6870 auto menu = new QMenu ();
6971
70- auto extractAction = menu->addAction (i18nc (" @action:inmenu" , " Extract…" ));
71- extractAction->setIcon (QIcon::fromTheme (QStringLiteral (" archive-extract-symbolic" )));
72- connect (extractAction, &QAction::triggered, this , [this , path] {
73- Q_EMIT extractFile (path);
74- });
75-
76- auto copyFilePathAction = menu->addAction (i18nc (" @action:inmenu" , " Copy file path" ));
77- copyFilePathAction->setIcon (QIcon::fromTheme (QStringLiteral (" edit-copy-symbolic" )));
78- connect (copyFilePathAction, &QAction::triggered, this , [this , path] {
79- QClipboard *clipboard = QGuiApplication::clipboard ();
80- clipboard->setText (path);
81- });
72+ // It doesn't make sense to extract folders
73+ if (!isFolder) {
74+ auto extractAction = menu->addAction (i18nc (" @action:inmenu" , " Extract…" ));
75+ extractAction->setIcon (QIcon::fromTheme (QStringLiteral (" archive-extract-symbolic" )));
76+ connect (extractAction, &QAction::triggered, this , [this , path] {
77+ Q_EMIT extractFile (path);
78+ });
79+ }
80+
81+ // It doesn't make sense to copy file paths for... a file or folder that doesn't have a path.
82+ if (!isUnknown) {
83+ auto copyFilePathAction = menu->addAction (i18nc (" @action:inmenu" , " Copy file path" ));
84+ copyFilePathAction->setIcon (QIcon::fromTheme (QStringLiteral (" edit-copy-symbolic" )));
85+ connect (copyFilePathAction, &QAction::triggered, this , [this , path] {
86+ QClipboard *clipboard = QGuiApplication::clipboard ();
87+ clipboard->setText (path);
88+ });
89+ }
8290
8391 menu->exec (treeWidget->mapToGlobal (pos));
8492 }
8593 });
8694
8795 connect (treeWidget, &QTreeView::clicked, [this , treeWidget](const QModelIndex &item) {
8896 if (item.isValid ()) {
89- auto path = m_searchModel->data (item, Qt::UserRole ).toString ();
97+ auto path = m_searchModel->data (item, FileTreeModel::CustomRoles::PathRole ).toString ();
9098 Q_EMIT pathSelected (path);
9199 }
92100 });
0 commit comments