zjes avatar zjes committed d85f0bf

Fix some bugs, join file modification messages

Comments (0)

Files changed (17)

bin/syntax/python.xml

 
                                 <DetectChar attribute="Normal" char="{" context="parenthesised" beginRegion="parenthesis"/>
                                 <DetectChar attribute="Normal" char="}" context="#pop" endRegion="parenthesis"/>
-				
+
+                                <DetectChar attribute="Normal" char="[" context="parenthesised" beginRegion="parenthesis"/>
+                                <DetectChar attribute="Normal" char="]" context="#pop" endRegion="parenthesis"/>
+
 				<AnyChar attribute="Operator" String="+*/%\|=;\!&lt;&gt;!^&amp;~-" context="#stay"/>
 				<RegExpr attribute="Decorator" String="@[_a-zA-Z][\._a-zA-Z0-9]*" firstNonSpace="true"/>
 			</context>

src/Core/CMakeLists.txt

 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
 
+SET(hdrs
+    Environment.h
+)
+
+SET(src
+    Environment.cpp
+)
 
 SET(moc_hdrs
     IPlugin.h
     PluginManager.h
     ColorChooser.h
     IPreferencesPage.h
-    Environment.h
     FileNameSelect.h
 )
 
     Aux.cpp
     ColorChooser.cpp
     IPreferencesPage.cpp
-    Environment.cpp
     FileNameSelect.cpp
 )
 
 
 ADD_LIBRARY(core
     ${moc}
+    ${src}
     ${uic}
     ${qrc}
 )

src/Designer/DesignerImpl.cpp

 bool DesignerImpl::load()
 { return _widget->load(); }
 
+bool DesignerImpl::reload()
+{ return _widget->reload(); }
+
 void DesignerImpl::undo()
 { _widget->undo(); }
 

src/Designer/DesignerImpl.h

 public slots:
     virtual bool save();
     virtual bool load();
+    virtual bool reload();
 
     virtual void undo();
     virtual void redo();

src/Designer/DesignerWidget.cpp

     return true;
 }
 
+bool DesignerWidget::reload()
+{
+    QFile f(_fileName);
+    f.open(QIODevice::ReadOnly | QIODevice::Text);
+    _form->setContents(f.readAll());
+    f.close();
+    return true;
+}
+
 
 void DesignerWidget::showEvent(QShowEvent *)
 {

src/Designer/DesignerWidget.h

     QString fileName();
     virtual bool save();
     virtual bool load();
+    virtual bool reload();
     bool isModified();
 
     bool isUndoAvailable();

src/Editors/IEditor.h

 public slots:
     virtual bool save() = 0;
     virtual bool load() = 0;
+    virtual bool reload() = 0;
 
     virtual void undo() = 0;
     virtual void redo() = 0;

src/EditorsManager/EditorsContainer.cpp

     a->setShortcut(Qt::ControlModifier + Qt::Key_Tab);
     connect(a, SIGNAL(triggered()), SLOT(historyNavigate()));
     _place->addAction(a);
+
+    _changedTimer.setSingleShot(true);
+    _changedTimer.setInterval(500);
+    _changedTimer.stop();
+    connect(&_changedTimer, SIGNAL(timeout()), SLOT(_onFileChanged()));
 }
 
 Editors::IEditor * EditorsContainer::createEditor(const QString& fileName, EditorType type, bool sample)
     return _openedEditors.contains(fileName);
 }
 
