Libksieve

sieveeditormenubar.cpp
1/*
2 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-only
5*/
6
7#include "sieveeditormenubar.h"
8#include "sieveeditortabwidget.h"
9#include "sieveeditortextmodewidget.h"
10
11#include <KLocalizedString>
12#include <KStandardActions>
13#include <QAction>
14#include <QIcon>
15using namespace KSieveUi;
16
17SieveEditorMenuBar::SieveEditorMenuBar(QWidget *parent)
18 : QMenuBar(parent)
19{
20 initActions();
21 initMenus();
22}
23
24SieveEditorMenuBar::~SieveEditorMenuBar() = default;
25
26void SieveEditorMenuBar::setEditorMode(bool editorMode)
27{
28 mGoToLine->setEnabled(editorMode);
29 mFindAction->setEnabled(editorMode);
30 mReplaceAction->setEnabled(editorMode);
31 mUndoAction->setEnabled(editorMode);
32 mRedoAction->setEnabled(editorMode);
33 mCopyAction->setEnabled(editorMode);
34 mPasteAction->setEnabled(editorMode);
35 mCutAction->setEnabled(editorMode);
36 mSelectAllAction->setEnabled(editorMode);
37 mCommentCodeAction->setEnabled(editorMode);
38 mUncommentCodeAction->setEnabled(editorMode);
39 mZoomInAction->setEnabled(editorMode);
40 mZoomOutAction->setEnabled(editorMode);
41 mZoomResetAction->setEnabled(editorMode);
42 mDebugSieveAction->setEnabled(editorMode);
43 mWordWrapAction->setEnabled(editorMode);
44 mPrintAction->setEnabled(editorMode);
45 mPrintPreviewAction->setEnabled(editorMode);
46}
47
48void SieveEditorMenuBar::initActions()
49{
50 mGoToLine = new QAction(i18nc("@action", "Go to Line"), this);
51 mGoToLine->setIcon(QIcon::fromTheme(QStringLiteral("go-jump")));
53 connect(mGoToLine, &QAction::triggered, this, &SieveEditorMenuBar::gotoLine);
54
55 mCommentCodeAction = new QAction(i18nc("@action", "Comment"), this);
56 mCommentCodeAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_D));
57 connect(mCommentCodeAction, &QAction::triggered, this, &SieveEditorMenuBar::comment);
58
59 mUncommentCodeAction = new QAction(i18nc("@action", "Uncomment"), this);
60 mUncommentCodeAction->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_D));
61 connect(mUncommentCodeAction, &QAction::triggered, this, &SieveEditorMenuBar::uncomment);
62
63 mDebugSieveAction = new QAction(i18nc("@action", "Debug Sieve Script…"), this);
64 mDebugSieveAction->setShortcut(QKeySequence(Qt::ALT | Qt::Key_D));
65 connect(mDebugSieveAction, &QAction::triggered, this, &SieveEditorMenuBar::debugSieveScript);
66
67 mFindAction = KStandardActions::find(this, &SieveEditorMenuBar::find, this);
68 mReplaceAction = KStandardActions::replace(this, &SieveEditorMenuBar::replace, this);
69 mUndoAction = KStandardActions::undo(this, &SieveEditorMenuBar::undo, this);
70 mRedoAction = KStandardActions::redo(this, &SieveEditorMenuBar::redo, this);
71 mCopyAction = KStandardActions::copy(this, &SieveEditorMenuBar::copy, this);
72 mPasteAction = KStandardActions::paste(this, &SieveEditorMenuBar::paste, this);
73 mCutAction = KStandardActions::cut(this, &SieveEditorMenuBar::cut, this);
74 mSelectAllAction = KStandardActions::selectAll(this, &SieveEditorMenuBar::selectAll, this);
75 mZoomInAction = KStandardActions::zoomIn(this, &SieveEditorMenuBar::zoomIn, this);
76 mZoomOutAction = KStandardActions::zoomOut(this, &SieveEditorMenuBar::zoomOut, this);
77 mPrintAction = KStandardActions::print(this, &SieveEditorMenuBar::print, this);
78 mPrintPreviewAction = KStandardActions::printPreview(this, &SieveEditorMenuBar::printPreview, this);
79
80 mZoomResetAction = KStandardActions::actualSize(this, &SieveEditorMenuBar::zoomReset, this);
81 mWordWrapAction = new QAction(i18nc("@action", "Wordwrap"), this);
82 mWordWrapAction->setCheckable(true);
83 connect(mWordWrapAction, &QAction::triggered, this, &SieveEditorMenuBar::wordWrap);
84
85 mUndoAction->setEnabled(false);
86 mRedoAction->setEnabled(false);
87 mCopyAction->setEnabled(false);
88 mCutAction->setEnabled(false);
89}
90
91QMenu *SieveEditorMenuBar::editorMenu() const
92{
93 return mEditorMenu;
94}
95
96void SieveEditorMenuBar::initMenus()
97{
98 mFileMenu = addMenu(i18nc("@title:menu", "File"));
99 mFileMenu->addAction(mPrintAction);
100 mFileMenu->addAction(mPrintPreviewAction);
101 mEditorMenu = addMenu(i18nc("@title:menu", "Edit"));
102 mEditorMenu->addAction(mUndoAction);
103 mEditorMenu->addAction(mRedoAction);
104 mEditorMenu->addSeparator();
105 mEditorMenu->addAction(mCutAction);
106 mEditorMenu->addAction(mCopyAction);
107 mEditorMenu->addAction(mPasteAction);
108 mEditorMenu->addSeparator();
109 mEditorMenu->addAction(mSelectAllAction);
110 mEditorMenu->addSeparator();
111 mEditorMenu->addAction(mFindAction);
112 mEditorMenu->addAction(mReplaceAction);
113 mEditorMenu->addSeparator();
114 mEditorMenu->addAction(mGoToLine);
115 mEditorMenu->addSeparator();
116 mEditorMenu->addAction(mWordWrapAction);
117 mEditorMenu->addSeparator();
118 mEditorMenu->addAction(mCommentCodeAction);
119 mEditorMenu->addAction(mUncommentCodeAction);
120
121 mViewMenu = addMenu(i18nc("@title:menu", "View"));
122 mViewMenu->addAction(mZoomInAction);
123 mViewMenu->addAction(mZoomOutAction);
124 mViewMenu->addSeparator();
125 mViewMenu->addAction(mZoomResetAction);
126
127 mToolsMenu = addMenu(i18nc("@title:menu", "Tools"));
128 mToolsMenu->addAction(mDebugSieveAction);
129}
130
131QAction *SieveEditorMenuBar::printAction() const
132{
133 return mPrintAction;
134}
135
136void SieveEditorMenuBar::slotUpdateActions()
137{
138 const bool hasActionInHtmlModeToo = mTextModeWidget->tabWidget()->currentPageIsHtmlPage();
139
140 mGoToLine->setEnabled(!hasActionInHtmlModeToo);
141 mFindAction->setEnabled(true);
142 mReplaceAction->setEnabled(!hasActionInHtmlModeToo);
143 mUndoAction->setEnabled(!hasActionInHtmlModeToo);
144 mRedoAction->setEnabled(!hasActionInHtmlModeToo);
145 mCopyAction->setEnabled(true);
146 mPasteAction->setEnabled(!hasActionInHtmlModeToo);
147 mCutAction->setEnabled(!hasActionInHtmlModeToo);
148 mSelectAllAction->setEnabled(true);
149 mCommentCodeAction->setEnabled(!hasActionInHtmlModeToo);
150 mUncommentCodeAction->setEnabled(!hasActionInHtmlModeToo);
151 mZoomInAction->setEnabled(true);
152 mZoomOutAction->setEnabled(true);
153 mZoomResetAction->setEnabled(true);
154 mDebugSieveAction->setEnabled(!hasActionInHtmlModeToo);
155 mWordWrapAction->setEnabled(!hasActionInHtmlModeToo);
156 mPrintAction->setEnabled(!hasActionInHtmlModeToo);
157 mPrintPreviewAction->setEnabled(!hasActionInHtmlModeToo);
158}
159
160QMenu *SieveEditorMenuBar::viewMenu() const
161{
162 return mViewMenu;
163}
164
165void SieveEditorMenuBar::setTextModeWidget(SieveEditorTextModeWidget *textModeWidget)
166{
167 if (!mTextModeWidget) {
168 mTextModeWidget = textModeWidget;
169 connect(mTextModeWidget->tabWidget(), &QTabWidget::currentChanged, this, &SieveEditorMenuBar::slotUpdateActions);
170 }
171}
172
173QAction *SieveEditorMenuBar::printPreviewAction() const
174{
175 return mPrintPreviewAction;
176}
177
178QAction *SieveEditorMenuBar::uncommentCodeAction() const
179{
180 return mUncommentCodeAction;
181}
182
183QAction *SieveEditorMenuBar::zoomResetAction() const
184{
185 return mZoomResetAction;
186}
187
188QAction *SieveEditorMenuBar::wordWrapAction() const
189{
190 return mWordWrapAction;
191}
192
193QAction *SieveEditorMenuBar::zoomInAction() const
194{
195 return mZoomInAction;
196}
197
198QAction *SieveEditorMenuBar::zoomOutAction() const
199{
200 return mZoomOutAction;
201}
202
203QAction *SieveEditorMenuBar::debugSieveScriptAction() const
204{
205 return mDebugSieveAction;
206}
207
208QAction *SieveEditorMenuBar::commentCodeAction() const
209{
210 return mCommentCodeAction;
211}
212
213QMenu *SieveEditorMenuBar::fileMenu() const
214{
215 return mFileMenu;
216}
217
218QMenu *SieveEditorMenuBar::toolsMenu() const
219{
220 return mToolsMenu;
221}
222
223QAction *SieveEditorMenuBar::selectAllAction() const
224{
225 return mSelectAllAction;
226}
227
228QAction *SieveEditorMenuBar::cutAction() const
229{
230 return mCutAction;
231}
232
233QAction *SieveEditorMenuBar::pasteAction() const
234{
235 return mPasteAction;
236}
237
238QAction *SieveEditorMenuBar::copyAction() const
239{
240 return mCopyAction;
241}
242
243QAction *SieveEditorMenuBar::redoAction() const
244{
245 return mRedoAction;
246}
247
248QAction *SieveEditorMenuBar::undoAction() const
249{
250 return mUndoAction;
251}
252
253QAction *SieveEditorMenuBar::replaceAction() const
254{
255 return mReplaceAction;
256}
257
258QAction *SieveEditorMenuBar::findAction() const
259{
260 return mFindAction;
261}
262
263QAction *SieveEditorMenuBar::goToLineAction() const
264{
265 return mGoToLine;
266}
267
268void SieveEditorMenuBar::slotUndoAvailable(bool b)
269{
270 mUndoAction->setEnabled(b);
271}
272
273void SieveEditorMenuBar::slotRedoAvailable(bool b)
274{
275 mRedoAction->setEnabled(b);
276}
277
278void SieveEditorMenuBar::slotCopyAvailable(bool b)
279{
280 mCutAction->setEnabled(b);
281 mCopyAction->setEnabled(b);
282}
283
284#include "moc_sieveeditormenubar.cpp"
The SieveEditorTextModeWidget class.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setCheckable(bool)
void setEnabled(bool)
void setIcon(const QIcon &icon)
void setShortcut(const QKeySequence &shortcut)
void triggered(bool checked)
QIcon fromTheme(const QString &name)
QAction * addAction(const QIcon &icon, const QString &text, Functor functor, const QKeySequence &shortcut)
QAction * addSeparator()
QAction * addMenu(QMenu *menu)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void currentChanged(int index)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:57:10 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.