OSDN Git Service

[denncoCreator] Implemented the functionality to check if editing script file is...
authortkawata <tkawata@users.sourceforge.jp>
Sat, 15 Dec 2012 02:32:45 +0000 (11:32 +0900)
committertkawata <tkawata@users.sourceforge.jp>
Sat, 15 Dec 2012 02:32:45 +0000 (11:32 +0900)
Source/codeeditor/dccellscriptseditorpagewidget.cpp
Source/codeeditor/dccellscriptseditorpagewidget.h
Source/codeeditor/dccellscriptseditortabwidget.cpp
Source/codeeditor/dccellscriptseditortabwidget.h
Source/codeeditor/dccodeeditorscriptmanager.cpp [new file with mode: 0644]
Source/codeeditor/dccodeeditorscriptmanager.h [new file with mode: 0644]
Source/codeeditor/dceditscriptfolder.cpp
Source/codeeditor/dceditscriptfolder.h
Source/denncoCreator.pro

index 8a40b0b..7b38ac7 100644 (file)
@@ -74,6 +74,8 @@ DCCellScriptsEditorPageWidget::DCCellScriptsEditorPageWidget(DCCell *targetCell,
     connect(&d_cellCodeScriptFolder, SIGNAL(scriptChanged()), this, SLOT(folderCellCodeScriptChanged()));
     connect(&d_customScriptFolder, SIGNAL(modificationStatusChanged(bool)), this, SLOT(folderCustomScriptModifiedStatusChanged(bool)));
     connect(&d_cellCodeScriptFolder, SIGNAL(modificationStatusChanged(bool)), this, SLOT(folderCellCodeScriptModifiedStatusChanged(bool)));
     connect(&d_cellCodeScriptFolder, SIGNAL(scriptChanged()), this, SLOT(folderCellCodeScriptChanged()));
     connect(&d_customScriptFolder, SIGNAL(modificationStatusChanged(bool)), this, SLOT(folderCustomScriptModifiedStatusChanged(bool)));
     connect(&d_cellCodeScriptFolder, SIGNAL(modificationStatusChanged(bool)), this, SLOT(folderCellCodeScriptModifiedStatusChanged(bool)));
+    connect(&d_customScriptFolder, SIGNAL(fileModifiedByExternalEditor(qint64)), this, SLOT(folderCustomScriptFileModifiedByExternalEditor(qint64)));
+    connect(&d_cellCodeScriptFolder, SIGNAL(fileModifiedByExternalEditor(qint64)), this, SLOT(folderCellCodeScriptFileModifiedByExternalEditor(qint64)));
 
     loadScripts();
 }
 
     loadScripts();
 }
@@ -193,6 +195,18 @@ void DCCellScriptsEditorPageWidget::folderCellCodeScriptModifiedStatusChanged(bo
     updateModifiedStatus();
 }
 
     updateModifiedStatus();
 }
 
+//slot
+void DCCellScriptsEditorPageWidget::folderCustomScriptFileModifiedByExternalEditor(qint64 notifiedTime)
+{
+    emit customScriptModifiedByExternalEditor(this,notifiedTime);
+}
+
+//slot
+void DCCellScriptsEditorPageWidget::folderCellCodeScriptFileModifiedByExternalEditor(qint64 notifiedTime)
+{
+    emit cellCodeScriptModifiedByExternalEditor(this,notifiedTime);
+}
+
 void DCCellScriptsEditorPageWidget::updateModifiedStatus()
 {
     bool modified = d_customScriptFolder.getIsModified();
 void DCCellScriptsEditorPageWidget::updateModifiedStatus()
 {
     bool modified = d_customScriptFolder.getIsModified();
@@ -323,6 +337,25 @@ bool DCCellScriptsEditorPageWidget::saveCellCodeScriptOnlyToFile(bool saveModifi
     return result;
 }
 
     return result;
 }
 
+bool DCCellScriptsEditorPageWidget::getIsCustomScriptModifiedByExternalEditor() const
+{
+    return d_customScriptFolder.getIsFileModifiedByExternalEditor();
+}
+
+bool DCCellScriptsEditorPageWidget::getIsCellCodeModifiedByExternalEditor() const
+{
+    return d_cellCodeScriptFolder.getIsFileModifiedByExternalEditor();
+}
+
+qint64 DCCellScriptsEditorPageWidget::getCustomScriptLoadedTime() const
+{
+    return d_customScriptFolder.getLoadedTime();
+}
+
+qint64 DCCellScriptsEditorPageWidget::getCellCodeScriptLoadedTime() const
+{
+    return d_cellCodeScriptFolder.getLoadedTime();
+}
 
 void DCCellScriptsEditorPageWidget::focusCustomScript()
 {
 
 void DCCellScriptsEditorPageWidget::focusCustomScript()
 {
@@ -338,3 +371,29 @@ void DCCellScriptsEditorPageWidget::focusCellCodeScript()
     d_cellCodeScriptEditor->setFocus();
 
 }
     d_cellCodeScriptEditor->setFocus();
 
 }
+
+void DCCellScriptsEditorPageWidget::reloadCustomScript()
+{
+    d_customScriptEditor->setPlainText(d_customScriptFolder.getCurrentScript(true));
+    updateModifiedStatus();
+}
+
+void DCCellScriptsEditorPageWidget::reloadCellCodeScript()
+{
+    if (d_cell->getIsCellCodeAssgined())
+    {
+        d_cellCodeScriptEditor->setPlainText(d_cellCodeScriptFolder.getCurrentScript(true));
+        d_cellCodeScriptEditor->setReadOnly(false);
+        d_cellCodeScriptEditor->document()->setModified(false);
+        d_splitter->widget(1)->show();
+    }
+    else
+    {
+        d_cellCodeScriptEditor->setPlainText("");
+        d_cellCodeScriptEditor->setReadOnly(true);
+        d_splitter->widget(1)->hide();
+    }
+
+    updateModifiedStatus();
+}
+
index e82ecd3..888948f 100644 (file)
@@ -44,6 +44,8 @@ class DCCellScriptsEditorPageWidget : public QWidget
     DCEditScriptFolder  d_customScriptFolder;
     DCEditScriptFolder  d_cellCodeScriptFolder;
 
     DCEditScriptFolder  d_customScriptFolder;
     DCEditScriptFolder  d_cellCodeScriptFolder;
 
+    bool            loadCustomScript(bool forceReload = false);
+    bool            loadCellCodeScript(bool forceReload = false);
     bool            loadScripts();
     void            updateModifiedStatus();
 
     bool            loadScripts();
     void            updateModifiedStatus();
 
@@ -52,6 +54,10 @@ public:
     virtual ~DCCellScriptsEditorPageWidget();
 
     bool            getIsModified() const;
     virtual ~DCCellScriptsEditorPageWidget();
 
     bool            getIsModified() const;
+    bool            getIsCustomScriptModifiedByExternalEditor() const;
+    bool            getIsCellCodeModifiedByExternalEditor() const;
+    qint64          getCustomScriptLoadedTime() const;
+    qint64          getCellCodeScriptLoadedTime() const;
 
     void            setReadOnly(bool readOnly);
     QSet<DCVCPage*> saveScriptsToFile(bool saveModifiedOnly);
 
     void            setReadOnly(bool readOnly);
     QSet<DCVCPage*> saveScriptsToFile(bool saveModifiedOnly);
@@ -61,10 +67,15 @@ public:
     void            focusCustomScript();
     void            focusCellCodeScript();
 
     void            focusCustomScript();
     void            focusCellCodeScript();
 
+    void            reloadCustomScript();
+    void            reloadCellCodeScript();
+
 signals:
     void editingCellDestroyed(DCCell *cell);
     void cellScriptsModifiedStatusChanged(QWidget *self, bool modified);
     void cellScriptsSaved(QWidget *self);
 signals:
     void editingCellDestroyed(DCCell *cell);
     void cellScriptsModifiedStatusChanged(QWidget *self, bool modified);
     void cellScriptsSaved(QWidget *self);
+    void customScriptModifiedByExternalEditor(QWidget *self, qint64 notifiedTime);
+    void cellCodeScriptModifiedByExternalEditor(QWidget *self, qint64 notifiedTime);
 
 private slots:
     void assignedCellCodeChanged();
 
 private slots:
     void assignedCellCodeChanged();
@@ -75,6 +86,8 @@ private slots:
     void folderCellCodeScriptChanged();
     void folderCustomScriptModifiedStatusChanged(bool modified);
     void folderCellCodeScriptModifiedStatusChanged(bool modified);
     void folderCellCodeScriptChanged();
     void folderCustomScriptModifiedStatusChanged(bool modified);
     void folderCellCodeScriptModifiedStatusChanged(bool modified);
+    void folderCustomScriptFileModifiedByExternalEditor(qint64 notifiedTime);
+    void folderCellCodeScriptFileModifiedByExternalEditor(qint64 notifiedTime);
 };
 
 #endif // DCCELLCODEEDITORPAGEWIDGET_H
 };
 
 #endif // DCCELLCODEEDITORPAGEWIDGET_H
