Changeset View
Changeset View
Standalone View
Standalone View
src/document/katedocument.cpp
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Line(s) | |||||
64 | #include <KFileItem> | 64 | #include <KFileItem> | ||
65 | #include <KJobWidgets> | 65 | #include <KJobWidgets> | ||
66 | #include <KMessageBox> | 66 | #include <KMessageBox> | ||
67 | #include <KStandardAction> | 67 | #include <KStandardAction> | ||
68 | #include <KXMLGUIFactory> | 68 | #include <KXMLGUIFactory> | ||
69 | #include <kdirwatch.h> | 69 | #include <kdirwatch.h> | ||
70 | #include <KCodecs> | 70 | #include <KCodecs> | ||
71 | #include <KStringHandler> | 71 | #include <KStringHandler> | ||
72 | #include <KToggleAction> | ||||
72 | #include <KConfigGroup> | 73 | #include <KConfigGroup> | ||
73 | #include <KMountPoint> | 74 | #include <KMountPoint> | ||
74 | 75 | | |||
75 | #include <QCryptographicHash> | 76 | #include <QCryptographicHash> | ||
76 | #include <QFile> | 77 | #include <QFile> | ||
77 | #include <QMap> | 78 | #include <QMap> | ||
78 | #include <QTextCodec> | 79 | #include <QTextCodec> | ||
79 | #include <QTextStream> | 80 | #include <QTextStream> | ||
▲ Show 20 Lines • Show All 176 Lines • ▼ Show 20 Line(s) | 213 | { | |||
256 | 257 | | |||
257 | /** | 258 | /** | ||
258 | * singleshot timer to handle updates of mod on hd state delayed | 259 | * singleshot timer to handle updates of mod on hd state delayed | ||
259 | */ | 260 | */ | ||
260 | m_modOnHdTimer.setSingleShot(true); | 261 | m_modOnHdTimer.setSingleShot(true); | ||
261 | m_modOnHdTimer.setInterval(200); | 262 | m_modOnHdTimer.setInterval(200); | ||
262 | connect(&m_modOnHdTimer, SIGNAL(timeout()), this, SLOT(slotDelayedHandleModOnHd())); | 263 | connect(&m_modOnHdTimer, SIGNAL(timeout()), this, SLOT(slotDelayedHandleModOnHd())); | ||
263 | 264 | | |||
265 | // Setup auto reload stuff | ||||
266 | m_autoReloadMode = new KToggleAction(i18n("Auto Reload Document"), this); | ||||
267 | m_autoReloadMode->setWhatsThis(i18n("Automatic reload the docuemnt when it was changed on disk")); | ||||
268 | connect(m_autoReloadMode, &KToggleAction::triggered, this, &DocumentPrivate::autoReloadToggled); | ||||
269 | // Prepare some reload amok protector | ||||
270 | m_autoReloadThrottle.setSingleShot(true); | ||||
271 | m_autoReloadThrottle.setInterval(3000); | ||||
272 | connect(&m_autoReloadThrottle, &QTimer::timeout, this, &DocumentPrivate::onModOnHdAutoReload); | ||||
273 | | ||||
264 | /** | 274 | /** | ||
265 | * load handling | 275 | * load handling | ||
266 | * this is needed to ensure we signal the user if a file ist still loading | 276 | * this is needed to ensure we signal the user if a file ist still loading | ||
267 | * and to disallow him to edit in that time | 277 | * and to disallow him to edit in that time | ||
268 | */ | 278 | */ | ||
269 | connect(this, SIGNAL(started(KIO::Job*)), this, SLOT(slotStarted(KIO::Job*))); | 279 | connect(this, SIGNAL(started(KIO::Job*)), this, SLOT(slotStarted(KIO::Job*))); | ||
270 | connect(this, SIGNAL(completed()), this, SLOT(slotCompleted())); | 280 | connect(this, SIGNAL(completed()), this, SLOT(slotCompleted())); | ||
271 | connect(this, SIGNAL(canceled(QString)), this, SLOT(slotCanceled())); | 281 | connect(this, SIGNAL(canceled(QString)), this, SLOT(slotCanceled())); | ||
▲ Show 20 Lines • Show All 3963 Lines • ▼ Show 20 Line(s) | |||||
4235 | } | 4245 | } | ||
4236 | 4246 | | |||
4237 | void KTextEditor::DocumentPrivate::slotModifiedOnDisk(KTextEditor::View * /*v*/) | 4247 | void KTextEditor::DocumentPrivate::slotModifiedOnDisk(KTextEditor::View * /*v*/) | ||
4238 | { | 4248 | { | ||
4239 | if (url().isEmpty() || !m_modOnHd) { | 4249 | if (url().isEmpty() || !m_modOnHd) { | ||
4240 | return; | 4250 | return; | ||
4241 | } | 4251 | } | ||
4242 | 4252 | | |||
4253 | if (!isModified() && isAutoReload()) { | ||||
4254 | onModOnHdAutoReload(); | ||||
4255 | return; | ||||
4256 | } | ||||
4257 | | ||||
4243 | if (!m_fileChangedDialogsActivated || m_modOnHdHandler) { | 4258 | if (!m_fileChangedDialogsActivated || m_modOnHdHandler) { | ||
4244 | return; | 4259 | return; | ||
4245 | } | 4260 | } | ||
4246 | 4261 | | |||
4247 | // don't ask the user again and again the same thing | 4262 | // don't ask the user again and again the same thing | ||
4248 | if (m_modOnHdReason == m_prevModOnHdReason) { | 4263 | if (m_modOnHdReason == m_prevModOnHdReason) { | ||
4249 | return; | 4264 | return; | ||
4250 | } | 4265 | } | ||
4251 | m_prevModOnHdReason = m_modOnHdReason; | 4266 | m_prevModOnHdReason = m_modOnHdReason; | ||
4252 | 4267 | | |||
4253 | m_modOnHdHandler = new KateModOnHdPrompt(this, m_modOnHdReason, reasonedMOHString()); | 4268 | m_modOnHdHandler = new KateModOnHdPrompt(this, m_modOnHdReason, reasonedMOHString()); | ||
4254 | connect(m_modOnHdHandler.data(), &KateModOnHdPrompt::saveAsTriggered, this, &DocumentPrivate::onModOnHdSaveAs); | 4269 | connect(m_modOnHdHandler.data(), &KateModOnHdPrompt::saveAsTriggered, this, &DocumentPrivate::onModOnHdSaveAs); | ||
4255 | connect(m_modOnHdHandler.data(), &KateModOnHdPrompt::reloadTriggered, this, &DocumentPrivate::onModOnHdReload); | 4270 | connect(m_modOnHdHandler.data(), &KateModOnHdPrompt::reloadTriggered, this, &DocumentPrivate::onModOnHdReload); | ||
4271 | connect(m_modOnHdHandler.data(), &KateModOnHdPrompt::autoReloadTriggered, this, &DocumentPrivate::onModOnHdAutoReload); | ||||
4256 | connect(m_modOnHdHandler.data(), &KateModOnHdPrompt::ignoreTriggered, this, &DocumentPrivate::onModOnHdIgnore); | 4272 | connect(m_modOnHdHandler.data(), &KateModOnHdPrompt::ignoreTriggered, this, &DocumentPrivate::onModOnHdIgnore); | ||
4257 | } | 4273 | } | ||
4258 | 4274 | | |||
4259 | void KTextEditor::DocumentPrivate::onModOnHdSaveAs() | 4275 | void KTextEditor::DocumentPrivate::onModOnHdSaveAs() | ||
4260 | { | 4276 | { | ||
4261 | m_modOnHd = false; | 4277 | m_modOnHd = false; | ||
4262 | QWidget *parentWidget(dialogParent()); | 4278 | QWidget *parentWidget(dialogParent()); | ||
4263 | const QUrl res = QFileDialog::getSaveFileUrl(parentWidget, i18n("Save File"), url(), {}, nullptr, | 4279 | const QUrl res = QFileDialog::getSaveFileUrl(parentWidget, i18n("Save File"), url(), {}, nullptr, | ||
Show All 16 Lines | |||||
4280 | { | 4296 | { | ||
4281 | m_modOnHd = false; | 4297 | m_modOnHd = false; | ||
4282 | m_prevModOnHdReason = OnDiskUnmodified; | 4298 | m_prevModOnHdReason = OnDiskUnmodified; | ||
4283 | emit modifiedOnDisk(this, false, OnDiskUnmodified); | 4299 | emit modifiedOnDisk(this, false, OnDiskUnmodified); | ||
4284 | documentReload(); | 4300 | documentReload(); | ||
4285 | delete m_modOnHdHandler; | 4301 | delete m_modOnHdHandler; | ||
4286 | } | 4302 | } | ||
4287 | 4303 | | |||
4304 | void KTextEditor::DocumentPrivate::autoReloadToggled(bool b) | ||||
4305 | { | ||||
4306 | m_autoReloadMode->setChecked(b); | ||||
4307 | if (b) { | ||||
4308 | connect(&m_modOnHdTimer, &QTimer::timeout, this, &DocumentPrivate::onModOnHdAutoReload); | ||||
4309 | } else { | ||||
4310 | disconnect(&m_modOnHdTimer, &QTimer::timeout, this, &DocumentPrivate::onModOnHdAutoReload); | ||||
4311 | } | ||||
4312 | } | ||||
4313 | | ||||
4314 | bool KTextEditor::DocumentPrivate::isAutoReload() | ||||
4315 | { | ||||
4316 | return m_autoReloadMode->isChecked(); | ||||
4317 | } | ||||
4318 | | ||||
4319 | void KTextEditor::DocumentPrivate::delayAutoReload() | ||||
4320 | { | ||||
4321 | if (isAutoReload()) { | ||||
4322 | m_autoReloadThrottle.start(); | ||||
4323 | } | ||||
4324 | } | ||||
4325 | | ||||
4326 | void KTextEditor::DocumentPrivate::onModOnHdAutoReload() | ||||
4327 | { | ||||
4328 | if (m_modOnHdHandler) { | ||||
4329 | delete m_modOnHdHandler; | ||||
4330 | autoReloadToggled(true); | ||||
4331 | } | ||||
4332 | | ||||
4333 | if (!isAutoReload()) { | ||||
4334 | return; | ||||
4335 | } | ||||
4336 | | ||||
4337 | if (m_modOnHd && !m_reloading && !m_autoReloadThrottle.isActive()) { | ||||
4338 | m_modOnHd = false; | ||||
4339 | m_prevModOnHdReason = OnDiskUnmodified; | ||||
4340 | emit modifiedOnDisk(this, false, OnDiskUnmodified); | ||||
4341 | documentReload(); | ||||
4342 | m_autoReloadThrottle.start(); | ||||
4343 | } | ||||
4344 | } | ||||
4345 | | ||||
4288 | void KTextEditor::DocumentPrivate::onModOnHdIgnore() | 4346 | void KTextEditor::DocumentPrivate::onModOnHdIgnore() | ||
4289 | { | 4347 | { | ||
4290 | // ignore as long as m_prevModOnHdReason == m_modOnHdReason | 4348 | // ignore as long as m_prevModOnHdReason == m_modOnHdReason | ||
4291 | delete m_modOnHdHandler; | 4349 | delete m_modOnHdHandler; | ||
4292 | } | 4350 | } | ||
4293 | 4351 | | |||
4294 | void KTextEditor::DocumentPrivate::setModifiedOnDisk(ModifiedOnDiskReason reason) | 4352 | void KTextEditor::DocumentPrivate::setModifiedOnDisk(ModifiedOnDiskReason reason) | ||
4295 | { | 4353 | { | ||
▲ Show 20 Lines • Show All 1725 Lines • Show Last 20 Lines |