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 178 Lines • ▼ Show 20 Line(s) | 215 | { | |||
258 | 259 | | |||
259 | /** | 260 | /** | ||
260 | * singleshot timer to handle updates of mod on hd state delayed | 261 | * singleshot timer to handle updates of mod on hd state delayed | ||
261 | */ | 262 | */ | ||
262 | m_modOnHdTimer.setSingleShot(true); | 263 | m_modOnHdTimer.setSingleShot(true); | ||
263 | m_modOnHdTimer.setInterval(200); | 264 | m_modOnHdTimer.setInterval(200); | ||
264 | connect(&m_modOnHdTimer, SIGNAL(timeout()), this, SLOT(slotDelayedHandleModOnHd())); | 265 | connect(&m_modOnHdTimer, SIGNAL(timeout()), this, SLOT(slotDelayedHandleModOnHd())); | ||
265 | 266 | | |||
267 | // Setup auto reload stuff | ||||
268 | m_autoReloadMode = new KToggleAction(i18n("Auto Reload Document"), this); | ||||
269 | m_autoReloadMode->setWhatsThis(i18n("Automatic reload the docuemnt when it was changed on disk")); | ||||
270 | connect(m_autoReloadMode, &KToggleAction::triggered, this, &DocumentPrivate::autoReloadToggled); | ||||
271 | // Prepare some reload amok protector | ||||
272 | m_autoReloadThrottle.setSingleShot(true); | ||||
273 | m_autoReloadThrottle.setInterval(3000); | ||||
274 | connect(&m_autoReloadThrottle, &QTimer::timeout, this, &DocumentPrivate::onModOnHdAutoReload); | ||||
275 | | ||||
266 | /** | 276 | /** | ||
267 | * load handling | 277 | * load handling | ||
268 | * this is needed to ensure we signal the user if a file ist still loading | 278 | * this is needed to ensure we signal the user if a file ist still loading | ||
269 | * and to disallow him to edit in that time | 279 | * and to disallow him to edit in that time | ||
270 | */ | 280 | */ | ||
271 | connect(this, SIGNAL(started(KIO::Job*)), this, SLOT(slotStarted(KIO::Job*))); | 281 | connect(this, SIGNAL(started(KIO::Job*)), this, SLOT(slotStarted(KIO::Job*))); | ||
272 | connect(this, SIGNAL(completed()), this, SLOT(slotCompleted())); | 282 | connect(this, SIGNAL(completed()), this, SLOT(slotCompleted())); | ||
273 | connect(this, SIGNAL(canceled(QString)), this, SLOT(slotCanceled())); | 283 | connect(this, SIGNAL(canceled(QString)), this, SLOT(slotCanceled())); | ||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Line(s) | |||||
4221 | } | 4231 | } | ||
4222 | 4232 | | |||
4223 | void KTextEditor::DocumentPrivate::slotModifiedOnDisk(KTextEditor::View * /*v*/) | 4233 | void KTextEditor::DocumentPrivate::slotModifiedOnDisk(KTextEditor::View * /*v*/) | ||
4224 | { | 4234 | { | ||
4225 | if (url().isEmpty() || !m_modOnHd) { | 4235 | if (url().isEmpty() || !m_modOnHd) { | ||
4226 | return; | 4236 | return; | ||
4227 | } | 4237 | } | ||
4228 | 4238 | | |||
4239 | if (!isModified() && isAutoReload()) { | ||||
4240 | onModOnHdAutoReload(); | ||||
4241 | return; | ||||
4242 | } | ||||
4243 | | ||||
4229 | if (!m_fileChangedDialogsActivated || m_modOnHdHandler) { | 4244 | if (!m_fileChangedDialogsActivated || m_modOnHdHandler) { | ||
4230 | return; | 4245 | return; | ||
4231 | } | 4246 | } | ||
4232 | 4247 | | |||
4233 | // don't ask the user again and again the same thing | 4248 | // don't ask the user again and again the same thing | ||
4234 | if (m_modOnHdReason == m_prevModOnHdReason) { | 4249 | if (m_modOnHdReason == m_prevModOnHdReason) { | ||
4235 | return; | 4250 | return; | ||
4236 | } | 4251 | } | ||
4237 | m_prevModOnHdReason = m_modOnHdReason; | 4252 | m_prevModOnHdReason = m_modOnHdReason; | ||
4238 | 4253 | | |||
4239 | m_modOnHdHandler = new KateModOnHdPrompt(this, m_modOnHdReason, reasonedMOHString()); | 4254 | m_modOnHdHandler = new KateModOnHdPrompt(this, m_modOnHdReason, reasonedMOHString()); | ||
4240 | connect(m_modOnHdHandler.data(), &KateModOnHdPrompt::saveAsTriggered, this, &DocumentPrivate::onModOnHdSaveAs); | 4255 | connect(m_modOnHdHandler.data(), &KateModOnHdPrompt::saveAsTriggered, this, &DocumentPrivate::onModOnHdSaveAs); | ||
4241 | connect(m_modOnHdHandler.data(), &KateModOnHdPrompt::reloadTriggered, this, &DocumentPrivate::onModOnHdReload); | 4256 | connect(m_modOnHdHandler.data(), &KateModOnHdPrompt::reloadTriggered, this, &DocumentPrivate::onModOnHdReload); | ||
4257 | connect(m_modOnHdHandler.data(), &KateModOnHdPrompt::autoReloadTriggered, this, &DocumentPrivate::onModOnHdAutoReload); | ||||
4242 | connect(m_modOnHdHandler.data(), &KateModOnHdPrompt::ignoreTriggered, this, &DocumentPrivate::onModOnHdIgnore); | 4258 | connect(m_modOnHdHandler.data(), &KateModOnHdPrompt::ignoreTriggered, this, &DocumentPrivate::onModOnHdIgnore); | ||
4243 | } | 4259 | } | ||
4244 | 4260 | | |||
4245 | void KTextEditor::DocumentPrivate::onModOnHdSaveAs() | 4261 | void KTextEditor::DocumentPrivate::onModOnHdSaveAs() | ||
4246 | { | 4262 | { | ||
4247 | m_modOnHd = false; | 4263 | m_modOnHd = false; | ||
4248 | QWidget *parentWidget(dialogParent()); | 4264 | QWidget *parentWidget(dialogParent()); | ||
4249 | const QUrl res = QFileDialog::getSaveFileUrl(parentWidget, i18n("Save File"), url(), {}, nullptr, | 4265 | const QUrl res = QFileDialog::getSaveFileUrl(parentWidget, i18n("Save File"), url(), {}, nullptr, | ||
Show All 16 Lines | |||||
4266 | { | 4282 | { | ||
4267 | m_modOnHd = false; | 4283 | m_modOnHd = false; | ||
4268 | m_prevModOnHdReason = OnDiskUnmodified; | 4284 | m_prevModOnHdReason = OnDiskUnmodified; | ||
4269 | emit modifiedOnDisk(this, false, OnDiskUnmodified); | 4285 | emit modifiedOnDisk(this, false, OnDiskUnmodified); | ||
4270 | documentReload(); | 4286 | documentReload(); | ||
4271 | delete m_modOnHdHandler; | 4287 | delete m_modOnHdHandler; | ||
4272 | } | 4288 | } | ||
4273 | 4289 | | |||
4290 | void KTextEditor::DocumentPrivate::autoReloadToggled(bool b) | ||||
4291 | { | ||||
4292 | m_autoReloadMode->setChecked(b); | ||||
4293 | if (b) { | ||||
4294 | connect(&m_modOnHdTimer, &QTimer::timeout, this, &DocumentPrivate::onModOnHdAutoReload); | ||||
4295 | } else { | ||||
4296 | disconnect(&m_modOnHdTimer, &QTimer::timeout, this, &DocumentPrivate::onModOnHdAutoReload); | ||||
4297 | } | ||||
4298 | } | ||||
4299 | | ||||
4300 | bool KTextEditor::DocumentPrivate::isAutoReload() | ||||
4301 | { | ||||
4302 | return m_autoReloadMode->isChecked(); | ||||
4303 | } | ||||
4304 | | ||||
4305 | void KTextEditor::DocumentPrivate::onModOnHdAutoReload() | ||||
4306 | { | ||||
4307 | if (m_modOnHdHandler) { | ||||
4308 | delete m_modOnHdHandler; | ||||
4309 | m_autoReloadMode->setChecked(true); | ||||
4310 | } | ||||
4311 | | ||||
4312 | if (!isAutoReload()) { | ||||
4313 | return; | ||||
4314 | } | ||||
4315 | | ||||
4316 | if (m_modOnHd && !m_reloading && !m_autoReloadThrottle.isActive()) { | ||||
4317 | m_modOnHd = false; | ||||
4318 | m_prevModOnHdReason = OnDiskUnmodified; | ||||
4319 | emit modifiedOnDisk(this, false, OnDiskUnmodified); | ||||
4320 | documentReload(); | ||||
4321 | m_autoReloadThrottle.start(); | ||||
4322 | } | ||||
4323 | } | ||||
4324 | | ||||
4274 | void KTextEditor::DocumentPrivate::onModOnHdIgnore() | 4325 | void KTextEditor::DocumentPrivate::onModOnHdIgnore() | ||
4275 | { | 4326 | { | ||
4276 | // ignore as long as m_prevModOnHdReason == m_modOnHdReason | 4327 | // ignore as long as m_prevModOnHdReason == m_modOnHdReason | ||
4277 | delete m_modOnHdHandler; | 4328 | delete m_modOnHdHandler; | ||
4278 | } | 4329 | } | ||
4279 | 4330 | | |||
4280 | void KTextEditor::DocumentPrivate::setModifiedOnDisk(ModifiedOnDiskReason reason) | 4331 | void KTextEditor::DocumentPrivate::setModifiedOnDisk(ModifiedOnDiskReason reason) | ||
4281 | { | 4332 | { | ||
▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |