diff -r 48ebcbe7f19b -r 02d09fc6eb90 editors/CodeFileEditor.py --- a/editors/CodeFileEditor.py Mon Mar 11 13:51:07 2019 +0100 +++ b/editors/CodeFileEditor.py Fri Mar 22 11:10:37 2019 +0100 @@ -56,6 +56,21 @@ EDGE_COLUMN = 80 +def GetSectionsText(controler, sections_headers): + parts = controler.GetTextParts() + text = "" + for section in controler.SECTIONS_NAMES: + text += sections_headers(section) + if parts[section] == "": + text += "\n" + else: + if not parts[section].startswith("\n"): + text += "\n" + text += parts[section] + if not parts[section].endswith("\n"): + text += "\n" + return text + class CodeEditor(CustomStyledTextCtrl): KEYWORDS = [] @@ -239,20 +254,9 @@ self.CurrentAction = None def GetCodeText(self): - parts = self.Controler.GetTextParts() - text = "" - for section in self.Controler.SECTIONS_NAMES: - section_comments = self.SectionsComments[section] - text += section_comments["comment"] - if parts[section] == "": - text += "\n" - else: - if not parts[section].startswith("\n"): - text += "\n" - text += parts[section] - if not parts[section].endswith("\n"): - text += "\n" - return text + return GetSectionsText( + self.Controler, + lambda section : self.SectionsComments[section]["comment"]) def RefreshView(self, scroll_to_highlight=False): self.ResetBuffer() @@ -644,6 +648,7 @@ """ for row in range(self.GetNumberRows()): + row_highlights = self.Highlights.get(row, {}) for col in range(self.GetNumberCols()): editor = None renderer = None @@ -656,7 +661,9 @@ grid.SetCellEditor(row, col, editor) grid.SetCellRenderer(row, col, renderer) - grid.SetCellBackgroundColour(row, col, wx.WHITE) + highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1] + grid.SetCellBackgroundColour(row, col, highlight_colours[0]) + grid.SetCellTextColour(row, col, highlight_colours[1]) self.ResizeRow(grid, row) @@ -859,6 +866,20 @@ return event.Skip() + def AddVariableHighlight(self, infos, highlight_type): + self.Table.AddHighlight(infos, highlight_type) + cell_visible = infos[0] + colnames = [colname.lower() for colname in self.Table.colnames] + self.VariablesGrid.MakeCellVisible(cell_visible, colnames.index(infos[1])) + self.Table.ResetView(self.VariablesGrid) + + def RemoveVariableHighlight(self, infos, highlight_type): + self.Table.RemoveHighlight(infos, highlight_type) + self.Table.ResetView(self.VariablesGrid) + + def ClearHighlights(self, highlight_type=None): + self.Table.ClearHighlights(highlight_type) + self.Table.ResetView(self.VariablesGrid) # ------------------------------------------------------------------------------- # CodeFileEditor Main Frame Class @@ -914,3 +935,21 @@ def Find(self, direction, search_params): self.CodeEditor.Find(direction, search_params) + + def AddHighlight(self, infos, start, end, highlight_type): + if self.VariablesPanel is not None and infos[0] == "var_inout": + self.VariablesPanel.AddVariableHighlight(infos[1:], highlight_type) + else: + self.CodeEditor.AddHighlight(start, end, highlight_type) + + def RemoveHighlight(self, infos, start, end, highlight_type): + if self.VariablesPanel is not None and infos[0] == "var_inout": + self.VariablesPanel.RemoveVariableHighlight(infos[1:], highlight_type) + else: + self.CodeEditor.RemoveHighlight(start, end, highlight_type) + + def ClearHighlights(self, highlight_type=None): + if self.VariablesPanel is not None: + self.VariablesPanel.ClearHighlights(highlight_type) + else: + self.CodeEditor.ClearHighlights(highlight_type)