initial support for add to PATH action
Signed-off-by: Ryan Cao <70191398+ryanccn@users.noreply.github.com>
This commit is contained in:
parent
2999afe781
commit
7b1e68bfa8
@ -163,6 +163,19 @@ bool ensureFolderPathExists(QString foldernamepath)
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool symlink(const QString& source, const QString& target)
|
||||||
|
{
|
||||||
|
std::error_code err;
|
||||||
|
|
||||||
|
fs::create_symlink(toStdString(source), toStdString(target));
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
qWarning() << "Failed to symlink files:" << QString::fromStdString(err.message());
|
||||||
|
}
|
||||||
|
|
||||||
|
return err.value() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool copy::operator()(const QString& offset)
|
bool copy::operator()(const QString& offset)
|
||||||
{
|
{
|
||||||
using copy_opts = fs::copy_options;
|
using copy_opts = fs::copy_options;
|
||||||
|
@ -53,6 +53,11 @@ class FileSystemException : public ::Exception {
|
|||||||
*/
|
*/
|
||||||
void write(const QString& filename, const QByteArray& data);
|
void write(const QString& filename, const QByteArray& data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create a symlink
|
||||||
|
*/
|
||||||
|
bool symlink(const QString& target, const QString& link);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read data from a file safely\
|
* read data from a file safely\
|
||||||
*/
|
*/
|
||||||
|
@ -61,6 +61,7 @@
|
|||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QFileDialog>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
@ -253,6 +254,7 @@ public:
|
|||||||
QMenu * helpMenu = nullptr;
|
QMenu * helpMenu = nullptr;
|
||||||
TranslatedToolButton helpMenuButton;
|
TranslatedToolButton helpMenuButton;
|
||||||
TranslatedAction actionClearMetadata;
|
TranslatedAction actionClearMetadata;
|
||||||
|
TranslatedAction actionAddToPATH;
|
||||||
TranslatedAction actionReportBug;
|
TranslatedAction actionReportBug;
|
||||||
TranslatedAction actionDISCORD;
|
TranslatedAction actionDISCORD;
|
||||||
TranslatedAction actionMATRIX;
|
TranslatedAction actionMATRIX;
|
||||||
@ -348,6 +350,14 @@ public:
|
|||||||
actionClearMetadata.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Clear cached metadata"));
|
actionClearMetadata.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Clear cached metadata"));
|
||||||
all_actions.append(&actionClearMetadata);
|
all_actions.append(&actionClearMetadata);
|
||||||
|
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
actionAddToPATH = TranslatedAction(MainWindow);
|
||||||
|
actionAddToPATH->setObjectName(QStringLiteral("actionAddToPATH"));
|
||||||
|
actionAddToPATH.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Add to &PATH"));
|
||||||
|
actionAddToPATH.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Add the prism binary to PATH."));
|
||||||
|
all_actions.append(&actionAddToPATH);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!BuildConfig.BUG_TRACKER_URL.isEmpty()) {
|
if (!BuildConfig.BUG_TRACKER_URL.isEmpty()) {
|
||||||
actionReportBug = TranslatedAction(MainWindow);
|
actionReportBug = TranslatedAction(MainWindow);
|
||||||
actionReportBug->setObjectName(QStringLiteral("actionReportBug"));
|
actionReportBug->setObjectName(QStringLiteral("actionReportBug"));
|
||||||
@ -448,6 +458,10 @@ public:
|
|||||||
|
|
||||||
helpMenu->addAction(actionClearMetadata);
|
helpMenu->addAction(actionClearMetadata);
|
||||||
|
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
helpMenu->addAction(actionAddToPATH);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!BuildConfig.BUG_TRACKER_URL.isEmpty()) {
|
if (!BuildConfig.BUG_TRACKER_URL.isEmpty()) {
|
||||||
helpMenu->addAction(actionReportBug);
|
helpMenu->addAction(actionReportBug);
|
||||||
}
|
}
|
||||||
@ -533,6 +547,9 @@ public:
|
|||||||
helpMenu = menuBar->addMenu(tr("&Help"));
|
helpMenu = menuBar->addMenu(tr("&Help"));
|
||||||
helpMenu->setSeparatorsCollapsible(false);
|
helpMenu->setSeparatorsCollapsible(false);
|
||||||
helpMenu->addAction(actionClearMetadata);
|
helpMenu->addAction(actionClearMetadata);
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
helpMenu->addAction(actionAddToPATH);
|
||||||
|
#endif
|
||||||
helpMenu->addSeparator();
|
helpMenu->addSeparator();
|
||||||
helpMenu->addAction(actionAbout);
|
helpMenu->addAction(actionAbout);
|
||||||
helpMenu->addAction(actionOpenWiki);
|
helpMenu->addAction(actionOpenWiki);
|
||||||
@ -1902,6 +1919,18 @@ void MainWindow::on_actionClearMetadata_triggered()
|
|||||||
APPLICATION->metacache()->evictAll();
|
APPLICATION->metacache()->evictAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_actionAddToPATH_triggered() {
|
||||||
|
auto binaryPath = APPLICATION->arguments().first();
|
||||||
|
|
||||||
|
auto outcome = FS::symlink(binaryPath, "/usr/local/bin/prism");
|
||||||
|
|
||||||
|
if (!outcome) {
|
||||||
|
QMessageBox::critical(this, tr("Failed to add Prism to PATH"), tr(""));
|
||||||
|
} else {
|
||||||
|
QMessageBox::information(this, tr("Added Prism to PATH"), tr("Prism was successfully added to your PATH."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionOpenWiki_triggered()
|
void MainWindow::on_actionOpenWiki_triggered()
|
||||||
{
|
{
|
||||||
DesktopServices::openUrl(QUrl(BuildConfig.HELP_URL.arg("")));
|
DesktopServices::openUrl(QUrl(BuildConfig.HELP_URL.arg("")));
|
||||||
|
@ -128,6 +128,8 @@ private slots:
|
|||||||
|
|
||||||
void on_actionClearMetadata_triggered();
|
void on_actionClearMetadata_triggered();
|
||||||
|
|
||||||
|
void on_actionAddToPATH_triggered();
|
||||||
|
|
||||||
void on_actionOpenWiki_triggered();
|
void on_actionOpenWiki_triggered();
|
||||||
|
|
||||||
void on_actionMoreNews_triggered();
|
void on_actionMoreNews_triggered();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user