editors/CodeFileEditor.py
author Laurent Bessard
Wed, 05 Jun 2013 23:13:33 +0200
changeset 1223 d51cea72baa7
parent 1178 3e2aebc9c7c0
child 1412 50192dd2f5ff
permissions -rw-r--r--
Fixed bug when adding standard function like ADD, SUB, MUL,... that are overloaded. Block type was not selected and shown when opening FBDBlockDialog to edit it.
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
     1
import re
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
     2
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
     3
import wx
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
     4
import wx.grid
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
     5
import wx.stc as stc
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
     6
import wx.lib.buttons
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
     7
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
     8
from plcopen.plcopen import TestTextElement
1146
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
     9
from plcopen.structures import TestIdentifier, IEC_KEYWORDS
738
413946c04c87 refactoring
laurent
parents: 734
diff changeset
    10
from controls import CustomGrid, CustomTable
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    11
from editors.ConfTreeNodeEditor import ConfTreeNodeEditor
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 801
diff changeset
    12
from util.BitmapLibrary import GetBitmap
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
    13
from controls.CustomStyledTextCtrl import CustomStyledTextCtrl, faces, GetCursorPos, NAVIGATION_KEYS
1146
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
    14
from controls.VariablePanel import VARIABLE_NAME_SUFFIX_MODEL
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
    15
from graphics.GraphicCommons import ERROR_HIGHLIGHT, SEARCH_RESULT_HIGHLIGHT, REFRESH_HIGHLIGHT_PERIOD
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    16
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
    17
[STC_CODE_ERROR, STC_CODE_SEARCH_RESULT, 
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
    18
 STC_CODE_SECTION] = range(15, 18)
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
    19
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
    20
HIGHLIGHT_TYPES = {
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
    21
    ERROR_HIGHLIGHT: STC_CODE_ERROR,
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
    22
    SEARCH_RESULT_HIGHLIGHT: STC_CODE_SEARCH_RESULT,
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
    23
}
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
    24
1161
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
    25
EDGE_COLUMN = 80
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
    26
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    27
class CodeEditor(CustomStyledTextCtrl):
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    28
    
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    29
    KEYWORDS = []
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    30
    COMMENT_HEADER = ""
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    31
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    32
    def __init__(self, parent, window, controler):
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    33
        CustomStyledTextCtrl.__init__(self, parent, -1, wx.DefaultPosition, 
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 874
diff changeset
    34
                 wx.Size(-1, 300), 0)
1161
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
    35
        
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    36
        self.SetMarginType(1, stc.STC_MARGIN_NUMBER)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    37
        self.SetMarginWidth(1, 25)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    38
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    39
        self.SetProperty("fold", "1")
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    40
        self.SetProperty("tab.timmy.whinge.level", "1")
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    41
        self.SetMargins(0,0)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    42
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    43
        self.SetViewWhiteSpace(False)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    44
        
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    45
        self.SetEdgeMode(stc.STC_EDGE_BACKGROUND)
1161
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
    46
        self.SetEdgeColumn(EDGE_COLUMN)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    47
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    48
        # Setup a margin to hold fold markers
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    49
        self.SetMarginType(2, stc.STC_MARGIN_SYMBOL)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    50
        self.SetMarginMask(2, stc.STC_MASK_FOLDERS)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    51
        self.SetMarginSensitive(2, True)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    52
        self.SetMarginWidth(2, 12)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    53
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    54
        # Like a flattened tree control using square headers
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    55
        self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_BOXMINUS,          "white", "#808080")
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    56
        self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_BOXPLUS,           "white", "#808080")
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    57
        self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_VLINE,             "white", "#808080")
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    58
        self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_LCORNER,           "white", "#808080")
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    59
        self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_BOXPLUSCONNECTED,  "white", "#808080")
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    60
        self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080")
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    61
        self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNER,           "white", "#808080")
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    62
        
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    63
        self.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUI)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    64
        self.Bind(stc.EVT_STC_MARGINCLICK, self.OnMarginClick)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    65
        self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    66
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    67
        # Make some styles,  The lexer defines what each style is used for, we
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    68
        # just have to define what each style looks like.  This set is adapted from
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    69
        # Scintilla sample property files.
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    70
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    71
        # Global default styles for all languages
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    72
        self.StyleSetSpec(stc.STC_STYLE_DEFAULT,     "face:%(mono)s,size:%(size)d" % faces)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    73
        self.StyleClearAll()  # Reset all to be like the default
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    74
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    75
        # Global default styles for all languages
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    76
        self.StyleSetSpec(stc.STC_STYLE_DEFAULT,     "face:%(mono)s,size:%(size)d" % faces)
1066
b6a5ae4a68d7 Fixed bug in CFileEditor
Laurent Bessard
parents: 1060
diff changeset
    77
        self.StyleSetSpec(stc.STC_STYLE_LINENUMBER,  "back:#C0C0C0,face:%(helv)s,size:%(size)d" % faces)
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
    78
        self.StyleSetSpec(stc.STC_STYLE_CONTROLCHAR, "face:%(mono)s" % faces)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    79
        self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT,  "fore:#FFFFFF,back:#0000FF,bold")
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    80
        self.StyleSetSpec(stc.STC_STYLE_BRACEBAD,    "fore:#000000,back:#FF0000,bold")
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    81
        
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
    82
        # Highlighting styles
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
    83
        self.StyleSetSpec(STC_CODE_ERROR, 'fore:#FF0000,back:#FFFF00,size:%(size)d' % faces)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
    84
        self.StyleSetSpec(STC_CODE_SEARCH_RESULT, 'fore:#FFFFFF,back:#FFA500,size:%(size)d' % faces)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
    85
        
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
    86
        # Section style
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
    87
        self.StyleSetSpec(STC_CODE_SECTION, 'fore:#808080,size:%(size)d')
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
    88
        self.StyleSetChangeable(STC_CODE_SECTION, False)
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
    89
        
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    90
        # Indentation size
