Skip to content

Commit 744159e

Browse files
Add folding markers in Text Editor
1 parent 324bd07 commit 744159e

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/robotide/editor/pythoneditor.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@
4545

4646
class PythonSTC(stc.StyledTextCtrl):
4747

48-
fold_symbols = 2
48+
fold_symbols = 0
4949

5050
def __init__(self, parent, idd, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0):
5151
stc.StyledTextCtrl.__init__(self, parent, idd, pos, size, style)
5252

53-
self.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN)
54-
self.CmdKeyAssign(ord('N'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT)
53+
# self.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN)
54+
# self.CmdKeyAssign(ord('N'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT)
5555

5656
self.SetLexer(stc.STC_LEX_PYTHON)
5757
self.SetKeyWords(0, " ".join(keyword.kwlist))
@@ -69,7 +69,7 @@ def __init__(self, parent, idd, pos=wx.DefaultPosition, size=wx.DefaultSize, sty
6969
self.SetMarginType(2, stc.STC_MARGIN_SYMBOL)
7070
self.SetMarginMask(2, stc.STC_MASK_FOLDERS)
7171
self.SetMarginSensitive(2, True)
72-
self.SetMarginWidth(2, 12)
72+
self.SetMarginWidth(2, 24)
7373

7474
if self.fold_symbols == 0:
7575
# Arrow pointing right for contracted folders, arrow pointing down for expanded
@@ -111,9 +111,11 @@ def __init__(self, parent, idd, pos=wx.DefaultPosition, size=wx.DefaultSize, sty
111111
self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080")
112112
self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNER, "white", "#808080")
113113

114+
"""
114115
self.Bind(stc.EVT_STC_UPDATEUI, self.on_update_ui)
115116
self.Bind(stc.EVT_STC_MARGINCLICK, self.on_margin_click)
116117
self.Bind(wx.EVT_KEY_DOWN, self.on_key_pressed)
118+
"""
117119

118120
# Make some styles, The lexer defines what each style is used for, we
119121
# just have to define what each style looks like. This set is adapted from
@@ -238,6 +240,8 @@ def on_update_ui(self, evt):
238240
self.BraceHighlight(brace_at_caret, brace_opposite)
239241

240242
def on_margin_click(self, evt):
243+
mod = evt.GetModificationType()
244+
# print(f"DEBUG: pythoneditor.py PythonSTC on_margin_click mod={mod} Margin={evt.GetMargin()}")
241245
# fold and unfold as needed
242246
if evt.GetMargin() == 2:
243247
if evt.GetShift() and evt.GetControl():

src/robotide/editor/texteditor.py

+19-9
Original file line numberDiff line numberDiff line change
@@ -2394,12 +2394,11 @@ def mark_file_dirty(self, dirty=True):
23942394
self._data.mark_data_pristine()
23952395

23962396

2397-
class RobotDataEditor(PythonSTC, stc.StyledTextCtrl):
2397+
class RobotDataEditor(PythonSTC):
23982398
margin = 1
23992399

24002400
def __init__(self, parent, readonly=False, language=None, style=wx.BORDER_NONE):
24012401
PythonSTC.__init__(self, parent, -1, style=style)
2402-
self.SetUpEditor()
24032402
# stc.StyledTextCtrl.__init__(self, parent)
24042403
self.parent = parent
24052404
self.language = language
@@ -2408,7 +2407,7 @@ def __init__(self, parent, readonly=False, language=None, style=wx.BORDER_NONE):
24082407
self._information_popup = None
24092408
self._old_details = None
24102409
self.readonly = readonly
2411-
self.SetMarginType(self.margin, stc.STC_MARGIN_NUMBER)
2410+
# self.SetMarginType(self.margin, stc.STC_MARGIN_NUMBER)
24122411
self.SetLexer(stc.STC_LEX_CONTAINER)
24132412
self.SetReadOnly(True)
24142413
self.SetUseTabs(False)
@@ -2420,9 +2419,13 @@ def __init__(self, parent, readonly=False, language=None, style=wx.BORDER_NONE):
24202419
caret_style = stc.STC_CARETSTYLE_BLOCK if caret_style.lower() == 'block' else stc.STC_CARETSTYLE_LINE
24212420
self.SetCaretStyle(caret_style)
24222421
self.SetTabWidth(parent.tab_size)
2423-
self.Bind(stc.EVT_STC_UPDATEUI, self.on_update_ui)
2422+
margin_background = self._settings['General'].get('secondary background', '')
2423+
margin_foreground = self._settings['General'].get('secondary foreground', '')
2424+
self.SetUpEditor(tab_size=parent.tab_size, m_bg=margin_background, m_fg=margin_foreground)
24242425
self.Bind(stc.EVT_STC_STYLENEEDED, self.on_style)
24252426
self.Bind(stc.EVT_STC_ZOOM, self.on_zoom)
2427+
self.Bind(stc.EVT_STC_UPDATEUI, self.on_update_ui)
2428+
self.Bind(stc.EVT_STC_MARGINCLICK, self.on_margin_click)
24262429
# DEBUG:
24272430
self.Bind(wx.EVT_KEY_DOWN, self.on_key_pressed)
24282431
# Only set, after language: self.stylizer = RobotStylizer(self, self._settings, self.readonly)
@@ -2487,6 +2490,7 @@ def set_text(self, text):
24872490
self.stylizer.stylize()
24882491
self.EmptyUndoBuffer()
24892492
self.SetMarginWidth(self.margin, self.calc_margin_width())
2493+
self.SetMarginWidth(2, self.TextWidth(stc.STC_STYLE_DEFAULT, "MM"))
24902494
self.Update()
24912495

24922496
def set_language(self, dlanguage):
@@ -2513,6 +2517,7 @@ def on_style(self, event):
25132517
def on_zoom(self, event):
25142518
__ = event
25152519
self.SetMarginWidth(self.margin, self.calc_margin_width())
2520+
self.SetMarginWidth(2, self.TextWidth(stc.STC_STYLE_FOLDDISPLAYTEXT, "MM"))
25162521
self._set_zoom()
25172522

25182523
def _set_zoom(self):
@@ -2669,6 +2674,7 @@ def on_update_ui(self, evt):
26692674
self.BraceBadLight(brace_at_caret)
26702675
else:
26712676
self.BraceHighlight(brace_at_caret, brace_opposite)
2677+
self.stylizer.stylize()
26722678

26732679
def _show_keyword_details(self, value, coords=None):
26742680
"""
@@ -2699,7 +2705,7 @@ def get_visible_color(self, colour):
26992705
return Colour(colour)
27002706
return Colour('black')
27012707

2702-
def SetUpEditor(self):
2708+
def SetUpEditor(self, tab_size=4, m_bg='', m_fg=''):
27032709
"""
27042710
This method carries out the work of setting up the Code editor.
27052711
It's seperate so as not to clutter up the init code.
@@ -2718,17 +2724,18 @@ def SetUpEditor(self):
27182724
# Set left and right margins
27192725
self.SetMargins(2, 2)
27202726

2727+
self.SetMarginBackground(1, m_bg)
27212728
# Set up the numbers in the margin for margin #1
27222729
self.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
27232730
# Reasonable value for, say, 4-5 digits using a mono font (40 pix)
2724-
self.SetMarginWidth(1, 40)
2731+
# self.SetMarginWidth(1, 40)
27252732

27262733
# Indentation and tab stuff
2727-
self.SetIndent(4) # Proscribed indent size for wx
2734+
self.SetIndent(tab_size) # Proscribed indent size for wx
27282735
self.SetIndentationGuides(True) # Show indent guides
27292736
self.SetBackSpaceUnIndents(True) # Backspace unindents rather than delete 1 space
27302737
self.SetTabIndents(True) # Tab key indents
2731-
self.SetTabWidth(4) # Proscribed tab size for wx
2738+
self.SetTabWidth(tab_size) # Proscribed tab size for wx
27322739
self.SetUseTabs(False) # Use spaces rather than tabs, or TabTimmy will complain!
27332740
# White space
27342741
self.SetViewWhiteSpace(False) # Don't view white space
@@ -2746,7 +2753,10 @@ def SetUpEditor(self):
27462753
self.SetMarginType(2, stc.STC_MARGIN_SYMBOL)
27472754
self.SetMarginMask(2, stc.STC_MASK_FOLDERS)
27482755
self.SetMarginSensitive(2, True)
2749-
self.SetMarginWidth(2, 12)
2756+
self.SetMarginBackground(2, m_bg)
2757+
self.SetFoldMarginColour(True, m_bg)
2758+
self.SetFoldMarginHiColour(True, m_bg)
2759+
self.SetMarginWidth(2, self.TextWidth(stc.STC_STYLE_FOLDDISPLAYTEXT, "MM"))
27502760

27512761
# Global default style
27522762
if wx.Platform == '__WXMSW__':

0 commit comments

Comments
 (0)