index 09ea1a9..419a0d2 100644 (file)
@@ -22,6 +22,9 @@
 #include <QVBoxLayout>
 #include <QHBoxLayout>
 #include <QLabel>
 #include <QVBoxLayout>
 #include <QHBoxLayout>
 #include <QLabel>
+#include <QMessageBox>
+#include <QMutex>
+#include <QMutexLocker>
 
 #include "dccodeeditor.h"
 #include "dccell.h"
 
 #include "dccodeeditor.h"
 #include "dccell.h"
@@ -121,7 +124,21 @@ void DCCellScriptsEditorTabWidget::tabRemoved(int index)
 
 void DCCellScriptsEditorTabWidget::slotCurrentIndexChanged(int index)
 {
 
 void DCCellScriptsEditorTabWidget::slotCurrentIndexChanged(int index)
 {
-    QMap<QWidget*, DCCell*>::iterator it = d_targets.find(widget(index));
+    DCCellScriptsEditorPageWidget *page = dynamic_cast<DCCellScriptsEditorPageWidget*>(widget(index));
+    if (!page)
+        return;
+
+    if (page->getIsCustomScriptModifiedByExternalEditor())
+    {
+        slotTabPageCustomScriptModifiedByExternal(page);
+    }
+
+    if (page->getIsCellCodeModifiedByExternalEditor())
+    {
+        slotTabPageCellCodeModifiedByExternal(page);
+    }
+
+    QMap<QWidget*, DCCell*>::iterator it = d_targets.find(page);
     if (it != d_targets.end())
     {
         emit activeEditTabChanged(it.value());
     if (it != d_targets.end())
     {
         emit activeEditTabChanged(it.value());
@@ -156,10 +173,72 @@ void DCCellScriptsEditorTabWidget::slotTabPageContentModifiedStatusChanged(QWidg
     }
 }
 
     }
 }
 
-void DCCellScriptsEditorTabWidget::slotTabPageContentChangedByExternal(QWidget *tabPage)
+void DCCellScriptsEditorTabWidget::slotTabPageCustomScriptModifiedByExternal(QWidget *tabPage)
 {
 {
-    //TODO
+    static QList<QWidget*> pendingPages;
+    static QMutex mutex;
 
 
+    if (currentWidget() == tabPage)
+    {
+        DCCellScriptsEditorPageWidget *pageWidget = dynamic_cast<DCCellScriptsEditorPageWidget*>(currentWidget());
+
+        {
+            QMutexLocker locker(&mutex);
+            if (pendingPages.contains(tabPage))
+            {
+                return;
+            }
+            pendingPages.append(tabPage);
+        }
+
+        QMessageBox::StandardButton ret;
+        ret = QMessageBox::warning(this, tr("Cell scripts editor"),
+            tr("The custom script has been modified by other editor.\n"
+            "Do you want to reload ?"),
+            QMessageBox::Yes | QMessageBox::No);
+        if (ret == QMessageBox::Yes)
+        {
+            pageWidget->reloadCustomScript();
+        }
+        {
+            QMutexLocker locker(&mutex);
+            pendingPages.removeOne(tabPage);
+        }
+    }
+}
+
+void DCCellScriptsEditorTabWidget::slotTabPageCellCodeModifiedByExternal(QWidget *tabPage)
+{
+    static QList<QWidget*> pendingPages;
+    static QMutex mutex;
+
+    if (currentWidget() == tabPage)
+    {
+        DCCellScriptsEditorPageWidget *pageWidget = dynamic_cast<DCCellScriptsEditorPageWidget*>(currentWidget());
+
+        {
+            QMutexLocker locker(&mutex);
+            if (pendingPages.contains(tabPage))
+            {
+                return;
+            }
+            pendingPages.append(tabPage);
+        }
+
+        QMessageBox::StandardButton ret;
+        ret = QMessageBox::warning(this, tr("Cell scripts editor"),
+            tr("The cell code script has been modified by other editor.\n"
+            "Do you want to reload ?"),
+            QMessageBox::Yes | QMessageBox::No);
+        if (ret == QMessageBox::Yes)
+        {
+            pageWidget->reloadCellCodeScript();
+        }
+        {
+            QMutexLocker locker(&mutex);
+            pendingPages.removeOne(tabPage);
+        }
+    }
 }
 
 void DCCellScriptsEditorTabWidget::slotTabPageContentSaved(QWidget *tabPage)
 }
 
 void DCCellScriptsEditorTabWidget::slotTabPageContentSaved(QWidget *tabPage)
@@ -231,6 +310,8 @@ void DCCellScriptsEditorTabWidget::openTab(DCCell *target, bool focusInCellCodeS
         connect(targetWidget, SIGNAL(editingCellDestroyed(DCCell*)), this, SLOT(slotCellDestroyed(DCCell*)));
         connect(targetWidget, SIGNAL(cellScriptsModifiedStatusChanged(QWidget*, bool)), this, SLOT(slotTabPageContentModifiedStatusChanged(QWidget*, bool)));
         connect(targetWidget, SIGNAL(cellScriptsSaved(QWidget*)), this, SLOT(slotTabPageContentSaved(QWidget*)));
         connect(targetWidget, SIGNAL(editingCellDestroyed(DCCell*)), this, SLOT(slotCellDestroyed(DCCell*)));
         connect(targetWidget, SIGNAL(cellScriptsModifiedStatusChanged(QWidget*, bool)), this, SLOT(slotTabPageContentModifiedStatusChanged(QWidget*, bool)));
         connect(targetWidget, SIGNAL(cellScriptsSaved(QWidget*)), this, SLOT(slotTabPageContentSaved(QWidget*)));
+        connect(targetWidget, SIGNAL(customScriptModifiedByExternalEditor(QWidget*, qint64)), this, SLOT(slotTabPageCustomScriptModifiedByExternal(QWidget*)));
+        connect(targetWidget, SIGNAL(cellCodeScriptModifiedByExternalEditor(QWidget*, qint64)), this, SLOT(slotTabPageCellCodeModifiedByExternal(QWidget*)));
     }
 
     if (targetWidget)
     }
 
     if (targetWidget)
