From 378d5bb660ee2e53c65e538ff0154bfd3ccfe69b Mon Sep 17 00:00:00 2001 From: garak Date: Tue, 11 Sep 2018 20:41:58 -0400 Subject: [PATCH 1/3] Open Map Scripts button --- mainwindow.cpp | 34 ++++++++++++++++++++++++++++++++++ mainwindow.h | 3 +++ mainwindow.ui | 49 ++++++++++++++++++++++++++++++++++++------------- 3 files changed, 73 insertions(+), 13 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index b9979dc3..7b09396c 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -15,8 +15,11 @@ #include #include #include +#include #include #include +#include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), @@ -549,6 +552,32 @@ void MainWindow::redo() { editor->redo(); } +// Open current map scripts in system default editor for .inc files +void MainWindow::openInTextEditor() { + QProcess *process = new QProcess(this); + QSysInfo sysInfo; + process->setWorkingDirectory(editor->project->root); + + #ifdef Q_OS_DARWIN + QString cmd = "open "; + #elif defined Q_OS_LINUX + QString cmd = "xdg-open "; + #elif defined Q_OS_WIN + QString cmd = "cmd /c start \""; + #else + qDebug() << "Functionality is not available with this OS (" + << sysInfo.productType() << ")"; + #endif + + cmd += "data/maps/" + editor->map->name + "/scripts.inc"; + + #ifdef Q_OS_WIN + cmd += "\""; + #endif + + process->start(cmd); +} + void MainWindow::on_action_Save_triggered() { editor->save(); updateMapList(); @@ -873,6 +902,11 @@ void MainWindow::on_toolButton_deleteObject_clicked() } } +void MainWindow::on_toolButton_Open_Scripts_clicked() +{ + openInTextEditor(); +} + void MainWindow::on_toolButton_Paint_clicked() { editor->map_edit_mode = "paint"; diff --git a/mainwindow.h b/mainwindow.h index b8a12f8b..be782842 100755 --- a/mainwindow.h +++ b/mainwindow.h @@ -37,6 +37,8 @@ private slots: void undo(); void redo(); + void openInTextEditor(); + void onLoadMapRequested(QString, QString); void onMapChanged(Map *map); void onMapNeedsRedrawing(Map *map); @@ -59,6 +61,7 @@ private slots: void on_actionRedo_triggered(); void on_toolButton_deleteObject_clicked(); + void on_toolButton_Open_Scripts_clicked(); void addNewEvent(QString); void updateSelectedObjects(); diff --git a/mainwindow.ui b/mainwindow.ui index f3f19222..d24583d2 100755 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -334,8 +334,8 @@ 0 0 - 429 - 620 + 462 + 599 @@ -708,7 +708,7 @@ 0 0 - 315 + 252 86 @@ -812,10 +812,10 @@ - 0 + 8 0 - 365 - 405 + 323 + 368 @@ -1050,8 +1050,8 @@ 0 0 - 381 - 657 + 371 + 643 @@ -1216,8 +1216,8 @@ 0 0 - 420 - 584 + 410 + 560 @@ -1330,6 +1330,29 @@ + + + + Open Map Scripts + + + false + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + @@ -1849,8 +1872,8 @@ 0 0 - 826 - 557 + 818 + 539 @@ -2022,7 +2045,7 @@ 0 0 1117 - 21 + 22 From 65adc2bdd0e375e29ae3550aa3f9001ef4e2d050 Mon Sep 17 00:00:00 2001 From: Marcus Huderle Date: Wed, 12 Sep 2018 09:17:50 -0500 Subject: [PATCH 2/3] Use Qt built-in functionality for opening scripts with default editor --- mainwindow.cpp | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 7b09396c..a596f0b3 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -20,6 +20,7 @@ #include #include #include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), @@ -554,28 +555,8 @@ void MainWindow::redo() { // Open current map scripts in system default editor for .inc files void MainWindow::openInTextEditor() { - QProcess *process = new QProcess(this); - QSysInfo sysInfo; - process->setWorkingDirectory(editor->project->root); - - #ifdef Q_OS_DARWIN - QString cmd = "open "; - #elif defined Q_OS_LINUX - QString cmd = "xdg-open "; - #elif defined Q_OS_WIN - QString cmd = "cmd /c start \""; - #else - qDebug() << "Functionality is not available with this OS (" - << sysInfo.productType() << ")"; - #endif - - cmd += "data/maps/" + editor->map->name + "/scripts.inc"; - - #ifdef Q_OS_WIN - cmd += "\""; - #endif - - process->start(cmd); + QString path = QDir::cleanPath(editor->project->root + QDir::separator() + "data/maps/" + editor->map->name + "/scripts.inc"); + QDesktopServices::openUrl(QUrl(path)); } void MainWindow::on_action_Save_triggered() { From 475f63d0f279a8c2953354ddf87517fed8ea0d4a Mon Sep 17 00:00:00 2001 From: garak Date: Wed, 12 Sep 2018 21:10:11 -0400 Subject: [PATCH 3/3] small fix --- mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index a596f0b3..a6484c80 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -555,7 +555,7 @@ void MainWindow::redo() { // Open current map scripts in system default editor for .inc files void MainWindow::openInTextEditor() { - QString path = QDir::cleanPath(editor->project->root + QDir::separator() + "data/maps/" + editor->map->name + "/scripts.inc"); + QString path = QDir::cleanPath("file://" + editor->project->root + QDir::separator() + "data/maps/" + editor->map->name + "/scripts.inc"); QDesktopServices::openUrl(QUrl(path)); }