1161
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
    91
        self.SetTabWidth(4)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    92
        self.SetUseTabs(0)
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    93
        
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    94
        self.SetCodeLexer()
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    95
        self.SetKeyWords(0, " ".join(self.KEYWORDS))
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    96
        
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    97
        self.Controler = controler
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    98
        self.ParentWindow = window
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    99
        
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   100
        self.DisableEvents = True
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   101
        self.CurrentAction = None
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   102
        
1178
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   103
        self.ResetSearchResults()
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   104
        
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   105
        self.RefreshHighlightsTimer = wx.Timer(self, -1)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   106
        self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   107
        
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   108
        self.SectionsComments = {}
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   109
        for section in self.Controler.SECTIONS_NAMES:
1110
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   110
            section_comment = " %s section " % (section)
1161
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
   111
            len_headers = EDGE_COLUMN - len(section_comment)
1110
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   112
            section_comment = self.COMMENT_HEADER * (len_headers / 2) + \
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   113
                              section_comment + \
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   114
                              self.COMMENT_HEADER * (len_headers - len_headers / 2)
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   115
            
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   116
            self.SectionsComments[section] = {
1110
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   117
                 "comment": section_comment,
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   118
            }
1110
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   119
            
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   120
        for i, section in enumerate(self.Controler.SECTIONS_NAMES):
1110
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   121
            section_infos = self.SectionsComments[section]
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   122
            if i + 1 < len(self.Controler.SECTIONS_NAMES):
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   123
                section_end = self.SectionsComments[
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   124
                    self.Controler.SECTIONS_NAMES[i + 1]]["comment"]
1110
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   125
            else:
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   126
                section_end = "$"
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   127
            section_infos["pattern"] = re.compile(
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   128
                section_infos["comment"] + "(.*)" + 
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   129
                section_end, re.DOTALL)
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   130
            
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   131
        self.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT|wx.stc.STC_MOD_BEFOREDELETE)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   132
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   133
        self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   134
        self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   135
        self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification)
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   136
    
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   137
    def SetCodeLexer(self):
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   138
        pass
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   139
    
1178
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   140
    def ResetSearchResults(self):
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   141
        self.Highlights = []
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   142
        self.SearchParams = None
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   143
        self.SearchResults = None
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   144
        self.CurrentFindHighlight = None
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   145
    
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   146
    def OnModification(self, event):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   147
        if not self.DisableEvents:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   148
            mod_type = event.GetModificationType()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   149
            if not (mod_type&wx.stc.STC_PERFORMED_UNDO or mod_type&wx.stc.STC_PERFORMED_REDO):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   150
                if mod_type&wx.stc.STC_MOD_BEFOREINSERT:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   151
                    if self.CurrentAction == None:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   152
                        self.StartBuffering()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   153
                    elif self.CurrentAction[0] != "Add" or self.CurrentAction[1] != event.GetPosition() - 1:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   154
                        self.Controler.EndBuffering()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   155
                        self.StartBuffering()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   156
                    self.CurrentAction = ("Add", event.GetPosition())
658
94417ab25510 Fixing some issues in c_ext plugin
laurent
parents: 656
diff changeset
   157
                    wx.CallAfter(self.RefreshModel)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   158
                elif mod_type&wx.stc.STC_MOD_BEFOREDELETE:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   159
                    if self.CurrentAction == None:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   160
                        self.StartBuffering()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   161
                    elif self.CurrentAction[0] != "Delete" or self.CurrentAction[1] != event.GetPosition() + 1:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   162
                        self.Controler.EndBuffering()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   163
                        self.StartBuffering()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   164
                    self.CurrentAction = ("Delete", event.GetPosition())
658
94417ab25510 Fixing some issues in c_ext plugin
laurent
parents: 656
diff changeset
   165
                    wx.CallAfter(self.RefreshModel)
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   166
        wx.CallAfter(self.RefreshSectionStyling)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   167
        event.Skip()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   168
    
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   169
    def OnDoDrop(self, event):
1138
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   170
        try:
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   171
            values = eval(event.GetDragText())
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   172
        except:
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   173
            values = event.GetDragText()
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   174
        if isinstance(values, tuple):
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   175
            message = None
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   176
            if values[3] == self.Controler.GetCurrentLocation():
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   177
                self.ResetBuffer()
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   178
                event.SetDragText(values[0])
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   179
                wx.CallAfter(self.RefreshModel)
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   180
            else:
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   181
                event.SetDragText("")
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   182
        else:
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   183
            self.ResetBuffer()
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   184
            wx.CallAfter(self.RefreshModel)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   185
        event.Skip()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   186
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   187
    # Buffer the last model state
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   188
    def RefreshBuffer(self):
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   189
        self.Controler.BufferCodeFile()
658
94417ab25510 Fixing some issues in c_ext plugin
laurent
parents: 656
diff changeset
   190
        if self.ParentWindow is not None:
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   191
            self.ParentWindow.RefreshTitle()
587
c6354f7fe26e Restore RefreshFileMenu in CFileEditor
Edouard Tisserant
parents: 586
diff changeset
   192
            self.ParentWindow.RefreshFileMenu()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   193
            self.ParentWindow.RefreshEditMenu()
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   194
            self.ParentWindow.RefreshPageTitles()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   195
    
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   196
    def StartBuffering(self):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   197
        self.Controler.StartBuffering()
658
94417ab25510 Fixing some issues in c_ext plugin
laurent
parents: 656
diff changeset
   198
        if self.ParentWindow is not None:
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   199
            self.ParentWindow.RefreshTitle()
587
c6354f7fe26e Restore RefreshFileMenu in CFileEditor
Edouard Tisserant
parents: 586
diff changeset
   200
            self.ParentWindow.RefreshFileMenu()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   201
            self.ParentWindow.RefreshEditMenu()
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   202
            self.ParentWindow.RefreshPageTitles()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   203
    
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   204
    def ResetBuffer(self):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   205
        if self.CurrentAction != None:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   206
            self.Controler.EndBuffering()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   207
            self.CurrentAction = None
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   208
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   209
    def GetCodeText(self):
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   210
        parts = self.Controler.GetTextParts()
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   211
        text = ""
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   212
        for section in self.Controler.SECTIONS_NAMES:
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   213
            section_comments = self.SectionsComments[section]