index c69d84f..4ea738a 100644 (file)
@@ -70,7 +70,8 @@ private slots:
     void slotCellDestroyed(DCCell *cell);
     void slotTabPageContentSaved(QWidget *tabPage);
     void slotTabPageContentModifiedStatusChanged(QWidget *tabPage, bool modified);
     void slotCellDestroyed(DCCell *cell);
     void slotTabPageContentSaved(QWidget *tabPage);
     void slotTabPageContentModifiedStatusChanged(QWidget *tabPage, bool modified);
-    void slotTabPageContentChangedByExternal(QWidget *tabPage);
+    void slotTabPageCustomScriptModifiedByExternal(QWidget *tabPage);
+    void slotTabPageCellCodeModifiedByExternal(QWidget *tabPage);
 };
 
 #endif // DCCELLSCRIPTSEDITORTABWIDGET_H
 };
 
 #endif // DCCELLSCRIPTSEDITORTABWIDGET_H
diff --git a/Source/codeeditor/dccodeeditorscriptmanager.cpp b/Source/codeeditor/dccodeeditorscriptmanager.cpp
new file mode 100644 (file)
index 0000000..6a5e0dc
--- /dev/null
@@ -0,0 +1,502 @@
+//  Copyright (c) 2012 Dennco Project
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+//
+//  Created by tkawata on Dec-15, 2012.
+//
+#include "dccodeeditorscriptmanager.h"
+
+#include <QMap>
+#include <QCryptographicHash>
+#include <QDateTime>
+#include <QMutex>
+
+#include "dccell.h"
+#include "dccellcode.h"
+#include "dceditscriptfolder.h"
+
+DCCodeEditorScriptManager* DCCodeEditorScriptManager::instance = NULL;
+
+class ScriptWatcher
+{
+    bool d_scriptLoadedFromFile;
+    void setModified(DCCodeEditorScriptManager::Attacher *modifier, bool modified)
+    {
+        if (d_modified != modified)
+        {
+            d_modified = modified;
+            d_manager->callbackModificationStatusChanged(this, modifier, modified);
+        }
+    }
+    QMutex d_mutex;
+
+public:
+    enum E_TYPE { E_CUSTOMSCRIPT, E_CELLCODESCRIPT};
+
+protected:
+    DCCodeEditorScriptManager   *d_manager;
+    E_TYPE                      d_type;
+    QString                     d_script;
+    qint64                      d_loadedTime;
+    QByteArray                  d_hashForOriginalScript;
+    bool                        d_modified;
+    bool                        d_fileModifiedByExternalEditor;
+    QList<DCCodeEditorScriptManager::Attacher*> d_attachers;
+
+    ScriptWatcher(DCCodeEditorScriptManager *manager, E_TYPE type) :
+        d_scriptLoadedFromFile(false), d_manager(manager), d_type(type), d_loadedTime(0),
+        d_modified(false), d_fileModifiedByExternalEditor(false)
+    {
+    }
+
+    virtual QString loadScriptFromFile() = 0;
+    virtual bool saveScriptToFile() = 0;
+
+public:
+    virtual ~ScriptWatcher() {}
+
+    virtual QString getWorkFilePathScript() = 0;
+
+    E_TYPE getType() const { return d_type; }
+    void attach(DCCodeEditorScriptManager::Attacher *attacher)
+    {
+        d_attachers.append(attacher);
+    }
+
+    void deattach(DCCodeEditorScriptManager::Attacher *attacher)
+    {
+        d_attachers.removeOne(attacher);
+    }
+
+    int getRefCount() const
+    {
+        return d_attachers.count();
+    }
+
+    const QList<DCCodeEditorScriptManager::Attacher*>* getAttachers() { return &d_attachers; }
+
+    QString getCurrentScript(DCCodeEditorScriptManager::Attacher *attacher, bool forceReload = false)
+    {
+        if (!d_scriptLoadedFromFile || forceReload)
+        {
+            d_hashForOriginalScript.clear();
+            d_script = loadScriptFromFile();
+            d_loadedTime = QDateTime::currentMSecsSinceEpoch();
+            d_hashForOriginalScript = QCryptographicHash::hash(d_script.toLocal8Bit(), QCryptographicHash::Md5);
+            setModified(attacher,false);
+            d_scriptLoadedFromFile = true;
+            d_fileModifiedByExternalEditor = false;
+        }
+        return d_script;
+    }
+
+    bool getIsModified(const DCCodeEditorScriptManager::Attacher *attacher) const
+    {
+        return d_modified;
+    }
+
+    qint64 getLoadedTime() const
+    {
+        return d_loadedTime;
+    }
+
+    void setScript(DCCodeEditorScriptManager::Attacher *attacher, const QString& newScript)
+    {
+        d_script = newScript;
+        d_manager->callbackScriptChanged(this, attacher);
+        setModified(attacher, d_hashForOriginalScript != QCryptographicHash::hash(newScript.toLocal8Bit(), QCryptographicHash::Md5));
+    }
+
+    bool saveScript(DCCodeEditorScriptManager::Attacher *attacher)
+    {
+        bool succeeded = saveScriptToFile();
+        if (succeeded)
+        {
+            d_loadedTime = QDateTime::currentMSecsSinceEpoch();
+            d_fileModifiedByExternalEditor = false;
+            d_hashForOriginalScript = QCryptographicHash::hash(d_script.toLocal8Bit(), QCryptographicHash::Md5);
+            setModified(attacher,false);
+        }
+        return succeeded;
+    }
+
+    bool checkIfModifiedByExternalEditor()
+    {
+        QMutexLocker locker(&d_mutex);
+
+        if (!d_fileModifiedByExternalEditor)
+        {
+            d_fileModifiedByExternalEditor = d_hashForOriginalScript != QCryptographicHash::hash(loadScriptFromFile().toLocal8Bit(), QCryptographicHash::Md5);
+        }
+        return d_fileModifiedByExternalEditor;
+    }
+
+    bool getIsFileModifiedByExternalEditor() const
+    {
+        return d_fileModifiedByExternalEditor;
+    }
+};
+
+class CustomScriptWatcher : public ScriptWatcher
+{
+    DCCell *d_cell;
+
+
+protected:
+    virtual QString loadScriptFromFile()
+    {
+        return d_cell->getCustomScript();
+    }
+
+    virtual bool saveScriptToFile()
+    {
+        return d_cell->saveCustomScript(d_script);
+    }
+
+public:
+    CustomScriptWatcher(DCCodeEditorScriptManager *manager, DCCell *cell)
+        : ScriptWatcher(manager, E_CUSTOMSCRIPT), d_cell(cell)
+    {
+    }
+
+    virtual QString getWorkFilePathScript()
+    {
+        return d_cell->getWorkFilePathForCustomScript();
+    }
+};
+
+class CellCodeScriptWatcher : public ScriptWatcher
+{
+    DCCellCode *d_cellCode;
+
+protected:
+    virtual QString loadScriptFromFile()
+    {
+        return d_cellCode->getOwnScript();
+    }
+
+    virtual bool saveScriptToFile()
+    {
+        return d_cellCode->saveScript(d_script);
+    }
+
+public:
+    CellCodeScriptWatcher(DCCodeEditorScriptManager *manager, DCCellCode *cellCode)
+        : ScriptWatcher(manager, E_CELLCODESCRIPT), d_cellCode(cellCode)
+    {
+    }
+
+    virtual QString getWorkFilePathScript()
+    {
+        return d_cellCode->getWorkFilePathForCellCodeScript();
+    }
+};
+
+DCCodeEditorScriptManager::Attacher::Attacher(DCEditScriptFolder *folder, DCCodeEditorScriptManager *manager, ScriptWatcher *watcher)
+        : d_folder(folder), d_manager(manager), d_watcher(watcher)
+{
+}
+
+DCCodeEditorScriptManager::Attacher::~Attacher()
+{
+    d_manager->attacherDeleting(this);
+}
+
+ScriptWatcher* DCCodeEditorScriptManager::Attacher::getWatcher() const
+{
+    return d_watcher;
+}
+
+QString DCCodeEditorScriptManager::Attacher::getCurrentScript(bool forceReload)
+{
+    return d_manager->getCurrentScript(this, forceReload);
+}
+
+bool DCCodeEditorScriptManager::Attacher::getIsModified() const
+{
+    return d_manager->getIsModified(this);
+}
+
+bool DCCodeEditorScriptManager::Attacher::getIsFileModifiedByExternalEditor() const
+{
+    return d_watcher->getIsFileModifiedByExternalEditor();
+}
+
+qint64 DCCodeEditorScriptManager::Attacher::getLoadedTime() const
+{
+    return d_watcher->getLoadedTime();
+}
+
+void DCCodeEditorScriptManager::Attacher::setScript(const QString& newScript)
+{
+    d_manager->setScript(this, newScript);
+}
+
+bool DCCodeEditorScriptManager::Attacher::saveScript()
+{
+    return d_manager->saveScript(this);
+}
+
+void DCCodeEditorScriptManager::Attacher::callbackScriptChanged()
+{
+    d_folder->callbackScriptChanged();
+}
+
+void DCCodeEditorScriptManager::Attacher::callbackModificationStatusChanged(bool modified)
+{
+    d_folder->callbackModificationStatusChanged(modified);
+}
+
+void DCCodeEditorScriptManager::Attacher::callbackFileModifiedByExternalEditor(qint64 notifiedTime)
+{
+    d_folder->callbackFileModifiedByExternalEditor(notifiedTime);
+
+}
+
+//static
+DCCodeEditorScriptManager::Attacher* DCCodeEditorScriptManager::createCustomScriptAttacher(DCEditScriptFolder *folder, DCCell *cell)
+{
+    DCCodeEditorScriptManager *instance = getInstance();
+    return instance->createCustomScriptAttacherPrivate(folder, cell);
+}
+
+//static
+DCCodeEditorScriptManager::Attacher* DCCodeEditorScriptManager::createCellCodeScriptAttacher(DCEditScriptFolder *folder, DCCellCode *cell)
+{
+    DCCodeEditorScriptManager *instance = getInstance();
+    return instance->createCellCodeScriptAttacherPrivate(folder, cell);
+}
+
+QString DCCodeEditorScriptManager::getCurrentScript(DCCodeEditorScriptManager::Attacher *attacher, bool forceReload)
+{
+    return attacher->getWatcher()->getCurrentScript(attacher,forceReload);
+}
+
+bool DCCodeEditorScriptManager::getIsModified(const DCCodeEditorScriptManager::Attacher *attacher) const
+{
+    return attacher->getWatcher()->getIsModified(attacher);
+}
+
+void DCCodeEditorScriptManager::setScript(DCCodeEditorScriptManager::Attacher *attacher, const QString& newScript)
+{
+    attacher->getWatcher()->setScript(attacher, newScript);
+}
+
+bool DCCodeEditorScriptManager::saveScript(DCCodeEditorScriptManager::Attacher *attacher)
+{
+    return attacher->getWatcher()->saveScript(attacher);
+}
+
+
+//static
+DCCodeEditorScriptManager* DCCodeEditorScriptManager::getInstance()
+{
+    if (!instance)
+    {
+        instance = new DCCodeEditorScriptManager();
+    }
+    return instance;
+}
+
+DCCodeEditorScriptManager::DCCodeEditorScriptManager()
+{
+    d_customScriptFileWatcher = new QFileSystemWatcher;
+    d_cellCodeScriptFileWatcher = new QFileSystemWatcher;
+
+    connect(d_customScriptFileWatcher, SIGNAL(fileChanged(QString)), this, SLOT(customScriptFileModified(QString)));
+    connect(d_cellCodeScriptFileWatcher, SIGNAL(fileChanged(QString)), this, SLOT(cellCodeScriptFileModified(QString)));
+}
+
+
+DCCodeEditorScriptManager::~DCCodeEditorScriptManager()
+{
+    delete d_customScriptFileWatcher;
+    delete d_cellCodeScriptFileWatcher;
+}
+
+DCCodeEditorScriptManager::Attacher* DCCodeEditorScriptManager::createCustomScriptAttacherPrivate(DCEditScriptFolder *folder, DCCell *cell)
+{
+    QMap<DCCell*, ScriptWatcher*>::const_iterator it = d_customScriptWatchers.find(cell);
+
+    ScriptWatcher* watcher = NULL;
+    if (it != d_customScriptWatchers.end())
+    {
+        watcher = it.value();
+    }
+    else
+    {
+        watcher = new CustomScriptWatcher(this, cell);
+        d_customScriptWatchers.insert(cell, watcher);
+        d_customScriptFileWatcher->addPath(watcher->getWorkFilePathScript());
+    }
+
+    Attacher *attacher = new Attacher(folder, this, watcher);
+    watcher->attach(attacher);
+
+    return attacher;
+}
+
+DCCodeEditorScriptManager::Attacher* DCCodeEditorScriptManager::createCellCodeScriptAttacherPrivate(DCEditScriptFolder *folder, DCCellCode *cellCode)
+{
+    QMap<DCCellCode*, ScriptWatcher*>::const_iterator it = d_cellCodeScriptWatchers.find(cellCode);
+
+    ScriptWatcher* watcher = NULL;
+    if (it != d_cellCodeScriptWatchers.end())
+    {
+        watcher = it.value();
+    }
+    else
+    {
+        watcher = new CellCodeScriptWatcher(this, cellCode);
+        d_cellCodeScriptFileWatcher->addPath(watcher->getWorkFilePathScript());
+        d_cellCodeScriptWatchers.insert(cellCode, watcher);
+    }
+
+    Attacher *attacher = new Attacher(folder, this, watcher);
+    watcher->attach(attacher);
+
+    return attacher;
+}
+
+void DCCodeEditorScriptManager::attacherDeleting(Attacher *attacher)
+{
+    ScriptWatcher *watcher = attacher->getWatcher();
+    if (watcher)
+    {
+        watcher->deattach(attacher);
+        if (watcher->getRefCount() <= 0)
+        {
+            if (watcher->getType() == ScriptWatcher::E_CUSTOMSCRIPT)
+            {
+                d_customScriptFileWatcher->removePath(watcher->getWorkFilePathScript());
+                QMap<DCCell*, ScriptWatcher*>::iterator i = d_customScriptWatchers.begin();
+                while (i != d_customScriptWatchers.end())
+                {
+                    if (i.value() == watcher)
+                    {
+                        d_customScriptWatchers.erase(i);
+                        delete watcher;
+                        break;
+                    }
+                    ++i;
+                }
+            }
+            else
+            {
+                d_cellCodeScriptFileWatcher->removePath(watcher->getWorkFilePathScript());
+                QMap<DCCellCode*, ScriptWatcher*>::iterator i = d_cellCodeScriptWatchers.begin();
+                while (i != d_cellCodeScriptWatchers.end())
+                {
+                    if (i.value() == watcher)
+                    {
+                        d_cellCodeScriptWatchers.erase(i);
+                        delete watcher;
+                        break;
+                    }
+                    ++i;
+                }
+            }
+        }
+    }
+}
+
+void DCCodeEditorScriptManager::callbackScriptChanged(ScriptWatcher *watcher, const Attacher *modifier)
+{
+    const QList<Attacher*> *attachers = watcher->getAttachers();
+
+    QList<Attacher*>::const_iterator it = attachers->constBegin();
+    while (it != attachers->constEnd())
+    {
+        if (*it != modifier)
+        {
+            (*it)->callbackScriptChanged();
+        }
+        ++it;
+    }
+}
+
+void DCCodeEditorScriptManager::callbackModificationStatusChanged(ScriptWatcher *watcher, Attacher *modifier, bool modified)
+{
+    (void)modifier;
+
+    const QList<Attacher*> *attachers = watcher->getAttachers();
+
+    QList<Attacher*>::const_iterator it = attachers->constBegin();
+    while (it != attachers->constEnd())
+    {
+        (*it)->callbackModificationStatusChanged(modified);
+        ++it;
+    }
+}
+
+//SLOT
+void DCCodeEditorScriptManager::customScriptFileModified(const QString &path)
+{
+    qint64 notifiedTime = QDateTime::currentMSecsSinceEpoch();
+    DCCell *modifiedCell = NULL;
+    ScriptWatcher *watcher = NULL;
+    QMap<DCCell*, ScriptWatcher*>::iterator it = d_customScriptWatchers.begin();
+    while(it != d_customScriptWatchers.end())
+    {
+        DCCell *cell = it.key();
+        if (cell && cell->getWorkFilePathForCustomScript() == path)
+        {
+            modifiedCell = cell;
+            watcher = it.value();
+            break;
+        }
+        ++it;
+    }
+    if (watcher && watcher->checkIfModifiedByExternalEditor())
+    {
+        const QList<DCCodeEditorScriptManager::Attacher*> *attachers = watcher->getAttachers();
+        QList<DCCodeEditorScriptManager::Attacher*>::const_iterator it = attachers->begin();
+        while(it != attachers->end())
+        {
+            (*it)->callbackFileModifiedByExternalEditor(notifiedTime);
+            ++it;
+        }
+    }
+}
+
+//SLOT
+void DCCodeEditorScriptManager::cellCodeScriptFileModified(const QString &path)
+{
+    qint64 notifiedTime = QDateTime::currentMSecsSinceEpoch();
+    DCCellCode *modifiedCellCode = NULL;
+    ScriptWatcher *watcher = NULL;
+    QMap<DCCellCode*, ScriptWatcher*>::iterator it = d_cellCodeScriptWatchers.begin();
+    while(it != d_cellCodeScriptWatchers.end())
+    {
+        DCCellCode *cellCode = it.key();
+        if (cellCode && cellCode->getWorkFilePathForCellCodeScript() == path)
+        {
+            modifiedCellCode = cellCode;
+            watcher = it.value();
+            break;
+        }
+        ++it;
+    }
+    if (watcher && watcher->checkIfModifiedByExternalEditor())
+    {
+        const QList<DCCodeEditorScriptManager::Attacher*> *attachers = watcher->getAttachers();
+        QList<DCCodeEditorScriptManager::Attacher*>::const_iterator it = attachers->begin();
+        while(it != attachers->end())
+        {
+            (*it)->callbackFileModifiedByExternalEditor(notifiedTime);
+            ++it;
+        }
+    }
+}
diff --git a/Source/codeeditor/dccodeeditorscriptmanager.h b/Source/codeeditor/dccodeeditorscriptmanager.h
new file mode 100644 (file)
index 0000000..da6b612
--- /dev/null
@@ -0,0 +1,88 @@
+//  Copyright (c) 2012 Dennco Project
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+//
+//  Created by tkawata on Dec-15, 2012.
+//
+#ifndef DCCODEEDITORSCRIPTMANAGER_H
+#define DCCODEEDITORSCRIPTMANAGER_H
+
+#include <QObject>
+#include <QFileSystemWatcher>
+#include <QMap>
+
+class DCEditScriptFolder;
+class ScriptWatcher;
+class DCCell;
+class DCCellCode;
+
+class DCCodeEditorScriptManager : public QObject
+{
+    Q_OBJECT
+
+public:
+    class Attacher
+    {
+        DCEditScriptFolder          *d_folder;
+        DCCodeEditorScriptManager   *d_manager;
+        ScriptWatcher               *d_watcher;
+
+    public:
+        Attacher(DCEditScriptFolder *folder, DCCodeEditorScriptManager *manager, ScriptWatcher *watcher);
+        ~Attacher();
+        ScriptWatcher* getWatcher() const;
+        QString getCurrentScript(bool forceReload = false);
+        bool getIsModified() const;
+        bool getIsFileModifiedByExternalEditor() const;
+        qint64 getLoadedTime() const;
+        void setScript(const QString& newScript);
+        bool saveScript();
+        void callbackScriptChanged();
+        void callbackModificationStatusChanged(bool modified);
+        void callbackFileModifiedByExternalEditor(qint64 notifiedTime);
+    };
+
+private:
+    DCCodeEditorScriptManager();
+    DCCodeEditorScriptManager::Attacher* createCustomScriptAttacherPrivate(DCEditScriptFolder *folder, DCCell *cell);
+    DCCodeEditorScriptManager::Attacher* createCellCodeScriptAttacherPrivate(DCEditScriptFolder *folder, DCCellCode *cellCode);
+
+    static DCCodeEditorScriptManager    *instance;
+    QMap<DCCell*, ScriptWatcher*>       d_customScriptWatchers;
+    QMap<DCCellCode*, ScriptWatcher*>   d_cellCodeScriptWatchers;
+    QFileSystemWatcher                  *d_customScriptFileWatcher;
+    QFileSystemWatcher                  *d_cellCodeScriptFileWatcher;
+
+public:
+    ~DCCodeEditorScriptManager();
+    static DCCodeEditorScriptManager* getInstance();
+    static DCCodeEditorScriptManager::Attacher* createCustomScriptAttacher(DCEditScriptFolder *folder, DCCell *cell);
+    static DCCodeEditorScriptManager::Attacher* createCellCodeScriptAttacher(DCEditScriptFolder *folder, DCCellCode *cell);
+    QString getCurrentScript(DCCodeEditorScriptManager::Attacher *attacher, bool forceReload = false);
+    bool getIsModified(const DCCodeEditorScriptManager::Attacher *attacher) const;
+    void setScript(DCCodeEditorScriptManager::Attacher *attacher, const QString& newScript);
+    bool saveScript(DCCodeEditorScriptManager::Attacher *attacher);
+    void attacherDeleting(DCCodeEditorScriptManager::Attacher *attacher);
+
+    void callbackScriptChanged(ScriptWatcher *watcher, const DCCodeEditorScriptManager::Attacher *modifier);
+    void callbackModificationStatusChanged(ScriptWatcher *watcher, DCCodeEditorScriptManager::Attacher* modifier, bool modified);
+
+signals:
+
+private slots:
+    void customScriptFileModified(const QString& path);
+    void cellCodeScriptFileModified(const QString& path);
+};
+#endif // DCCODEEDITORSCRIPTMANAGER_H
index 1a3c783..1e60306 100644 (file)
 //
 #include "dceditscriptfolder.h"
 
 //
 #include "dceditscriptfolder.h"
 
