Commits

zjes  committed 51a93c1

Fix file closing and fatal message while python import

  • Participants
  • Parent commits 536689b

Comments (0)

Files changed (9)

File bin/python3/srv.zip

Binary file modified.

File src/EditorsManager/EditorsContainer.cpp

 #include "Include/ITextEditor.h"
 #include "Include/IEditorPlugin.h"
 #include "Include/PynotoApplication.h"
+#include "Include/IProjectPlugin.h"
+#include "Include/IProject.h"
 #include "FindDialog.h"
 #include "HistoryNavigate.h"
 #include "Settings.h"
     _watcher = new QFileSystemWatcher(this);
     connect(_watcher, SIGNAL(fileChanged(QString)), SLOT(onFileChanged(QString)));
 
+    _project = Aux::plugin<Project::IProjectPlugin*>("project")->project();
+
     _place = new QStackedWidget(this);
 
     _find = new FindDialog(this);
             _stack.removeOne(fileName);
             _watcher->removePath(fileName);
             emit editorClosed(fileName);
-            if (activate && _stack.length() > 0)
+            if (activate && _stack.length() > 0){
+                _project->closeFile(fileName);
                 activateEditor(_stack.first());
+            }
             break;
         }
     }

File src/EditorsManager/EditorsContainer.h

 namespace Editors {
     class IEditor;
 }
+namespace Project {
+    class IProject;
+}
 class QFileSystemWatcher;
 class QAbstractTableModel;
 namespace EditorsManager {
     QStringList _changedFiles;
     QTimer _changedTimer;
     QStringList _toSaveFile;
+    Project::IProject *_project;
 };
 
 }

File src/EditorsManager/EditorsManagerPlugin.cpp

     connect(_widget, SIGNAL(findAvailable(bool)),       this, SIGNAL(findAvailable(bool)));
     connect(_widget, SIGNAL(replaceAvailable(bool)),    this, SIGNAL(replaceAvailable(bool)));
     connect(_widget, SIGNAL(errorListChanged(QAbstractTableModel*)), this, SIGNAL(errorListChanged(QAbstractTableModel*)));
+    connect(_widget, SIGNAL(editorClosed(QString)),     this, SIGNAL(editorClosed(QString)));
     return _widget;
 }
 

File src/EditorsManager/IEditorsManagerPlugin.h

     void findAvailable(bool);
     void replaceAvailable(bool);
     void modificationChanged(bool);
+    void editorClosed(const QString& fileName);
 public slots:
     virtual void openFileOffset(const QString& fileName, int offset = 0) = 0;
     virtual void resetEditor() = 0;

File src/Main/Consoles/LogOutput.cpp

     QPlainTextEdit(parent)
 {
     Project::IProject *prj = Aux::plugin<Project::IProjectPlugin*>("project")->project();
-    connect(prj, SIGNAL(systemError(QString)), SLOT(appendLog(QString)));
+    if (prj)
+        connect(prj, SIGNAL(systemError(QString)), SLOT(appendLog(QString)));
 }
 
 LogOutput::~LogOutput()

File src/Project/IProject.h

     void systemError(const QString& err);
 public slots:
     virtual void openFile(const QString& fileName, int offset = 0) = 0;
+    virtual void closeFile(const QString& fileName) = 0;
 signals:
     void loaded();
     void unloaded();

File src/Project/ProjectFile.cpp

 
 QStringList ProjectFile::openedDirs()
 {
+    if (!_settings)
+        return QStringList();
     QStringList list;
     int size = _settings->beginReadArray("openedDirs");
     for (int i = 0; i < size; ++i) {
         _settings->setValue("dir", dirs[i]);
     }
     _settings->endArray();
+    _settings->sync();
 }
 
 
 QStringList ProjectFile::openedFiles()
 {
+    if (!_settings)
+        return QStringList();
     QStringList list;
     int size = _settings->beginReadArray("openedFiles");
     for (int i = 0; i < size; ++i) {
 
 void ProjectFile::openFile(const QString& fileName, int offset)
 {
+    if (!_settings)
+        return;
     QStringList files = openedFiles();
     if (!files.contains(fileName)){
+        qDebug() << "open file" << fileName;
         files.append(fileName);
         _settings->remove("openedFiles");
         _settings->beginWriteArray("openedFiles");
             _settings->setValue("file", files[i]);
         }
         _settings->endArray();
-
+        _settings->sync();
     }
     emit openFileOffset(fileName, offset);
 }
 
+void ProjectFile::closeFile(const QString& fileName)
+{
+    if (!_settings)
+        return;
+    QStringList files = openedFiles();
+    if (files.contains(fileName)){
+        qDebug() << "close file" << fileName;
+        files.removeAll(fileName);
+        _settings->remove("openedFiles");
+        _settings->beginWriteArray("openedFiles");
+        for (int i = 0; i < files.length(); ++i) {
+            _settings->setArrayIndex(i);
+            _settings->setValue("file", files[i]);
+        }
+        _settings->endArray();
+        _settings->sync();
+    }
+}
+
 QString ProjectFile::mainScript()
 {
     return _settings->value("common/mainscript", "").toString();
         _pythonCode = Aux::plugin<PythonCode::IPythonCodePlugin*>("pythoncode")->python();
         _pythonCode->init(interpretExec(), path(), mainScript(), _settings->fileName(), interpretPathes() + extraPathes());
     }
-    connect(_pythonCode, SIGNAL(systemError(QString)), SIGNAL(systemError(QString)));
+    if (_pythonCode)
+        connect(_pythonCode, SIGNAL(systemError(QString)), SIGNAL(systemError(QString)));
     return _pythonCode;
 }
 

File src/Project/ProjectFile.h

     void setExtraPathes(const QStringList& pathes);
 public slots:
     virtual void openFile(const QString& fileName, int offset = 0);
+    virtual void closeFile(const QString& fileName);
 private:
     bool _loaded;
     QSettings * _settings;