From f0543c5500f3b188d8b69eb0ee02ee5d262c5e59 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sun, 17 Nov 2024 17:41:00 +0400 Subject: [PATCH 1/2] Implement a context menu for data directories page (feature 8130) --- CHANGELOG.md | 1 + apps/launcher/datafilespage.cpp | 45 +++++++++++++++++++++++++++++++ apps/launcher/datafilespage.hpp | 5 ++++ apps/launcher/ui/datafilespage.ui | 3 +++ files/lang/launcher_de.ts | 8 ++++++ files/lang/launcher_en.ts | 8 ++++++ files/lang/launcher_fr.ts | 8 ++++++ files/lang/launcher_ru.ts | 8 ++++++ files/lang/launcher_sv.ts | 8 ++++++ 9 files changed, 94 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c22ac65daf2..cbd918ddb20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -274,6 +274,7 @@ Feature #8067: Support Game Mode on macOS Feature #8078: OpenMW-CS Terrain Equalize Tool Feature #8087: Creature movement flags are not exposed + Feature #8130: Launcher: Add the ability to open a selected data directory in the file browser Feature #8145: Starter spell flag is not exposed Task #5859: User openmw-cs.cfg has comment talking about settings.cfg Task #5896: Do not use deprecated MyGUI properties diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 086707b0532..45518b4fe4d 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -1,7 +1,9 @@ #include "datafilespage.hpp" #include "maindialog.hpp" +#include #include +#include #include #include #include @@ -244,6 +246,31 @@ void Launcher::DataFilesPage::buildView() &DataFilesPage::navMeshToolFinished); buildArchiveContextMenu(); + buildDataFilesContextMenu(); +} + +void Launcher::DataFilesPage::slotCopySelectedItemsPaths() +{ + QClipboard* clipboard = QApplication::clipboard(); + QString filepaths; + + for (QListWidgetItem* item : ui.directoryListWidget->selectedItems()) + { + QString path = qvariant_cast(item->data(Qt::UserRole)).originalRepresentation; + filepaths += path + "\n"; + } + + if (!filepaths.isEmpty()) + { + clipboard->setText(filepaths); + } +} + +void Launcher::DataFilesPage::slotOpenSelectedItemsPaths() +{ + QListWidgetItem* item = ui.directoryListWidget->currentItem(); + QUrl confFolderUrl = QUrl::fromLocalFile(qvariant_cast(item->data(Qt::UserRole)).value); + QDesktopServices::openUrl(confFolderUrl); } void Launcher::DataFilesPage::buildArchiveContextMenu() @@ -256,6 +283,18 @@ void Launcher::DataFilesPage::buildArchiveContextMenu() mArchiveContextMenu->addAction(tr("&Uncheck Selected"), this, SLOT(slotUncheckMultiSelectedItems())); } +void Launcher::DataFilesPage::buildDataFilesContextMenu() +{ + connect(ui.directoryListWidget, &QListWidget::customContextMenuRequested, this, + &DataFilesPage::slotShowDataFilesContextMenu); + + mDataFilesContextMenu = new QMenu(ui.directoryListWidget); + mDataFilesContextMenu->addAction( + tr("&Copy Path(s) to Clipboard"), this, &Launcher::DataFilesPage::slotCopySelectedItemsPaths); + mDataFilesContextMenu->addAction( + tr("&Open Path in File Explorer"), this, &Launcher::DataFilesPage::slotOpenSelectedItemsPaths); +} + bool Launcher::DataFilesPage::loadSettings() { ui.navMeshMaxSizeSpinBox->setValue(getMaxNavMeshDbFileSizeMiB()); @@ -832,6 +871,12 @@ void Launcher::DataFilesPage::slotShowArchiveContextMenu(const QPoint& pos) mArchiveContextMenu->exec(globalPos); } +void Launcher::DataFilesPage::slotShowDataFilesContextMenu(const QPoint& pos) +{ + QPoint globalPos = ui.directoryListWidget->viewport()->mapToGlobal(pos); + mDataFilesContextMenu->exec(globalPos); +} + void Launcher::DataFilesPage::setCheckStateForMultiSelectedItems(bool checked) { Qt::CheckState checkState = checked ? Qt::Checked : Qt::Unchecked; diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index 7e347c08443..5d03cdf800c 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -42,6 +42,7 @@ namespace Launcher ContentSelectorView::ContentSelector* mSelector; Ui::DataFilesPage ui; QMenu* mArchiveContextMenu; + QMenu* mDataFilesContextMenu; public: explicit DataFilesPage(const Files::ConfigurationManager& cfg, Config::GameSettings& gameSettings, @@ -79,6 +80,7 @@ namespace Launcher void moveSources(QListWidget* sourceList, int step); void slotShowArchiveContextMenu(const QPoint& pos); + void slotShowDataFilesContextMenu(const QPoint& pos); void slotCheckMultiSelectedItems(); void slotUncheckMultiSelectedItems(); @@ -129,6 +131,7 @@ namespace Launcher void addArchivesFromDir(const QString& dir); void buildView(); void buildArchiveContextMenu(); + void buildDataFilesContextMenu(); void setCheckStateForMultiSelectedItems(bool checked); void setProfile(int index, bool savePrevious); void setProfile(const QString& previous, const QString& current, bool savePrevious); @@ -140,6 +143,8 @@ namespace Launcher void reloadCells(QStringList selectedFiles); void refreshDataFilesView(); void updateNavMeshProgress(int minDataSize); + void slotCopySelectedItemsPaths(); + void slotOpenSelectedItemsPaths(); /** * Returns the file paths of all selected content files diff --git a/apps/launcher/ui/datafilespage.ui b/apps/launcher/ui/datafilespage.ui index 1f537b1cc84..65236ca5ca9 100644 --- a/apps/launcher/ui/datafilespage.ui +++ b/apps/launcher/ui/datafilespage.ui @@ -58,6 +58,9 @@ QAbstractItemView::ExtendedSelection + + Qt::CustomContextMenu + diff --git a/files/lang/launcher_de.ts b/files/lang/launcher_de.ts index 080fa5f57c3..86773e5a54f 100644 --- a/files/lang/launcher_de.ts +++ b/files/lang/launcher_de.ts @@ -390,6 +390,14 @@ to default Morrowind fonts. Check this box if you still prefer original fonts ov This archive is enabled in an openmw.cfg other than the user one + + &Copy Path(s) to Clipboard + + + + &Open Path in File Explorer + + Launcher::GraphicsPage diff --git a/files/lang/launcher_en.ts b/files/lang/launcher_en.ts index 99ab3ea974f..a0319318e8f 100644 --- a/files/lang/launcher_en.ts +++ b/files/lang/launcher_en.ts @@ -390,6 +390,14 @@ to default Morrowind fonts. Check this box if you still prefer original fonts ov Delete + + &Copy Path(s) to Clipboard + + + + &Open Path in File Explorer + + Launcher::GraphicsPage diff --git a/files/lang/launcher_fr.ts b/files/lang/launcher_fr.ts index 5d05d85138e..569a460cd00 100644 --- a/files/lang/launcher_fr.ts +++ b/files/lang/launcher_fr.ts @@ -390,6 +390,14 @@ to default Morrowind fonts. Check this box if you still prefer original fonts ov This archive is enabled in an openmw.cfg other than the user one Cette archive est activée dans un fichier openmw.cfg qui n'est pas celui de l'utilisateur. + + &Copy Path(s) to Clipboard + &Copier l'emplacement dans le presse papier + + + &Open Path in File Explorer + &Ouvrir l'emplacement dans l'explorateur de fichiers + Launcher::GraphicsPage diff --git a/files/lang/launcher_ru.ts b/files/lang/launcher_ru.ts index cee55f86def..879f24dc762 100644 --- a/files/lang/launcher_ru.ts +++ b/files/lang/launcher_ru.ts @@ -392,6 +392,14 @@ to default Morrowind fonts. Check this box if you still prefer original fonts ov This archive is enabled in an openmw.cfg other than the user one Этот архив включен в openmw.cfg, не являющемся пользовательским + + &Copy Path(s) to Clipboard + &Скопировать пути в буфер обмена + + + &Open Path in File Explorer + &Открыть путь в диспетчере файлов + Launcher::GraphicsPage diff --git a/files/lang/launcher_sv.ts b/files/lang/launcher_sv.ts index 969c609bf3b..f2cca2346ca 100644 --- a/files/lang/launcher_sv.ts +++ b/files/lang/launcher_sv.ts @@ -393,6 +393,14 @@ de ordinarie fonterna i Morrowind. Bocka denna ruta om du ändå föredrar ordin This archive is enabled in an openmw.cfg other than the user one Detta arkiv är aktiverat i en annan openmw.cfg än användarens + + &Copy Path(s) to Clipboard + &Kopiera sökväg(ar) till klippbordet + + + &Open Path in File Explorer + Öppna katalogen i filutforskaren + Launcher::GraphicsPage From bd5924727005c3ee16ae34fa495689aae39112cf Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Wed, 20 Nov 2024 09:04:22 +0400 Subject: [PATCH 2/2] Avoid trailing line breaks --- apps/launcher/datafilespage.cpp | 6 +++--- components/contentselector/view/contentselector.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 45518b4fe4d..9bb54fdb8e6 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -252,17 +252,17 @@ void Launcher::DataFilesPage::buildView() void Launcher::DataFilesPage::slotCopySelectedItemsPaths() { QClipboard* clipboard = QApplication::clipboard(); - QString filepaths; + QStringList filepaths; for (QListWidgetItem* item : ui.directoryListWidget->selectedItems()) { QString path = qvariant_cast(item->data(Qt::UserRole)).originalRepresentation; - filepaths += path + "\n"; + filepaths.push_back(path); } if (!filepaths.isEmpty()) { - clipboard->setText(filepaths); + clipboard->setText(filepaths.join("\n")); } } diff --git a/components/contentselector/view/contentselector.cpp b/components/contentselector/view/contentselector.cpp index 2bcb73689e2..bce136b3351 100644 --- a/components/contentselector/view/contentselector.cpp +++ b/components/contentselector/view/contentselector.cpp @@ -320,17 +320,17 @@ void ContentSelectorView::ContentSelector::slotCheckMultiSelectedItems() void ContentSelectorView::ContentSelector::slotCopySelectedItemsPaths() { QClipboard* clipboard = QApplication::clipboard(); - QString filepaths; + QStringList filepaths; for (const QModelIndex& index : ui->addonView->selectionModel()->selectedIndexes()) { int row = mAddonProxyModel->mapToSource(index).row(); const ContentSelectorModel::EsmFile* file = mContentModel->item(row); - filepaths += file->filePath() + "\n"; + filepaths.push_back(file->filePath()); } if (!filepaths.isEmpty()) { - clipboard->setText(filepaths); + clipboard->setText(filepaths.join("\n")); } }