File indexing completed on 2024-04-14 03:55:24
0001 /* 0002 SPDX-FileCopyrightText: 2008-2009 Michel Ludwig <michel.ludwig@kdemail.net> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef SPELLINGMENU_H 0008 #define SPELLINGMENU_H 0009 0010 #include <QObject> 0011 0012 #include <KActionCollection> 0013 #include <KActionMenu> 0014 #include <ktexteditor/movingrange.h> 0015 #include <ktexteditor/movingrangefeedback.h> 0016 #include <ktexteditor/range.h> 0017 #include <ktexteditor/view.h> 0018 0019 namespace KTextEditor 0020 { 0021 class ViewPrivate; 0022 } 0023 class KateOnTheFlyChecker; 0024 0025 class KateSpellingMenu : public QObject 0026 { 0027 Q_OBJECT 0028 friend class KateOnTheFlyChecker; 0029 0030 public: 0031 explicit KateSpellingMenu(KTextEditor::ViewPrivate *view); 0032 ~KateSpellingMenu() override; 0033 0034 bool isEnabled() const; 0035 bool isVisible() const; 0036 0037 void createActions(KActionCollection *ac); 0038 0039 /** 0040 * This method has to be called before the menu is shown in response to a context 0041 * menu event. Ensure contextMenu is valid pointer! 0042 **/ 0043 void prepareToBeShown(QMenu *contextMenu); 0044 0045 /** 0046 * This method has to be called after a context menu event. 0047 **/ 0048 void cleanUpAfterShown(); 0049 0050 void setEnabled(bool b); 0051 void setVisible(bool b); 0052 0053 protected: 0054 KTextEditor::ViewPrivate *m_view; 0055 KActionMenu *m_spellingMenuAction; 0056 QAction *m_ignoreWordAction, *m_addToDictionaryAction; 0057 QActionGroup *m_dictionaryGroup; 0058 QList<QAction *> m_menuOnTopSuggestionList; 0059 QMenu *m_spellingMenu; 0060 KTextEditor::MovingRange *m_currentMisspelledRange; 0061 /** 0062 * Set to true when a word was selected. Needed because in such case we got no "exited-notification" 0063 * and end up with an always active m_currentMisspelledRange 0064 **/ 0065 bool m_currentMisspelledRangeNeedCleanUp = false; 0066 KTextEditor::Range m_selectedRange; 0067 QString m_currentDictionary; 0068 QStringList m_currentSuggestions; 0069 0070 // These methods are called from KateOnTheFlyChecker to inform about events involving 0071 // moving ranges. 0072 void rangeDeleted(KTextEditor::MovingRange *range); 0073 void caretEnteredMisspelledRange(KTextEditor::MovingRange *range); 0074 void caretExitedMisspelledRange(KTextEditor::MovingRange *range); 0075 0076 protected Q_SLOTS: 0077 void populateSuggestionsMenu(); 0078 void replaceWordBySuggestion(const QString &suggestion); 0079 0080 void addCurrentWordToDictionary(); 0081 void ignoreCurrentWord(); 0082 }; 0083 0084 #endif