1110
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   214
            text += section_comments["comment"]
1117
1aef6a7db08d Fixed CodeFileEditor allowing to have no line of code between two section headers
Laurent Bessard
parents: 1115
diff changeset
   215
            if parts[section] == "":
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   216
                text += "\n"
1117
1aef6a7db08d Fixed CodeFileEditor allowing to have no line of code between two section headers
Laurent Bessard
parents: 1115
diff changeset
   217
            else:
1aef6a7db08d Fixed CodeFileEditor allowing to have no line of code between two section headers
Laurent Bessard
parents: 1115
diff changeset
   218
                if not parts[section].startswith("\n"):
1aef6a7db08d Fixed CodeFileEditor allowing to have no line of code between two section headers
Laurent Bessard
parents: 1115
diff changeset
   219
                    text += "\n"
1aef6a7db08d Fixed CodeFileEditor allowing to have no line of code between two section headers
Laurent Bessard
parents: 1115
diff changeset
   220
                text += parts[section]
1aef6a7db08d Fixed CodeFileEditor allowing to have no line of code between two section headers
Laurent Bessard
parents: 1115
diff changeset
   221
                if not parts[section].endswith("\n"):
1aef6a7db08d Fixed CodeFileEditor allowing to have no line of code between two section headers
Laurent Bessard
parents: 1115
diff changeset
   222
                    text += "\n"
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   223
        return text
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   224
1101
5a0b439cf576 Fixed search in CodeFileEditor STC panel
Laurent Bessard
parents: 1097
diff changeset
   225
    def RefreshView(self, scroll_to_highlight=False):
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   226
        self.ResetBuffer()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   227
        self.DisableEvents = True
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   228
        old_cursor_pos = self.GetCurrentPos()
1060
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   229
        line = self.GetFirstVisibleLine()
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   230
        column = self.GetXOffset()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   231
        old_text = self.GetText()
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   232
        new_text = self.GetCodeText()
1060
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   233
        if old_text != new_text:
1101
5a0b439cf576 Fixed search in CodeFileEditor STC panel
Laurent Bessard
parents: 1097
diff changeset
   234
            self.SetText(new_text)
1060
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   235
            new_cursor_pos = GetCursorPos(old_text, new_text)
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   236
            self.LineScroll(column, line)
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   237
            if new_cursor_pos != None:
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   238
                self.GotoPos(new_cursor_pos)
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   239
            else:
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   240
                self.GotoPos(old_cursor_pos)
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   241
            self.EmptyUndoBuffer()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   242
        self.DisableEvents = False
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   243
        
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   244
        self.RefreshSectionStyling()
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   245
        
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   246
        self.ShowHighlights()
1178
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   247
        
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   248
    def RefreshSectionStyling(self):
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   249
        self.Colourise(0, -1)
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   250
        
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   251
        text = self.GetText()
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   252
        for line in xrange(self.GetLineCount()):
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   253
            self.SetLineState(line, 0)
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   254
        
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   255
        for section in self.Controler.SECTIONS_NAMES:
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   256
            section_comments = self.SectionsComments[section]
1110
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   257
            start_pos = text.find(section_comments["comment"])
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   258
            end_pos = start_pos + len(section_comments["comment"])
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   259
            self.StartStyling(start_pos, 0xff)
1110
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   260
            self.SetStyling(end_pos - start_pos, STC_CODE_SECTION)
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   261
            self.SetLineState(self.LineFromPosition(start_pos), 1)
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   262
            
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   263
        self.StartStyling(end_pos, 0x00)
b6e252733c64 Fixed code section headers in CodeFileEditor
Laurent Bessard
parents: 1109
diff changeset
   264
        self.SetStyling(len(self.GetText()) - end_pos, stc.STC_STYLE_DEFAULT)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   265
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   266
    def DoGetBestSize(self):
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   267
        return self.ParentWindow.GetPanelBestSize()
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   268
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   269
    def RefreshModel(self):
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   270
        text = self.GetText()
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   271
        parts = {}
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   272
        for section in self.Controler.SECTIONS_NAMES:
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   273
            section_comments = self.SectionsComments[section]
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   274
            result = section_comments["pattern"].search(text)
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   275
            if result is not None:
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   276
                parts[section] = result.group(1)
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   277
            else:
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   278
                parts[section] = ""
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   279
        self.Controler.SetTextParts(parts)
1178
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   280
        self.ResetSearchResults()
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   281
    
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   282
    def OnKeyPressed(self, event):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   283
        if self.CallTipActive():
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   284
            self.CallTipCancel()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   285
        key = event.GetKeyCode()
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   286
        current_pos = self.GetCurrentPos()
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   287
        selected = self.GetSelection()
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   288
        text_selected = selected[0] != selected[1]
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   289
        
1139
f9cf74053b7d Fixed bug when deleting line between code and headers on Windows
Laurent Bessard
parents: 1138
diff changeset
   290
        # Test if caret is before Windows like new line
f9cf74053b7d Fixed bug when deleting line between code and headers on Windows
Laurent Bessard
parents: 1138
diff changeset
   291
        text = self.GetText()
1150
b1c84771e1cf Fixed bug when typing and caret is at last test position in CodeFileEditor
Laurent Bessard
parents: 1146
diff changeset
   292
        if current_pos < len(text) and ord(text[current_pos]) == 13:
1139
f9cf74053b7d Fixed bug when deleting line between code and headers on Windows
Laurent Bessard
parents: 1138
diff changeset
   293
            newline_size = 2
f9cf74053b7d Fixed bug when deleting line between code and headers on Windows
Laurent Bessard
parents: 1138
diff changeset
   294
        else:
f9cf74053b7d Fixed bug when deleting line between code and headers on Windows
Laurent Bessard
parents: 1138
diff changeset
   295
            newline_size = 1
