Skip to content

Commit

Permalink
Merge branch 'data_files_menu' into 'master'
Browse files Browse the repository at this point in the history
Implement a context menu for data directories page

Closes #8130

See merge request OpenMW/openmw!4458
  • Loading branch information
psi29a committed Nov 21, 2024
2 parents 17203c5 + bd59247 commit cf3badb
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,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
Expand Down
45 changes: 45 additions & 0 deletions apps/launcher/datafilespage.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "datafilespage.hpp"
#include "maindialog.hpp"

#include <QClipboard>
#include <QDebug>
#include <QDesktopServices>
#include <QFileDialog>
#include <QList>
#include <QMessageBox>
Expand Down Expand Up @@ -244,6 +246,31 @@ void Launcher::DataFilesPage::buildView()
&DataFilesPage::navMeshToolFinished);

buildArchiveContextMenu();
buildDataFilesContextMenu();
}

void Launcher::DataFilesPage::slotCopySelectedItemsPaths()
{
QClipboard* clipboard = QApplication::clipboard();
QStringList filepaths;

for (QListWidgetItem* item : ui.directoryListWidget->selectedItems())
{
QString path = qvariant_cast<Config::SettingValue>(item->data(Qt::UserRole)).originalRepresentation;
filepaths.push_back(path);
}

if (!filepaths.isEmpty())
{
clipboard->setText(filepaths.join("\n"));
}
}

void Launcher::DataFilesPage::slotOpenSelectedItemsPaths()
{
QListWidgetItem* item = ui.directoryListWidget->currentItem();
QUrl confFolderUrl = QUrl::fromLocalFile(qvariant_cast<Config::SettingValue>(item->data(Qt::UserRole)).value);
QDesktopServices::openUrl(confFolderUrl);
}

void Launcher::DataFilesPage::buildArchiveContextMenu()
Expand All @@ -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());
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions apps/launcher/datafilespage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions apps/launcher/ui/datafilespage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
</widget>
</item>
<item row="0" column="1">
Expand Down
6 changes: 3 additions & 3 deletions components/contentselector/view/contentselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}

Expand Down
8 changes: 8 additions & 0 deletions files/lang/launcher_de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,14 @@ to default Morrowind fonts. Check this box if you still prefer original fonts ov
<source>This archive is enabled in an openmw.cfg other than the user one</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&amp;Copy Path(s) to Clipboard</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&amp;Open Path in File Explorer</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Launcher::GraphicsPage</name>
Expand Down
8 changes: 8 additions & 0 deletions files/lang/launcher_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,14 @@ to default Morrowind fonts. Check this box if you still prefer original fonts ov
<source>Delete</source>
<translation></translation>
</message>
<message>
<source>&amp;Copy Path(s) to Clipboard</source>
<translation></translation>
</message>
<message>
<source>&amp;Open Path in File Explorer</source>
<translation></translation>
</message>
</context>
<context>
<name>Launcher::GraphicsPage</name>
Expand Down
8 changes: 8 additions & 0 deletions files/lang/launcher_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,14 @@ to default Morrowind fonts. Check this box if you still prefer original fonts ov
<source>This archive is enabled in an openmw.cfg other than the user one</source>
<translation>Cette archive est activée dans un fichier openmw.cfg qui n&apos;est pas celui de l&apos;utilisateur.</translation>
</message>
<message>
<source>&amp;Copy Path(s) to Clipboard</source>
<translation>&amp;Copier l&apos;emplacement dans le presse papier</translation>
</message>
<message>
<source>&amp;Open Path in File Explorer</source>
<translation>&amp;Ouvrir l&apos;emplacement dans l&apos;explorateur de fichiers</translation>
</message>
</context>
<context>
<name>Launcher::GraphicsPage</name>
Expand Down
8 changes: 8 additions & 0 deletions files/lang/launcher_ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,14 @@ to default Morrowind fonts. Check this box if you still prefer original fonts ov
<source>This archive is enabled in an openmw.cfg other than the user one</source>
<translation>Этот архив включен в openmw.cfg, не являющемся пользовательским</translation>
</message>
<message>
<source>&amp;Copy Path(s) to Clipboard</source>
<translation>&amp;Скопировать пути в буфер обмена</translation>
</message>
<message>
<source>&amp;Open Path in File Explorer</source>
<translation>&amp;Открыть путь в диспетчере файлов</translation>
</message>
</context>
<context>
<name>Launcher::GraphicsPage</name>
Expand Down
8 changes: 8 additions & 0 deletions files/lang/launcher_sv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,14 @@ de ordinarie fonterna i Morrowind. Bocka denna ruta om du ändå föredrar ordin
<source>This archive is enabled in an openmw.cfg other than the user one</source>
<translation>Detta arkiv är aktiverat i en annan openmw.cfg än användarens</translation>
</message>
<message>
<source>&amp;Copy Path(s) to Clipboard</source>
<translation>&amp;Kopiera sökväg(ar) till klippbordet</translation>
</message>
<message>
<source>&amp;Open Path in File Explorer</source>
<translation>Öppna katalogen i filutforskaren</translation>
</message>
</context>
<context>
<name>Launcher::GraphicsPage</name>
Expand Down

0 comments on commit cf3badb

Please sign in to comment.