-#include <QMap>
-#include <QCryptographicHash>
+#include "dccodeeditorscriptmanager.h"
 
 
-#include "dccell.h"
-#include "dccellcode.h"
-
-class ScriptAttacher;
-class ScriptWatcher;
-
-class ScriptManager
-{
-    static ScriptManager* getInstance();
-    ScriptManager();
-    ~ScriptManager();
-    ScriptAttacher* createCustomScriptAttacherPrivate(DCEditScriptFolder *folder, DCCell *cell);
-    ScriptAttacher* createCellCodeScriptAttacherPrivate(DCEditScriptFolder *folder, DCCellCode *cellCode);
-
-    static ScriptManager *instance;
-    QMap<DCCell*, ScriptWatcher*>       d_customScriptWatchers;
-    QMap<DCCellCode*, ScriptWatcher*>   d_cellCodeScriptWatchers;
-
-public:
-    static ScriptAttacher* createCustomScriptAttacher(DCEditScriptFolder *folder, DCCell *cell);
-    static ScriptAttacher* createCellCodeScriptAttacher(DCEditScriptFolder *folder, DCCellCode *cell);
-    QString getCurrentScript(ScriptAttacher *attacher);
-    bool getIsModified(const ScriptAttacher *attacher) const;
-    void setScript(ScriptAttacher *attacher, const QString& newScript);
-    bool saveScript(ScriptAttacher *attacher);
-    void attacherDeleting(ScriptAttacher *attacher);
-
-    void callbackScriptChanged(ScriptWatcher *watcher, const ScriptAttacher *modifier);
-    void callbackModificationStatusChanged(ScriptWatcher *watcher, ScriptAttacher* modifier, bool modified);
-
-};
-
-class ScriptWatcher
-{
-    bool d_scriptLoadedFromFile;
-    void setModified(ScriptAttacher *modifier, bool modified)
-    {
-        if (d_modified != modified)
-        {
-            d_modified = modified;
-            d_manager->callbackModificationStatusChanged(this, modifier, modified);
-        }
-    }
-
-public:
-    enum E_TYPE { E_CUSTOMSCRIPT, E_CELLCODESCRIPT};
-
-protected:
-    ScriptManager           *d_manager;
-    E_TYPE                   d_type;
-    QList<ScriptAttacher*>  d_attachers;
-    QString                 d_script;
-    QByteArray              d_hashForOriginalScript;
-    bool                    d_modified;
-
-    ScriptWatcher(ScriptManager *manager, E_TYPE type) :
-        d_scriptLoadedFromFile(false), d_manager(manager), d_type(type), d_modified(false)
-    {
-    }
-
-    virtual bool loadScriptFromFile() = 0;
-    virtual bool saveScriptToFile() = 0;
-
-public:
-    virtual ~ScriptWatcher() {}
-    E_TYPE getType() const { return d_type; }
-    void attach(ScriptAttacher *attacher)
-    {
-        d_attachers.append(attacher);
-    }
-
-    void deattach(ScriptAttacher *attacher)
-    {
-        d_attachers.removeOne(attacher);
-    }
-
-    int getRefCount() const
-    {
-        return d_attachers.count();
-    }
-
-    const QList<ScriptAttacher*>* getAttachers() { return &d_attachers; }
-
-    virtual QString getCurrentScript(ScriptAttacher *attacher)
-    {
-        if (!d_scriptLoadedFromFile)
-        {
-            d_hashForOriginalScript.clear();
-            d_scriptLoadedFromFile = loadScriptFromFile();
-            if (d_scriptLoadedFromFile)
-            {
-                d_hashForOriginalScript = QCryptographicHash::hash(d_script.toLocal8Bit(), QCryptographicHash::Md5);
-                setModified(attacher,false);
-            }
-        }
-        return d_script;
-    }
-
-    virtual bool getIsModified(const ScriptAttacher *attacher) const
-    {
-        return d_modified;
-    }
-
-    virtual void setScript(ScriptAttacher *attacher, const QString& newScript)
-    {
-        d_script = newScript;
-        d_manager->callbackScriptChanged(this, attacher);
-        setModified(attacher, d_hashForOriginalScript != QCryptographicHash::hash(newScript.toLocal8Bit(), QCryptographicHash::Md5));
-    }
-
-    virtual bool saveScript(ScriptAttacher *attacher)
-    {
-        bool succeeded = saveScriptToFile();
-        if (succeeded)
-        {
-            d_hashForOriginalScript = QCryptographicHash::hash(d_script.toLocal8Bit(), QCryptographicHash::Md5);
-            setModified(attacher,false);
-        }
-        return succeeded;
-    }
-
-};
-
-class CustomScriptWatcher : public ScriptWatcher
-{
-    DCCell *d_cell;
-
-
-protected:
-    virtual bool loadScriptFromFile()
-    {
-        d_script = d_cell->getCustomScript();
-        return true;
-    }
-
-    virtual bool saveScriptToFile()
-    {
-        return d_cell->saveCustomScript(d_script);
-    }
-
-public:
-    CustomScriptWatcher(ScriptManager *manager, DCCell *cell)
-        : ScriptWatcher(manager, E_CUSTOMSCRIPT), d_cell(cell)
-    {
-    }
-};
-
-class CellCodeScriptWatcher : public ScriptWatcher
-{
-    DCCellCode *d_cellCode;
-
-protected:
-    virtual bool loadScriptFromFile()
-    {
-        d_script = d_cellCode->getOwnScript();
-        return true;
-    }
-
-    virtual bool saveScriptToFile()
-    {
-        return d_cellCode->saveScript(d_script);
-    }
-
-public:
-    CellCodeScriptWatcher(ScriptManager *manager, DCCellCode *cellCode)
-        : ScriptWatcher(manager, E_CELLCODESCRIPT), d_cellCode(cellCode)
-    {
-    }
-
-};
-
-class ScriptAttacher
-{
-    DCEditScriptFolder  *d_folder;
-    ScriptManager       *d_manager;
-    ScriptWatcher       *d_watcher;
-
-public:
-    ScriptAttacher(DCEditScriptFolder *folder, ScriptManager *manager, ScriptWatcher *watcher)
-        : d_folder(folder), d_manager(manager), d_watcher(watcher)
-    {
-    }
-
-    ~ScriptAttacher()
-    {
-        d_manager->attacherDeleting(this);
-    }
-
-    ScriptWatcher* getWatcher() const
-    {
-        return d_watcher;
-    }
-
-    QString getCurrentScript()
-    {
-        return d_manager->getCurrentScript(this);
-    }
-
-    bool getIsModified() const
-    {
-        return d_manager->getIsModified(this);
-    }
-
-    void setScript(const QString& newScript)
-    {
-        d_manager->setScript(this, newScript);
-    }
-
-    bool saveScript()
-    {
-        return d_manager->saveScript(this);
-    }
-
-    void callbackScriptChanged()
-    {
-        d_folder->callbackScriptChanged();
-    }
-
-    void callbackModificationStatusChanged(bool modified)
-    {
-        d_folder->callbackModificationStatusChanged(modified);
-    }
-
-};
-
-ScriptManager* ScriptManager::instance = NULL;
-
-//static
-ScriptAttacher* ScriptManager::createCustomScriptAttacher(DCEditScriptFolder *folder, DCCell *cell)
-{
-    ScriptManager *instance = getInstance();
-    return instance->createCustomScriptAttacherPrivate(folder, cell);
-}
-
-//static
-ScriptAttacher* ScriptManager::createCellCodeScriptAttacher(DCEditScriptFolder *folder, DCCellCode *cell)
-{
-    ScriptManager *instance = getInstance();
-    return instance->createCellCodeScriptAttacherPrivate(folder, cell);
-}
-
-QString ScriptManager::getCurrentScript(ScriptAttacher *attacher)
-{
-    return attacher->getWatcher()->getCurrentScript(attacher);
-}
-
-bool ScriptManager::getIsModified(const ScriptAttacher *attacher) const
-{
-    return attacher->getWatcher()->getIsModified(attacher);
-}
-
-void ScriptManager::setScript(ScriptAttacher *attacher, const QString& newScript)
-{
-    attacher->getWatcher()->setScript(attacher, newScript);
-}
-
-bool ScriptManager::saveScript(ScriptAttacher *attacher)
-{
-    return attacher->getWatcher()->saveScript(attacher);
-}
-
-
-//static
-ScriptManager* ScriptManager::getInstance()
-{
-    if (!instance)
-    {
-        instance = new ScriptManager();
-    }
-    return instance;
-}
-
-ScriptManager::ScriptManager()
-{
-}
-
-ScriptManager::~ScriptManager()
-{
-}
-
-ScriptAttacher* ScriptManager::createCustomScriptAttacherPrivate(DCEditScriptFolder *folder, DCCell *cell)
-{
-    QMap<DCCell*, ScriptWatcher*>::const_iterator it = d_customScriptWatchers.find(cell);
-
-    ScriptWatcher* watcher = NULL;
-    if (it != d_customScriptWatchers.end())
-    {
-        watcher = it.value();
-    }
-    else
-    {
-        watcher = new CustomScriptWatcher(this, cell);
-        d_customScriptWatchers.insert(cell, watcher);
-    }
-
-    ScriptAttacher *attacher = new ScriptAttacher(folder, this, watcher);
-    watcher->attach(attacher);
-
-    return attacher;
-}
-
-ScriptAttacher* ScriptManager::createCellCodeScriptAttacherPrivate(DCEditScriptFolder *folder, DCCellCode *cellCode)
-{
-    QMap<DCCellCode*, ScriptWatcher*>::const_iterator it = d_cellCodeScriptWatchers.find(cellCode);
-
-    ScriptWatcher* watcher = NULL;
-    if (it != d_cellCodeScriptWatchers.end())
-    {
-        watcher = it.value();
-    }
-    else
-    {
-        watcher = new CellCodeScriptWatcher(this, cellCode);
-        d_cellCodeScriptWatchers.insert(cellCode, watcher);
-    }
-
-    ScriptAttacher *attacher = new ScriptAttacher(folder, this, watcher);
-    watcher->attach(attacher);
-
-    return attacher;
-}
-
-void ScriptManager::attacherDeleting(ScriptAttacher *attacher)
-{
-    ScriptWatcher *watcher = attacher->getWatcher();
-    if (watcher)
-    {
-        watcher->deattach(attacher);
-        if (watcher->getRefCount() <= 0)
-        {
-            if (watcher->getType() == ScriptWatcher::E_CUSTOMSCRIPT)
-            {
-                QMap<DCCell*, ScriptWatcher*>::iterator i = d_customScriptWatchers.begin();
-                while (i != d_customScriptWatchers.end())
-                {
-                    if (i.value() == watcher)
-                    {
-                        d_customScriptWatchers.erase(i);
-                        delete watcher;
-                        break;
-                    }
-                    ++i;
-                }
-            }
-            else
-            {
-                QMap<DCCellCode*, ScriptWatcher*>::iterator i = d_cellCodeScriptWatchers.begin();
-                while (i != d_cellCodeScriptWatchers.end())
-                {
-                    if (i.value() == watcher)
-                    {
-                        d_cellCodeScriptWatchers.erase(i);
-                        delete watcher;
-                        break;
-                    }
-                    ++i;
-                }
-            }
-        }
-    }
-}
-
-void ScriptManager::callbackScriptChanged(ScriptWatcher *watcher, const ScriptAttacher *modifier)
-{
-    const QList<ScriptAttacher*> *attachers = watcher->getAttachers();
-
-    QList<ScriptAttacher*>::const_iterator it = attachers->constBegin();
-    while (it != attachers->constEnd())
-    {
-        if (*it != modifier)
-        {
-            (*it)->callbackScriptChanged();
-        }
-        ++it;
-    }
-}
-
-void ScriptManager::callbackModificationStatusChanged(ScriptWatcher *watcher, ScriptAttacher *modifier, bool modified)
-{
-    (void)modifier;
-
-    const QList<ScriptAttacher*> *attachers = watcher->getAttachers();
-
-    QList<ScriptAttacher*>::const_iterator it = attachers->constBegin();
-    while (it != attachers->constEnd())
-    {
-        (*it)->callbackModificationStatusChanged(modified);
-        ++it;
-    }
-}
-
-
-/*--------------------
- * DCEditScriptFolder
- *-------------------*/
 DCEditScriptFolder::DCEditScriptFolder(QObject *parent) :
     QObject(parent), d_attacher(NULL)
 {
 DCEditScriptFolder::DCEditScriptFolder(QObject *parent) :
     QObject(parent), d_attacher(NULL)
 {
@@ -429,13 +33,13 @@ DCEditScriptFolder::~DCEditScriptFolder()
 void DCEditScriptFolder::attach(DCCell *cell)
 {
     deattach();
 void DCEditScriptFolder::attach(DCCell *cell)
 {
     deattach();
-    d_attacher = ScriptManager::createCustomScriptAttacher(this, cell);
+    d_attacher = DCCodeEditorScriptManager::createCustomScriptAttacher(this, cell);
 }
 
 void DCEditScriptFolder::attach(DCCellCode *cellCode)
 {
     deattach();
 }
 
 void DCEditScriptFolder::attach(DCCellCode *cellCode)
 {
     deattach();
-    d_attacher = ScriptManager::createCellCodeScriptAttacher(this, cellCode);
+    d_attacher = DCCodeEditorScriptManager::createCellCodeScriptAttacher(this, cellCode);
 }
 
 void DCEditScriptFolder::deattach()
 }
 
 void DCEditScriptFolder::deattach()
@@ -447,11 +51,11 @@ void DCEditScriptFolder::deattach()
     }
 }
 
     }
 }
 