f9cf74053b7d Fixed bug when deleting line between code and headers on Windows
Laurent Bessard
parents: 1138
diff changeset
   296
        
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   297
        # Disable to type any character in section header lines
1117
1aef6a7db08d Fixed CodeFileEditor allowing to have no line of code between two section headers
Laurent Bessard
parents: 1115
diff changeset
   298
        if (self.GetLineState(self.LineFromPosition(current_pos)) and
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   299
            not text_selected and
1117
1aef6a7db08d Fixed CodeFileEditor allowing to have no line of code between two section headers
Laurent Bessard
parents: 1115
diff changeset
   300
            key not in NAVIGATION_KEYS + [
1aef6a7db08d Fixed CodeFileEditor allowing to have no line of code between two section headers
Laurent Bessard
parents: 1115
diff changeset
   301
                wx.WXK_RETURN,
1aef6a7db08d Fixed CodeFileEditor allowing to have no line of code between two section headers
Laurent Bessard
parents: 1115
diff changeset
   302
                wx.WXK_NUMPAD_ENTER]):
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   303
            return
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   304
        
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   305
        # Disable to delete line between code and header lines
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   306
        elif (self.GetCurLine()[0].strip() != "" and not text_selected and
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   307
              (key == wx.WXK_BACK and
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   308
               self.GetLineState(self.LineFromPosition(max(0, current_pos - 1))) or
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   309
               key in [wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE] and
1139
f9cf74053b7d Fixed bug when deleting line between code and headers on Windows
Laurent Bessard
parents: 1138
diff changeset
   310
               self.GetLineState(self.LineFromPosition(min(len(text), current_pos + newline_size))))):
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   311
            return
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   312
        
1104
017cd95bc07e Added support for excluding code section headers to be modified in CodeFileEditor
Laurent Bessard
parents: 1101
diff changeset
   313
        elif key == 32 and event.ControlDown():
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   314
            pos = self.GetCurrentPos()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   315
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   316
            # Tips
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   317
            if event.ShiftDown():
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   318
                pass
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   319
            # Code completion
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   320
            else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   321
                self.AutoCompSetIgnoreCase(False)  # so this needs to match
1136
5fac491d3a0e Added global variable names in CodeFileEditor auto-completion list
Laurent Bessard
parents: 1126
diff changeset
   322
                
5fac491d3a0e Added global variable names in CodeFileEditor auto-completion list
Laurent Bessard
parents: 1126
diff changeset
   323
                keywords = self.KEYWORDS + [var["Name"]
5fac491d3a0e Added global variable names in CodeFileEditor auto-completion list
Laurent Bessard
parents: 1126
diff changeset
   324
                                            for var in self.Controler.GetVariables()]
5fac491d3a0e Added global variable names in CodeFileEditor auto-completion list
Laurent Bessard
parents: 1126
diff changeset
   325
                keywords.sort()
5fac491d3a0e Added global variable names in CodeFileEditor auto-completion list
Laurent Bessard
parents: 1126
diff changeset
   326
                self.AutoCompShow(0, " ".join(keywords))
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   327
        else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   328
            event.Skip()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   329
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   330
    def OnKillFocus(self, event):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   331
        self.AutoCompCancel()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   332
        event.Skip()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   333
1126
26baa0ae9fd7 Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents: 1124
diff changeset
   334
    def OnUpdateUI(self, event):
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   335
        # check for matching braces
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   336
        braceAtCaret = -1
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   337
        braceOpposite = -1
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   338
        charBefore = None
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   339
        caretPos = self.GetCurrentPos()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   340
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   341
        if caretPos > 0:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   342
            charBefore = self.GetCharAt(caretPos - 1)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   343
            styleBefore = self.GetStyleAt(caretPos - 1)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   344
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   345
        # check before
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   346
        if charBefore and chr(charBefore) in "[]{}()" and styleBefore == stc.STC_P_OPERATOR:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   347
            braceAtCaret = caretPos - 1
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   348
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   349
        # check after
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   350
        if braceAtCaret < 0:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   351
            charAfter = self.GetCharAt(caretPos)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   352
            styleAfter = self.GetStyleAt(caretPos)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   353
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   354
            if charAfter and chr(charAfter) in "[]{}()" and styleAfter == stc.STC_P_OPERATOR:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   355
                braceAtCaret = caretPos
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   356
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   357
        if braceAtCaret >= 0:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   358
            braceOpposite = self.BraceMatch(braceAtCaret)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   359
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   360
        if braceAtCaret != -1  and braceOpposite == -1:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   361
            self.BraceBadLight(braceAtCaret)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   362
        else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   363
            self.BraceHighlight(braceAtCaret, braceOpposite)
1146
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   364
        
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   365
        selected_text = self.GetSelectedText()
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   366
        if selected_text:
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   367
            self.ParentWindow.SetCopyBuffer(selected_text, True)
1161
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
   368
    
1126
26baa0ae9fd7 Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents: 1124
diff changeset
   369
    def OnMarginClick(self, event):
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   370
        # fold and unfold as needed
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   371
        if evt.GetMargin() == 2:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   372
            if evt.GetShift() and evt.GetControl():
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   373
                self.FoldAll()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   374
            else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   375
                lineClicked = self.LineFromPosition(evt.GetPosition())
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   376
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   377
                if self.GetFoldLevel(lineClicked) & stc.STC_FOLDLEVELHEADERFLAG:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   378
                    if evt.GetShift():
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   379
                        self.SetFoldExpanded(lineClicked, True)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   380
                        self.Expand(lineClicked, True, True, 1)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   381
                    elif evt.GetControl():
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   382
                        if self.GetFoldExpanded(lineClicked):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   383
                            self.SetFoldExpanded(lineClicked, False)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   384
                            self.Expand(lineClicked, False, True, 0)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   385
                        else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   386
                            self.SetFoldExpanded(lineClicked, True)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   387
                            self.Expand(lineClicked, True, True, 100)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   388
                    else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   389
                        self.ToggleFold(lineClicked)
