17 from io
import StringIO, BytesIO
21 from wx
import stc, Colour
22 from wx.adv
import HyperlinkCtrl, EVT_HYPERLINK
24 from ..
import robotapi
25 from ..context
import IS_WINDOWS, IS_MAC
26 from ..controller.ctrlcommands
import SetDataFile
27 from ..controller.filecontrollers
import ResourceFileController
28 from ..controller.macrocontrollers
import _WithStepsController
29 from ..namespace.suggesters
import SuggestionSource
30 from ..pluginapi
import Plugin, TreeAwarePluginMixin
31 from ..publish.messages
import (RideSaving, RideTreeSelection, RideNotebookTabChanging, RideDataChanged, RideOpenSuite,
32 RideDataChangedToDirty)
33 from ..preferences.editors
import ReadFonts
34 from ..publish
import RideSettingsChanged, PUBLISHER
35 from ..publish.messages
import RideMessage
36 from ..widgets
import TextField, Label, HtmlDialog
37 from ..widgets
import VerticalSizer, HorizontalSizer, ButtonWithHandler, RIDEDialog
40 from pygments.lexers
import robotframework
as robotframeworklexer
42 robotframeworklexer =
None
49 Plugin.__init__(self, application)
51 self.
reformatreformat = application.settings.get(
'reformat',
False)
66 self.add_self_as_tree_aware_plugin()
67 self.subscribe(self.
OnSavingOnSaving, RideSaving)
70 self.subscribe(self.
OnTabChangeOnTabChange, RideNotebookTabChanging)
81 self.register_shortcut(
'CtrlCmd-X', focused(
lambda e: self.
_editor_editor_editor.cut()))
82 self.register_shortcut(
'CtrlCmd-C', focused(
lambda e: self.
_editor_editor_editor.copy()))
84 self.register_shortcut(
'CtrlCmd-A', focused(
lambda e: self.
_editor_editor_editor.select_all()))
85 if IS_WINDOWS
or IS_MAC:
86 self.register_shortcut(
'CtrlCmd-V', focused(
lambda e: self.
_editor_editor_editor.paste()))
87 self.register_shortcut(
'CtrlCmd-Z', focused(
lambda e: self.
_editor_editor_editor.undo()))
88 self.register_shortcut(
'CtrlCmd-Y', focused(
lambda e: self.
_editor_editor_editor.redo()))
90 self.register_shortcut(
'Alt-Up', focused(
lambda e: self.
_editor_editor_editor.move_row_up(e)))
91 self.register_shortcut(
'Alt-Down', focused(
lambda e: self.
_editor_editor_editor.move_row_down(e)))
93 self.register_shortcut(
'CtrlCmd-I', focused(
lambda e: self.
_editor_editor_editor.insert_row(e)))
94 self.register_shortcut(
'CtrlCmd-3', focused(
lambda e: self.
_editor_editor_editor.execute_comment(e)))
95 self.register_shortcut(
'CtrlCmd-Shift-3', focused(
lambda e: self.
_editor_editor_editor.execute_sharp_comment(e)))
96 self.register_shortcut(
'CtrlCmd-4', focused(
lambda e: self.
_editor_editor_editor.execute_uncomment(e)))
97 self.register_shortcut(
'CtrlCmd-Shift-4', focused(
lambda e: self.
_editor_editor_editor.execute_sharp_uncomment(e)))
98 self.register_shortcut(
'CtrlCmd-F',
lambda e: self.
_editor_editor_editor._search_field.SetFocus())
99 self.register_shortcut(
'CtrlCmd-G',
lambda e: self.
_editor_editor_editor.OnFind(e))
100 self.register_shortcut(
'CtrlCmd-Shift-G',
lambda e: self.
_editor_editor_editor.OnFindBackwards(e))
101 self.register_shortcut(
'Ctrl-Space',
lambda e: focused(self.
_editor_editor_editor.OnContentAssist(e)))
102 self.register_shortcut(
'CtrlCmd-Space',
lambda e: focused(self.
_editor_editor_editor.OnContentAssist(e)))
103 self.register_shortcut(
'Alt-Space',
lambda e: focused(self.
_editor_editor_editor.OnContentAssist(e)))
106 self.remove_self_from_tree_aware_plugins()
107 self.unsubscribe_all()
108 self.unregister_actions()
116 datafile_controller = self.tree.get_selected_datafile_controller()
117 if datafile_controller:
133 if isinstance(message, RideOpenSuite):
137 if isinstance(message, RideNotebookTabChanging):
150 return isinstance(message, RideDataChanged)
and \
151 not isinstance(message, RideDataChangedToDirty)
157 next_datafile_controller = message.item
and message.item.datafile_controller
159 if self.
_editor_editor_editor.datafile_controller != next_datafile_controller:
160 self.tree.select_controller_node(self.
_editor_editor_editor.datafile_controller)
163 if next_datafile_controller:
171 if not isinstance(message, bool):
172 self.
_editor_editor_editor._editor.readonly =
not message.item.datafile_controller.is_modifiable()
179 datafile_controller = self.tree.get_selected_datafile_controller()
180 except AttributeError:
182 if datafile_controller:
185 self.
_editor_editor_editor._editor.readonly =
not datafile_controller.is_modifiable()
191 self.
_editor_editor_editor._editor.readonly =
not datafile_controller.is_modifiable()
195 if message.newtab == self.
titletitle:
203 elif message.oldtab == self.
titletitle:
205 self.unregister_actions()
212 if 'Edit' in message.oldtab:
224 return self.notebook.current_page_title == self.
titletitle
244 if other.__class__ != self.__class__:
246 return self.
_data_data == other._data
249 return hash(repr(self))
264 m_text = text.decode(
"utf-8")
270 if self.
_editor_editor._reformat:
271 data.update_from(m_text)
273 data.update_from(m_text)
279 self.
_editor_editor.set_editor_caret_position()
285 for line
in text.split(
'\n'):
286 comment = line.strip().startswith(
'#')
289 text = text.replace(line,
'')
291 formatted_text = data.format_text(text)
295 return len(c) == len(e)
298 for item
in tuple(string.whitespace) + (
'...',
'*'):
300 text = text.replace(item,
'')
309 dlg = wx.MessageDialog(self.
_editor_editor,
310 'ERROR: Data sanity check failed!\n'
312 'Can not apply changes from Txt Editor',
314 dlg.InheritAttributes()
316 dlg.SetBackgroundColour(Colour(200, 222, 40))
317 dlg.SetOwnBackgroundColour(Colour(200, 222, 40))
318 dlg.SetForegroundColour(Colour(7, 0, 70))
319 dlg.SetOwnForegroundColour(Colour(7, 0, 70))
343 return self.
_data_data == other._data
350 src = BytesIO(content.encode(
"utf-8"))
361 self.
_data_data.mark_dirty()
365 self.
_data_data.unmark_dirty()
368 data = self.
_data_data.data
369 target_class =
type(data)
372 target.initfile = data.initfile
374 return target_class(source=self.
_data_data.source)
384 data.save(output=output, format=
'txt',
385 txt_separating_spaces=self.
_settings_settings.get(
386 'txt number of spaces', 4))
388 return output.getvalue()
394 wx.Panel.__init__(self, parent)
395 self.
dlgdlg = RIDEDialog()
396 self.SetBackgroundColour(Colour(self.
dlgdlg.color_background))
397 self.SetForegroundColour(Colour(self.
dlgdlg.color_foreground))
404 'txt number of spaces', 4)
414 PUBLISHER.subscribe(self.
OnSettingsChangedOnSettingsChanged, RideSettingsChanged)
415 PUBLISHER.subscribe(self.
OnTabChangeOnTabChange, RideNotebookTabChanging)
426 cnt = self.
_parent_parent.GetPageCount()
428 editor_created =
False
429 while cnt > 0
and not editor_created:
431 editor_created = self.
_parent_parent.GetPageText(cnt) == self.
_title_title
432 if not editor_created:
433 self.SetSizer(VerticalSizer())
436 self.
_parent_parent.add_tab(self, title, allow_closing=
False)
442 default_components = HorizontalSizer()
443 button = ButtonWithHandler(self,
'Apply Changes', handler=
lambda e: self.
savesave())
444 button.SetBackgroundColour(Colour(self.
dlgdlg.color_secondary_background))
445 button.SetForegroundColour(Colour(self.
dlgdlg.color_secondary_foreground))
446 default_components.add_with_padding(button)
448 self.
editor_toolbareditor_toolbar.add_expanding(default_components)
449 self.Sizer.add_expanding(self.
editor_toolbareditor_toolbar, propotion=0)
452 container_sizer.AddSpacer(20)
454 self.
_search_field_search_field.SetBackgroundColour(Colour(self.
dlgdlg.color_secondary_background))
455 self.
_search_field_search_field.SetForegroundColour(Colour(self.
dlgdlg.color_secondary_foreground))
457 container_sizer.add_with_padding(self.
_search_field_search_field)
458 button = ButtonWithHandler(self,
'Search', handler=self.
OnFindOnFind)
459 button.SetBackgroundColour(Colour(self.
dlgdlg.color_secondary_background))
460 button.SetForegroundColour(Colour(self.
dlgdlg.color_secondary_foreground))
461 container_sizer.add_with_padding(button)
468 label = Label(self, label=
"Syntax colorization disabled due to missing requirements.")
469 link = HyperlinkCtrl(self, -1, label=
"Get help", url=
"")
471 flags = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT
472 syntax_colorization_help_sizer = wx.BoxSizer(wx.VERTICAL)
473 syntax_colorization_help_sizer.AddMany([
477 self.
editor_toolbareditor_toolbar.add_expanding(syntax_colorization_help_sizer)
482 content =
"""<h1>Syntax colorization</h1>
484 Syntax colorization for Text Edit uses <a href='http://pygments.org/'>Pygments</a> syntax highlighter.
487 Install Pygments from command line with:
493 easy_install pygments
498 If you do not have pip or easy_install,
499 <a href='http://pythonhosted.org/an_example_pypi_project/setuptools.html#installing-setuptools-and-easy-install'>follow
500 these instructions</a>.
503 For more information about installing Pygments, <a href='http://pygments.org/download/'>see the site</a>.
506 HtmlDialog(
"Getting syntax colorization", content).Show()
510 cur_pos = self.
_editor_editor.GetCurrentPos()
521 self.
_editor_editor.SetCurrentPos(position)
522 self.
_editor_editor.SetSelection(position, position)
523 self.
_editor_editor.SetAnchor(position)
524 self.
_editor_editor.GotoPos(position)
532 return self.
_dirty_dirty == 1
535 datafile_controller = property
538 return self.
_data_data._data
if self.
_data_data
else None
542 text = self.
_editor_editor.GetSelectedText()
543 if len(text) > 0
and text.lower() != self.
_search_field_search_field.GetValue().
lower()
and event.GetEventType() == wx.wxEVT_TOOL:
553 self.
_editor_editor.SetAnchor(0)
554 self.
_editor_editor.SetCurrentPos(0)
561 self.
_find_find(forward=
False)
564 txt = self.
_search_field_search_field.GetValue().encode(
'utf-8')
570 file_end = len(self.
_editor_editor.utf8_text)
571 search_end = file_end
if forward
else 0
572 anchor = self.
_editor_editor.GetAnchor()
573 anchor += 1
if forward
else 0
574 position = self.
_editor_editor.FindText(anchor, search_end, txt, 0)
576 start, end = (0, file_end)
if forward
else (file_end - 1, 0)
577 position = self.
_editor_editor.FindText(start, end, txt, 0)
582 if type(position)
is tuple:
583 position = position[0]
586 self.
_editor_editor.SetCurrentPos(position)
587 self.
_editor_editor.SetSelection(position, position + len(txt))
588 self.
_editor_editor.ScrollToLine(self.
_editor_editor.GetCurrentLine())
598 selected = self.
_editor_editor.get_selected_or_near_text()
599 sugs = [s.name
for s
in self.
_suggestions_suggestions.get_suggestions(
602 self.
_editor_editor.AutoCompSetDropRestOfWord(
True)
603 self.
_editor_editor.AutoCompSetSeparator(ord(
';'))
604 self.
_editor_editor.AutoCompShow(0,
";".join(sugs))
610 self.
_data_data = data
613 if isinstance(self.
_data_data._data, ResourceFileController):
636 if self.
_data_data == data:
644 line, _ = self.
_editor_editor.GetCurLine()
646 linenum = self.
_editor_editor.GetCurrentLine()
649 while idx<lenline
and line[idx] ==
' ':
652 if idx < lenline
and (line.strip().startswith(
"FOR")
or line.strip().startswith(
"IF")
653 or line.strip().startswith(
"ELSE")):
656 elif linenum > 0
and tsize == 0:
657 prevline = self.
_editor_editor.GetLine(linenum-1).
lower()
658 if prevline.startswith(
"**")
and not (
"variables" in prevline
or "settings" in prevline):
660 elif prevline.startswith(
"\n"):
662 elif line.strip().startswith(
"END"):
663 pos = self.
_editor_editor.GetCurrentPos()
664 self.
_editor_editor.SetCurrentPos(pos)
665 self.
_editor_editor.SetSelection(pos, pos)
675 pos = self.
_editor_editor.GetCurrentLine()
676 self.
_editor_editor.SetCurrentPos(self.
_editor_editor.GetLineEndPosition(pos))
680 start, end = self.
_editor_editor.GetSelection()
681 caret = self.
_editor_editor.GetCurrentPos()
682 ini_line = self.
_editor_editor.LineFromPosition(start)
683 end_line = self.
_editor_editor.LineFromPosition(end)
685 self.
_editor_editor.SelectNone()
688 self.
_editor_editor.BeginUndoAction()
689 while line <= end_line:
691 pos = self.
_editor_editor.PositionFromLine(line)
692 self.
_editor_editor.SetCurrentPos(pos)
693 self.
_editor_editor.SetSelection(pos, pos)
694 self.
_editor_editor.SetInsertionPoint(pos)
696 if content == (
' ' * self.
_tab_size_tab_size):
703 self.
_editor_editor.EndUndoAction()
707 new_start = max(0, start - self.
_tab_size_tab_size)
708 new_end = max(0, end - (count * self.
_tab_size_tab_size))
715 self.
_editor_editor.SetSelection(new_start, new_end)
716 self.
_editor_editor.SetCurrentPos(ini)
717 self.
_editor_editor.SetAnchor(fini)
721 pos = self.
_editor_editor.PositionFromLine(line)
722 text = self.
_editor_editor.GetLine(line-1)
726 while idx < lenline
and text[idx] ==
' ':
729 if idx < lenline
and (text.strip().startswith(
"FOR")
or text.strip().startswith(
"IF")
730 or text.strip().startswith(
"ELSE")
or text.strip().startswith(
"TRY")
731 or text.strip().startswith(
"EXCEPT")
or text.strip().startswith(
"WHILE")):
735 if text.startswith(
"**"):
736 if not (
"variables" in text
or "settings" in text):
738 self.
_editor_editor.SetCurrentPos(pos)
739 self.
_editor_editor.SetSelection(pos, pos)
740 self.
_editor_editor.SetInsertionPoint(pos)
741 for _
in range(tsize):
745 start, end = self.
_editor_editor.GetSelection()
746 caret = self.
_editor_editor.GetCurrentPos()
747 ini_line = self.
_editor_editor.LineFromPosition(start)
748 end_line = self.
_editor_editor.LineFromPosition(end)
750 self.
_editor_editor.SelectNone()
752 while line <= end_line:
753 pos = self.
_editor_editor.PositionFromLine(line)
754 self.
_editor_editor.SetCurrentPos(pos)
755 self.
_editor_editor.SetSelection(pos, pos)
756 self.
_editor_editor.SetInsertionPoint(pos)
760 new_start = start + self.
_tab_size_tab_size
761 new_end = end + (count * self.
_tab_size_tab_size)
768 self.
_editor_editor.SetSelection(new_start, new_end)
769 self.
_editor_editor.SetCurrentPos(ini)
770 self.
_editor_editor.SetAnchor(fini)
774 self.
_editor_editor.WriteText(spaces)
793 def direct_save(self, text):
794 print(f"DEBUG: direct_save path={self.datafile_controller.source}")
795 f = open(self.datafile_controller.source, "wb")
798 self._mark_file_dirty(False)
799 print(f"DEBUG: direct_save Content:\n{text}")
800 except Exception as e:
807 # DEBUG Code not in use
810 # print(f"DEBUG: Delete called")
811 if self._editor.GetSelectionStart() == self._editor.GetSelectionEnd():
812 self._editor.CharRight()
813 self._editor.DeleteBack()
814 self._mark_file_dirty(self._editor.GetModify())
825 focus = wx.Window.FindFocus()
826 if focus == self.
_editor_editor:
833 self.
_editor_editor.SelectAll()
853 self.Sizer.add_expanding(self.
_editor_editor)
856 self.
_editor_editor.set_text(text)
865 self.
_editor_editor.AcceptsFocusFromKeyboard()
867 self.
_editor_editor.SetCaretPeriod(0)
871 self.
_editor_editor.AcceptsFocusFromKeyboard()
872 self.
_editor_editor.SetCaretPeriod(500)
886 keycode = event.GetKeyCode()
887 if keycode == wx.WXK_DELETE:
888 selected = self.
_editor_editor.GetSelection()
889 if selected[0] == selected[1]:
890 pos = self.
_editor_editor.GetInsertionPoint()
891 if pos != self.
_editor_editor.GetLastPosition():
892 self.
_editor_editor.DeleteRange(selected[0], 1)
894 self.
_editor_editor.DeleteRange(selected[0], selected[1] - selected[0])
895 if keycode
in [wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER]:
898 if self.
is_focusedis_focused()
and keycode != wx.WXK_CONTROL
and self.
_dirty_dirty == 0:
907 keycode = event.GetUnicodeKey()
908 if event.GetKeyCode() == wx.WXK_DELETE:
911 if event.GetKeyCode() == wx.WXK_TAB
and not event.ControlDown()
and not event.ShiftDown():
916 selected = self.
_editor_editor.GetSelection()
917 if selected[0] == selected[1]:
921 elif event.GetKeyCode() == wx.WXK_TAB
and event.ShiftDown():
922 selected = self.
_editor_editor.GetSelection()
923 if selected[0] == selected[1]:
924 pos = self.
_editor_editor.GetCurrentPos()
927 if not event.ControlDown():
928 pos = self.
_editor_editor.GetCurrentPos()
929 self.
_editor_editor.SetSelection(pos, pos)
932 elif event.GetKeyCode()
in [ wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER ]:
938 elif keycode
in (ord(
'1'), ord(
'2'), ord(
'5'))
and event.ControlDown():
940 dict_variable=(keycode == ord(
'5')))
942 elif keycode == ord(
'D')
and event.ControlDown():
947 elif keycode == ord('3') and event.ControlDown() and event.ShiftDown():
948 self.execute_sharp_comment()
949 self.store_position()
950 elif keycode == ord('4') and event.ControlDown() and event.ShiftDown():
951 self.execute_sharp_uncomment()
952 self.store_position()
958 keycode = event.GetUnicodeKey()
959 if chr(keycode)
in [
'[',
'{',
'(',
"'",
'\"',
'`']:
966 from_, to_ = self.
_editor_editor.GetSelection()
967 text = self.
_editor_editor.SelectedText
968 size = len(bytes(text, encoding=
'utf-8'))
977 self.
_editor_editor.SetInsertionPoint(to_)
979 self.
_editor_editor.SetInsertionPoint(from_ + 2)
981 self.
_editor_editor.DeleteRange(from_, size)
982 self.
_editor_editor.SetInsertionPoint(from_)
984 self.
_editor_editor.SetSelection(from_ + 2, from_ + size + 2)
988 return symbol +
'{' + value +
'}'
991 from_, to_ = self.
_editor_editor.GetSelection()
992 text = self.
_editor_editor.SelectedText
993 size = len(bytes(text, encoding=
'utf-8'))
996 self.
_editor_editor.SetInsertionPoint(to_)
998 pos = self.
_editor_editor.GetCurrentPos()
999 self.
_editor_editor.SetSelection(pos + 1, pos + 1)
1001 self.
_editor_editor.DeleteRange(from_, size)
1002 self.
_editor_editor.SetInsertionPoint(from_)
1004 self.
_editor_editor.SetSelection(from_ + 1, from_ + size + 1)
1008 if open_symbol ==
'[':
1010 elif open_symbol ==
'{':
1012 elif open_symbol ==
'(':
1015 close_symbol = open_symbol
1016 return open_symbol+value+close_symbol
1019 start, end = self.
_editor_editor.GetSelection()
1020 cursor = self.
_editor_editor.GetCurrentPos()
1021 ini_line = self.
_editor_editor.LineFromPosition(start)
1024 end_line = self.
_editor_editor.LineFromPosition(end)
1026 rowabove = self.
_editor_editor.GetLine(ini_line-1)
1027 lenabove = len(rowabove.encode(
'utf-8'))
1031 while rowcnt <= end_line:
1032 rowselblock += self.
_editor_editor.GetLine(rowcnt)
1035 rowselblock += rowabove
1036 begpos = self.
_editor_editor.PositionFromLine(ini_line-1)
1037 endpos = self.
_editor_editor.PositionFromLine(end_line+1)
1038 self.
_editor_editor.Replace(begpos, endpos, rowselblock)
1039 self.
_editor_editor.SetSelection(begpos, endpos-lenabove-1)
1045 start, end = self.
_editor_editor.GetSelection()
1046 cursor = self.
_editor_editor.GetCurrentPos()
1047 ini_line = self.
_editor_editor.LineFromPosition(start)
1048 end_line = self.
_editor_editor.LineFromPosition(end)
1050 rowbelow = self.
_editor_editor.GetLine(end_line+1)
1051 lenbelow = len(rowbelow.encode(
'utf-8'))
1058 rowselblock = rowbelow
1060 while rowcnt <= end_line:
1061 rowselblock += self.
_editor_editor.GetLine(rowcnt)
1063 begpos = self.
_editor_editor.PositionFromLine(ini_line)
1064 endpos = self.
_editor_editor.PositionFromLine(end_line+2)
1065 self.
_editor_editor.Replace(begpos, endpos, rowselblock)
1066 self.
_editor_editor.SetSelection(begpos+lenbelow, endpos-1)
1072 start, end = self.
_editor_editor.GetSelection()
1073 cursor = self.
_editor_editor.GetCurrentPos()
1074 ini_line = self.
_editor_editor.LineFromPosition(start)
1075 end_line = self.
_editor_editor.LineFromPosition(end)
1076 begpos = self.
_editor_editor.PositionFromLine(ini_line)
1077 self.
_editor_editor.SelectNone()
1082 for line
in range(ini_line, end_line + 1):
1083 self.
_editor_editor.GotoLine(ini_line)
1084 self.
_editor_editor.LineDelete()
1086 if ini_line != end_line:
1087 self.
_editor_editor.SetCurrentPos(begpos)
1088 self.
_editor_editor.SetAnchor(begpos)
1090 self.
_editor_editor.SetCurrentPos(cursor)
1091 self.
_editor_editor.SetAnchor(cursor)
1095 start, end = self.
_editor_editor.GetSelection()
1096 ini_line = self.
_editor_editor.LineFromPosition(start)
1097 end_line = self.
_editor_editor.LineFromPosition(end)
1098 delta = end_line - ini_line
1099 positionfromline = self.
_editor_editor.PositionFromLine(ini_line)
1100 self.
_editor_editor.SelectNone()
1101 self.
_editor_editor.InsertText(positionfromline,
'\n')
1102 for nl
in range(delta):
1103 self.
_editor_editor.InsertText(positionfromline + nl,
'\n')
1104 self.
_editor_editor.SetCurrentPos(positionfromline)
1105 self.
_editor_editor.SetAnchor(positionfromline)
1106 self.
_editor_editor.GotoLine(ini_line)
1111 start, end = self.
_editor_editor.GetSelection()
1112 cursor = self.
_editor_editor.GetCurrentPos()
1113 ini_line = self.
_editor_editor.LineFromPosition(start)
1114 end_line = self.
_editor_editor.LineFromPosition(end)
1116 comment =
'Comment' + spaces
1117 cpos = cursor + len(comment)
1119 self.
_editor_editor.SelectNone()
1123 while row <= end_line:
1124 pos = self.
_editor_editor.PositionFromLine(row)
1125 self.
_editor_editor.SetCurrentPos(pos)
1126 self.
_editor_editor.SetSelection(pos, pos)
1127 self.
_editor_editor.SetInsertionPoint(pos)
1128 line = self.
_editor_editor.GetLine(row)
1133 while idx < lenline
and line[idx] ==
' ':
1135 self.
_editor_editor.InsertText(pos + idx, comment)
1139 new_end = end + (count * len(comment))
1146 self.
_editor_editor.SetSelection(new_start, new_end)
1147 self.
_editor_editor.SetCurrentPos(ini)
1148 self.
_editor_editor.SetAnchor(fini)
1152 start, end = self.
_editor_editor.GetSelection()
1153 cursor = self.
_editor_editor.GetCurrentPos()
1154 ini_line = self.
_editor_editor.LineFromPosition(start)
1155 end_line = self.
_editor_editor.LineFromPosition(end)
1157 comment =
'Comment' + spaces
1158 commentlong =
'BuiltIn.Comment' + spaces
1159 cpos = cursor - len(comment)
1160 self.
_editor_editor.SelectNone()
1163 while row <= end_line:
1164 pos = self.
_editor_editor.PositionFromLine(row)
1165 self.
_editor_editor.SetCurrentPos(pos)
1166 self.
_editor_editor.SetSelection(pos, pos)
1167 self.
_editor_editor.SetInsertionPoint(pos)
1168 line = self.
_editor_editor.GetLine(row)
1172 while idx<lenline
and line[idx] ==
' ':
1174 if (line[idx:len(comment) + idx]).
lower() == comment.lower():
1175 self.
_editor_editor.DeleteRange(pos + idx, len(comment))
1176 if (line[idx:len(commentlong) + idx]).
lower() == commentlong.lower():
1177 self.
_editor_editor.DeleteRange(pos + idx, len(commentlong))
1181 new_end = end - (count * len(comment))
1188 self.
_editor_editor.SetSelection(new_start, new_end)
1189 self.
_editor_editor.SetCurrentPos(ini)
1190 self.
_editor_editor.SetAnchor(fini)
1194 start, end = self.
_editor_editor.GetSelection()
1195 cursor = self.
_editor_editor.GetCurrentPos()
1196 ini_line = self.
_editor_editor.LineFromPosition(start)
1197 end_line = self.
_editor_editor.LineFromPosition(end)
1200 maxsize = self.
_editor_editor.GetLineCount()
1202 if ini_line < end_line:
1203 for line
in range(ini_line, end_line+1):
1206 self.
_editor_editor.GotoLine(line)
1208 self.
_editor_editor.GotoLine(maxsize)
1209 pos = self.
_editor_editor.PositionFromLine(line)
1210 self.
_editor_editor.SetCurrentPos(pos)
1211 self.
_editor_editor.SetSelection(pos, pos)
1212 self.
_editor_editor.SetInsertionPoint(pos)
1213 row = self.
_editor_editor.GetLine(line)
1217 while idx < lenline
and row[idx] ==
' ':
1219 self.
_editor_editor.InsertText(pos + idx,
'# ')
1222 pos = self.
_editor_editor.PositionFromLine(ini_line)
1223 row = self.
_editor_editor.GetLine(ini_line)
1227 while idx < lenline
and row[idx] ==
' ':
1229 self.
_editor_editor.InsertText(pos + idx,
'# ')
1232 pos = self.
_editor_editor.PositionFromLine(ini_line)
1233 row = self.
_editor_editor.GetLine(ini_line)
1236 while idx >= len(spaces):
1237 if row[idx-len(spaces):idx] != spaces:
1241 if idx < len(spaces):
1243 self.
_editor_editor.InsertText(pos + idx,
'# ')
1245 new_end = end + (count * 2)
1252 self.
_editor_editor.SetSelection(new_start, new_end)
1253 self.
_editor_editor.SetCurrentPos(ini)
1254 self.
_editor_editor.SetAnchor(fini)
1255 self.
_editor_editor.SetCurrentPos(cursor + count * 2)
1259 start, end = self.
_editor_editor.GetSelection()
1260 cursor = self.
_editor_editor.GetCurrentPos()
1261 ini_line = self.
_editor_editor.LineFromPosition(start)
1262 end_line = self.
_editor_editor.LineFromPosition(end)
1266 maxsize = self.
_editor_editor.GetLineCount()
1268 if ini_line < end_line:
1269 for line
in range(ini_line, end_line+1):
1270 pos = self.
_editor_editor.PositionFromLine(line)
1271 row = self.
_editor_editor.GetLine(line)
1275 while idx < lenline
and row[idx] ==
' ':
1278 if idx + 1 < lenline
and row[idx:idx+1] ==
'#':
1279 if idx + 2 < lenline
and row[idx+1:idx+2] ==
' ':
1282 if idx + size < lenline:
1283 newrow = row[idx + size:]
1284 newrow = newrow.replace(
'\\ ',
' ')
1285 size += len(row[idx:]) - len(newrow) - size
1286 self.
_editor_editor.DeleteRange(pos + idx, len(newrow) + size)
1287 self.
_editor_editor.InsertText(pos + idx, newrow)
1290 pos = self.
_editor_editor.PositionFromLine(ini_line)
1291 row = self.
_editor_editor.GetLine(ini_line)
1295 while idx < lenline
and row[idx] ==
' ':
1297 while count == 0
and idx < lenline:
1299 if idx + 1 < lenline
and row[idx:idx + 1] ==
'#':
1300 if idx + 2 < lenline
and row[idx + 1:idx + 2] ==
' ':
1303 if idx + size < lenline:
1304 newrow = row[idx + size:]
1305 newrow = newrow.replace(
'\\ ',
' ')
1306 size += len(row[idx:]) - len(newrow) - size
1307 self.
_editor_editor.DeleteRange(pos + idx, len(newrow) + size)
1308 self.
_editor_editor.InsertText(pos + idx, newrow )
1313 pos = self.
_editor_editor.PositionFromLine(ini_line)
1314 row = self.
_editor_editor.GetLine(ini_line)
1318 while idx >= len(spaces):
1319 if row[idx-len(spaces):idx] != spaces:
1323 if idx < len(spaces):
1325 while count == 0
and idx > 0:
1327 if idx + 1 < lenline
and row[idx:idx + 1] ==
'#':
1328 if idx + 2 < lenline
and row[idx + 1:idx + 2] ==
' ':
1331 if idx + size < lenline:
1332 newrow = row[idx + size:]
1333 newrow = newrow.replace(
'\\ ',
' ')
1334 size += len(row[idx:]) - len(newrow) - size
1335 self.
_editor_editor.DeleteRange(pos + idx, len(newrow) + size)
1336 self.
_editor_editor.InsertText(pos + idx, newrow)
1343 new_end = end - count
1350 self.
_editor_editor.SetSelection(new_start, new_end)
1351 self.
_editor_editor.SetCurrentPos(cursor - count)
1356 _, setting = message.keys
1357 if setting ==
'txt number of spaces':
1358 self.
_tab_size_tab_size = self.
_parent_parent._app.settings.get(
'txt number of spaces', 4)
1359 if setting ==
'reformat':
1360 self.
_reformat_reformat = self.
_parent_parent._app.settings.get(
'reformat',
False)
1366 if self.
_dirty_dirty == 0
and dirty:
1367 self.
_data_data.mark_data_dirty()
1369 elif self.
_dirty_dirty == 1:
1371 self.
_data_data.mark_data_pristine()
1379 stc.StyledTextCtrl.__init__(self, parent)
1382 self.SetMarginType(self.
marginmargin, stc.STC_MARGIN_NUMBER)
1383 self.SetLexer(stc.STC_LEX_CONTAINER)
1384 self.SetReadOnly(
True)
1385 self.SetUseTabs(
False)
1386 self.SetTabWidth(parent._tab_size)
1387 self.Bind(stc.EVT_STC_STYLENEEDED, self.
OnStyleOnStyle)
1388 self.Bind(stc.EVT_STC_ZOOM, self.
OnZoomOnZoom)
1392 self.SetReadOnly(
False)
1395 self.EmptyUndoBuffer()
1399 utf8_text = property
1402 return self.GetText().encode(
'UTF-8')
1412 new = self.GetZoom()
1413 old = self.
_settings_settings[
'Text Edit'].get(
'zoom factor', 0)
1415 self.
_settings_settings[
'Text Edit'].set(
'zoom factor', new)
1418 style = stc.STC_STYLE_LINENUMBER
1419 width = self.TextWidth(style, str(self.GetLineCount()))
1420 return width + self.TextWidth(style,
"1")
1424 selected = self.GetSelectedText()
1425 self.SetInsertionPoint(self.GetInsertionPoint() - len(selected))
1429 self.SetSelectionEnd(self.GetInsertionPoint())
1430 self.WordLeftEndExtend()
1431 selected = self.GetSelectedText()
1432 select = selected.strip()
1433 self.SetInsertionPoint(self.GetInsertionPoint() + len(selected)
1435 if select
and len(select) > 0:
1438 self.SetSelectionStart(self.GetInsertionPoint())
1439 self.WordRightEndExtend()
1440 selected = self.GetSelectedText()
1441 select = selected.strip()
1442 self.SetInsertionPoint(self.GetInsertionPoint() - len(select))
1443 if select
and len(select) > 0:
1461 if robotframeworklexer:
1462 self.
lexerlexer = robotframeworklexer.RobotFrameworkLexer()
1464 self.
editoreditor.GetParent().create_syntax_colorization_help()
1466 PUBLISHER.subscribe(self.
OnSettingsChangedOnSettingsChanged, RideSettingsChanged)
1470 section, setting = message.keys
1471 if section ==
'Text Edit':
1475 return self.
settingssettings[
'Text Edit'].get(
'font size', 10)
1478 return self.
settingssettings[
'Text Edit'].get(
'font face',
'Courier New')
1481 return self.
settingssettings[
'Text Edit'].get(
'zoom factor', 0)
1484 color_settings = self.
settingssettings.get_without_default(
'Text Edit')
1485 background = color_settings.get(
'background',
'#FFFFFF')
1487 h = background.lstrip(
'#')
1488 if h.upper() == background.upper():
1489 from wx
import ColourDatabase
1490 cdb = ColourDatabase()
1491 bkng = cdb.Find(h.upper())
1492 bkg = (bkng[0], bkng[1], bkng[2])
1494 bkg = tuple(
int(h[i:i + 2], 16)
for i
in (0, 2, 4))
1495 if bkg >= (180, 180, 180):
1496 bkg = (max(160, bkg[0]-80), max(160, bkg[1]-80),
1497 max(160, bkg[2]-80))
1499 bkg = (min(255, bkg[0]+180), min(255, bkg[1]+180),
1500 min(255, bkg[2]+180))
1501 background =
'#%02X%02X%02X' % bkg
1502 if robotframeworklexer:
1504 robotframeworklexer.ARGUMENT: {
1505 'fore': color_settings.get(
'argument',
'#bb8844')
1507 robotframeworklexer.COMMENT: {
1508 'fore': color_settings.get(
'comment',
'black')
1510 robotframeworklexer.ERROR: {
1511 'fore': color_settings.get(
'error',
'black')
1513 robotframeworklexer.GHERKIN: {
1514 'fore': color_settings.get(
'gherkin',
'black')
1516 robotframeworklexer.HEADING: {
1517 'fore': color_settings.get(
'heading',
'#999999'),
1520 robotframeworklexer.IMPORT: {
1521 'fore': color_settings.get(
'import',
'#555555')
1523 robotframeworklexer.KEYWORD: {
1524 'fore': color_settings.get(
'keyword',
'#990000'),
1527 robotframeworklexer.SEPARATOR: {
1528 'fore': color_settings.get(
'separator',
'black')
1530 robotframeworklexer.SETTING: {
1531 'fore': color_settings.get(
'setting',
'black'),
1534 robotframeworklexer.SYNTAX: {
1535 'fore': color_settings.get(
'syntax',
'black')
1537 robotframeworklexer.TC_KW_NAME: {
1538 'fore': color_settings.get(
'tc_kw_name',
'#aaaaaa')
1540 robotframeworklexer.VARIABLE: {
1541 'fore': color_settings.get(
'variable',
'#008080')
1545 for index, token
in enumerate(styles):
1546 self.
tokenstokens[token] = index
1547 self.
editoreditor.StyleSetSpec(index,
1551 foreground = color_settings.get(
'setting',
'black')
1554 self.
editoreditor.StyleSetBackground(wx.stc.STC_STYLE_DEFAULT, background)
1556 self.
editoreditor.Refresh()
1559 word = self.
editoreditor.GetTextRange(current_position,
1560 self.
editoreditor.WordEndPosition(
1563 return word, len(word)
1567 settings.update(size=self.
_font_size_font_size())
1568 settings.update(face=self.
_font_face_font_face())
1569 return ','.join(
'%s:%s' % (name, value)
1570 for name, value
in settings.items()
if value)
1578 sys_font = wx.SystemSettings.GetFont(wx.SYS_ANSI_FIXED_FONT)
1579 self.
settingssettings[
'Text Edit'][
'font face'] = sys_font.GetFaceName()
1582 if not self.
lexerlexer:
1584 self.
editoreditor.ConvertEOLs(2)
1586 for position, token, value
in self.
lexerlexer.get_tokens_unprocessed(self.
editoreditor.GetText()):
1587 if wx.VERSION < (4, 1, 0):
1588 self.
editoreditor.StartStyling(position+shift, 31)
1590 self.
editoreditor.StartStyling(position + shift)
1592 self.
editoreditor.SetStyling(len(value.encode(
'utf-8')), self.
tokenstokens[token])
1593 shift += len(value.encode(
'utf-8'))-len(value)
1594 except UnicodeEncodeError:
1595 self.
editoreditor.SetStyling(len(value), self.
tokenstokens[token])
1596 shift += len(value) - len(value)
def mark_data_dirty(self)
def update_from(self, content)
def _create_target_from(self, content)
def __init__(self, data, settings)
def _txt_data(self, data)
def mark_data_pristine(self)
def format_text(self, text)
def __init__(self, plugin)
def _normalize(self, text)
def set_editor(self, editor)
def _handle_sanity_check_failure(self)
def validate_and_update(self, data, text)
def _sanity_check(self, data, text)
def get_local_variables(self)
def _init(self, data=None)
def populate(self, content, tab_size)
def __init__(self, parent, readonly=False)
def calc_margin_width(self)
def get_selected_or_near_text(self)
def _get_style_string(self, back='#FFFFFF', fore='#000000', bold='', underline='')
def _get_word_and_length(self, current_position)
def _ensure_default_font_is_valid(self)
Checks if default font is installed.
def __init__(self, editor, settings, readonly=False)
def OnSettingsChanged(self, message)
Redraw the colors if the color settings are modified.
def _set_styles(self, readonly=False)
def move_row_up(self, event)
def delete_row(self, event)
def OnContentAssist(self, event)
def GetFocus(self, event)
def execute_enclose_text(self, keycode)
def OnFindBackwards(self, event)
def insert_row(self, event)
def _find(self, forward=True)
def execute_uncomment(self, event)
def OnKeyDown(self, event)
def execute_sharp_comment(self, event)
def __init__(self, parent, title, data_validator)
def LeaveFocus(self, event)
def store_position(self, force=False)
def _create_ui(self, title)
def OnTabChange(self, message)
_search_field_notification
def _create_editor_text_control(self, text=None)
def execute_variable_creator(self, list_variable=False, dict_variable=False)
def _variable_creator_value(symbol, value='')
def _show_search_results(self, position, txt)
def set_editor_caret_position(self)
def OnSettingsChanged(self, message)
Update tab size if txt spaces size setting is modified.
def OnEditorKey(self, event)
def indent_line(self, line)
def _create_editor_toolbar(self)
_syntax_colorization_help_exists
def create_syntax_colorization_help(self)
def _create_search(self, container_sizer)
def execute_comment(self, event)
def show_help_dialog(self, event)
def execute_sharp_uncomment(self, event)
def _mark_file_dirty(self, dirty=True)
def _find_text_position(self, forward, txt)
def _enclose_text(open_symbol, value='')
def move_row_down(self, event)
def datafile_controller(self)
def remove_and_store_state(self)
def _set_read_only(self, message)
def _register_shortcuts(self)
def _open_data_for_controller(self, datafile_controller)
def _open_tree_selection_in_editor(self)
def OnTabChange(self, message)
def OnTreeSelection(self, message)
def _apply_txt_changes_to_model(self)
def OnDataChanged(self, message)
def __init__(self, application)
def OnTabChanged(self, event)
def OnSaving(self, message)
def OnTabChanging(self, message)
def _on_timer(self, event)
def _should_process_data_changed_message(self, message)
The parsed test data directory object.
def ReadFonts(fixed=False)
Returns list with fixed width fonts.