1 /*
2 * This file is part of SpellChecker plugin for Code::Blocks Studio
3 * Copyright (C) 2009 Daniel Anselmi
4 *
5 * SpellChecker plugin is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * SpellChecker plugin is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with SpellChecker. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19 
20 #ifndef SPELLCHECKER_H_INCLUDED
21 #define SPELLCHECKER_H_INCLUDED
22 
23 // For compilers that support precompilation, includes <wx/wx.h>
24 #include <wx/wxprec.h>
25 
26 #ifndef WX_PRECOMP
27 #include <wx/wx.h>
28 #endif
29 
30 #include <cbplugin.h> // for "class cbPlugin"
31 class wxSpellCheckEngineInterface;
32 class SpellCheckHelper;
33 class OnlineSpellChecker;
34 class Thesaurus;
35 class SpellCheckerConfig;
36 class MySpellingDialog;
37 class SpellCheckerStatusField;
38 
39 class SpellCheckerPlugin : public cbPlugin
40 {
41 public:
42     /** Constructor. */
43     SpellCheckerPlugin();
44     /** Destructor. */
45     virtual ~SpellCheckerPlugin();
46 
47     /** Return the plugin's configuration priority.
48       * This is a number (default is 50) that is used to sort plugins
49       * in configuration dialogs. Lower numbers mean the plugin's
50       * configuration is put higher in the list.
51       */
GetConfigurationPriority()52     virtual int GetConfigurationPriority() const
53     {
54         return 50;
55     }
56 
57     /** Return the configuration group for this plugin. Default is cgUnknown.
58       * Notice that you can logically OR more than one configuration groups,
59       * so you could set it, for example, as "cgCompiler | cgContribPlugin".
60       */
GetConfigurationGroup()61     virtual int GetConfigurationGroup() const
62     {
63         return cgEditor;
64     }
65 
66     /** Return plugin's configuration panel.
67       * @param parent The parent window.
68       * @return A pointer to the plugin's cbConfigurationPanel. It is deleted by the caller.
69       */
70     virtual cbConfigurationPanel* GetConfigurationPanel(wxWindow* parent);
71 
72     /** Return plugin's configuration panel for projects.
73       * The panel returned from this function will be added in the project's
74       * configuration dialog.
75       * @param parent The parent window.
76       * @param project The project that is being edited.
77       * @return A pointer to the plugin's cbConfigurationPanel. It is deleted by the caller.
78       */
GetProjectConfigurationPanel(cb_unused wxWindow * parent,cb_unused cbProject * project)79     virtual cbConfigurationPanel* GetProjectConfigurationPanel(cb_unused wxWindow* parent, cb_unused cbProject* project)
80     {
81         return 0;
82     }
83 
84     /** This method is called by Code::Blocks and is used by the plugin
85       * to add any menu items it needs on Code::Blocks's menu bar.\n
86       * It is a pure virtual method that needs to be implemented by all
87       * plugins. If the plugin does not need to add items on the menu,
88       * just do nothing ;)
89       * @param menuBar the wxMenuBar to create items in
90       */
91     virtual void BuildMenu(wxMenuBar* menuBar);
92 
93     /** This method is called by Code::Blocks core modules (EditorManager,
94       * ProjectManager etc) and is used by the plugin to add any menu
95       * items it needs in the module's popup menu. For example, when
96       * the user right-clicks on a project file in the project tree,
97       * ProjectManager prepares a popup menu to display with context
98       * sensitive options for that file. Before it displays this popup
99       * menu, it asks all attached plugins (by asking PluginManager to call
100       * this method), if they need to add any entries
101       * in that menu. This method is called.\n
102       * If the plugin does not need to add items in the menu,
103       * just do nothing ;)
104       * @param type the module that's preparing a popup menu
105       * @param menu pointer to the popup menu
106       * @param data pointer to FileTreeData object (to access/modify the file tree)
107       */
108     virtual void BuildModuleMenu(const ModuleType type, wxMenu* menu, const FileTreeData* data = 0);
109 
110     /** This method is called by Code::Blocks and is used by the plugin
111       * to add any toolbar items it needs on Code::Blocks's toolbar.\n
112       * It is a pure virtual method that needs to be implemented by all
113       * plugins. If the plugin does not need to add items on the toolbar,
114       * just do nothing ;)
115       * @param toolBar the wxToolBar to create items on
116       * @return The plugin should return true if it needed the toolbar, false if not
117       */
118     virtual bool BuildToolBar(wxToolBar* toolBar);
119 
120 #ifdef wxUSE_STATUSBAR
121     virtual void CreateStatusField(cbStatusBar *bar);
122 #endif
123 
124     void OnEditorHook(cbEditor* editor, wxScintillaEvent& event);
125 
126 protected:
127     /** Any descendent plugin should override this virtual method and
128       * perform any necessary initialization. This method is called by
129       * Code::Blocks (PluginManager actually) when the plugin has been
130       * loaded and should attach in Code::Blocks. When Code::Blocks
131       * starts up, it finds and <em>loads</em> all plugins but <em>does
132       * not</em> activate (attaches) them. It then activates all plugins
133       * that the user has selected to be activated on start-up.\n
134       * This means that a plugin might be loaded but <b>not</b> activated...\n
135       * Think of this method as the actual constructor...
136       */
137     virtual void OnAttach();
138 
139     /** Any descendent plugin should override this virtual method and
140       * perform any necessary de-initialization. This method is called by
141       * Code::Blocks (PluginManager actually) when the plugin has been
142       * loaded, attached and should de-attach from Code::Blocks.\n
143       * Think of this method as the actual destructor...
144       * @param appShutDown If true, the application is shutting down. In this
145       *         case *don't* use Manager::Get()->Get...() functions or the
146       *         behaviour is undefined...
147       */
148     virtual void OnRelease(bool appShutDown);
149 
150 
151 public:
152     void ReloadSettings();
153     static wxString GetOnlineCheckerConfigPath();
154 
155 private:
156     void OnSpelling(wxCommandEvent &event);
157     void OnUpdateSpelling(wxUpdateUIEvent &event);
158     void OnUpdateThesaurus(wxUpdateUIEvent &event);
159     void OnThesaurus(wxCommandEvent &event);
160     void OnCamelCase(wxCommandEvent &event);
161     bool DoGetWordStarts(const wxString& word, wxArrayInt& wordStarts, int numWords);
162     void OnReplaceBySuggestion(wxCommandEvent &event);
163     void OnMoreSuggestions(wxCommandEvent &event);
164     void OnAddToPersonalDictionary(wxCommandEvent &event);
165 
166     void ConfigureHunspellSpellCheckEngine();
167     void ConfigureThesaurus();
168     void ConfigurePersonalDictionary();
169     void SavePersonalDictionary();
170     void OnEditorSaved(CodeBlocksEvent& event);
171     void OnEditorTooltip(CodeBlocksEvent& event);
172     //void OnRightUpOverStatus(wxMouseEvent &event);
173     bool ActiveEditorHasTextSelected(void);
174 
175 public:
176     void EditPersonalDictionary();
177 
178 private:
179     int m_FunctorId;
180     wxSpellCheckEngineInterface* m_pSpellChecker;
181     MySpellingDialog *m_pSpellingDialog;
182     SpellCheckHelper *m_pSpellHelper;
183     OnlineSpellChecker *m_pOnlineChecker;
184     Thesaurus *m_pThesaurus;
185     SpellCheckerConfig *m_sccfg;
186 
187     wxArrayString m_suggestions;
188     int m_wordstart, m_wordend;
189     void AppStartupDone(CodeBlocksEvent& event);
190     void Init();
191 #ifdef wxUSE_STATUSBAR
192 private:
193     SpellCheckerStatusField *m_fld;
194 #endif
195 
196 private:
197     DECLARE_EVENT_TABLE();
198 };
199 
200 #endif // SPELLCHECKER_H_INCLUDED
201