1126
26baa0ae9fd7 Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents: 1124
diff changeset
   390
        event.Skip()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   391
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   392
    def FoldAll(self):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   393
        lineCount = self.GetLineCount()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   394
        expanding = True
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   395
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   396
        # find out if we are folding or unfolding
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   397
        for lineNum in range(lineCount):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   398
            if self.GetFoldLevel(lineNum) & stc.STC_FOLDLEVELHEADERFLAG:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   399
                expanding = not self.GetFoldExpanded(lineNum)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   400
                break
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   401
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   402
        lineNum = 0
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   403
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   404
        while lineNum < lineCount:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   405
            level = self.GetFoldLevel(lineNum)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   406
            if level & stc.STC_FOLDLEVELHEADERFLAG and \
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   407
               (level & stc.STC_FOLDLEVELNUMBERMASK) == stc.STC_FOLDLEVELBASE:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   408
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   409
                if expanding:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   410
                    self.SetFoldExpanded(lineNum, True)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   411
                    lineNum = self.Expand(lineNum, True)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   412
                    lineNum = lineNum - 1
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   413
                else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   414
                    lastChild = self.GetLastChild(lineNum, -1)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   415
                    self.SetFoldExpanded(lineNum, False)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   416
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   417
                    if lastChild > lineNum:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   418
                        self.HideLines(lineNum+1, lastChild)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   419
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   420
            lineNum = lineNum + 1
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   421
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   422
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   423
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   424
    def Expand(self, line, doExpand, force=False, visLevels=0, level=-1):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   425
        lastChild = self.GetLastChild(line, level)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   426
        line = line + 1
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   427
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   428
        while line <= lastChild:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   429
            if force:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   430
                if visLevels > 0:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   431
                    self.ShowLines(line, line)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   432
                else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   433
                    self.HideLines(line, line)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   434
            else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   435
                if doExpand:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   436
                    self.ShowLines(line, line)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   437
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   438
            if level == -1:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   439
                level = self.GetFoldLevel(line)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   440
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   441
            if level & stc.STC_FOLDLEVELHEADERFLAG:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   442
                if force:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   443
                    if visLevels > 1:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   444
                        self.SetFoldExpanded(line, True)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   445
                    else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   446
                        self.SetFoldExpanded(line, False)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   447
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   448
                    line = self.Expand(line, doExpand, force, visLevels-1)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   449
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   450
                else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   451
                    if doExpand and self.GetFoldExpanded(line):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   452
                        line = self.Expand(line, True, force, visLevels-1)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   453
                    else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   454
                        line = self.Expand(line, False, force, visLevels-1)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   455
            else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   456
                line = line + 1
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   457
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   458
        return line
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   459
637
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   460
    def Cut(self):
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   461
        self.ResetBuffer()
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   462
        self.DisableEvents = True
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   463
        self.CmdKeyExecute(wx.stc.STC_CMD_CUT)
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   464
        self.DisableEvents = False
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   465
        self.RefreshModel()
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   466
        self.RefreshBuffer()
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   467
    
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   468
    def Copy(self):
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   469
        self.CmdKeyExecute(wx.stc.STC_CMD_COPY)
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1117
diff changeset
   470
        self.ParentWindow.RefreshEditMenu()
637
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   471
    
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   472
    def Paste(self):
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   473
        self.ResetBuffer()
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   474
        self.DisableEvents = True
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   475
        self.CmdKeyExecute(wx.stc.STC_CMD_PASTE)
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   476
        self.DisableEvents = False
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   477
        self.RefreshModel()
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   478
        self.RefreshBuffer()
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   479
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   480
    def Find(self, direction, search_params):
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   481
        if self.SearchParams != search_params:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   482
            self.ClearHighlights(SEARCH_RESULT_HIGHLIGHT)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   483
            
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   484
            self.SearchParams = search_params
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   485
            criteria = {
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   486
                "raw_pattern": search_params["find_pattern"], 
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   487
                "pattern": re.compile(search_params["find_pattern"]),
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   488
                "case_sensitive": search_params["case_sensitive"],
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   489
                "regular_expression": search_params["regular_expression"],
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   490
                "filter": "all"}
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   491
            
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   492
            self.SearchResults = [
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   493
                (start, end, SEARCH_RESULT_HIGHLIGHT)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   494
                for start, end, text in 
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   495
                TestTextElement(self.GetText(), criteria)]
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   496
            self.CurrentFindHighlight = None
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   497
        
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   498
        if len(self.SearchResults) > 0:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   499
            if self.CurrentFindHighlight is not None:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   500
                old_idx = self.SearchResults.index(self.CurrentFindHighlight)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   501
                if self.SearchParams["wrap"]:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   502
                    idx = (old_idx + direction) % len(self.SearchResults)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   503
                else:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   504
                    idx = max(0, min(old_idx + direction, len(self.SearchResults) - 1))
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   505
                if idx != old_idx:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   506
                    self.RemoveHighlight(*self.CurrentFindHighlight)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   507
                    self.CurrentFindHighlight = self.SearchResults[idx]
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   508
                    self.AddHighlight(*self.CurrentFindHighlight)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   509
            else:
1178
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   510
                caret_pos = self.GetCurrentPos()
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   511
                if self.SearchParams["wrap"]:
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   512
                    self.CurrentFindHighlight = self.SearchResults[0]
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   513
                else:
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   514
                    self.CurrentFindHighlight = None
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   515
                for start, end, highlight_type in self.SearchResults:
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   516
                    if start[0] == 0:
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   517
                        highlight_start_pos = start[1]
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   518
                    else:
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   519
                        highlight_start_pos = self.GetLineEndPosition(start[0] - 1) + start[1] + 1
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   520
                    if highlight_start_pos >= caret_pos:
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   521
                        self.CurrentFindHighlight = (start, end, highlight_type)
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   522
                        break
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   523
                if self.CurrentFindHighlight is not None:
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   524
                    self.AddHighlight(*self.CurrentFindHighlight)
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   525
            
