]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/modules/lseditor/lseditorpl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: lseditorpl.cpp
3 // Purpose: Language-sensative editor plugin for wxStudio
4 // Copyright: (c) Aleksandars Gluchovas
8 // Copyright: (c) Aleskandars Gluchovas
9 // Licence: GNU General Public License
10 /////////////////////////////////////////////////////////////////////////////
12 // This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 /////////////////////////////////////////////////////////////////////////////
28 // For compilers that support precompilation, includes "wx/wx.h".
29 #include "wx/wxprec.h"
40 #include "lseditorpl.h"
43 /***** Impelmentation for class wxsLSEditorPlugin *****/
45 wxsLSEditorPlugin::wxsLSEditorPlugin()
51 wxsLSEditorPlugin::~wxsLSEditorPlugin()
53 // view is destroyed by wxWindows along
54 // with it's owned model
57 void wxsLSEditorPlugin::Create( wxWindow
* parent
, wxWindowID id
)
59 mpModel
= new wxTextEditorModel();
61 mpView
= new wxTextEditorView( parent
, id
, mpModel
);
63 mpModel
->AddView( mpView
);
66 mpView
->AddPinPainter( new TBreakpointPainter() );
68 mpView
->SyncScrollbars();
71 void wxsLSEditorPlugin::OnOpen( const string
& fname
)
73 mpModel
->LoadTextFromFile( fname
);
78 void wxsLSEditorPlugin::OnSave( const string
& fname
)
80 mpModel
->SaveTextToFile( fname
);
83 void wxsLSEditorPlugin::OnCopy()
88 void wxsLSEditorPlugin::OnCut()
93 void wxsLSEditorPlugin::OnPaste()
98 void wxsLSEditorPlugin::OnDelete()
103 void wxsLSEditorPlugin::OnUndo()
108 void wxsLSEditorPlugin::OnRedo()
113 void wxsLSEditorPlugin::SelectAll()
115 mpModel
->OnSelectAll();
118 void wxsLSEditorPlugin::OnGotoLine()
120 mpModel
->OnGotoLine();
123 void wxsLSEditorPlugin::OnGotoLine( int lineNo
, int column
)
125 mpModel
->ResetSelection();
126 mpModel
->OnGotoLine( lineNo
, column
);
129 void wxsLSEditorPlugin::OnProperties()
134 void wxsLSEditorPlugin::OnFind()
139 void wxsLSEditorPlugin::OnFindNext()
141 mpModel
->OnFindNext();
144 void wxsLSEditorPlugin::OnFindPrevious()
146 mpModel
->OnFindPrevious();
149 void wxsLSEditorPlugin::OnReplace()
154 void wxsLSEditorPlugin::OnToggleBookmark()
156 mpModel
->OnToggleBookmark();
159 void wxsLSEditorPlugin::OnNextBookmark()
161 mpModel
->OnNextBookmark();
164 void wxsLSEditorPlugin::OnPreviousBookmark()
166 mpModel
->OnPreviousBookmark();
169 void wxsLSEditorPlugin::OnShowBookmarks()
174 void wxsLSEditorPlugin::SetCheckpoint()
176 mpModel
->SetCheckpoint();
179 bool wxsLSEditorPlugin::CheckpointModified()
181 return mpModel
->CheckpointModified();
186 bool wxsLSEditorPlugin::CanCopy()
188 return mpModel
->CanCopy();
191 bool wxsLSEditorPlugin::CanCut()
193 return mpModel
->CanCopy();
196 bool wxsLSEditorPlugin::CanPaste()
198 return mpModel
->CanPaste();
201 bool wxsLSEditorPlugin::CanUndo()
203 return mpModel
->CanUndo();
206 bool wxsLSEditorPlugin::CanRedo()
208 return mpModel
->CanRedo();
211 // accesed by framework
213 bool wxsLSEditorPlugin::IsModified()
215 return mpModel
->IsModified();
218 wxWindow
* wxsLSEditorPlugin::GetWindow()
223 void wxsLSEditorPlugin::GetAllText( char** ppBuf
, size_t* length
)
225 mpModel
->GetAllText( ppBuf
, *length
);
228 void wxsLSEditorPlugin::SetFileName( const string
& fname
)
234 mpView
->SetName( fname
);
237 void wxsLSEditorPlugin::HoldCursor( bool hold
)
239 mpView
->HoldCursor( hold
);
242 string
wxsLSEditorPlugin::FindWordAtCursor()
244 mpModel
->OnSelectWord();
246 char* buf
= NULL
; size_t len
= 0;
248 mpModel
->GetSelection( &buf
, len
);
252 string word
= string( buf
, 0, len
);
260 void wxsLSEditorPlugin::GetCursorPos( int* line
, int* column
)
262 TPosition pos
= mpModel
->GetCursor();
264 *line
= (int)pos
.mRow
;
265 *column
= (int)pos
.mCol
;
268 void wxsLSEditorPlugin::SetCursorPos( int line
, int column
)
270 mpModel
->OnGotoLine( line
, column
);
273 void wxsLSEditorPlugin::GetPagePos( int* line
, int* column
)
275 TPosition pos
= mpView
->GetPagePos();
281 void wxsLSEditorPlugin::GetText( int fromLine
, int fromColumn
,
282 int tillLine
, int tillColumn
,
283 char** ppBuf
, size_t* length
)
285 mpModel
->GetTextFromRange( TPosition( fromLine
, fromColumn
),
286 TPosition( tillLine
, tillColumn
),
290 void wxsLSEditorPlugin::InsertText( int line
, int column
,
291 char* text
, size_t lenght
)
293 mpModel
->InsertText( TPosition( line
, column
),
297 void wxsLSEditorPlugin::DeleteText( int fromLine
, int fromColumn
,
298 int tillLine
, int tillColumn
)
300 mpModel
->DeleteRange( TPosition( fromLine
, fromColumn
),
301 TPosition( tillLine
, tillColumn
) );
304 void wxsLSEditorPlugin::PositionToXY( int line
, int column
, int* x
, int* y
)
308 mpView
->TextPosToScreenPos( TPosition( line
, column
), scrPos
);
309 mpView
->ScreenPosToPixels( scrPos
, *x
, *y
);
311 *y
+= mpView
->mCharDim
.y
; // lower-right corner
314 void wxsLSEditorPlugin::GetSelectionRange( int* fromLine
, int* fromColumn
,
315 int* tillLine
, int* tillColumn
)
317 TPosition start
= mpModel
->GetStartOfSelection();
318 TPosition end
= mpModel
->GetEndOfSelection();
320 *fromLine
= (int)start
.mRow
;
321 *fromColumn
= (int)start
.mCol
;
322 *tillLine
= (int)end
.mRow
;
323 *tillColumn
= (int)end
.mCol
;
326 wxSize
wxsLSEditorPlugin::GetCharacterSize()
328 return mpView
->GetCharacterSize();
331 bool wxsLSEditorPlugin::IsUnixText()
333 return mpModel
->IsUnixText();
336 wxTextEditorModel
& wxsLSEditorPlugin::GetModel()
341 wxTextEditorView
& wxsLSEditorPlugin::GetView()