OSDN Git Service

[denncoCreator] fixed a crash bug.
[dennco/denncoCreator.git] / Source / mainwindow.cpp
index 03c3369..d9f74b6 100644 (file)
@@ -25,6 +25,7 @@
 #include "dccontent.h"
 #include "dcglvisualizerwidget.h"
 #include "dctreeviewwidget.h"
+#include "dccellcodescripttreeviewwidget.h"
 #include "TKConsole.h"
 #include "utils/dcresources.h"
 #include "utils/dcskeltoncreatorutil.h"
@@ -42,7 +43,7 @@
 #if defined(Q_WS_WIN)
     const QString DENNCO_ENGINE = "QtDennco.exe";
 #elif defined(Q_WS_MAC)
-    const QString DENNCO_ENGINE = "QtDennco";
+    const QString DENNCO_ENGINE = "QtDennco.app";
 #elif defined(Q_OS_UNIX)
     const QString DENNCO_ENGINE = "./QtDennco";
 #endif
@@ -80,10 +81,15 @@ MainWindow::MainWindow(QWidget *parent) :
     d_treeViewWidget = new DCTreeViewWidget(this, d_creator);
     ui->treeViewDock->layout()->addWidget(d_treeViewWidget);
 
+    d_cellCodeScriptTreeViewWidget = new DCCellCodeScriptTreeViewWidget(this, d_creator);
+    ui->cellCodeScriptTreeViewDock->layout()->addWidget(d_cellCodeScriptTreeViewWidget);
+
     DCCellScriptsEditorWindow::construct(d_creator);
 
     setCurrentContent("");
     setUnifiedTitleAndToolBarOnMac(true);
+
+    tabifyDockWidget(ui->dock2,ui->dock1);
 }
 
 MainWindow::~MainWindow()
@@ -146,7 +152,7 @@ bool MainWindow::openRecent(int idx)
     {
         if (d_contentOpenHistory.length() > idx)
         {
-            loadContent(d_contentOpenHistory.at(idx));
+            loadContent(QString(d_contentOpenHistory.at(idx)));
             return true;
         }
     }
@@ -547,10 +553,18 @@ void MainWindow::playContent()
     if (d_player.state() == QProcess::NotRunning)
     {
         QStringList args;
+#ifdef Q_WS_MAC
+        args << QCoreApplication::applicationDirPath() + "/../../../" + DENNCO_ENGINE;
+        args << "--args";
+#endif
         args << "-creatorControlled";
         args << d_IPCServerName;
 
+#ifdef Q_WS_MAC
+        d_player.start("open" , args);
+#else
         d_player.start(DENNCO_ENGINE, args);
+#endif
         d_player.waitForStarted();
     }
 
@@ -584,3 +598,57 @@ void MainWindow::manageCellCode()
     DCManageCellCodeDialog dialog(d_creator, NULL, this);
     dialog.exec();
 }
+
+
+//static
+bool MainWindow::openExternalEditorFor(const QString &path)
+{
+    static QList<QProcess*> s_processes;
+    static QMutex s_mutex;
+
+    QMutexLocker locker(&s_mutex);
+
+    QString editorPath = readSettingsForExternalScriptEditorPath();
+    if (editorPath.isEmpty() || editorPath.length() == 0)
+    {
+        DCCodeEditorExternalEditorSettingDialog dialog;
+        dialog.exec();
+        editorPath = readSettingsForExternalScriptEditorPath();
+    }
+    if (editorPath.isEmpty() || editorPath.length() == 0)
+        return false;
+
+    QString parameterOrg = readSettingsForExternalScriptEditorParameters();
+    QString parameter = "";
+    int i = 0;
+    int j = parameterOrg.indexOf(QRegExp("%F[ \t\"']|%F$"),i);
+    while (j >= 0)
+    {
+        parameter += parameterOrg.mid(i, j-i);
+        parameter += path;
+        i = j + 2;
+        if (i > parameterOrg.length())
+            break;
+        j = parameterOrg.indexOf(QRegExp("%F[ \t\"']|%F$"),i);
+    }
+    if (i < parameterOrg.length())
+        parameter += parameterOrg.mid(i);
+
+    QList<QProcess*>::iterator it = s_processes.begin();
+    while (it != s_processes.end())
+    {
+        if ((*it)->state() != QProcess::Running)
+        {
+            delete (*it);
+            it = s_processes.erase(it);
+        }
+        else
+            ++it;
+    }
+    QProcess *newProcess = new QProcess;
+    newProcess->start("\"" + editorPath + "\" " + parameter);
+
+    s_processes.append(newProcess);
+
+    return true;
+}