1101
5a0b439cf576 Fixed search in CodeFileEditor STC panel
Laurent Bessard
parents: 1097
diff changeset
   526
            self.ScrollToLine(self.CurrentFindHighlight[0][0])
5a0b439cf576 Fixed search in CodeFileEditor STC panel
Laurent Bessard
parents: 1097
diff changeset
   527
            
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   528
        else:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   529
            if self.CurrentFindHighlight is not None:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   530
                self.RemoveHighlight(*self.CurrentFindHighlight)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   531
            self.CurrentFindHighlight = None
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   532
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   533
#-------------------------------------------------------------------------------
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   534
#                        Highlights showing functions
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   535
#-------------------------------------------------------------------------------
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   536
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   537
    def OnRefreshHighlightsTimer(self, event):
1101
5a0b439cf576 Fixed search in CodeFileEditor STC panel
Laurent Bessard
parents: 1097
diff changeset
   538
        self.RefreshView(True)
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   539
        event.Skip()
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   540
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   541
    def ClearHighlights(self, highlight_type=None):
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   542
        if highlight_type is None:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   543
            self.Highlights = []
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   544
        else:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   545
            highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   546
            if highlight_type is not None:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   547
                self.Highlights = [(start, end, highlight) for (start, end, highlight) in self.Highlights if highlight != highlight_type]
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   548
        self.RefreshView()
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   549
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   550
    def AddHighlight(self, start, end, highlight_type):
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   551
        highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   552
        if highlight_type is not None:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   553
            self.Highlights.append((start, end, highlight_type))
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   554
            self.GotoPos(self.PositionFromLine(start[0]) + start[1])
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   555
            self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   556
            self.RefreshView()
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   557
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   558
    def RemoveHighlight(self, start, end, highlight_type):
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   559
        highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   560
        if (highlight_type is not None and 
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   561
            (start, end, highlight_type) in self.Highlights):
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   562
            self.Highlights.remove((start, end, highlight_type))
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   563
            self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   564
    
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   565
    def ShowHighlights(self):
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   566
        for start, end, highlight_type in self.Highlights:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   567
            if start[0] == 0:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   568
                highlight_start_pos = start[1]
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   569
            else:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   570
                highlight_start_pos = self.GetLineEndPosition(start[0] - 1) + start[1] + 1
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   571
            if end[0] == 0:
1178
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   572
                highlight_end_pos = end[1] + 1
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   573
            else:
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   574
                highlight_end_pos = self.GetLineEndPosition(end[0] - 1) + end[1] + 2
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   575
            self.StartStyling(highlight_start_pos, 0xff)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   576
            self.SetStyling(highlight_end_pos - highlight_start_pos, highlight_type)
1178
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1161
diff changeset
   577
            self.StartStyling(highlight_end_pos, 0x00)
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   578
            self.SetStyling(len(self.GetText()) - highlight_end_pos, stc.STC_STYLE_DEFAULT)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   579
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   580
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   581
#-------------------------------------------------------------------------------
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   582
#                         Helper for VariablesGrid values
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   583
#-------------------------------------------------------------------------------
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   584
651
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 637
diff changeset
   585
class VariablesTable(CustomTable):
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 637
diff changeset
   586
    
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   587
    def GetValue(self, row, col):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   588
        if row < self.GetNumberRows():
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   589
            if col == 0:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   590
                return row + 1
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   591
            else:
651
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 637
diff changeset
   592
                return str(self.data[row].get(self.GetColLabelValue(col, False), ""))
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 637
diff changeset
   593
    
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   594
    def _updateColAttrs(self, grid):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   595
        """
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   596
        wxGrid -> update the column attributes to add the
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   597
        appropriate renderer given the column name.
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   598
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   599
        Otherwise default to the default renderer.
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   600
        """
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   601
        
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   602
        typelist = None
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   603
        accesslist = None
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   604
        for row in range(self.GetNumberRows()):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   605
            for col in range(self.GetNumberCols()):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   606
                editor = None
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   607
                renderer = None
665
aec7aca89f3e Fixing bug in c_ext plugin variable grid cells not editable
laurent
parents: 658
diff changeset
   608
                colname = self.GetColLabelValue(col, False)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   609
                
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   610
                if colname in ["Name", "Initial"]:
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   611
                    editor = wx.grid.GridCellTextEditor()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   612
                elif colname == "Class":
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   613
                    editor = wx.grid.GridCellChoiceEditor()
603
e1ef99c609eb added memory location support to C file pluguin
Edouard Tisserant
parents: 587
diff changeset
   614
                    editor.SetParameters("input,memory,output")
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   615
                elif colname == "Type":
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   616
                    pass
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   617
                else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   618
                    grid.SetReadOnly(row, col, True)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   619
                
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   620
                grid.SetCellEditor(row, col, editor)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   621
                grid.SetCellRenderer(row, col, renderer)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   622
                
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   623
                grid.SetCellBackgroundColour(row, col, wx.WHITE)
651
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 637
diff changeset
   624
            self.ResizeRow(grid, row)
848
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   625
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   626
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   627
class VariablesEditor(wx.Panel):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   628
    
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   629
    def __init__(self, parent, window, controler):
848
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   630
        wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   631
        
1161
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
   632
        main_sizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=4)
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
   633
        main_sizer.AddGrowableCol(1)
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
   634
        main_sizer.AddGrowableRow(0)
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
   635
        
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
   636
        controls_sizer = wx.BoxSizer(wx.VERTICAL)
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
   637
        main_sizer.AddSizer(controls_sizer, border=5, flag=wx.ALL)
848
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   638
        
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   639
        for name, bitmap, help in [
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   640
                ("AddVariableButton", "add_element", _("Add variable")),
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   641
                ("DeleteVariableButton", "remove_element", _("Remove variable")),
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   642
                ("UpVariableButton", "up", _("Move variable up")),
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   643
                ("DownVariableButton", "down", _("Move variable down"))]:
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   644
            button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap), 
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   645
                  size=wx.Size(28, 28), style=wx.NO_BORDER)
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   646
            button.SetToolTipString(help)
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   647
            setattr(self, name, button)
