~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/plugins/contrib/codesnippets/codesnippets.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        This file is part of Code Snippets, a plugin for Code::Blocks
 
3
        Copyright (C) 2006 Arto Jonsson
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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.
 
18
*/
 
19
 
 
20
#ifndef CODESNIPPETS_H_INCLUDED
 
21
#define CODESNIPPETS_H_INCLUDED
 
22
 
 
23
#include <wx/dnd.h>
 
24
 
 
25
#include "cbplugin.h" // for "class cbPlugin"
 
26
//#include "wxaui/manager.h"
 
27
#include "snippetsconfig.h"
 
28
 
 
29
 
 
30
class CodeSnippetsWindow;
 
31
class wxMemoryMappedFile;
 
32
 
 
33
// ----------------------------------------------------------------------------
 
34
class CodeSnippets : public cbPlugin
 
35
// ----------------------------------------------------------------------------
 
36
{
 
37
    friend class wxMyFileDropTarget;
 
38
    friend class DropTargets;
 
39
 
 
40
        public:
 
41
                /** Constructor. */
 
42
                CodeSnippets();
 
43
                /** Destructor. */
 
44
                ~CodeSnippets();
 
45
 
 
46
                /** Invoke configuration dialog. */
 
47
                int Configure() { return 0; }
 
48
 
 
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.
 
53
                */
 
54
                int GetConfigurationPriority() const { return 50; }
 
55
 
 
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".
 
59
                */
 
60
                int GetConfigurationGroup() const { return cgContribPlugin; }
 
61
 
 
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.
 
65
                  */
 
66
                cbConfigurationPanel* GetConfigurationPanel(wxWindow* parent){ return 0; }
 
67
 
 
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.
 
74
                */
 
75
                cbConfigurationPanel* GetProjectConfigurationPanel(wxWindow* parent, cbProject* project){ return 0; }
 
76
 
 
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,
 
81
                 * just do nothing ;)
 
82
                 * @param menuBar the wxMenuBar to create items in
 
83
                */
 
84
                void BuildMenu(wxMenuBar* menuBar);
 
85
 
 
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,
 
96
                 * just do nothing ;)
 
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)
 
100
                */
 
101
                void BuildModuleMenu(const ModuleType type, wxMenu* menu, const FileTreeData* data = 0){}
 
102
 
 
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,
 
107
                 * just do nothing ;)
 
108
                 * @param toolBar the wxToolBar to create items on
 
109
                 * @return The plugin should return true if it needed the toolbar, false if not
 
110
                */
 
111
                bool BuildToolBar(wxToolBar* toolBar){ return false; }
 
112
        protected:
 
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...
 
122
                */
 
123
                void OnAttach();
 
124
 
 
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...
 
133
                */
 
134
                void OnRelease(bool appShutDown);
 
135
        void OnDisable(bool appShutDown);
 
136
 
 
137
                // ---
 
138
                void SetSnippetsWindow(CodeSnippetsWindow* p);
 
139
                CodeSnippetsWindow*  GetSnippetsWindow(){return GetConfig()->GetSnippetsWindow();}
 
140
        void OnTreeDragEvent(wxTreeEvent& event);
 
141
 
 
142
        private:
 
143
 
 
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();
 
157
 
 
158
 
 
159
        #if defined(__WXMSW__)
 
160
            void MSW_MouseMove(int x, int y );
 
161
        #endif
 
162
 
 
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);
 
172
 
 
173
                wxWindow*       m_pAppWin;
 
174
        ProjectManager* m_pPrjMan;
 
175
        wxWindow*       m_pOpenFilesList;
 
176
        wxTreeCtrl*     m_pMgtTreeBeginDrag;
 
177
        wxPoint         m_TreeMousePosn;
 
178
        wxTreeItemId    m_TreeItemId;
 
179
        wxString        m_TreeText;
 
180
        int             m_nOnActivateBusy;
 
181
        long            m_ExternalPid;
 