-QString DCEditScriptFolder::getCurrentScript()
+QString DCEditScriptFolder::getCurrentScript(bool forceReload)
 {
     if (d_attacher)
     {
 {
     if (d_attacher)
     {
-        return d_attacher->getCurrentScript();
+        return d_attacher->getCurrentScript(forceReload);
     }
     return "";
 }
     }
     return "";
 }
@@ -464,6 +68,24 @@ bool DCEditScriptFolder::getIsModified() const
     return false;
 }
 
     return false;
 }
 
+bool DCEditScriptFolder::getIsFileModifiedByExternalEditor() const
+{
+    if (d_attacher)
+    {
+        return d_attacher->getIsFileModifiedByExternalEditor();
+    }
+    return false;
+}
+
+qint64 DCEditScriptFolder::getLoadedTime() const
+{
+    if (d_attacher)
+    {
+        return d_attacher->getLoadedTime();
+    }
+    return 0;
+}
+
 void DCEditScriptFolder::setScript(const QString& newScript)
 {
     if (d_attacher)
 void DCEditScriptFolder::setScript(const QString& newScript)
 {
     if (d_attacher)
@@ -491,3 +113,7 @@ void DCEditScriptFolder::callbackModificationStatusChanged(bool modified)
     emit modificationStatusChanged(modified);
 }
 
     emit modificationStatusChanged(modified);
 }
 
