Commits

Anonymous committed 376b93a

Continue work after pause

  • Participants
  • Parent commits a588d03

Comments (0)

Files changed (12)

File src/EditorsManager/EditorsContainer.cpp

 { closeCurrentEditor(); }
 
 void EditorsContainer::save()
-{ if (_currentEditor) _currentEditor->save(); }
+{
+    if (_currentEditor){
+        _toSaveFile.append(_currentEditor->fileName());
+        _currentEditor->save();
+    }
+}
 
 void EditorsContainer::saveAll()
 {
-    foreach(Editors::IEditor *ed, _openedEditors.values())
+    foreach(Editors::IEditor *ed, _openedEditors.values()){
+        _toSaveFile.append(ed->fileName());
         ed->save();
+    }
 }
 
 void EditorsContainer::saveAs()
 {
     if (_changedFiles.contains(file))
         return;
+
     _changedFiles.append(file);
     _changedTimer.start();
 }
 
 void EditorsContainer::_onFileChanged()
 {
+    foreach(QString file, _changedFiles){
+        if (_toSaveFile.contains(file)){
+            _toSaveFile.removeAll(file);
+            _changedFiles.removeAll(file);
+            qDebug() << file << _toSaveFile;
+            continue;
+        }
+    }
+
     if (!_changedFiles.length())
         return;
+
     int btn = QMessageBox::question(this, tr("File was changed"), tr("Files\n%1\nWas changed externaly, Reload it?").arg(_changedFiles.join("\n")), QMessageBox::Yes, QMessageBox::No);
     if (btn == QMessageBox::Yes){
         foreach(QString file, _changedFiles){

File src/EditorsManager/EditorsContainer.h

     QFileSystemWatcher *_watcher;
     QStringList _changedFiles;
     QTimer _changedTimer;
+    QStringList _toSaveFile;
 };
 
 }

File src/Project/CMakeLists.txt

     Properties/CodeCheck.h
     CreateProjectDlg.h
     Properties/PathesModel.h
+    NewItems/AddNewWizard.h
 )
 
 SET(moc
     Properties/CodeCheck.cpp
     CreateProjectDlg.cpp
     Properties/PathesModel.cpp
+    NewItems/AddNewWizard.cpp
 )
 
 SET(res

File src/Project/IProject.h

     virtual QString fileName() = 0;
     virtual QStringList shownFiles() = 0;
     virtual QStringList openedDirs() = 0;
+    virtual void setOpenedDirs(const QStringList&) = 0;
+    virtual void openDir(const QString&) = 0;
+    virtual void closeDir(const QString&) = 0;
     virtual QStringList openedFiles() = 0;
     virtual QString mainScript() = 0;
     virtual QString fileDisplayName(const QString& fileName) = 0;

File src/Project/NewItems/AddNewWizard.cpp

+#include "AddNewWizard.h"
+
+namespace Project {
+
+AddNewWizard::AddNewWizard(const QString& path, NodeTypes type, QWidget * parent):
+    QWizard(parent),
+    _path(path),
+    _type(type)
+{
+
+}
+
+}

File src/Project/NewItems/AddNewWizard.h

+#ifndef _ADDNEWWIZARD_H_
+#define _ADDNEWWIZARD_H_
+
+#include <QWizard>
+#include "Node.h"
+
+namespace Project {
+
+class AddNewWizard: public QWizard
+{
+    Q_OBJECT
+public:
+    AddNewWizard(const QString& path, NodeTypes type, QWidget * parent);
+private:
+    QString _path;
+    NodeTypes _type;
+};
+
+}
+
+#endif

File src/Project/Node.cpp

 
 }
 
-//Q_DECLARE_METATYPE(Node*);
+//Q_DECLARE_METATYPE(Project::NodeTypes);

File src/Project/ProjectFile.cpp

 
 QString ProjectFile::interpretName()
 {
+    if (!_settings)
+        return "";
     return _settings->value("python/interpret", "").toString();
 }
 
     return list;
 }
 
+void ProjectFile::setOpenedDirs(const QStringList& dirs)
+{
+    _settings->remove("openedDirs");
+    _settings->beginWriteArray("openedDirs");
+    for (int i = 0; i < dirs.length(); ++i) {
+        _settings->setArrayIndex(i);
+        _settings->setValue("dir", dirs[i]);
+    }
+    _settings->endArray();
+}
+
+
 QStringList ProjectFile::openedFiles()
 {
     QStringList list;
     }
 }
 
+void ProjectFile::openDir(const QString& path)
+{
+    QStringList dirs = openedDirs();
+    dirs.append(path);
+    setOpenedDirs(dirs);
+}
+
+void ProjectFile::closeDir(const QString& path)
+{
+    QStringList dirs = openedDirs();
+    dirs.removeAll(path);
+    setOpenedDirs(dirs);
+}
+
 
 }

