Skip to content

Commit

Permalink
Fixes reload when changing tab issue (eteran#112)! (eteran#227)
Browse files Browse the repository at this point in the history
* Fixes issue eteran#112!

So the problem was that by checking for file changes in the focus event itself, we are popping up
the messagebox BEFORE the focus event is complete. And the update caused by the focus event happens
AFTER it is complete.

So the solution is to NOT check for changes inside the focus event, but instead to schedule
a check for the immediate future. (Done via a single shot timer with a 0 timeout). Inspired
by kernel "bottom half interrupt handlers".

This allows the windowing system to complete processes of existing events, including the repaint
and then will immediately check for changes.

Woot!

* Following @sjtringali's advice, this is a bit of a cleaner solution since it doesn't need a `QTimer` but has the same effect
  • Loading branch information
eteran authored and 1div0 committed Dec 29, 2020
1 parent 5f8b714 commit 29fbca9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
for (MainWindow *window : windows) {
window->ui.action_Move_Tab_To->setEnabled(enabled);
}

connect(
this, &MainWindow::checkForChangesToFile, this, [](DocumentWidget *document) {
document->checkForChangesToFile();
},
Qt::QueuedConnection);
}

/**
Expand Down Expand Up @@ -4787,7 +4793,6 @@ DocumentWidget *MainWindow::editNewFile(MainWindow *window, const QString &geome
document->raiseDocumentWindow();
}


return document;
}

Expand Down Expand Up @@ -5445,7 +5450,7 @@ void MainWindow::focusChanged(QWidget *from, QWidget *to) {
endISearch();

// Check for changes to read-only status and/or file modifications
document->checkForChangesToFile();
Q_EMIT checkForChangesToFile(document);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ class MainWindow final : public QMainWindow {
void focusChanged(QWidget *from, QWidget *to);
void updateWindowHints(DocumentWidget *);

Q_SIGNALS:
void checkForChangesToFile(DocumentWidget *document);

public Q_SLOTS:
void selectionChanged(bool selected);
void undoAvailable(bool available);
Expand Down

0 comments on commit 29fbca9

Please sign in to comment.