mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
Blocking signals also blocks the notification of file creation (#10595)
This commit is contained in:
parent
fa9ab74ffa
commit
6c4b9c97cb
@ -82,7 +82,7 @@ void FileSystemWatcher::debug()
|
||||
|
||||
FileMonitorGuard::FileMonitorGuard(string const & filename,
|
||||
QFileSystemWatcher * qwatcher)
|
||||
: filename_(filename), qwatcher_(qwatcher)
|
||||
: filename_(filename), qwatcher_(qwatcher), exists_(true)
|
||||
{
|
||||
QObject::connect(qwatcher, SIGNAL(fileChanged(QString const &)),
|
||||
this, SLOT(notifyChange(QString const &)));
|
||||
@ -99,7 +99,7 @@ FileMonitorGuard::~FileMonitorGuard()
|
||||
}
|
||||
|
||||
|
||||
void FileMonitorGuard::refresh(bool new_file)
|
||||
void FileMonitorGuard::refresh()
|
||||
{
|
||||
QString const qfilename = toqstr(filename_);
|
||||
if(!qwatcher_->files().contains(qfilename)) {
|
||||
@ -117,16 +117,10 @@ void FileMonitorGuard::refresh(bool new_file)
|
||||
LYXERR(Debug::FILES,
|
||||
"Could not add path to QFileSystemWatcher: "
|
||||
<< filename_);
|
||||
if (new_file || !exists)
|
||||
QTimer::singleShot(1000, this, SLOT(refreshTrue()));
|
||||
else
|
||||
QTimer::singleShot(1000, this, SLOT(refreshFalse()));
|
||||
// Better (qt>=5.4):
|
||||
/*QTimer::singleShot(1000, this, [=](){
|
||||
refresh(new_file || !exists);
|
||||
});*/
|
||||
} else if (exists && new_file)
|
||||
QTimer::singleShot(2000, this, SLOT(refresh()));
|
||||
} else if (exists && !exists_)
|
||||
Q_EMIT fileChanged();
|
||||
setExists(exists);
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,13 +140,15 @@ void FileMonitorGuard::notifyChange(QString const & path)
|
||||
FileMonitor::FileMonitor(std::shared_ptr<FileMonitorGuard> monitor)
|
||||
: monitor_(monitor)
|
||||
{
|
||||
connectToFileMonitorGuard();
|
||||
QObject::connect(monitor_.get(), SIGNAL(fileChanged()),
|
||||
this, SLOT(changed()));
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
||||
void FileMonitor::connectToFileMonitorGuard()
|
||||
void FileMonitor::reconnectToFileMonitorGuard()
|
||||
{
|
||||
monitor_->setExists(true);
|
||||
QObject::connect(monitor_.get(), SIGNAL(fileChanged()),
|
||||
this, SLOT(changed()));
|
||||
}
|
||||
|
@ -101,12 +101,14 @@ public:
|
||||
~FileMonitorGuard();
|
||||
/// absolute path being tracked
|
||||
std::string const & filename() { return filename_; }
|
||||
/// if false, emit fileChanged() when we notice the existence of the file
|
||||
void setExists(bool exists) { exists_ = exists; }
|
||||
|
||||
public Q_SLOTS:
|
||||
/// Make sure it is being monitored, after e.g. a deletion. See
|
||||
/// <https://bugreports.qt.io/browse/QTBUG-46483>. This is called
|
||||
/// automatically.
|
||||
/// \param new_file If true, emit fileChanged if the file exists and was
|
||||
/// successfully added.
|
||||
void refresh(bool new_file = false);
|
||||
void refresh();
|
||||
|
||||
Q_SIGNALS:
|
||||
/// Connect to this to be notified when the file changes
|
||||
@ -116,17 +118,10 @@ private Q_SLOTS:
|
||||
/// Receive notifications from the QFileSystemWatcher
|
||||
void notifyChange(QString const & path);
|
||||
|
||||
/// nonsense introduced for when QT_VERSION < 0x050000, cannot be placed
|
||||
/// between #ifdef
|
||||
void refreshTrue() { refresh(true); }
|
||||
/// nonsense introduced for when QT_VERSION < 0x050000, cannot be placed
|
||||
/// between #ifdef
|
||||
void refreshFalse() { refresh(false); }
|
||||
|
||||
|
||||
private:
|
||||
std::string const filename_;
|
||||
QFileSystemWatcher * qwatcher_;
|
||||
bool exists_;
|
||||
};
|
||||
|
||||
|
||||
@ -183,7 +178,7 @@ private Q_SLOTS:
|
||||
/// Receive notifications from the FileMonitorGuard
|
||||
void changed();
|
||||
///
|
||||
void connectToFileMonitorGuard();
|
||||
void reconnectToFileMonitorGuard();
|
||||
|
||||
private:
|
||||
// boost signal
|
||||
|
Loading…
Reference in New Issue
Block a user