119 self.RefreshHighlightsTimer = wx.Timer(self, -1) |
119 self.RefreshHighlightsTimer = wx.Timer(self, -1) |
120 self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer) |
120 self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer) |
121 |
121 |
122 self.SectionsComments = {} |
122 self.SectionsComments = {} |
123 for section in SECTIONS_NAMES: |
123 for section in SECTIONS_NAMES: |
124 section_start_comment = "%s %s section %s" % ( |
124 section_comment = " %s section " % (section) |
125 self.COMMENT_HEADER, section, self.COMMENT_HEADER) |
125 len_headers = 78 - len(section_comment) |
126 section_end_comment = "%s End %s section %s" % ( |
126 section_comment = self.COMMENT_HEADER * (len_headers / 2) + \ |
127 self.COMMENT_HEADER, section, self.COMMENT_HEADER) |
127 section_comment + \ |
|
128 self.COMMENT_HEADER * (len_headers - len_headers / 2) |
|
129 |
128 self.SectionsComments[section] = { |
130 self.SectionsComments[section] = { |
129 "start": section_start_comment, |
131 "comment": section_comment, |
130 "end": section_end_comment, |
|
131 "pattern": re.compile(section_start_comment + |
|
132 "(.*)" + |
|
133 section_end_comment, |
|
134 re.DOTALL) |
|
135 } |
132 } |
136 |
133 |
|
134 for i, section in enumerate(SECTIONS_NAMES): |
|
135 section_infos = self.SectionsComments[section] |
|
136 if i + 1 < len(SECTIONS_NAMES): |
|
137 section_end = self.SectionsComments[SECTIONS_NAMES[i + 1]]["comment"] |
|
138 else: |
|
139 section_end = "$" |
|
140 section_infos["pattern"] = re.compile( |
|
141 section_infos["comment"] + "(.*)" + |
|
142 section_end, re.DOTALL) |
|
143 |
137 self.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT|wx.stc.STC_MOD_BEFOREDELETE) |
144 self.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT|wx.stc.STC_MOD_BEFOREDELETE) |
138 |
145 |
139 self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop) |
146 self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop) |
140 self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus) |
147 self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus) |
141 self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification) |
148 self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification) |
196 def GetCodeText(self): |
203 def GetCodeText(self): |
197 parts = self.Controler.GetTextParts() |
204 parts = self.Controler.GetTextParts() |
198 text = "" |
205 text = "" |
199 for section in SECTIONS_NAMES: |
206 for section in SECTIONS_NAMES: |
200 section_comments = self.SectionsComments[section] |
207 section_comments = self.SectionsComments[section] |
201 text += section_comments["start"] |
208 text += section_comments["comment"] |
202 if not parts[section].startswith("\n") or parts[section] == "\n": |
209 if not parts[section].startswith("\n") or parts[section] == "\n": |
203 text += "\n" |
210 text += "\n" |
204 text += parts[section] |
211 text += parts[section] |
205 if not parts[section].endswith("\n"): |
212 if not parts[section].endswith("\n"): |
206 text += "\n" |
213 text += "\n" |
207 text += section_comments["end"] |
|
208 if section != SECTIONS_NAMES[-1]: |
|
209 text += "\n\n" |
|
210 return text |
214 return text |
211 |
215 |
212 def RefreshView(self, scroll_to_highlight=False): |
216 def RefreshView(self, scroll_to_highlight=False): |
213 self.ResetBuffer() |
217 self.ResetBuffer() |
214 self.DisableEvents = True |
218 self.DisableEvents = True |
237 |
241 |
238 text = self.GetText() |
242 text = self.GetText() |
239 for line in xrange(self.GetLineCount()): |
243 for line in xrange(self.GetLineCount()): |
240 self.SetLineState(line, 0) |
244 self.SetLineState(line, 0) |
241 |
245 |
242 last_styled_pos = None |
|
243 end_pos = None |
|
244 for section in SECTIONS_NAMES: |
246 for section in SECTIONS_NAMES: |
245 section_comments = self.SectionsComments[section] |
247 section_comments = self.SectionsComments[section] |
246 start_pos = text.find(section_comments["start"]) |
248 start_pos = text.find(section_comments["comment"]) |
247 end_pos = start_pos + len(section_comments["start"]) |
249 end_pos = start_pos + len(section_comments["comment"]) |
248 if last_styled_pos is None: |
|
249 last_styled_pos = start_pos |
|
250 self.StartStyling(start_pos, 0xff) |
|
251 self.SetStyling(end_pos - last_styled_pos, STC_CODE_SECTION) |
|
252 for line in xrange(self.LineFromPosition(last_styled_pos), |
|
253 self.LineFromPosition(end_pos) + 1): |
|
254 self.SetLineState(line, 1) |
|
255 start_pos = text.find(section_comments["end"]) |
|
256 self.StartStyling(start_pos, 0xff) |
250 self.StartStyling(start_pos, 0xff) |
257 last_styled_pos = start_pos |
251 self.SetStyling(end_pos - start_pos, STC_CODE_SECTION) |
258 end_pos = start_pos + len(section_comments["end"]) |
252 self.SetLineState(self.LineFromPosition(start_pos), 1) |
259 |
253 |
260 if last_styled_pos is not None and end_pos: |
254 self.StartStyling(end_pos, 0x00) |
261 self.SetStyling(end_pos - last_styled_pos, STC_CODE_SECTION) |
255 self.SetStyling(len(self.GetText()) - end_pos, stc.STC_STYLE_DEFAULT) |
262 for line in xrange(self.LineFromPosition(last_styled_pos), |
|
263 self.LineFromPosition(end_pos) + 1): |
|
264 self.SetLineState(line, 1) |
|
265 |
256 |
266 def DoGetBestSize(self): |
257 def DoGetBestSize(self): |
267 return self.ParentWindow.GetPanelBestSize() |
258 return self.ParentWindow.GetPanelBestSize() |
268 |
259 |
269 def RefreshModel(self): |
260 def RefreshModel(self): |