-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMiniDoc.cpp
More file actions
258 lines (224 loc) · 7.42 KB
/
MiniDoc.cpp
File metadata and controls
258 lines (224 loc) · 7.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#include <sdk.h> // Code::Blocks SDK
#include <configurationpanel.h>
#include <editor_hooks.h>
#include <cbcolourmanager.h>
#include <editormanager.h>
#include <logmanager.h>
#include <cbeditor.h>
#include "MiniDoc.h"
#include "MiniDocPanel.h"
#include "MiniDocConfigPanel.h"
namespace
{
PluginRegistrant<MiniDoc> reg(_T("MiniDoc"));
const long idViewMiniDocPanel = wxNewId();
}
// events handling
BEGIN_EVENT_TABLE(MiniDoc, cbPlugin)
// add any events you want to handle here
EVT_MENU(idViewMiniDocPanel, MiniDoc::OnViewMiniDocPanel)
EVT_UPDATE_UI(idViewMiniDocPanel, MiniDoc::OnUpdateViewMenu)
EVT_IDLE( MiniDoc::OnIdle)
END_EVENT_TABLE()
// constructor
MiniDoc::MiniDoc():
updatePending_(false),
m_pPanel(NULL),
m_pViewMenu(NULL)
{
// Make sure our resources are available.
// In the generated boilerplate code we have no resources but when
// we add some, it will be nice that this code is in place already ;)
if(!Manager::LoadResource(_T("MiniDoc.zip")))
NotifyMissingFile(_T("MiniDoc.zip"));
}
void MiniDoc::OnAttach()
{
// do whatever initialization you need for your plugin
// NOTE: after this function, the inherited member variable
// m_IsAttached will be TRUE...
// You should check for it in other functions, because if it
// is FALSE, it means that the application did *not* "load"
// (see: does not need) this plugin...
ColourManager* cm = Manager::Get()->GetColourManager();
cm->RegisterColour(_("MiniDoc"), _("Background"), wxT("minidoc_background"), *wxLIGHT_GREY );
m_pPanel = new MiniDocPanel(Manager::Get()->GetAppWindow());
if(!m_pPanel)
{
Manager::Get()->GetLogManager()->Log(_T("Could not create MiniDoc!"));
return;
}
EditorHooks::HookFunctorBase *editor_hook = new EditorHooks::HookFunctor<MiniDoc>(this, &MiniDoc::OnEditorHook);
m_FunctorId = EditorHooks::RegisterHook( editor_hook );
// add the MiniDoc-panel to the docking system
CodeBlocksDockEvent dockevt(cbEVT_ADD_DOCK_WINDOW);
dockevt.name = _T("MiniDoc");
dockevt.title = _("MiniDoc");
dockevt.pWindow = m_pPanel;
dockevt.minimumSize.Set(50, 50);
dockevt.desiredSize.Set(150, 100);
dockevt.floatingSize.Set(100, 150);
dockevt.dockSide = CodeBlocksDockEvent::dsRight;
dockevt.stretch = true;
Manager::Get()->ProcessEvent(dockevt);
Manager::Get()->RegisterEventSink(cbEVT_EDITOR_CLOSE, new cbEventFunctor<MiniDoc, CodeBlocksEvent>(this, &MiniDoc::OnEditorClose));
Manager::Get()->RegisterEventSink(cbEVT_EDITOR_ACTIVATED, new cbEventFunctor<MiniDoc, CodeBlocksEvent>(this, &MiniDoc::OnEditorActivated));
Manager::Get()->RegisterEventSink(cbEVT_EDITOR_SPLIT, new cbEventFunctor<MiniDoc, CodeBlocksEvent>(this, &MiniDoc::OnEditorSplit));
// check if editor is open
EditorBase *eb = Manager::Get()->GetEditorManager()->GetActiveEditor();
if(eb && eb->IsBuiltinEditor())
{
cbEditor *ed = dynamic_cast<cbEditor*>(eb);
if(ed)
{
ConnectSizeEvent(ed);
m_pPanel->ShowMiniatureOf(ed);
}
}
}
void MiniDoc::OnRelease(bool appShutDown)
{
EditorHooks::UnregisterHook(m_FunctorId);
if ( m_pPanel && !appShutDown )
{
m_pPanel->ShowMiniatureOf(NULL);
CodeBlocksDockEvent docevt(cbEVT_REMOVE_DOCK_WINDOW);
docevt.pWindow = m_pPanel;
Manager::Get()->ProcessEvent(docevt);
// and destroy the panel
m_pPanel->Destroy();
m_pPanel = NULL;
}
}
void MiniDoc::ConnectSizeEvent(cbEditor *ed)
{
if(ed)
{
ed->GetLeftSplitViewControl()->Connect(wxEVT_SIZE,wxSizeEventHandler(MiniDoc::OnResize), nullptr, this);
if(cbStyledTextCtrl *stc = ed->GetRightSplitViewControl())
stc->Connect(wxEVT_SIZE,wxSizeEventHandler(MiniDoc::OnResize), nullptr, this);
}
}
void MiniDoc::OnEditorClose(CodeBlocksEvent& event)
{
OnEditorEvent();
}
void MiniDoc::OnEditorActivated(CodeBlocksEvent& event)
{
OnEditorEvent();
}
void MiniDoc::OnEditorEvent()
{
if (m_pPanel && IsAttached())
{
cbEditor *ed = NULL;
EditorBase *eb = Manager::Get()->GetEditorManager()->GetActiveEditor();
if(eb && eb->IsBuiltinEditor())
{
ed = dynamic_cast<cbEditor*>(eb);
ConnectSizeEvent(ed);
}
m_pPanel->ShowMiniatureOf(ed);
}
}
void MiniDoc::OnIdle(wxIdleEvent &event)
{
if(updatePending_)
UpdatePanel();
updatePending_ = false;
event.Skip();
}
void MiniDoc::OnEditorSplit(CodeBlocksEvent& event)
{
if (m_pPanel && IsAttached())
{
if (event.GetEditor()->IsBuiltinEditor())
{
if(cbEditor *ed = dynamic_cast<cbEditor*>(event.GetEditor()))
{
if(cbStyledTextCtrl *stc = ed->GetRightSplitViewControl())
stc->Connect(wxEVT_SIZE,wxSizeEventHandler(MiniDoc::OnResize), nullptr, this);
}
}
}
}
void MiniDoc::OnResize(wxSizeEvent& event)
{
UpdatePanel();
event.Skip();
}
void MiniDoc::UpdatePanel()
{
EditorBase *eb = Manager::Get()->GetEditorManager()->GetActiveEditor();
if(eb && eb->IsBuiltinEditor())
if(cbEditor *ed = dynamic_cast<cbEditor*>(eb))
m_pPanel->Update(ed);
}
void MiniDoc::OnEditorHook(cbEditor* editor, wxScintillaEvent& event)
{
if(event.GetEventType() != wxEVT_SCI_UPDATEUI) return;
static wxTimer timer;
if(!timer.IsRunning())
{
updatePending_ = false;
timer.Start(100, true);
m_pPanel->Update(editor);
}
else
updatePending_ = true;
}
int MiniDoc::Configure()
{
//create and display the configuration dialog for your plugin
cbConfigurationDialog dlg(Manager::Get()->GetAppWindow(), wxID_ANY, _("Your dialog title"));
if (cbConfigurationPanel* panel = GetConfigurationPanel(&dlg))
{
dlg.AttachConfigurationPanel(panel);
PlaceWindow(&dlg);
return dlg.ShowModal() == wxID_OK ? 0 : -1;
}
return -1;
}
void MiniDoc::BuildMenu(wxMenuBar* menuBar)
{
// insert entry in the View menu
int viewPos = menuBar->FindMenu(_("&View"));
if (viewPos != wxNOT_FOUND)
{
m_pViewMenu = menuBar->GetMenu(viewPos);
if(m_pViewMenu)
{
wxMenuItemList& items = m_pViewMenu->GetMenuItems();
// find the first separator and insert before it
for (size_t i = 0; i < items.GetCount(); ++i)
{
if (items[i]->IsSeparator())
{
m_pViewMenu->InsertCheckItem(i, idViewMiniDocPanel, _("&MiniDoc"), _("Toggle displaying the MiniDoc panel"));
return;
}
}
// not found so just append
m_pViewMenu->AppendCheckItem(idViewMiniDocPanel, _("&MiniDoc"), _("Toggle displaying the MiniDoc panel"));
}
}
}
void MiniDoc::OnViewMiniDocPanel(wxCommandEvent& event)
{
CodeBlocksDockEvent evt(event.IsChecked() ? cbEVT_SHOW_DOCK_WINDOW : cbEVT_HIDE_DOCK_WINDOW);
evt.pWindow = m_pPanel;
Manager::Get()->ProcessEvent(evt);
}
void MiniDoc::OnUpdateViewMenu(wxUpdateUIEvent &event)
{
if (m_pViewMenu)
{
bool isVis = IsWindowReallyShown((wxWindow*)m_pPanel);
m_pViewMenu->Check(idViewMiniDocPanel, isVis);
}
event.Skip();
}
cbConfigurationPanel* MiniDoc::GetConfigurationPanel(wxWindow* parent)
{
return new MiniDocConfigPanel(parent, m_pPanel);
}