-bool EditorsContainer::_closeEditor(const QString& fileName, bool activate)
+bool EditorsContainer::_closeEditor(const QString& fileName, bool activate, bool ask)
 {
-    if (_openedEditors[fileName]->isModified()){
-        if (QMessageBox::question(this, tr("File is modified"), tr("File is modified, do you want to close this anyway?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
+    if (ask && _openedEditors[fileName]->isModified()){
+        if (QMessageBox::question(this, tr("File is modified"), tr("File is modified")+"\n"+fileName+tr("\nDo you want to close this anyway?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
             return false;
     }
-
     for(int i = 0; i < _place->count(); i++){
         if (qobject_cast<Editors::IEditor*>(_place->widget(i))->fileName() == fileName){
             _place->removeWidget(_place->widget(i));
     if (_changedFiles.contains(file))
         return;
     _changedFiles.append(file);
-
-    QTimer* timer = new QTimer(this);
-    timer->setProperty("file", file);
-    timer->setSingleShot(true);
-    connect(timer, SIGNAL(timeout()), SLOT(_onFileChanged()));
-    timer->start(300);
+    _changedTimer.start();
 }
 
 void EditorsContainer::_onFileChanged()
 {
-    QString file = sender()->property("file").toString();
-    if (_changedFiles.contains(file))
-        _changedFiles.removeAll(file);
-    int btn = QMessageBox::question(this, tr("File was changed"), tr("File %1 was changed externaly, Reload it?").arg(file), QMessageBox::Yes, QMessageBox::No);
+    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){
-        _openedEditors[file]->load();
+        foreach(QString file, _changedFiles){
+            _openedEditors[file]->reload();
+        }
     }
+    _changedFiles.clear();
 }
 
 void EditorsContainer::findNext(bool inc)
 
 bool EditorsContainer::close()
 {
+    QStringList modified;
+    foreach(Editors::IEditor* ed, _openedEditors.values()){
+        if (ed->isModified())
+            modified.append(ed->fileName());
+    }
+    if (modified.length()){
+        if (QMessageBox::question(this, tr("File is modified"), tr("File is modified")+"\n"+modified.join("\n")+tr("\nDo you want to close this anyway?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
+            return false;
+    }
+
     foreach(QString fileName, _openedEditors.keys()){
-        if (!_closeEditor(fileName, false))
+        if (!_closeEditor(fileName, false, false))
             return false;
     }
     return true;

src/EditorsManager/EditorsContainer.h

 #define _EDITORSCONTAINER_H_
 #include <QWidget>
 #include <QMap>
+#include <QTimer>
 #include <QStackedWidget>
 
 namespace Editors {
     void jumpLine(int line);
 private:
     bool isTextFile(const QString& fileName);
-    bool _closeEditor(const QString& fileName, bool activate = true);
+    bool _closeEditor(const QString& fileName, bool activate = true, bool ask = true);
     EditorType typeByFileName(const QString& fileName);
     EditorType editorTypeByName(const QString& name);
 private slots:
     QStringList _stack;
     QFileSystemWatcher *_watcher;
     QStringList _changedFiles;
+    QTimer _changedTimer;
 };
 
 }

src/Main/Consoles/IssuesTable.cpp

 void IssuesTable::setModel(QAbstractItemModel *newModel)
 {
     QTableView::setModel(newModel);
-    QTimer::singleShot(10, this, SLOT(resizeRowsToContents()));
+    if (newModel)
+        QTimer::singleShot(10, this, SLOT(resizeRowsToContents()));
 }
 
 void IssuesTable::currentChanged(const QModelIndex & current, const QModelIndex & /*previous*/)
 
 void IssuesTable::resizeEvent(QResizeEvent *event)
 {
-    setColumnWidth(0, 50);
-    setColumnWidth(1, width() - 120);
+    setColumnWidth(0, 25);
+    setColumnWidth(1, width() - 100);
     setColumnWidth(2, 50);
     QTableView::resizeEvent(event);
 }

src/Main/PynotoWindow.cpp

 
 void PynotoWindow::closeEvent(QCloseEvent *ev)
 {
-    if (!_editors->close())
+    if (!_editors->close()){
         ev->ignore();
+        return;
+    }
 
     Settings set;
     set.setEditorSplitSize(_split->saveState());

src/PythonEditor/ErrorModel.cpp

 #include "ErrorModel.h"
+#include "Include/PynotoApplication.h"
+#include "Include/IIconProvider.h"
 
 ErrorModel::ErrorModel(const QList<Python::IPython::ErrorItem> & list, QObject * parent):
     QAbstractTableModel(parent),
     _list(list)
 {
-
+    _warn = Aux::icons()->icon("warning");
+    _info = Aux::icons()->icon("codestyle");
+    _error = Aux::icons()->icon("error");
+    _suggestion = Aux::icons()->icon("suggestion");
 }
 
 int ErrorModel::rowCount(const QModelIndex &/*parent*/) const
     Python::IPython::ErrorItem node = _list.at(index.row());
     if (role == Qt::DisplayRole){
         switch(index.column()){
-        case 0:
-            return node.severity;
         case 1:
             return node.message;
         case 2:
-            return node.line;
+            return node.line + 1;
+        }
+        return QVariant();
+    }
+    if (role == Qt::DecorationRole){
+        if (index.column() == 0){
+            switch(node.severity){
+            case Python::IPython::CodeStyle:
+                return _info;
+            case Python::IPython::Warning:
+                return _warn;
+            case Python::IPython::Error:
+                return _error;
+            case Python::IPython::Suggestion:
+                return _suggestion;
+            }
         }
+        return QVariant();
     }
     if (role == Qt::EditRole)
         return node.line;
 {
     if (orientation == Qt::Horizontal && role == Qt::DisplayRole){
         switch(section){
-        case 0:
-            return tr("Code");
         case 1:
             return tr("Message");
         case 2:

src/PythonEditor/ErrorModel.h

 #ifndef _ERRORMODEL_H_
 #define _ERRORMODEL_H_
 #include <QAbstractTableModel>
+#include <QIcon>
 #include "Include/IPython.h"
 
 class ErrorModel : public QAbstractTableModel
     QVariant headerData(int section, Qt::Orientation orientation, int role) const;
 private:
     QList<Python::IPython::ErrorItem> _list;
+    QIcon _warn;
+    QIcon _info;
+    QIcon _error;
+    QIcon _suggestion;
 };
 
 #endif // ERRORMODEL_H

src/TextEditor/TextEditorImpl.cpp

 bool TextEditorImpl::load()
 { return _widget->load(); }
 
+bool TextEditorImpl::reload()
+{ return _widget->reload(); }
+
 void TextEditorImpl::undo()
 { _widget->undo(); }
 

src/TextEditor/TextEditorImpl.h

 public slots:
     virtual bool save();
     virtual bool load();
+    virtual bool reload();
 
     virtual void undo();
     virtual void redo();

src/TextEditor/TextEditorWidget.cpp

     return false;
 }
 
+bool TextEditorWidget::reload()
+{
+    saveState();
+    QFile f(_fileName);
+    if (f.open(QIODevice::ReadOnly)){
+        setPlainText(f.readAll());
+        if (_highlighter)
+            _highlighter->rehighlight();
+        restoreState();
+        return true;
+    }
+    return false;
+}
+
 Highlighter* TextEditorWidget::hightlighter()
 {
     return new Highlighter(document(), "default");
             if (ndata)
                 nident = ndata->_foldingIndent;
         }
-        if (ident < nident && !block.text().trimmed().isEmpty()){
+        if (ident < nident && !block.text().trimmed().isEmpty() && !block.text().trimmed().startsWith("#")){
             FoldInfo info;
             QTextBlock nnext = next;
             info.count = 1;
             while(nnext.isValid()){
                 TextBlockData * nndata = static_cast<TextBlockData*>(nnext.userData());
-                if (ident >= nndata->_foldingIndent && !nnext.text().trimmed().isEmpty())
+                if (ident >= nndata->_foldingIndent && !nnext.text().trimmed().isEmpty() && !nnext.text().trimmed().startsWith("#"))
                     break;
                 ++info.count;
                 nnext = nnext.next();

src/TextEditor/TextEditorWidget.h

     void saveState();
 public:
     virtual bool load();
+    virtual bool reload();
     bool isModified();
     bool save();
     QString selectedText();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.