182
        wxMemoryMappedFile* m_pMappedFile;
 
183
 
 
184
 
 
185
                DECLARE_EVENT_TABLE();
 
186
 
 
187
}; //class CodeSnippets
 
188
// ----------------------------------------------------------------------------
 
189
//  ::MainFrame Drop Target (taken from ../src/main.cpp)
 
190
// ----------------------------------------------------------------------------
 
191
class wxMyFileDropTarget : public wxFileDropTarget
 
192
// ----------------------------------------------------------------------------
 
193
{
 
194
    // This class declaration must mirror the one used in ::MainFrame
 
195
    // We pass our filename array off to MainFrame using this class
 
196
 
 
197
  public:
 
198
    wxMyFileDropTarget(CodeSnippets* frame):m_frame(frame){}
 
199
    virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames)
 
200
    {
 
201
        if(!m_frame) return false;
 
202
        return m_frame->OnDropFiles(x,y,filenames);
 
203
    }
 
204
  private:
 
205
    CodeSnippets* m_frame;
 
206
};
 
207
 
 
208
// ----------------------------------------------------------------------------
 
209
// Local drop targets
 
210
// ----------------------------------------------------------------------------
 
211
class DropTargets: public wxDropTarget
 
212
// ----------------------------------------------------------------------------
 
213
{
 
214
  public:
 
215
 
 
216
    // constructor
 
217
    DropTargets (CodeSnippets* pcbDndExtn);
 
218
 
 
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);
 
222
 
 
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)
 
226
    {
 
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.
 
231
        #ifdef LOGGING
 
232
         LOGIT( wxT("DropTargets:OnDrop") );
 
233
        #endif //LOGGING
 
234
        return true;
 
235
    }
 
236
 
 
237
    void OnLeave();
 
238
 
 
239
  private:
 
240
 
 
241
    CodeSnippets* m_pcbDndExtn;
 
242
 
 
243
    wxFileDataObject *m_file;
 
244
    wxTextDataObject *m_text;
 
245
 
 
246
};
 
247
//----------------------------------------------------------------------------
 
248
// drop targets composite
 
249
// ----------------------------------------------------------------------------
 
250
class DropTargetsComposite: public wxDataObjectComposite
 
251
// ----------------------------------------------------------------------------
 
252
{
 
253
  public:
 
254
    // constructor
 
255
    DropTargetsComposite () { m_dataObjectLast = NULL; };
 
256
 
 
257
    bool SetData (const wxDataFormat& format, size_t len, const void *buf)
 
258
    {
 
259
        m_dataObjectLast = GetObject (format);
 
260
        wxCHECK_MSG ( m_dataObjectLast, FALSE, wxT("unsupported format in wxDataObjectComposite"));
 
261
        return m_dataObjectLast->SetData (len, buf);
 
262
    }
 
263
 
 
264
    wxDataObjectSimple *GetLastDataObject() { return m_dataObjectLast; }
 
265
 
 
266
  private:
 
267
    wxDataObjectSimple *m_dataObjectLast;
 
268
 
 
269
};
 
270
 
 
271
#endif // CODESNIPPETS_H_INCLUDED
 
272
// 2007/08/1
 
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
////// ----------------------------------------------------------------------------
 
280
////{
 
281
////  public:
 
282
////
 
283
////    // constructor
 
284
////    DropSource (wxDataObject& data, wxWindow* win = NULL)
 
285
////        :wxDropSource(data, win)
 
286
////        {  //LOGIT( _T("DropSource ctor") );
 
287
////        }
 
288
////
 
289
////    virtual bool GiveFeedback(wxDragResult WXUNUSED(effect))
 
290
////        {
 
291
////            LOGIT( _T("DropSource GiveFeedBack"));
 
292
////            //asm("int3");
 
293
////            return true;
 
294
////            //return false;
 
295
////        }
 
296
////  private:
 
297
////
 
298
////};
 
299
// ----------------------------------------------------------------------------