File indexing completed on 2024-12-29 04:54:47
0001 /* 0002 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-only 0005 */ 0006 0007 #include "sieveeditormenubar.h" 0008 #include "sieveeditortabwidget.h" 0009 #include "sieveeditortextmodewidget.h" 0010 0011 #include <KLocalizedString> 0012 #include <KStandardAction> 0013 #include <QAction> 0014 #include <QIcon> 0015 using namespace KSieveUi; 0016 0017 SieveEditorMenuBar::SieveEditorMenuBar(QWidget *parent) 0018 : QMenuBar(parent) 0019 { 0020 initActions(); 0021 initMenus(); 0022 } 0023 0024 SieveEditorMenuBar::~SieveEditorMenuBar() = default; 0025 0026 void SieveEditorMenuBar::setEditorMode(bool editorMode) 0027 { 0028 mGoToLine->setEnabled(editorMode); 0029 mFindAction->setEnabled(editorMode); 0030 mReplaceAction->setEnabled(editorMode); 0031 mUndoAction->setEnabled(editorMode); 0032 mRedoAction->setEnabled(editorMode); 0033 mCopyAction->setEnabled(editorMode); 0034 mPasteAction->setEnabled(editorMode); 0035 mCutAction->setEnabled(editorMode); 0036 mSelectAllAction->setEnabled(editorMode); 0037 mCommentCodeAction->setEnabled(editorMode); 0038 mUncommentCodeAction->setEnabled(editorMode); 0039 mZoomInAction->setEnabled(editorMode); 0040 mZoomOutAction->setEnabled(editorMode); 0041 mZoomResetAction->setEnabled(editorMode); 0042 mDebugSieveAction->setEnabled(editorMode); 0043 mWordWrapAction->setEnabled(editorMode); 0044 mPrintAction->setEnabled(editorMode); 0045 mPrintPreviewAction->setEnabled(editorMode); 0046 } 0047 0048 void SieveEditorMenuBar::initActions() 0049 { 0050 mGoToLine = new QAction(i18n("Go to Line"), this); 0051 mGoToLine->setIcon(QIcon::fromTheme(QStringLiteral("go-jump"))); 0052 mGoToLine->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_G)); 0053 connect(mGoToLine, &QAction::triggered, this, &SieveEditorMenuBar::gotoLine); 0054 0055 mCommentCodeAction = new QAction(i18n("Comment"), this); 0056 mCommentCodeAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_D)); 0057 connect(mCommentCodeAction, &QAction::triggered, this, &SieveEditorMenuBar::comment); 0058 0059 mUncommentCodeAction = new QAction(i18n("Uncomment"), this); 0060 mUncommentCodeAction->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_D)); 0061 connect(mUncommentCodeAction, &QAction::triggered, this, &SieveEditorMenuBar::uncomment); 0062 0063 mDebugSieveAction = new QAction(i18n("Debug Sieve Script..."), this); 0064 mDebugSieveAction->setShortcut(QKeySequence(Qt::ALT | Qt::Key_D)); 0065 connect(mDebugSieveAction, &QAction::triggered, this, &SieveEditorMenuBar::debugSieveScript); 0066 0067 mFindAction = KStandardAction::find(this, &SieveEditorMenuBar::find, this); 0068 mReplaceAction = KStandardAction::replace(this, &SieveEditorMenuBar::replace, this); 0069 mUndoAction = KStandardAction::undo(this, &SieveEditorMenuBar::undo, this); 0070 mRedoAction = KStandardAction::redo(this, &SieveEditorMenuBar::redo, this); 0071 mCopyAction = KStandardAction::copy(this, &SieveEditorMenuBar::copy, this); 0072 mPasteAction = KStandardAction::paste(this, &SieveEditorMenuBar::paste, this); 0073 mCutAction = KStandardAction::cut(this, &SieveEditorMenuBar::cut, this); 0074 mSelectAllAction = KStandardAction::selectAll(this, &SieveEditorMenuBar::selectAll, this); 0075 mZoomInAction = KStandardAction::zoomIn(this, &SieveEditorMenuBar::zoomIn, this); 0076 mZoomOutAction = KStandardAction::zoomOut(this, &SieveEditorMenuBar::zoomOut, this); 0077 mPrintAction = KStandardAction::print(this, &SieveEditorMenuBar::print, this); 0078 mPrintPreviewAction = KStandardAction::printPreview(this, &SieveEditorMenuBar::printPreview, this); 0079 0080 mZoomResetAction = KStandardAction::actualSize(this, &SieveEditorMenuBar::zoomReset, this); 0081 mWordWrapAction = new QAction(i18n("Wordwrap"), this); 0082 mWordWrapAction->setCheckable(true); 0083 connect(mWordWrapAction, &QAction::triggered, this, &SieveEditorMenuBar::wordWrap); 0084 0085 mUndoAction->setEnabled(false); 0086 mRedoAction->setEnabled(false); 0087 mCopyAction->setEnabled(false); 0088 mCutAction->setEnabled(false); 0089 } 0090 0091 QMenu *SieveEditorMenuBar::editorMenu() const 0092 { 0093 return mEditorMenu; 0094 } 0095 0096 void SieveEditorMenuBar::initMenus() 0097 { 0098 mFileMenu = addMenu(i18nc("@title:menu", "File")); 0099 mFileMenu->addAction(mPrintAction); 0100 mFileMenu->addAction(mPrintPreviewAction); 0101 mEditorMenu = addMenu(i18nc("@title:menu", "Edit")); 0102 mEditorMenu->addAction(mUndoAction); 0103 mEditorMenu->addAction(mRedoAction); 0104 mEditorMenu->addSeparator(); 0105 mEditorMenu->addAction(mCutAction); 0106 mEditorMenu->addAction(mCopyAction); 0107 mEditorMenu->addAction(mPasteAction); 0108 mEditorMenu->addSeparator(); 0109 mEditorMenu->addAction(mSelectAllAction); 0110 mEditorMenu->addSeparator(); 0111 mEditorMenu->addAction(mFindAction); 0112 mEditorMenu->addAction(mReplaceAction); 0113 mEditorMenu->addSeparator(); 0114 mEditorMenu->addAction(mGoToLine); 0115 mEditorMenu->addSeparator(); 0116 mEditorMenu->addAction(mWordWrapAction); 0117 mEditorMenu->addSeparator(); 0118 mEditorMenu->addAction(mCommentCodeAction); 0119 mEditorMenu->addAction(mUncommentCodeAction); 0120 0121 mViewMenu = addMenu(i18nc("@title:menu", "View")); 0122 mViewMenu->addAction(mZoomInAction); 0123 mViewMenu->addAction(mZoomOutAction); 0124 mViewMenu->addSeparator(); 0125 mViewMenu->addAction(mZoomResetAction); 0126 0127 mToolsMenu = addMenu(i18nc("@title:menu", "Tools")); 0128 mToolsMenu->addAction(mDebugSieveAction); 0129 } 0130 0131 QAction *SieveEditorMenuBar::printAction() const 0132 { 0133 return mPrintAction; 0134 } 0135 0136 void SieveEditorMenuBar::slotUpdateActions() 0137 { 0138 const bool hasActionInHtmlModeToo = mTextModeWidget->tabWidget()->currentPageIsHtmlPage(); 0139 0140 mGoToLine->setEnabled(!hasActionInHtmlModeToo); 0141 mFindAction->setEnabled(true); 0142 mReplaceAction->setEnabled(!hasActionInHtmlModeToo); 0143 mUndoAction->setEnabled(!hasActionInHtmlModeToo); 0144 mRedoAction->setEnabled(!hasActionInHtmlModeToo); 0145 mCopyAction->setEnabled(true); 0146 mPasteAction->setEnabled(!hasActionInHtmlModeToo); 0147 mCutAction->setEnabled(!hasActionInHtmlModeToo); 0148 mSelectAllAction->setEnabled(true); 0149 mCommentCodeAction->setEnabled(!hasActionInHtmlModeToo); 0150 mUncommentCodeAction->setEnabled(!hasActionInHtmlModeToo); 0151 mZoomInAction->setEnabled(true); 0152 mZoomOutAction->setEnabled(true); 0153 mZoomResetAction->setEnabled(true); 0154 mDebugSieveAction->setEnabled(!hasActionInHtmlModeToo); 0155 mWordWrapAction->setEnabled(!hasActionInHtmlModeToo); 0156 mPrintAction->setEnabled(!hasActionInHtmlModeToo); 0157 mPrintPreviewAction->setEnabled(!hasActionInHtmlModeToo); 0158 } 0159 0160 QMenu *SieveEditorMenuBar::viewMenu() const 0161 { 0162 return mViewMenu; 0163 } 0164 0165 void SieveEditorMenuBar::setTextModeWidget(SieveEditorTextModeWidget *textModeWidget) 0166 { 0167 if (!mTextModeWidget) { 0168 mTextModeWidget = textModeWidget; 0169 connect(mTextModeWidget->tabWidget(), &QTabWidget::currentChanged, this, &SieveEditorMenuBar::slotUpdateActions); 0170 } 0171 } 0172 0173 QAction *SieveEditorMenuBar::printPreviewAction() const 0174 { 0175 return mPrintPreviewAction; 0176 } 0177 0178 QAction *SieveEditorMenuBar::uncommentCodeAction() const 0179 { 0180 return mUncommentCodeAction; 0181 } 0182 0183 QAction *SieveEditorMenuBar::zoomResetAction() const 0184 { 0185 return mZoomResetAction; 0186 } 0187 0188 QAction *SieveEditorMenuBar::wordWrapAction() const 0189 { 0190 return mWordWrapAction; 0191 } 0192 0193 QAction *SieveEditorMenuBar::zoomInAction() const 0194 { 0195 return mZoomInAction; 0196 } 0197 0198 QAction *SieveEditorMenuBar::zoomOutAction() const 0199 { 0200 return mZoomOutAction; 0201 } 0202 0203 QAction *SieveEditorMenuBar::debugSieveScriptAction() const 0204 { 0205 return mDebugSieveAction; 0206 } 0207 0208 QAction *SieveEditorMenuBar::commentCodeAction() const 0209 { 0210 return mCommentCodeAction; 0211 } 0212 0213 QMenu *SieveEditorMenuBar::fileMenu() const 0214 { 0215 return mFileMenu; 0216 } 0217 0218 QMenu *SieveEditorMenuBar::toolsMenu() const 0219 { 0220 return mToolsMenu; 0221 } 0222 0223 QAction *SieveEditorMenuBar::selectAllAction() const 0224 { 0225 return mSelectAllAction; 0226 } 0227 0228 QAction *SieveEditorMenuBar::cutAction() const 0229 { 0230 return mCutAction; 0231 } 0232 0233 QAction *SieveEditorMenuBar::pasteAction() const 0234 { 0235 return mPasteAction; 0236 } 0237 0238 QAction *SieveEditorMenuBar::copyAction() const 0239 { 0240 return mCopyAction; 0241 } 0242 0243 QAction *SieveEditorMenuBar::redoAction() const 0244 { 0245 return mRedoAction; 0246 } 0247 0248 QAction *SieveEditorMenuBar::undoAction() const 0249 { 0250 return mUndoAction; 0251 } 0252 0253 QAction *SieveEditorMenuBar::replaceAction() const 0254 { 0255 return mReplaceAction; 0256 } 0257 0258 QAction *SieveEditorMenuBar::findAction() const 0259 { 0260 return mFindAction; 0261 } 0262 0263 QAction *SieveEditorMenuBar::goToLineAction() const 0264 { 0265 return mGoToLine; 0266 } 0267 0268 void SieveEditorMenuBar::slotUndoAvailable(bool b) 0269 { 0270 mUndoAction->setEnabled(b); 0271 } 0272 0273 void SieveEditorMenuBar::slotRedoAvailable(bool b) 0274 { 0275 mRedoAction->setEnabled(b); 0276 } 0277 0278 void SieveEditorMenuBar::slotCopyAvailable(bool b) 0279 { 0280 mCutAction->setEnabled(b); 0281 mCopyAction->setEnabled(b); 0282 } 0283 0284 #include "moc_sieveeditormenubar.cpp"