74
77
indenter=None, # Auto indenter
75
78
lang_id=0) # Language ID from syntax module
77
self.vert_edit = vertedit.VertEdit(self)
80
self.vert_edit = vertedit.VertEdit(self, markerNumber=MARKER_VERT_EDIT)
78
81
self._line_num = True # Show line numbers
82
self._last_cwidth = 1 # one pixel
81
85
## Outer Left Margin Bookmarks
82
86
self.SetMarginType(MARK_MARGIN, wx.stc.STC_MARGIN_SYMBOL)
83
self.SetMarginMask(MARK_MARGIN, self.ED_STC_MASK_MARKERS)
87
self.SetMarginMask(MARK_MARGIN, EditraBaseStc.ED_STC_MASK_MARKERS)
84
88
self.SetMarginSensitive(MARK_MARGIN, True)
85
self.SetMarginWidth(MARK_MARGIN, 12)
89
self.SetMarginWidth(MARK_MARGIN, 16)
87
91
## Middle Left Margin Line Number Indication
88
92
self.SetMarginType(NUM_MARGIN, wx.stc.STC_MARGIN_NUMBER)
98
102
for keys in _GetMacKeyBindings():
99
103
self.CmdKeyAssign(*keys)
101
# Setup Autocomp images
105
# Setup Auto-comp images
102
106
# TODO: should be called on theme change messages
103
107
self.RegisterImages()
110
self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy, self)
106
111
self.Bind(wx.stc.EVT_STC_CHANGE, self.OnChanged)
107
112
self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModified)
108
113
self.Bind(wx.stc.EVT_STC_AUTOCOMP_SELECTION, self.OnAutoCompSel)
111
# Cleanup the file object callbacks
112
self.file.RemoveModifiedCallback(self.FireModified)
115
def OnDestroy(self, evt):
116
if evt.GetId() == self.GetId():
117
# Cleanup the file object callbacks
118
self.file.RemoveModifiedCallback(self.FireModified)
115
122
#---- Public Methods ----#
117
def AddBookmark(self):
118
"""Add a bookmark and return its handle"""
119
cline = self.GetCurrentLine()
120
return self.MarkerAdd(cline, MARK_MARGIN)
125
def AddMarker(self, marker, line=-1):
126
"""Add a bookmark and return its handle
127
@param marker: ed_marker.Marker instance
128
@keyword line: if < 0 bookmark will be added to current line
131
assert isinstance(marker, ed_marker.Marker)
133
line = self.GetCurrentLine()
134
marker.Set(self, line)
137
def RemoveMarker(self, marker, line):
138
"""Remove the book mark from the given line
139
@param marker: ed_marker.Marker instance
143
assert isinstance(marker, ed_marker.Marker)
144
marker.Set(self, line, delete=True)
146
def RemoveAllMarkers(self, marker):
147
"""Remove all the bookmarks in the buffer
148
@param marker: ed_marker.Marker instance
151
assert isinstance(marker, ed_marker.Marker)
152
marker.DeleteAll(self)
154
#-- Breakpoint marker api --#
155
def DeleteAllBreakpoints(self):
156
"""Delete all the breakpoints in the buffer"""
157
ed_marker.Breakpoint().DeleteAll(self)
158
ed_marker.BreakpointDisabled().DeleteAll(self)
159
ed_marker.BreakpointStep().DeleteAll(self)
161
def DeleteBreakpoint(self, line):
162
"""Delete the breakpoint from the given line"""
163
ed_marker.Breakpoint().Set(self, line, delete=True)
164
ed_marker.BreakpointDisabled().Set(self, line, delete=True)
166
def _SetBreakpoint(self, mobj, line=-1):
167
"""Set the breakpoint state
168
@param mtype: Marker object
169
@return: int (-1 if already set)
174
line = self.GetCurrentLine()
175
if not mobj.IsSet(self, line):
176
# Clear other set breakpoint marker states on same line
177
ed_marker.Breakpoint().Set(self, line, delete=True)
178
ed_marker.BreakpointDisabled().Set(self, line, delete=True)
179
mobj.Set(self, line, delete=False)
183
def SetBreakpoint(self, line=-1, disabled=False):
184
"""Set a breakpoint marker on the given line
185
@keyword line: line number
186
@keyword disabled: bool
187
@return: breakpoint handle
191
handle = self._SetBreakpoint(ed_marker.Breakpoint(), line)
193
handle = self._SetBreakpoint(ed_marker.BreakpointDisabled(), line)
196
def ShowStepMarker(self, line=-1, show=True):
197
"""Show the step (arrow) marker to the given line."""
199
line = self.GetCurrentLine()
200
mark = ed_marker.BreakpointStep()
202
mark.Set(self, line, delete=False)
122
206
def AddLine(self, before=False, indent=False):
123
207
"""Add a new line to the document
140
224
def AutoIndent(self):
141
225
"""Indent from the current position to match the indentation
142
of the previous line.
143
@postcondition: proper type of white space is added from current pos
144
to match that of indentation in above line
226
of the previous line. Unless the current file type has registered
227
a custom AutoIndenter in which case it will implement its own
146
231
cpos = self.GetCurrentPos()
148
233
# Check if a special purpose indenter has been registered
149
234
if self._code['indenter'] is not None:
150
txt = self._code['indenter'](self, cpos, self.GetIndentChar())
151
txt = txt.replace('\n', self.GetEOLChar())
235
self.BeginUndoAction()
236
self._code['indenter'](self, cpos, self.GetIndentChar())
153
239
# Default Indenter
154
240
line = self.GetCurrentLine()
385
469
rgb = eclib.HexToRGB(fore[1:])
386
470
fore = wx.Colour(red=rgb[0], green=rgb[1], blue=rgb[2])
388
self.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEROPEN,
389
wx.stc.STC_MARK_BOXMINUS, fore, back)
390
self.MarkerDefine(wx.stc.STC_MARKNUM_FOLDER,
391
wx.stc.STC_MARK_BOXPLUS, fore, back)
392
self.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERSUB,
393
wx.stc.STC_MARK_VLINE, fore, back)
394
self.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERTAIL,
395
wx.stc.STC_MARK_LCORNER, fore, back)
396
self.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEREND,
397
wx.stc.STC_MARK_BOXPLUSCONNECTED, fore, back)
398
self.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEROPENMID,
399
wx.stc.STC_MARK_BOXMINUSCONNECTED, fore, back)
400
self.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERMIDTAIL,
401
wx.stc.STC_MARK_TCORNER, fore, back)
402
self.MarkerDefine(0, wx.stc.STC_MARK_SHORTARROW, fore, back)
403
self.SetFoldMarginHiColour(True, fore)
404
self.SetFoldMarginColour(True, fore)
472
# Buffer background highlight
473
caret_line = self.GetItemByName('caret_line').GetBack()
474
rgb = eclib.HexToRGB(caret_line[1:])
475
clback = wx.Colour(*rgb)
477
# Code Folding markers
478
folder = ed_marker.FoldMarker()
479
folder.Foreground = fore
480
folder.Background = back
481
folder.RegisterWithStc(self)
484
ed_marker.Bookmark().RegisterWithStc(self)
487
ed_marker.Breakpoint().RegisterWithStc(self)
488
ed_marker.BreakpointDisabled().RegisterWithStc(self)
489
step = ed_marker.BreakpointStep()
490
step.Background = clback
491
step.RegisterWithStc(self)
492
ed_marker.StackMarker().RegisterWithStc(self)
495
errmk = ed_marker.ErrorMarker()
496
errsty = self.GetItemByName('error_style')
497
rgb = eclib.HexToRGB(errsty.GetBack()[1:])
498
errmk.Background = wx.Colour(*rgb)
499
rgb = eclib.HexToRGB(errsty.GetFore()[1:])
500
errmk.Foreground = wx.Colour(*rgb)
501
errmk.RegisterWithStc(self)
503
ed_marker.LintMarker().RegisterWithStc(self)
504
ed_marker.LintMarkerWarning().RegisterWithStc(self)
505
ed_marker.LintMarkerError().RegisterWithStc(self)
406
507
def DoZoom(self, mode):
407
508
"""Zoom control in or out
488
595
if interp != wx.EmptyString:
489
596
interp = interp.split(u"/")[-1]
490
597
interp = interp.strip().split()
491
if len(interp) and interp[-1][0] != "-":
598
if len(interp) and interp[-1][0] != u"-":
492
599
interp = interp[-1]
493
600
elif len(interp):
494
601
interp = interp[0]
604
# TODO: should check user config to ensure the explict
605
# extension is still associated with the expected
497
607
ex_map = { "python" : "py", "wish" : "tcl", "ruby" : "rb",
498
608
"bash" : "sh", "csh" : "csh", "perl" : "pl",
499
609
"ksh" : "ksh", "php" : "php", "booi" : "boo",
506
616
self.OnChanged(wx.stc.StyledTextEvent(wx.stc.wxEVT_STC_CHANGE,
509
def GetCommandStr(self):
619
def GetCommandStr(self, line=None, col=None):
510
620
"""Gets the command string to the left of the autocomp
511
621
activation character.
622
@keyword line: optional if None current cursor position used
623
@keyword col: optional if None current cursor position used
512
624
@return: the command string to the left of the autocomp char
513
625
@todo: fillups are currently disabled. See note in Configure.
516
# NOTE: the column position returned by GetCurLine is not correct
517
# for multibyte characters.
518
line, col = self.GetCurLine()
519
col = self.GetColumn(self.GetCurrentPos())
628
if None in (line, col):
629
# NOTE: the column position returned by GetCurLine is not correct
630
# for multibyte characters.
631
line, col = self.GetCurLine()
632
col = self.GetColumn(self.GetCurrentPos())
633
line = line.expandtabs(self.GetTabWidth())
520
634
cmd_lmt = list(self._code['compsvc'].GetAutoCompStops() + \
521
635
self._code['compsvc'].GetAutoCompFillups())
522
636
for key in self._code['compsvc'].GetAutoCompKeys():