From 108ff1543c6db72a007cad8c770c62af2646a70e Mon Sep 17 00:00:00 2001 From: Le Tan Date: Wed, 18 Apr 2018 20:55:28 +0800 Subject: [PATCH] make discard action the default one when DiscardAndExit --- src/veditarea.cpp | 4 ++-- src/veditarea.h | 4 +++- src/vedittab.h | 3 ++- src/veditwindow.cpp | 4 ++-- src/veditwindow.h | 4 +++- src/vhtmltab.cpp | 4 ++-- src/vhtmltab.h | 2 +- src/vmainwindow.cpp | 4 +++- src/vmdtab.cpp | 4 ++-- src/vmdtab.h | 2 +- 10 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/veditarea.cpp b/src/veditarea.cpp index 9c6f6ad8..5fd5e065 100644 --- a/src/veditarea.cpp +++ b/src/veditarea.cpp @@ -413,10 +413,10 @@ void VEditArea::saveFile() win->saveFile(); } -void VEditArea::readFile() +void VEditArea::readFile(bool p_discard) { VEditWindow *win = getWindow(curWindowIndex); - win->readFile(); + win->readFile(p_discard); } void VEditArea::saveAndReadFile() diff --git a/src/veditarea.h b/src/veditarea.h index 17c1ffd3..1ac09943 100644 --- a/src/veditarea.h +++ b/src/veditarea.h @@ -118,7 +118,9 @@ public slots: void editFile(); void saveFile(); - void readFile(); + + void readFile(bool p_discard = false); + void saveAndReadFile(); // Scroll current tab to @p_header. diff --git a/src/vedittab.h b/src/vedittab.h index 5c1fdb84..2b7f59ab 100644 --- a/src/vedittab.h +++ b/src/vedittab.h @@ -28,7 +28,8 @@ public: virtual bool closeFile(bool p_forced) = 0; // Enter read mode. - virtual void readFile() = 0; + // @p_discard: whether set the discard action as the default one. + virtual void readFile(bool p_discard = false) = 0; // Save file. virtual bool saveFile() = 0; diff --git a/src/veditwindow.cpp b/src/veditwindow.cpp index df6e0ee7..315fc093 100644 --- a/src/veditwindow.cpp +++ b/src/veditwindow.cpp @@ -508,11 +508,11 @@ bool VEditWindow::closeTab(int p_index) return ok; } -void VEditWindow::readFile() +void VEditWindow::readFile(bool p_discard) { VEditTab *editor = getTab(currentIndex()); Q_ASSERT(editor); - editor->readFile(); + editor->readFile(p_discard); } void VEditWindow::saveAndReadFile() diff --git a/src/veditwindow.h b/src/veditwindow.h index 0a6b8d9f..085d3460 100644 --- a/src/veditwindow.h +++ b/src/veditwindow.h @@ -37,7 +37,9 @@ public: bool closeFile(const VNotebook *p_notebook, bool p_forced); void editFile(); void saveFile(); - void readFile(); + + void readFile(bool p_discard = false); + void saveAndReadFile(); bool closeAllFiles(bool p_forced); diff --git a/src/vhtmltab.cpp b/src/vhtmltab.cpp index 0d0aad61..4bbd68f6 100644 --- a/src/vhtmltab.cpp +++ b/src/vhtmltab.cpp @@ -95,7 +95,7 @@ void VHtmlTab::editFile() showFileEditMode(); } -void VHtmlTab::readFile() +void VHtmlTab::readFile(bool p_discard) { if (!m_isEditMode) { return; @@ -114,7 +114,7 @@ void VHtmlTab::readFile() | QMessageBox::Cancel) : (QMessageBox::Discard | QMessageBox::Cancel), - modifiable ? QMessageBox::Save + modifiable ? (p_discard ? QMessageBox::Discard : QMessageBox::Save) : QMessageBox::Cancel, this); switch (ret) { diff --git a/src/vhtmltab.h b/src/vhtmltab.h index e28fe673..c4292247 100644 --- a/src/vhtmltab.h +++ b/src/vhtmltab.h @@ -21,7 +21,7 @@ public: // Enter read mode. // Will prompt user to save the changes. - void readFile() Q_DECL_OVERRIDE; + void readFile(bool p_discard = false) Q_DECL_OVERRIDE; // Save file. bool saveFile() Q_DECL_OVERRIDE; diff --git a/src/vmainwindow.cpp b/src/vmainwindow.cpp index d6eccb0b..3694c534 100644 --- a/src/vmainwindow.cpp +++ b/src/vmainwindow.cpp @@ -722,7 +722,9 @@ void VMainWindow::initFileToolBar(QSize p_iconSize) VUtils::fixTextWithCaptainShortcut(m_discardExitAct, "DiscardAndRead"); m_discardExitAct->setStatusTip(tr("Discard changes and exit edit mode")); connect(m_discardExitAct, &QAction::triggered, - m_editArea, &VEditArea::readFile); + this, [this]() { + m_editArea->readFile(true); + }); updateEditReadAct(NULL); diff --git a/src/vmdtab.cpp b/src/vmdtab.cpp index 62ffbec0..9b73114c 100644 --- a/src/vmdtab.cpp +++ b/src/vmdtab.cpp @@ -270,7 +270,7 @@ void VMdTab::editFile() showFileEditMode(); } -void VMdTab::readFile() +void VMdTab::readFile(bool p_discard) { if (!m_isEditMode) { return; @@ -288,7 +288,7 @@ void VMdTab::readFile() | QMessageBox::Cancel) : (QMessageBox::Discard | QMessageBox::Cancel), - modifiable ? QMessageBox::Save + modifiable ? (p_discard ? QMessageBox::Discard: QMessageBox::Save) : QMessageBox::Cancel, this); switch (ret) { diff --git a/src/vmdtab.h b/src/vmdtab.h index f050721a..7e723447 100644 --- a/src/vmdtab.h +++ b/src/vmdtab.h @@ -32,7 +32,7 @@ public: // Enter read mode. // Will prompt user to save the changes. - void readFile() Q_DECL_OVERRIDE; + void readFile(bool p_discard = false) Q_DECL_OVERRIDE; // Save file. bool saveFile() Q_DECL_OVERRIDE;