Skip to content

Commit

Permalink
fix: file not finish loadding cannot be saved.
Browse files Browse the repository at this point in the history
Change-Id: Ie14794978eac590e6124c258cc7acbf933e03c42
  • Loading branch information
rekols committed Sep 12, 2018
1 parent 54c6259 commit 2e75eab
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions editor/src/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ void Editor::loadFile(const QString &filepath)
// QApplication::setOverrideCursor(Qt::WaitCursor);

m_isWritable = QFileInfo(filepath).isWritable();
m_isLoadFinished = false;

// update file path.
updatePath(filepath);
Expand Down Expand Up @@ -180,6 +181,7 @@ void Editor::handleFileLoadFinished(const QByteArray &encode, const QString &con
// restore mouse style.
// QApplication::restoreOverrideCursor();

m_isLoadFinished = true;
m_fileEncode = encode;

// set text.
Expand Down
2 changes: 2 additions & 0 deletions editor/src/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Editor : public QWidget
bool saveFile(const QString &encode, const QString &newline);
bool saveFile();
bool isWritable() { return m_isWritable; }
bool isLoadFinished() { return m_isLoadFinished; }

void updatePath(QString file);
QByteArray fileEncode() { return m_fileEncode; }
Expand All @@ -60,6 +61,7 @@ class Editor : public QWidget
int m_autoSaveInternal;
bool m_hasLoadFile = false;
bool m_isWritable = false;
bool m_isLoadFinished = false;
QString m_newline;
};

Expand Down
10 changes: 10 additions & 0 deletions editor/src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ Window::Window(DMainWindow *parent)
DAnchorsBase::setAnchor(m_themePanel, Qt::AnchorBottom, m_centralWidget, Qt::AnchorBottom);
DAnchorsBase::setAnchor(m_themePanel, Qt::AnchorRight, m_centralWidget, Qt::AnchorRight);

// for the first time open the need be init.
m_themePanel->setSelectionTheme(m_themePath);

connect(m_themePanel, &ThemePanel::themeChanged, this, &Window::themeChanged);
connect(this, &Window::requestDragEnterEvent, this, &Window::dragEnterEvent);
connect(this, &Window::requestDropEvent, this, &Window::dropEvent);
Expand Down Expand Up @@ -483,6 +486,13 @@ bool Window::saveFile()
const QString &currentDir = QFileInfo(currentPath).absolutePath();
bool isBlankFile = QFileInfo(currentPath).dir().absolutePath() == m_blankFileDir;

// file not finish loadding cannot be saved
// otherwise you will save the content of the empty.
if (!m_editorMap[currentPath]->isLoadFinished()) {
showNotify(tr("File cannot be saved if it is not loaded."));
return false;
}

// save blank file.
if (isBlankFile) {
QString encode, newline;
Expand Down

0 comments on commit 2e75eab

Please sign in to comment.