+void DCEditScriptFolder::callbackFileModifiedByExternalEditor(qint64 notifiedTime)
+{
+    emit fileModifiedByExternalEditor(notifiedTime);
+}
index 205ac1f..70bf86b 100644 (file)
 class DCCell;
 class DCCellCode;
 
 class DCCell;
 class DCCellCode;
 
-class ScriptAttacher;
+#include "dccodeeditorscriptmanager.h"
 
 class DCEditScriptFolder : public QObject
 {
     Q_OBJECT
 
 
 class DCEditScriptFolder : public QObject
 {
     Q_OBJECT
 
-    ScriptAttacher   *d_attacher;
+    DCCodeEditorScriptManager::Attacher   *d_attacher;
 
 public:
     explicit DCEditScriptFolder(QObject *parent = 0);
 
 public:
     explicit DCEditScriptFolder(QObject *parent = 0);
@@ -40,18 +40,22 @@ public:
     void    attach(DCCellCode *cellCode);
     void    deattach();
 
     void    attach(DCCellCode *cellCode);
     void    deattach();
 
-    QString getCurrentScript();
+    QString getCurrentScript(bool forceReload = false);
     bool    getIsModified() const;
     bool    getIsModified() const;
+    bool    getIsFileModifiedByExternalEditor() const;
+    qint64  getLoadedTime() const;
 
     void    setScript(const QString& newScript);
     bool    saveScript();
 
     void    callbackScriptChanged();
     void    callbackModificationStatusChanged(bool modified);
 
     void    setScript(const QString& newScript);
     bool    saveScript();
 
     void    callbackScriptChanged();
     void    callbackModificationStatusChanged(bool modified);
+    void    callbackFileModifiedByExternalEditor(qint64 notifiedTime);
 
 signals:
     void    scriptChanged();
     void    modificationStatusChanged(bool modified);
 
 signals:
     void    scriptChanged();
     void    modificationStatusChanged(bool modified);
+    void    fileModifiedByExternalEditor(qint64 notifiedTime);
     
 public slots:
     
     
 public slots:
     
index e9a414d..a1b94f8 100644 (file)
@@ -100,7 +100,8 @@ HEADERS       = mainwindow.h \
     codeeditor/dccellscriptseditorpagewidget.h \
     dialog/dcmanagecellcodedialog.h \
     engine/versioninfo.h \
     codeeditor/dccellscriptseditorpagewidget.h \
     dialog/dcmanagecellcodedialog.h \
     engine/versioninfo.h \
-    codeeditor/dceditscriptfolder.h
+    codeeditor/dceditscriptfolder.h \
+    codeeditor/dccodeeditorscriptmanager.h
 
 SOURCES       = main.cpp \
                 mainwindow.cpp \
 
 SOURCES       = main.cpp \
                 mainwindow.cpp \
@@ -194,7 +195,8 @@ SOURCES       = main.cpp \
     codeeditor/dccellscriptseditortabwidget.cpp \
     codeeditor/dccellscriptseditorpagewidget.cpp \
     dialog/dcmanagecellcodedialog.cpp \
     codeeditor/dccellscriptseditortabwidget.cpp \
     codeeditor/dccellscriptseditorpagewidget.cpp \
     dialog/dcmanagecellcodedialog.cpp \
-    codeeditor/dceditscriptfolder.cpp
+    codeeditor/dceditscriptfolder.cpp \
+    codeeditor/dccodeeditorscriptmanager.cpp
 
 RESOURCES     = denncoCreator.qrc
 
 
 RESOURCES     = denncoCreator.qrc