diff options
-rw-r--r-- | src/mainwindow/menubar.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/mainwindow/menubar.cpp b/src/mainwindow/menubar.cpp index ed0eb8f..8e2180d 100644 --- a/src/mainwindow/menubar.cpp +++ b/src/mainwindow/menubar.cpp @@ -36,6 +36,12 @@ inline void run_if(SubWindow *_subwindow, std::function<void(SubWindow*, int)> f f(_subwindow, _subwindow->currentTabIndex()); } +inline void trigger_if(WebView *_view, QWebEnginePage::WebAction action) +{ + if(_view != nullptr) + _view->triggerPageAction(action); +} + inline QDialog *createDevToolsDialog(QWebEnginePage *page) { Q_CHECK_PTR(page); @@ -412,6 +418,85 @@ MenuBar::MenuBar(const Configuration *config, MainWindow *parent) }); #endif } + + this->addSeparator(); + + auto *edit = this->addMenu(tr("Edit")); + { + edit->addAction(tr("Undo"), parent, [parent]() { + trigger_if(parent->currentView, QWebEnginePage::Undo); + }); + edit->addAction(tr("Redo"), parent, [parent]() { + trigger_if(parent->currentView, QWebEnginePage::Redo); + }); + + edit->addSeparator(); + + edit->addAction(tr("Cut"), parent, [parent]() { + trigger_if(parent->currentView, QWebEnginePage::Cut); + }); + edit->addAction(tr("Copy"), parent, [parent]() { + trigger_if(parent->currentView, QWebEnginePage::Copy); + }); + edit->addAction(tr("Paste"), parent, [parent]() { + trigger_if(parent->currentView, QWebEnginePage::Paste); + }); + edit->addAction(tr("Paste and match Style"), parent, [parent]() { + trigger_if(parent->currentView, QWebEnginePage::PasteAndMatchStyle); + }); + + edit->addSeparator(); + + edit->addAction(tr("Select all"), parent, [parent]() { + trigger_if(parent->currentView, QWebEnginePage::SelectAll); + }); + edit->addAction(tr("Clear selection"), parent, [parent]() { + trigger_if(parent->currentView, QWebEnginePage::Unselect); + }); + + edit->addSeparator()->setText(tr("Editing")); + + edit->addAction(tr("Make editable"), parent, [parent]() { + if(parent->currentView != nullptr) + parent->currentView->page()->runJavaScript("document.documentElement.contentEditable = true"); + }); + edit->addAction(tr("Bold"), parent, [parent]() { + trigger_if(parent->currentView, QWebEnginePage::ToggleBold); + }); + edit->addAction(tr("Italic"), parent, [parent]() { + trigger_if(parent->currentView, QWebEnginePage::ToggleItalic); + }); + edit->addAction(tr("Underline"), parent, [parent]() { + trigger_if(parent->currentView, QWebEnginePage::ToggleUnderline); + }); + edit->addAction(tr("Strikethrough"), parent, [parent]() { + trigger_if(parent->currentView, QWebEnginePage::ToggleStrikethrough); + }); + edit->addAction(tr("Align left"), parent, [parent]() { + trigger_if(parent->currentView, QWebEnginePage::AlignLeft); + }); + edit->addAction(tr("Align right"), parent, [parent]() { + trigger_if(parent->currentView, QWebEnginePage::AlignRight); + }); + edit->addAction(tr("Align center"), parent, [parent]() { + trigger_if(parent->currentView, QWebEnginePage::AlignCenter); + }); + edit->addAction(tr("Align justified"), parent, [parent]() { + trigger_if(parent->currentView, QWebEnginePage::AlignJustified); + }); + edit->addAction(tr("Indent"), parent, [parent]() { + trigger_if(parent->currentView, QWebEnginePage::Indent); + }); + edit->addAction(tr("Outdent"), parent, [parent]() { + trigger_if(parent->currentView, QWebEnginePage::Outdent); + }); + edit->addAction(tr("Insert ordered list"), parent, [parent]() { + trigger_if(parent->currentView, QWebEnginePage::InsertOrderedList); + }); + edit->addAction(tr("Insert unordered list"), parent, [parent]() { + trigger_if(parent->currentView, QWebEnginePage::InsertUnorderedList); + }); + } } QAction *MenuBar::insertPlugin(QMenu *menu) |