File src/Project/ProjectFile.h

     void setShownFiles(const QStringList&);
 
     virtual QStringList openedDirs();
+    virtual void setOpenedDirs(const QStringList& dirs);
+    virtual void openDir(const QString&);
+    virtual void closeDir(const QString&);
+
     virtual QStringList openedFiles();
     virtual QString mainScript();
     void setMainScript(const QString& mainScript);

File src/Project/ProjectManagerWidget.cpp

 #include <QDebug>
 #include <QFileInfo>
 #include <QHeaderView>
+#include <QMenu>
 #include "ProjectManagerWidget.h"
 #include "ProjectTreeModel.h"
 #include "Include/IProject.h"
+#include "Node.h"
+#include "NewItems/AddNewWizard.h"
 
 namespace Project {
 
 ProjectManagerWidget::ProjectManagerWidget(QWidget * parent, IProject* project):
     QTreeView(parent),
-    _project(project)
+    _project(project),
+    _menu(NULL)
 {
     header()->hide();
     setContextMenuPolicy(Qt::CustomContextMenu);
     }
 }
 
-void ProjectManagerWidget::onItemCollapsed(const QModelIndex&)
+void ProjectManagerWidget::onItemCollapsed(const QModelIndex& index)
 {
-
+    QString path = index.data(Qt::EditRole).toString();
+    _project->closeDir(path);
 }
 
-void ProjectManagerWidget::onItemExpanded(const QModelIndex&)
+void ProjectManagerWidget::onItemExpanded(const QModelIndex& index)
 {
-
+    QString path = index.data(Qt::EditRole).toString();
+    _project->openDir(path);
 }
 
-void ProjectManagerWidget::onMenuShow(const QPoint&)
+void ProjectManagerWidget::onMenuShow(const QPoint& pt)
 {
-
+    if (!_menu){
+        _menu = new QMenu(this);
+        _actions["new"] = _menu->addAction(tr("Add new"), this, SLOT(addNew()));
+        _actions["delete"] = _menu->addAction(tr("Delete"));
+        _actions["rename"] = _menu->addAction(tr("Rename"));
+        _menu->addSeparator();
+        _actions["open"] = _menu->addAction(tr("Open"), this, SLOT(openFile()));
+        _actions["compile"] = _menu->addAction(tr("Compile"));
+    }
+    QModelIndex index = indexAt(pt);
+    if (index.isValid()){
+        NodeTypes type = (NodeTypes)index.data(Qt::UserRole+1).toInt();
+        _actions["new"]->setEnabled(type == DirectoryType || type == PyModuleType);
+        _actions["delete"]->setEnabled(true);
+        _actions["rename"]->setEnabled(true);
+        _actions["open"]->setEnabled(type != DirectoryType && type != PyModuleType);
+        _actions["compile"]->setEnabled(type == DesignerType || type == ResourcesType);
+    } else {
+        _actions["new"]->setEnabled(true);
+        _actions["delete"]->setEnabled(false);
+        _actions["rename"]->setEnabled(false);
+        _actions["open"]->setEnabled(false);
+        _actions["compile"]->setEnabled(false);
+    }
+    _menu->popup(mapToGlobal(pt));
 }
 
 QSize ProjectManagerWidget::minimumSizeHint()
     return QSize(250, 200);
 }
 
+void ProjectManagerWidget::openFile()
+{
+    QString path = currentIndex().data(Qt::EditRole).toString();
+    if (QFileInfo(path).isFile()){
+        _project->openFile(path);
+    }
+}
+
+void ProjectManagerWidget::addNew()
+{
+    QString path = currentIndex().data(Qt::EditRole).toString();
+    NodeTypes type = (NodeTypes)currentIndex().data(Qt::UserRole+1).toInt();
+    AddNewWizard wiz(path, type, this);
+    wiz.exec();
+}
+
 }

File src/Project/ProjectManagerWidget.h

 #define _PROJECTMANAGERWIDGET_H_
 #include <QTreeView>
 
+class QMenu;
 namespace Project {
 
 class IProject;
 
     void onMenuShow(const QPoint&);
     virtual QSize minimumSizeHint();
+private slots:
+    void openFile();
+    void addNew();
 private:
     void restoreSession();
 private:
     IProject * _project;
+    QMenu * _menu;
+    QMap<QString, QAction*> _actions;
 };
 
 }

File src/TextEditor/TextEditorWidget.cpp

 
 bool TextEditorWidget::save()
 {
-    qDebug() << "save";
+    QFile file(_fileName);
+    if (file.open(QIODevice::WriteOnly | QIODevice::Text)){
+        file.write(toPlainText().toUtf8());
+        file.flush();
+        file.waitForBytesWritten(1000);
+        file.close();
+        document()->setModified(false);
+        return true;
+    }
     return false;
 }