9 from controls import CustomGrid, CustomTable |
9 from controls import CustomGrid, CustomTable |
10 from editors.ConfTreeNodeEditor import ConfTreeNodeEditor |
10 from editors.ConfTreeNodeEditor import ConfTreeNodeEditor |
11 from util.BitmapLibrary import GetBitmap |
11 from util.BitmapLibrary import GetBitmap |
12 from controls.CustomStyledTextCtrl import CustomStyledTextCtrl, faces, GetCursorPos, NAVIGATION_KEYS |
12 from controls.CustomStyledTextCtrl import CustomStyledTextCtrl, faces, GetCursorPos, NAVIGATION_KEYS |
13 from graphics.GraphicCommons import ERROR_HIGHLIGHT, SEARCH_RESULT_HIGHLIGHT, REFRESH_HIGHLIGHT_PERIOD |
13 from graphics.GraphicCommons import ERROR_HIGHLIGHT, SEARCH_RESULT_HIGHLIGHT, REFRESH_HIGHLIGHT_PERIOD |
14 |
|
15 SECTIONS_NAMES = ["Includes", "Globals", "Init", |
|
16 "CleanUp", "Retrieve", "Publish"] |
|
17 |
14 |
18 [STC_CODE_ERROR, STC_CODE_SEARCH_RESULT, |
15 [STC_CODE_ERROR, STC_CODE_SEARCH_RESULT, |
19 STC_CODE_SECTION] = range(15, 18) |
16 STC_CODE_SECTION] = range(15, 18) |
20 |
17 |
21 HIGHLIGHT_TYPES = { |
18 HIGHLIGHT_TYPES = { |
118 |
115 |
119 self.RefreshHighlightsTimer = wx.Timer(self, -1) |
116 self.RefreshHighlightsTimer = wx.Timer(self, -1) |
120 self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer) |
117 self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer) |
121 |
118 |
122 self.SectionsComments = {} |
119 self.SectionsComments = {} |
123 for section in SECTIONS_NAMES: |
120 for section in self.Controler.SECTIONS_NAMES: |
124 section_comment = " %s section " % (section) |
121 section_comment = " %s section " % (section) |
125 len_headers = 78 - len(section_comment) |
122 len_headers = 78 - len(section_comment) |
126 section_comment = self.COMMENT_HEADER * (len_headers / 2) + \ |
123 section_comment = self.COMMENT_HEADER * (len_headers / 2) + \ |
127 section_comment + \ |
124 section_comment + \ |
128 self.COMMENT_HEADER * (len_headers - len_headers / 2) |
125 self.COMMENT_HEADER * (len_headers - len_headers / 2) |
129 |
126 |
130 self.SectionsComments[section] = { |
127 self.SectionsComments[section] = { |
131 "comment": section_comment, |
128 "comment": section_comment, |
132 } |
129 } |
133 |
130 |
134 for i, section in enumerate(SECTIONS_NAMES): |
131 for i, section in enumerate(self.Controler.SECTIONS_NAMES): |
135 section_infos = self.SectionsComments[section] |
132 section_infos = self.SectionsComments[section] |
136 if i + 1 < len(SECTIONS_NAMES): |
133 if i + 1 < len(self.Controler.SECTIONS_NAMES): |
137 section_end = self.SectionsComments[SECTIONS_NAMES[i + 1]]["comment"] |
134 section_end = self.SectionsComments[ |
|
135 self.Controler.SECTIONS_NAMES[i + 1]]["comment"] |
138 else: |
136 else: |
139 section_end = "$" |
137 section_end = "$" |
140 section_infos["pattern"] = re.compile( |
138 section_infos["pattern"] = re.compile( |
141 section_infos["comment"] + "(.*)" + |
139 section_infos["comment"] + "(.*)" + |
142 section_end, re.DOTALL) |
140 section_end, re.DOTALL) |
201 self.CurrentAction = None |
199 self.CurrentAction = None |
202 |
200 |
203 def GetCodeText(self): |
201 def GetCodeText(self): |
204 parts = self.Controler.GetTextParts() |
202 parts = self.Controler.GetTextParts() |
205 text = "" |
203 text = "" |
206 for section in SECTIONS_NAMES: |
204 for section in self.Controler.SECTIONS_NAMES: |
207 section_comments = self.SectionsComments[section] |
205 section_comments = self.SectionsComments[section] |
208 text += section_comments["comment"] |
206 text += section_comments["comment"] |
209 if parts[section] == "": |
207 if parts[section] == "": |
210 text += "\n" |
208 text += "\n" |
211 else: |
209 else: |
244 |
242 |
245 text = self.GetText() |
243 text = self.GetText() |
246 for line in xrange(self.GetLineCount()): |
244 for line in xrange(self.GetLineCount()): |
247 self.SetLineState(line, 0) |
245 self.SetLineState(line, 0) |
248 |
246 |
249 for section in SECTIONS_NAMES: |
247 for section in self.Controler.SECTIONS_NAMES: |
250 section_comments = self.SectionsComments[section] |
248 section_comments = self.SectionsComments[section] |
251 start_pos = text.find(section_comments["comment"]) |
249 start_pos = text.find(section_comments["comment"]) |
252 end_pos = start_pos + len(section_comments["comment"]) |
250 end_pos = start_pos + len(section_comments["comment"]) |
253 self.StartStyling(start_pos, 0xff) |
251 self.StartStyling(start_pos, 0xff) |
254 self.SetStyling(end_pos - start_pos, STC_CODE_SECTION) |
252 self.SetStyling(end_pos - start_pos, STC_CODE_SECTION) |
261 return self.ParentWindow.GetPanelBestSize() |
259 return self.ParentWindow.GetPanelBestSize() |
262 |
260 |
263 def RefreshModel(self): |
261 def RefreshModel(self): |
264 text = self.GetText() |
262 text = self.GetText() |
265 parts = {} |
263 parts = {} |
266 for section in SECTIONS_NAMES: |
264 for section in self.Controler.SECTIONS_NAMES: |
267 section_comments = self.SectionsComments[section] |
265 section_comments = self.SectionsComments[section] |
268 result = section_comments["pattern"].search(text) |
266 result = section_comments["pattern"].search(text) |
269 if result is not None: |
267 if result is not None: |
270 parts[section] = result.group(1) |
268 parts[section] = result.group(1) |
271 else: |
269 else: |
274 |
272 |
275 def OnKeyPressed(self, event): |
273 def OnKeyPressed(self, event): |
276 if self.CallTipActive(): |
274 if self.CallTipActive(): |
277 self.CallTipCancel() |
275 self.CallTipCancel() |
278 key = event.GetKeyCode() |
276 key = event.GetKeyCode() |
279 current_pos = self.GetSelection()[0] |
277 current_pos = self.GetCurrentPos() |
280 |
278 selected = self.GetSelection() |
|
279 text_selected = selected[0] != selected[1] |
|
280 |
|
281 # Disable to type any character in section header lines |
281 if (self.GetLineState(self.LineFromPosition(current_pos)) and |
282 if (self.GetLineState(self.LineFromPosition(current_pos)) and |
|
283 not text_selected and |
282 key not in NAVIGATION_KEYS + [ |
284 key not in NAVIGATION_KEYS + [ |
283 wx.WXK_RETURN, |
285 wx.WXK_RETURN, |
284 wx.WXK_NUMPAD_ENTER]): |
286 wx.WXK_NUMPAD_ENTER]): |
|
287 return |
|
288 |
|
289 # Disable to delete line between code and header lines |
|
290 elif (self.GetCurLine()[0].strip() != "" and not text_selected and |
|
291 (key == wx.WXK_BACK and |
|
292 self.GetLineState(self.LineFromPosition(max(0, current_pos - 1))) or |
|
293 key in [wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE] and |
|
294 self.GetLineState(self.LineFromPosition(min(len(self.GetText()), current_pos + 1))))): |
285 return |
295 return |
286 |
296 |
287 elif key == 32 and event.ControlDown(): |
297 elif key == 32 and event.ControlDown(): |
288 pos = self.GetCurrentPos() |
298 pos = self.GetCurrentPos() |
289 |
299 |