mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 05:49:53 +08:00
add Ctrl+S to save file
Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
17c136f11d
commit
2dd84bdc93
12
vedit.cpp
12
vedit.cpp
@ -38,12 +38,7 @@ void VEdit::beginEdit()
|
||||
}
|
||||
}
|
||||
|
||||
bool VEdit::tryEndEdit()
|
||||
{
|
||||
return !document()->isModified();
|
||||
}
|
||||
|
||||
void VEdit::beginSave()
|
||||
void VEdit::saveFile()
|
||||
{
|
||||
if (!document()->isModified()) {
|
||||
return;
|
||||
@ -61,11 +56,6 @@ void VEdit::beginSave()
|
||||
}
|
||||
}
|
||||
|
||||
void VEdit::endSave()
|
||||
{
|
||||
document()->setModified(false);
|
||||
}
|
||||
|
||||
void VEdit::reloadFile()
|
||||
{
|
||||
switch (noteFile->docType) {
|
||||
|
21
vedit.h
21
vedit.h
@ -14,12 +14,12 @@ class VEdit : public QTextEdit
|
||||
public:
|
||||
VEdit(VNoteFile *noteFile, QWidget *parent = 0);
|
||||
void beginEdit();
|
||||
bool tryEndEdit();
|
||||
|
||||
// begin: sync the buffer to noteFile->content;
|
||||
// end: setModified(false)
|
||||
void beginSave();
|
||||
void endSave();
|
||||
// Save buffer content to noteFile->content.
|
||||
void saveFile();
|
||||
|
||||
inline void setModified(bool modified);
|
||||
inline bool isModified() const;
|
||||
|
||||
void reloadFile();
|
||||
|
||||
@ -33,4 +33,15 @@ private:
|
||||
HGMarkdownHighlighter *mdHighlighter;
|
||||
};
|
||||
|
||||
|
||||
inline bool VEdit::isModified() const
|
||||
{
|
||||
return document()->isModified();
|
||||
}
|
||||
|
||||
inline void VEdit::setModified(bool modified)
|
||||
{
|
||||
document()->setModified(modified);
|
||||
}
|
||||
|
||||
#endif // VEDIT_H
|
||||
|
13
veditor.cpp
13
veditor.cpp
@ -118,8 +118,8 @@ void VEditor::readFile()
|
||||
if (!isEditMode) {
|
||||
return;
|
||||
}
|
||||
bool canExit = textEditor->tryEndEdit();
|
||||
if (!canExit) {
|
||||
|
||||
if (textEditor->isModified()) {
|
||||
// Need to save the changes
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText("The note has been modified.");
|
||||
@ -149,21 +149,22 @@ void VEditor::readFile()
|
||||
|
||||
bool VEditor::saveFile()
|
||||
{
|
||||
if (!isEditMode || !noteFile->modifiable) {
|
||||
if (!isEditMode || !noteFile->modifiable || !textEditor->isModified()) {
|
||||
return true;
|
||||
}
|
||||
textEditor->beginSave();
|
||||
textEditor->saveFile();
|
||||
bool ret = VUtils::writeFileToDisk(QDir(noteFile->path).filePath(noteFile->name),
|
||||
noteFile->content);
|
||||
noteFile->content);
|
||||
if (!ret) {
|
||||
QMessageBox msgBox(QMessageBox::Warning, tr("Fail to save to file"),
|
||||
QString("Fail to write to disk when saving a note. Please try it again."));
|
||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||
msgBox.setDefaultButton(QMessageBox::Ok);
|
||||
msgBox.exec();
|
||||
textEditor->setModified(true);
|
||||
return false;
|
||||
}
|
||||
textEditor->endSave();
|
||||
textEditor->setModified(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -110,6 +110,7 @@ void VMainWindow::initActions()
|
||||
|
||||
saveNoteAct = new QAction(tr("&Save"), this);
|
||||
saveNoteAct->setStatusTip(tr("Save current note"));
|
||||
saveNoteAct->setShortcut(QKeySequence::Save);
|
||||
connect(saveNoteAct, &QAction::triggered,
|
||||
tabs, &VTabWidget::saveFile);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user