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