2
This file is part of Code Snippets, a plugin for Code::Blocks
3
Copyright (C) 2006 Arto Jonsson
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License
7
as published by the Free Software Foundation; either version 2
8
of the License, or (at your option) any later version.
10
This program 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.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
#ifndef CODESNIPPETS_H_INCLUDED
21
#define CODESNIPPETS_H_INCLUDED
25
#include "cbplugin.h" // for "class cbPlugin"
26
//#include "wxaui/manager.h"
27
#include "snippetsconfig.h"
30
class CodeSnippetsWindow;
31
class wxMemoryMappedFile;
33
// ----------------------------------------------------------------------------
34
class CodeSnippets : public cbPlugin
35
// ----------------------------------------------------------------------------
37
friend class wxMyFileDropTarget;
38
friend class DropTargets;
46
/** Invoke configuration dialog. */
47
int Configure() { return 0; }
49
/** Return the plugin's configuration priority.
50
* This is a number (default is 50) that is used to sort plugins
51
* in configuration dialogs. Lower numbers mean the plugin's
52
* configuration is put higher in the list.
54
int GetConfigurationPriority() const { return 50; }
56
/** Return the configuration group for this plugin. Default is cgUnknown.
57
* Notice that you can logically AND more than one configuration groups,
58
* so you could set it, for example, as "cgCompiler | cgContribPlugin".
60
int GetConfigurationGroup() const { return cgContribPlugin; }
62
/** Return plugin's configuration panel.
63
* @param parent The parent window.
64
* @return A pointer to the plugin's cbConfigurationPanel. It is deleted by the caller.
66
cbConfigurationPanel* GetConfigurationPanel(wxWindow* parent){ return 0; }
68
/** Return plugin's configuration panel for projects.
69
* The panel returned from this function will be added in the project's
70
* configuration dialog.
71
* @param parent The parent window.
72
* @param project The project that is being edited.
73
* @return A pointer to the plugin's cbConfigurationPanel. It is deleted by the caller.
75
cbConfigurationPanel* GetProjectConfigurationPanel(wxWindow* parent, cbProject* project){ return 0; }
77
/** This method is called by Code::Blocks and is used by the plugin
78
* to add any menu items it needs on Code::Blocks's menu bar.\n
79
* It is a pure virtual method that needs to be implemented by all
80
* plugins. If the plugin does not need to add items on the menu,
82
* @param menuBar the wxMenuBar to create items in
84
void BuildMenu(wxMenuBar* menuBar);
86
/** This method is called by Code::Blocks core modules (EditorManager,
87
* ProjectManager etc) and is used by the plugin to add any menu
88
* items it needs in the module's popup menu. For example, when
89
* the user right-clicks on a project file in the project tree,
90
* ProjectManager prepares a popup menu to display with context
91
* sensitive options for that file. Before it displays this popup
92
* menu, it asks all attached plugins (by asking PluginManager to call
93
* this method), if they need to add any entries
94
* in that menu. This method is called.\n
95
* If the plugin does not need to add items in the menu,
97
* @param type the module that's preparing a popup menu
98
* @param menu pointer to the popup menu
99
* @param data pointer to FileTreeData object (to access/modify the file tree)
101
void BuildModuleMenu(const ModuleType type, wxMenu* menu, const FileTreeData* data = 0){}
103
/** This method is called by Code::Blocks and is used by the plugin
104
* to add any toolbar items it needs on Code::Blocks's toolbar.\n
105
* It is a pure virtual method that needs to be implemented by all
106
* plugins. If the plugin does not need to add items on the toolbar,
108
* @param toolBar the wxToolBar to create items on
109
* @return The plugin should return true if it needed the toolbar, false if not
111
bool BuildToolBar(wxToolBar* toolBar){ return false; }
113
/** Any descendent plugin should override this virtual method and
114
* perform any necessary initialization. This method is called by
115
* Code::Blocks (PluginManager actually) when the plugin has been
116
* loaded and should attach in Code::Blocks. When Code::Blocks
117
* starts up, it finds and <em>loads</em> all plugins but <em>does
118
* not</em> activate (attaches) them. It then activates all plugins
119
* that the user has selected to be activated on start-up.\n
120
* This means that a plugin might be loaded but <b>not</b> activated...\n
121
* Think of this method as the actual constructor...
125
/** Any descendent plugin should override this virtual method and
126
* perform any necessary de-initialization. This method is called by
127
* Code::Blocks (PluginManager actually) when the plugin has been
128
* loaded, attached and should de-attach from Code::Blocks.\n
129
* Think of this method as the actual destructor...
130
* @param appShutDown If true, the application is shutting down. In this
131
* case *don't* use Manager::Get()->Get...() functions or the
132
* behaviour is undefined...
134
void OnRelease(bool appShutDown);
135
void OnDisable(bool appShutDown);
138
void SetSnippetsWindow(CodeSnippetsWindow* p);
139
CodeSnippetsWindow* GetSnippetsWindow(){return GetConfig()->GetSnippetsWindow();}
140
void OnTreeDragEvent(wxTreeEvent& event);
144
void CreateSnippetWindow();
145
void SetTreeCtrlHandler(wxWindow *p, WXTYPE eventType);
146
void RemoveTreeCtrlHandler(wxWindow *p, WXTYPE eventType);
147
bool GetTreeSelectionData(wxTreeCtrl* pTree, wxTreeItemId itemID, wxString& selString);
148
wxArrayString* TextToFilenames(const wxString& string);
149
bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& files);
150
wxString FindAppPath(const wxString& argv0, const wxString& cwd, const wxString& appVariableName);
151
int LaunchProcess(const wxString& cmd, const wxString& cwd);
152
long LaunchExternalSnippets();
153
bool ReleaseMemoryMappedFile();
154
void TellExternalSnippetsToTerminate();
155
void CloseDockWindow();
156
wxWindow* FindOpenFilesListWindow();
159
#if defined(__WXMSW__)
160
void MSW_MouseMove(int x, int y );
163
void OnViewSnippets(wxCommandEvent& event);
164
void OnUpdateUI(wxUpdateUIEvent& event);
165
void OnActivate(wxActivateEvent& event);
166
void OnWindowDestroy(wxEvent& event);
167
void OnIdle(wxIdleEvent& event);
168
void OnSwitchViewLayout(CodeBlocksLayoutEvent& event);
169
void OnSwitchedViewLayout(CodeBlocksLayoutEvent& event);
170
void OnDockWindowVisability(CodeBlocksDockEvent& event);
171
void OnAppStartupDone(CodeBlocksEvent& event);
174
ProjectManager* m_pPrjMan;
175
wxWindow* m_pOpenFilesList;
176
wxTreeCtrl* m_pMgtTreeBeginDrag;
177
wxPoint m_TreeMousePosn;
178
wxTreeItemId m_TreeItemId;
180
int m_nOnActivateBusy;
182
wxMemoryMappedFile* m_pMappedFile;
185
DECLARE_EVENT_TABLE();
187
}; //class CodeSnippets
188
// ----------------------------------------------------------------------------
189
// ::MainFrame Drop Target (taken from ../src/main.cpp)
190
// ----------------------------------------------------------------------------
191
class wxMyFileDropTarget : public wxFileDropTarget
192
// ----------------------------------------------------------------------------
194
// This class declaration must mirror the one used in ::MainFrame
195
// We pass our filename array off to MainFrame using this class
198
wxMyFileDropTarget(CodeSnippets* frame):m_frame(frame){}
199
virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames)
201
if(!m_frame) return false;
202
return m_frame->OnDropFiles(x,y,filenames);
205
CodeSnippets* m_frame;
208
// ----------------------------------------------------------------------------
209
// Local drop targets
210
// ----------------------------------------------------------------------------
211
class DropTargets: public wxDropTarget
212
// ----------------------------------------------------------------------------
217
DropTargets (CodeSnippets* pcbDndExtn);
219
virtual wxDragResult OnData (wxCoord x, wxCoord y, wxDragResult def);
220
bool OnDataText (wxCoord x, wxCoord y, const wxString& data);
221
bool OnDataFiles (wxCoord x, wxCoord y, const wxArrayString& filenames);
223
wxDragResult OnDragOver (wxCoord x, wxCoord y, wxDragResult def);
224
wxDragResult OnEnter (wxCoord x, wxCoord y, wxDragResult def);
225
virtual bool OnDrop(wxCoord x, wxCoord y)
227
//wxDropTarget::OnDrop
228
//virtual bool OnDrop(wxCoord x, wxCoord y)
229
//Called when the user drops a data object on the target.
230
//Return false to veto the operation.
232
LOGIT( wxT("DropTargets:OnDrop") );
241
CodeSnippets* m_pcbDndExtn;
243
wxFileDataObject *m_file;
244
wxTextDataObject *m_text;
247
//----------------------------------------------------------------------------
248
// drop targets composite
249
// ----------------------------------------------------------------------------
250
class DropTargetsComposite: public wxDataObjectComposite
251
// ----------------------------------------------------------------------------
255
DropTargetsComposite () { m_dataObjectLast = NULL; };
257
bool SetData (const wxDataFormat& format, size_t len, const void *buf)
259
m_dataObjectLast = GetObject (format);
260
wxCHECK_MSG ( m_dataObjectLast, FALSE, wxT("unsupported format in wxDataObjectComposite"));
261
return m_dataObjectLast->SetData (len, buf);
264
wxDataObjectSimple *GetLastDataObject() { return m_dataObjectLast; }
267
wxDataObjectSimple *m_dataObjectLast;
271
#endif // CODESNIPPETS_H_INCLUDED
273
// The following was an unsuccessful attempt to work-around the drag-n-drop crash
274
// on Linux which occurs when the user drags the cursor too fast, giving the message
275
// Gtk-CRITICAL ** : gtk_drag_set_icon_widget assert DRAG_CONTEXT (context) failed
276
// and then the system freezes up.
277
////// ----------------------------------------------------------------------------
278
////class DropSource: public wxDropSource
279
////// ----------------------------------------------------------------------------
284
//// DropSource (wxDataObject& data, wxWindow* win = NULL)
285
//// :wxDropSource(data, win)
286
//// { //LOGIT( _T("DropSource ctor") );
289
//// virtual bool GiveFeedback(wxDragResult WXUNUSED(effect))
291
//// LOGIT( _T("DropSource GiveFeedBack"));
299
// ----------------------------------------------------------------------------