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