1161
2d6ec60c48de Moved CodeFileEditor Variable Panel button to grid left
Laurent Bessard
parents: 1152
diff changeset
   648
            controls_sizer.AddWindow(button, border=5, flag=wx.BOTTOM)
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   649
        
1152
0a8fbd2a00f7 Fixed bug scrollbar not displayed in CodeFileEditor VariablePanel when grid is to small to show all variables
Laurent Bessard
parents: 1150
diff changeset
   650
        self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL)
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   651
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnVariablesGridCellChange)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   652
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnVariablesGridCellLeftClick)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   653
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnVariablesGridEditorShown)
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   654
        main_sizer.AddWindow(self.VariablesGrid, flag=wx.GROW)
848
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   655
        
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   656
        self.SetSizer(main_sizer)
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   657
                
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   658
        self.ParentWindow = window
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   659
        self.Controler = controler
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   660
        
1146
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   661
        self.VariablesDefaultValue = {"Name" : "", "Type" : "INT", "Initial": ""}
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   662
        self.Table = VariablesTable(self, [], ["#", "Name", "Type", "Initial"])
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   663
        self.ColAlignements = [wx.ALIGN_RIGHT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT]
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   664
        self.ColSizes = [40, 200, 150, 150]
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   665
        self.VariablesGrid.SetTable(self.Table)
626
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   666
        self.VariablesGrid.SetButtons({"Add": self.AddVariableButton,
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   667
                                       "Delete": self.DeleteVariableButton,
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   668
                                       "Up": self.UpVariableButton,
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   669
                                       "Down": self.DownVariableButton})
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   670
        
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   671
        def _AddVariable(new_row):
1146
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   672
            if new_row > 0:
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   673
                row_content = self.Table.data[new_row - 1].copy()
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   674
                result = VARIABLE_NAME_SUFFIX_MODEL.search(row_content["Name"])
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   675
                if result is not None:
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   676
                    name = row_content["Name"][:result.start(1)]
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   677
                    suffix = result.group(1)
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   678
                    if suffix != "":
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   679
                        start_idx = int(suffix)
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   680
                    else:
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   681
                        start_idx = 0
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   682
                else:
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   683
                    name = row_content["Name"]
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   684
                    start_idx = 0
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   685
                row_content["Name"] = self.Controler.GenerateNewName(
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   686
                        name + "%d", start_idx)
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   687
            else:
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   688
                row_content = self.VariablesDefaultValue.copy()
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   689
            self.Table.InsertRow(new_row, row_content)
626
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   690
            self.RefreshModel()
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   691
            self.RefreshView()
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   692
            return new_row
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   693
        setattr(self.VariablesGrid, "_AddRow", _AddVariable)
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   694
        
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   695
        def _DeleteVariable(row):
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   696
            self.Table.RemoveRow(row)
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   697
            self.RefreshModel()
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   698
            self.RefreshView()
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   699
        setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable)
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   700
        
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   701
        def _MoveVariable(row, move):
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   702
            new_row = self.Table.MoveRow(row, move)
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   703
            if new_row != row:
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   704
                self.RefreshModel()
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   705
                self.RefreshView()
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   706
            return new_row
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   707
        setattr(self.VariablesGrid, "_MoveRow", _MoveVariable)
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   708
        
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   709
        self.VariablesGrid.SetRowLabelSize(0)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   710
        for col in range(self.Table.GetNumberCols()):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   711
            attr = wx.grid.GridCellAttr()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   712
            attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   713
            self.VariablesGrid.SetColAttr(col, attr)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   714
            self.VariablesGrid.SetColSize(col, self.ColSizes[col])
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   715
        self.Table.ResetView(self.VariablesGrid)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   716
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   717
    def RefreshModel(self):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   718
        self.Controler.SetVariables(self.Table.GetData())
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   719
        self.RefreshBuffer()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   720
        
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   721
    # Buffer the last model state
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   722
    def RefreshBuffer(self):
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   723
        self.Controler.BufferCodeFile()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   724
        self.ParentWindow.RefreshTitle()
587
c6354f7fe26e Restore RefreshFileMenu in CFileEditor
Edouard Tisserant
parents: 586
diff changeset
   725
        self.ParentWindow.RefreshFileMenu()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   726
        self.ParentWindow.RefreshEditMenu()
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   727
        self.ParentWindow.RefreshPageTitles()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   728
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   729
    def RefreshView(self):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   730
        self.Table.SetData(self.Controler.GetVariables())
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   731
        self.Table.ResetView(self.VariablesGrid)
626
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   732
        self.VariablesGrid.RefreshButtons()
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   733
    
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   734
    def DoGetBestSize(self):
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   735
        return self.ParentWindow.GetPanelBestSize()
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   736
    
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   737
    def OnVariablesGridCellChange(self, event):
1146
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   738
        row, col = event.GetRow(), event.GetCol()
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   739
        colname = self.Table.GetColLabelValue(col, False)
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   740
        value = self.Table.GetValue(row, col)
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   741
        message = None
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   742
        
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   743
        if colname == "Name" and value != "":
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   744
            if not TestIdentifier(value):
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   745
                message = _("\"%s\" is not a valid identifier!") % value
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   746
            elif value.upper() in IEC_KEYWORDS:
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   747
                message = _("\"%s\" is a keyword. It can't be used!") % value
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   748
            elif value.upper() in [var["Name"].upper() 
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   749
                                   for var_row, var in enumerate(self.Table.data) 
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   750
                                   if var_row != row]:
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   751
                message = _("A variable with \"%s\" as name already exists!") % value
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   752
            else:
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   753
                self.RefreshModel()
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   754
                wx.CallAfter(self.RefreshView)
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   755
        else:
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   756
            self.RefreshModel()
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   757
            wx.CallAfter(self.RefreshView)
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   758
        
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   759
        if message is not None:
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   760
            dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   761
            dialog.ShowModal()
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   762
            dialog.Destroy()
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   763
            event.Veto()
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   764
        else:
