mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
add SaveAndRead and DiscardAndRead to the context menu in edit mode
This commit is contained in:
parent
022d3ae2f7
commit
c642d60757
@ -8,6 +8,7 @@
|
||||
#include "utils/vutils.h"
|
||||
#include "veditoperations.h"
|
||||
#include "dialog/vfindreplacedialog.h"
|
||||
#include "vedittab.h"
|
||||
|
||||
extern VConfigManager vconfig;
|
||||
extern VNote *g_vnote;
|
||||
@ -501,3 +502,62 @@ void VEdit::clearSearchedWordHighlight()
|
||||
highlightExtraSelections();
|
||||
}
|
||||
|
||||
void VEdit::contextMenuEvent(QContextMenuEvent *p_event)
|
||||
{
|
||||
QMenu *menu = createStandardContextMenu();
|
||||
menu->setToolTipsVisible(true);
|
||||
|
||||
const QList<QAction *> actions = menu->actions();
|
||||
|
||||
VEditTab *editTab = dynamic_cast<VEditTab *>(parent());
|
||||
V_ASSERT(editTab);
|
||||
if (editTab->getIsEditMode()) {
|
||||
QAction *saveExitAct = new QAction(QIcon(":/resources/icons/save_exit.svg"),
|
||||
tr("&Save Changes And Read"), this);
|
||||
saveExitAct->setToolTip(tr("Save changes and exit edit mode"));
|
||||
connect(saveExitAct, &QAction::triggered,
|
||||
this, &VEdit::handleSaveExitAct);
|
||||
|
||||
QAction *discardExitAct = new QAction(QIcon(":/resources/icons/discard_exit.svg"),
|
||||
tr("&Discard Changes And Read"), this);
|
||||
discardExitAct->setToolTip(tr("Discard changes and exit edit mode"));
|
||||
connect(discardExitAct, &QAction::triggered,
|
||||
this, &VEdit::handleDiscardExitAct);
|
||||
|
||||
menu->insertAction(actions.isEmpty() ? NULL : actions[0], discardExitAct);
|
||||
menu->insertAction(discardExitAct, saveExitAct);
|
||||
if (!actions.isEmpty()) {
|
||||
menu->insertSeparator(actions[0]);
|
||||
}
|
||||
} else if (m_file->isModifiable()) {
|
||||
// HTML.
|
||||
QAction *editAct= new QAction(QIcon(":/resources/icons/edit_note.svg"),
|
||||
tr("&Edit"), this);
|
||||
editAct->setToolTip(tr("Edit current note"));
|
||||
connect(editAct, &QAction::triggered,
|
||||
this, &VEdit::handleEditAct);
|
||||
menu->insertAction(actions.isEmpty() ? NULL : actions[0], editAct);
|
||||
// actions does not contain editAction.
|
||||
if (!actions.isEmpty()) {
|
||||
menu->insertSeparator(actions[0]);
|
||||
}
|
||||
}
|
||||
|
||||
menu->exec(p_event->globalPos());
|
||||
delete menu;
|
||||
}
|
||||
|
||||
void VEdit::handleSaveExitAct()
|
||||
{
|
||||
emit saveAndRead();
|
||||
}
|
||||
|
||||
void VEdit::handleDiscardExitAct()
|
||||
{
|
||||
emit discardAndRead();
|
||||
}
|
||||
|
||||
void VEdit::handleEditAct()
|
||||
{
|
||||
emit editNote();
|
||||
}
|
||||
|
@ -49,10 +49,18 @@ public:
|
||||
void setReadOnly(bool p_ro);
|
||||
void clearSearchedWordHighlight();
|
||||
|
||||
signals:
|
||||
void saveAndRead();
|
||||
void discardAndRead();
|
||||
void editNote();
|
||||
|
||||
private slots:
|
||||
void labelTimerTimeout();
|
||||
void triggerHighlightSelectedWord();
|
||||
void highlightSelectedWord();
|
||||
void handleSaveExitAct();
|
||||
void handleDiscardExitAct();
|
||||
void handleEditAct();
|
||||
|
||||
protected slots:
|
||||
virtual void highlightCurrentLine();
|
||||
@ -63,6 +71,7 @@ protected:
|
||||
QColor m_cursorLineColor;
|
||||
|
||||
virtual void updateFontAndPalette();
|
||||
virtual void contextMenuEvent(QContextMenuEvent *p_event) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
QLabel *m_wrapLabel;
|
||||
|
@ -67,6 +67,10 @@ void VEditTab::setupUI()
|
||||
this, SLOT(updateCurHeader(int, int)));
|
||||
connect(m_textEditor, &VEdit::textChanged,
|
||||
this, &VEditTab::handleTextChanged);
|
||||
connect(m_textEditor, &VEdit::saveAndRead,
|
||||
this, &VEditTab::saveAndRead);
|
||||
connect(m_textEditor, &VEdit::discardAndRead,
|
||||
this, &VEditTab::discardAndRead);
|
||||
m_textEditor->reloadFile();
|
||||
addWidget(m_textEditor);
|
||||
} else {
|
||||
@ -79,6 +83,12 @@ void VEditTab::setupUI()
|
||||
m_textEditor = new VEdit(m_file, this);
|
||||
connect(m_textEditor, &VEdit::textChanged,
|
||||
this, &VEditTab::handleTextChanged);
|
||||
connect(m_textEditor, &VEdit::saveAndRead,
|
||||
this, &VEditTab::saveAndRead);
|
||||
connect(m_textEditor, &VEdit::discardAndRead,
|
||||
this, &VEditTab::discardAndRead);
|
||||
connect(m_textEditor, &VEdit::editNote,
|
||||
this, &VEditTab::editFile);
|
||||
m_textEditor->reloadFile();
|
||||
addWidget(m_textEditor);
|
||||
webPreviewer = NULL;
|
||||
@ -269,6 +279,17 @@ bool VEditTab::saveFile()
|
||||
return ret;
|
||||
}
|
||||
|
||||
void VEditTab::saveAndRead()
|
||||
{
|
||||
saveFile();
|
||||
readFile();
|
||||
}
|
||||
|
||||
void VEditTab::discardAndRead()
|
||||
{
|
||||
readFile();
|
||||
}
|
||||
|
||||
void VEditTab::setupMarkdownPreview()
|
||||
{
|
||||
const QString jsHolder("JS_PLACE_HOLDER");
|
||||
|
@ -71,6 +71,8 @@ private slots:
|
||||
void handleTextChanged();
|
||||
void noticeStatusChanged();
|
||||
void handleWebKeyPressed(int p_key, bool p_ctrl, bool p_shift);
|
||||
void saveAndRead();
|
||||
void discardAndRead();
|
||||
|
||||
private:
|
||||
void setupUI();
|
||||
|
@ -224,7 +224,7 @@ void VMainWindow::initFileToolBar()
|
||||
editArea, &VEditArea::editFile);
|
||||
|
||||
discardExitAct = new QAction(QIcon(":/resources/icons/discard_exit.svg"),
|
||||
tr("Discard Changes And Exit"), this);
|
||||
tr("Discard Changes And Read"), this);
|
||||
discardExitAct->setStatusTip(tr("Discard changes and exit edit mode"));
|
||||
connect(discardExitAct, &QAction::triggered,
|
||||
editArea, &VEditArea::readFile);
|
||||
@ -233,7 +233,7 @@ void VMainWindow::initFileToolBar()
|
||||
exitEditMenu->addAction(discardExitAct);
|
||||
|
||||
saveExitAct = new QAction(QIcon(":/resources/icons/save_exit.svg"),
|
||||
tr("Save Changes And Exit"), this);
|
||||
tr("Save Changes And Read"), this);
|
||||
saveExitAct->setStatusTip(tr("Save changes and exit edit mode"));
|
||||
saveExitAct->setMenu(exitEditMenu);
|
||||
saveExitAct->setShortcut(QKeySequence("Ctrl+R"));
|
||||
|
@ -17,20 +17,24 @@ void VWebView::contextMenuEvent(QContextMenuEvent *p_event)
|
||||
{
|
||||
QMenu *menu = page()->createStandardContextMenu();
|
||||
menu->setToolTipsVisible(true);
|
||||
|
||||
const QList<QAction *> actions = menu->actions();
|
||||
|
||||
QAction *editAction = new QAction(QIcon(":/resources/icons/edit_note.svg"),
|
||||
tr("&Edit"), this);
|
||||
editAction->setToolTip(tr("Edit current note"));
|
||||
connect(editAction, &QAction::triggered,
|
||||
this, &VWebView::handleEditAction);
|
||||
if (!m_file->isModifiable()) {
|
||||
editAction->setEnabled(false);
|
||||
if (!hasSelection() && m_file->isModifiable()) {
|
||||
QAction *editAct= new QAction(QIcon(":/resources/icons/edit_note.svg"),
|
||||
tr("&Edit"), this);
|
||||
editAct->setToolTip(tr("Edit current note"));
|
||||
connect(editAct, &QAction::triggered,
|
||||
this, &VWebView::handleEditAction);
|
||||
menu->insertAction(actions.isEmpty() ? NULL : actions[0], editAct);
|
||||
// actions does not contain editAction.
|
||||
if (!actions.isEmpty()) {
|
||||
menu->insertSeparator(actions[0]);
|
||||
}
|
||||
}
|
||||
menu->insertAction(actions.isEmpty() ? NULL : actions[0], editAction);
|
||||
|
||||
connect(menu, &QMenu::aboutToHide, menu, &QObject::deleteLater);
|
||||
menu->popup(p_event->globalPos());
|
||||
menu->exec(p_event->globalPos());
|
||||
delete menu;
|
||||
}
|
||||
|
||||
void VWebView::handleEditAction()
|
||||
|
Loading…
x
Reference in New Issue
Block a user