Skip to content

Commit

Permalink
fix: delay 'document changed' banner on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleds committed May 11, 2018
1 parent 16bb278 commit 56aa8aa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/ui/docengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ bool DocEngine::trySudoSave(QString sudoProgram, QUrl outFileName, Editor* edito

int DocEngine::saveDocument(EditorTabWidget *tabWidget, int tab, QUrl outFileName, bool copy)
{
Editor *editor = tabWidget->editor(tab);
QSharedPointer<Editor> editor = tabWidget->editorSharedPtr(tabWidget->editor(tab));

if (!copy)
unmonitorDocument(editor);
Expand All @@ -681,7 +681,7 @@ int DocEngine::saveDocument(EditorTabWidget *tabWidget, int tab, QUrl outFileNam

do
{
if (write(&file, editor)) {
if (write(&file, editor.data())) {
break;
} else {
static QString sudoProgram = getAvailableSudoProgram();
Expand All @@ -705,7 +705,7 @@ int DocEngine::saveDocument(EditorTabWidget *tabWidget, int tab, QUrl outFileNam
} else if (clicked == retry) {
continue;
} else if (clicked == retryRoot) {
if (trySudoSave(sudoProgram, outFileName, editor))
if (trySudoSave(sudoProgram, outFileName, editor.data()))
break;
else {
continue;
Expand All @@ -727,7 +727,13 @@ int DocEngine::saveDocument(EditorTabWidget *tabWidget, int tab, QUrl outFileNam

file.close();

#ifdef Q_OS_MACX
// On macOS we need to give it a little bit of time, otherwise we get the
// "document changed" banner as soon as the document is saved.
QTimer::singleShot(100, [=](){ monitorDocument(editor); });
#else
monitorDocument(editor);
#endif

if (!copy) {
emit documentSaved(tabWidget, tab);
Expand Down Expand Up @@ -779,6 +785,16 @@ void DocEngine::unmonitorDocument(Editor *editor)
unmonitorDocument(editor->filePath().toLocalFile());
}

void DocEngine::monitorDocument(QSharedPointer<Editor> editor)
{
monitorDocument(editor->filePath().toLocalFile());
}

void DocEngine::unmonitorDocument(QSharedPointer<Editor> editor)
{
unmonitorDocument(editor->filePath().toLocalFile());
}

bool DocEngine::isMonitored(Editor *editor)
{
return m_fsWatcher->files().contains(editor->filePath().toLocalFile());
Expand Down
2 changes: 2 additions & 0 deletions src/ui/include/docengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ class DocEngine : public QObject
QPair<int, int> findOpenEditorByUrl(const QUrl &filename) const;

void monitorDocument(Editor *editor);
void monitorDocument(QSharedPointer<Editor> editor);
void unmonitorDocument(Editor *editor);
void unmonitorDocument(QSharedPointer<Editor> editor);
bool isMonitored(Editor *editor);

int addNewDocument(QString name, bool setFocus, EditorTabWidget *tabWidget);
Expand Down

0 comments on commit 56aa8aa

Please sign in to comment.