510d1ea1f6c1 Fixed variable panel in CodeFileEditor
Laurent Bessard
parents: 1139
diff changeset
   765
            event.Skip()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   766
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   767
    def OnVariablesGridEditorShown(self, event):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   768
        row, col = event.GetRow(), event.GetCol() 
801
435e49e80832 Update list of messages to be translated for internationalization and french translations
laurent
parents: 782
diff changeset
   769
        if self.Table.GetColLabelValue(col, False) == "Type":
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   770
            type_menu = wx.Menu(title='')
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   771
            base_menu = wx.Menu(title='')
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   772
            for base_type in self.Controler.GetBaseTypes():
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   773
                new_id = wx.NewId()
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   774
                base_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   775
                self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   776
            type_menu.AppendMenu(wx.NewId(), "Base Types", base_menu)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   777
            datatype_menu = wx.Menu(title='')
1097
233681f2a00e Fixed Python editor adding variable panel
Laurent Bessard
parents: 1096
diff changeset
   778
            for datatype in self.Controler.GetDataTypes():
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   779
                new_id = wx.NewId()
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   780
                datatype_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   781
                self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   782
            type_menu.AppendMenu(wx.NewId(), "User Data Types", datatype_menu)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   783
            rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col))
708
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 675
diff changeset
   784
            
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   785
            self.VariablesGrid.PopupMenuXY(type_menu, rect.x + rect.width, rect.y + self.VariablesGrid.GetColLabelSize())
708
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 675
diff changeset
   786
            type_menu.Destroy()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   787
            event.Veto()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   788
        else:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   789
            event.Skip()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   790
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   791
    def GetVariableTypeFunction(self, base_type):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   792
        def VariableTypeFunction(event):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   793
            row = self.VariablesGrid.GetGridCursorRow()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   794
            self.Table.SetValueByName(row, "Type", base_type)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   795
            self.Table.ResetView(self.VariablesGrid)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   796
            self.RefreshModel()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   797
            self.RefreshView()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   798
            event.Skip()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   799
        return VariableTypeFunction
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   800
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   801
    def OnVariablesGridCellLeftClick(self, event):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   802
        if event.GetCol() == 0:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   803
            row = event.GetRow()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   804
            data_type = self.Table.GetValueByName(row, "Type")
401
8106a853a7c7 Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents: 213
diff changeset
   805
            var_name = self.Table.GetValueByName(row, "Name")
1138
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   806
            data = wx.TextDataObject(str((var_name, "Global", data_type, 
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   807
                    self.Controler.GetCurrentLocation())))
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   808
            dragSource = wx.DropSource(self.VariablesGrid)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   809
            dragSource.SetData(data)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   810
            dragSource.DoDragDrop()
874
8b24e9312f18 Fix bug when Drag'n Dropping located variables on Windows
Laurent Bessard
parents: 848
diff changeset
   811
            return
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   812
        event.Skip()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   813
    
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   814
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   815
#-------------------------------------------------------------------------------
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   816
#                          CodeFileEditor Main Frame Class
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   817
#-------------------------------------------------------------------------------
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   818
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   819
class CodeFileEditor(ConfTreeNodeEditor):
738
413946c04c87 refactoring
laurent
parents: 734
diff changeset
   820
    
1138
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   821
    CONFNODEEDITOR_TABS = []
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   822
    CODE_EDITOR = None
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   823
    
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   824
    def _create_CodePanel(self, prnt):
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   825
        self.CodeEditorPanel = wx.SplitterWindow(prnt)
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   826
        self.CodeEditorPanel.SetMinimumPaneSize(1)
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   827
        
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   828
        self.VariablesPanel = VariablesEditor(self.CodeEditorPanel, 
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   829
                self.ParentWindow, self.Controler)
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   830
        
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   831
        if self.CODE_EDITOR is not None:
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   832
            self.CodeEditor = self.CODE_EDITOR(self.CodeEditorPanel, 
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   833
                        self.ParentWindow, self.Controler)
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   834
            
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   835
            self.CodeEditorPanel.SplitHorizontally(self.VariablesPanel, 
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   836
                    self.CodeEditor, 150)
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   837
        else:
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   838
            self.CodeEditorPanel.Initialize(self.VariablesPanel)
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   839
        
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   840
        return self.CodeEditorPanel
738
413946c04c87 refactoring
laurent
parents: 734
diff changeset
   841
    
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   842
    def __init__(self, parent, controler, window):
743
4645a3a398ad Fix bugs with ConfigTreeNode
laurent
parents: 738
diff changeset
   843
        ConfTreeNodeEditor.__init__(self, parent, controler, window)
1138
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   844
        
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   845
        wx.CallAfter(self.CodeEditorPanel.SetSashPosition, 150)
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   846
    
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   847
    def GetBufferState(self):
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   848
        return self.Controler.GetBufferState()
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   849
        
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   850
    def Undo(self):
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   851
        self.Controler.LoadPrevious()
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   852
        self.RefreshView()
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   853
            
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   854
    def Redo(self):
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   855
        self.Controler.LoadNext()
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   856
        self.RefreshView()
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   857
    
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   858
    def RefreshView(self):
751
a8dace95f965 Fixing bug on ConfNodeEditors refresh
laurent
parents: 744
diff changeset
   859
        ConfTreeNodeEditor.RefreshView(self)
a8dace95f965 Fixing bug on ConfNodeEditors refresh
laurent
parents: 744
diff changeset
   860
        
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   861
        self.VariablesPanel.RefreshView()
1138
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   862
        self.CodeEditor.RefreshView()
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   863
    
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   864
    def Find(self, direction, search_params):
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   865
        self.CodeEditor.Find(direction, search_params)
cf2a6a7c87e8 Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
Laurent Bessard
parents: 1136
diff changeset
   866