plugins/c_ext/CppSTC.py
author etisserant
Mon, 24 Sep 2007 17:08:54 +0200
changeset 54 ff82e7088ec5
parent 31 33b38700d0db
permissions -rw-r--r--
Comments...
31
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
     1
import  wx
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
     2
import  wx.stc  as  stc
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
     3
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
     4
#----------------------------------------------------------------------
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
     5
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
     6
demoText = """\
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
     7
## This version of the editor has been set up to edit Python source
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
     8
## code.  Here is a copy of wxPython/demo/Main.py to play with.
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
     9
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    10
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    11
"""
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    12
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    13
#----------------------------------------------------------------------
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    14
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    15
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    16
if wx.Platform == '__WXMSW__':
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    17
    faces = { 'times': 'Times New Roman',
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    18
              'mono' : 'Courier New',
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    19
              'helv' : 'Arial',
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    20
              'other': 'Comic Sans MS',
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    21
              'size' : 10,
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    22
              'size2': 8,
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    23
             }
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    24
else:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    25
    faces = { 'times': 'Times',
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    26
              'mono' : 'Courier',
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    27
              'helv' : 'Helvetica',
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    28
              'other': 'new century schoolbook',
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    29
              'size' : 12,
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    30
              'size2': 10,
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    31
             }
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    32
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    33
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    34
#----------------------------------------------------------------------
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    35
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    36
class CppSTC(stc.StyledTextCtrl):
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    37
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    38
    fold_symbols = 3
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    39
    
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    40
    def __init__(self, parent, ID,
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    41
                 pos=wx.DefaultPosition, size=wx.DefaultSize,
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    42
                 style=0):
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    43
        stc.StyledTextCtrl.__init__(self, parent, ID, pos, size, style)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    44
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    45
        self.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    46
        self.CmdKeyAssign(ord('N'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    47
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    48
        self.SetLexer(stc.STC_LEX_CPP)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    49
        #self.SetKeyWords(0, " ".join(keyword.kwlist))
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    50
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    51
        self.SetProperty("fold", "1")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    52
        self.SetProperty("tab.timmy.whinge.level", "1")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    53
        self.SetMargins(0,0)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    54
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    55
        self.SetViewWhiteSpace(False)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    56
        #self.SetBufferedDraw(False)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    57
        #self.SetViewEOL(True)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    58
        #self.SetEOLMode(stc.STC_EOL_CRLF)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    59
        #self.SetUseAntiAliasing(True)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    60
        
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    61
        self.SetEdgeMode(stc.STC_EDGE_BACKGROUND)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    62
        self.SetEdgeColumn(78)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    63
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    64
        # Setup a margin to hold fold markers
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    65
        #self.SetFoldFlags(16)  ###  WHAT IS THIS VALUE?  WHAT ARE THE OTHER FLAGS?  DOES IT MATTER?
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    66
        self.SetMarginType(2, stc.STC_MARGIN_SYMBOL)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    67
        self.SetMarginMask(2, stc.STC_MASK_FOLDERS)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    68
        self.SetMarginSensitive(2, True)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    69
        self.SetMarginWidth(2, 12)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    70
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    71
        if self.fold_symbols == 0:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    72
            # Arrow pointing right for contracted folders, arrow pointing down for expanded
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    73
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_ARROWDOWN, "black", "black")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    74
            self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_ARROW, "black", "black")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    75
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_EMPTY, "black", "black")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    76
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_EMPTY, "black", "black")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    77
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_EMPTY,     "white", "black")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    78
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY,     "white", "black")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    79
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY,     "white", "black")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    80
            
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    81
        elif self.fold_symbols == 1:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    82
            # Plus for contracted folders, minus for expanded
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    83
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_MINUS, "white", "black")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    84
            self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_PLUS,  "white", "black")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    85
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_EMPTY, "white", "black")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    86
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_EMPTY, "white", "black")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    87
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_EMPTY, "white", "black")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    88
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    89
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    90
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    91
        elif self.fold_symbols == 2:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    92
            # Like a flattened tree control using circular headers and curved joins
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    93
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_CIRCLEMINUS,          "white", "#404040")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    94
            self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_CIRCLEPLUS,           "white", "#404040")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    95
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_VLINE,                "white", "#404040")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    96
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_LCORNERCURVE,         "white", "#404040")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    97
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_CIRCLEPLUSCONNECTED,  "white", "#404040")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    98
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_CIRCLEMINUSCONNECTED, "white", "#404040")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    99
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNERCURVE,         "white", "#404040")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   100
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   101
        elif self.fold_symbols == 3:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   102
            # Like a flattened tree control using square headers
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   103
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_BOXMINUS,          "white", "#808080")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   104
            self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_BOXPLUS,           "white", "#808080")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   105
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_VLINE,             "white", "#808080")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   106
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_LCORNER,           "white", "#808080")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   107
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_BOXPLUSCONNECTED,  "white", "#808080")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   108
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   109
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNER,           "white", "#808080")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   110
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   111
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   112
        self.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUI)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   113
        self.Bind(stc.EVT_STC_MARGINCLICK, self.OnMarginClick)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   114
        self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   115
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   116
        # Make some styles,  The lexer defines what each style is used for, we
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   117
        # just have to define what each style looks like.  This set is adapted from
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   118
        # Scintilla sample property files.
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   119
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   120
        # Global default styles for all languages
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   121
        self.StyleSetSpec(stc.STC_STYLE_DEFAULT,     "face:%(mono)s,size:%(size)d" % faces)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   122
        self.StyleClearAll()  # Reset all to be like the default
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   123
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   124
        # Global default styles for all languages
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   125
        self.StyleSetSpec(stc.STC_STYLE_DEFAULT,     "face:%(mono)s,size:%(size)d" % faces)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   126
        self.StyleSetSpec(stc.STC_STYLE_LINENUMBER,  "back:#C0C0C0,face:%(helv)s,size:%(size2)d" % faces)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   127
        self.StyleSetSpec(stc.STC_STYLE_CONTROLCHAR, "face:%(other)s" % faces)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   128
        self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT,  "fore:#FFFFFF,back:#0000FF,bold")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   129
        self.StyleSetSpec(stc.STC_STYLE_BRACEBAD,    "fore:#000000,back:#FF0000,bold")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   130
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   131
        self.StyleSetSpec(stc.STC_C_COMMENT, 'fore:#dcc000')
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   132
        self.StyleSetSpec(stc.STC_C_COMMENTLINE, 'fore:#dcc000')
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   133
        self.StyleSetSpec(stc.STC_C_COMMENTDOC, 'fore:#dcc000')
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   134
        self.StyleSetSpec(stc.STC_C_NUMBER, 'fore:#0076AE')
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   135
        self.StyleSetSpec(stc.STC_C_WORD, 'bold,fore:#004080')
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   136
        self.StyleSetSpec(stc.STC_C_STRING, 'fore:#800080')
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   137
        self.StyleSetSpec(stc.STC_C_PREPROCESSOR, 'fore:#808000')
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   138
        self.StyleSetSpec(stc.STC_C_OPERATOR, 'bold')
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   139
        self.StyleSetSpec(stc.STC_C_STRINGEOL, 'back:#FFD5FF')
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   140
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   141
        """
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   142
        # Python styles
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   143
        # Default 
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   144
        self.StyleSetSpec(stc.STC_P_DEFAULT, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   145
        # Comments
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   146
        self.StyleSetSpec(stc.STC_P_COMMENTLINE, "fore:#007F00,face:%(other)s,size:%(size)d" % faces)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   147
        # Number
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   148
        self.StyleSetSpec(stc.STC_P_NUMBER, "fore:#007F7F,size:%(size)d" % faces)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   149
        # String
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   150
        self.StyleSetSpec(stc.STC_P_STRING, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   151
        # Single quoted string
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   152
        self.StyleSetSpec(stc.STC_P_CHARACTER, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   153
        # Keyword
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   154
        self.StyleSetSpec(stc.STC_P_WORD, "fore:#00007F,bold,size:%(size)d" % faces)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   155
        # Triple quotes
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   156
        self.StyleSetSpec(stc.STC_P_TRIPLE, "fore:#7F0000,size:%(size)d" % faces)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   157
        # Triple double quotes
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   158
        self.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, "fore:#7F0000,size:%(size)d" % faces)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   159
        # Class name definition
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   160
        self.StyleSetSpec(stc.STC_P_CLASSNAME, "fore:#0000FF,bold,underline,size:%(size)d" % faces)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   161
        # Function or method name definition
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   162
        self.StyleSetSpec(stc.STC_P_DEFNAME, "fore:#007F7F,bold,size:%(size)d" % faces)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   163
        # Operators
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   164
        self.StyleSetSpec(stc.STC_P_OPERATOR, "bold,size:%(size)d" % faces)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   165
        # Identifiers
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   166
        self.StyleSetSpec(stc.STC_P_IDENTIFIER, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   167
        # Comment-blocks
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   168
        self.StyleSetSpec(stc.STC_P_COMMENTBLOCK, "fore:#7F7F7F,size:%(size)d" % faces)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   169
        # End of line where string is not closed
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   170
        self.StyleSetSpec(stc.STC_P_STRINGEOL, "fore:#000000,face:%(mono)s,back:#E0C0E0,eol,size:%(size)d" % faces)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   171
        """
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   172
        self.SetCaretForeground("BLUE")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   173
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   174
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   175
        # register some images for use in the AutoComplete box.
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   176
        #self.RegisterImage(1, images.getSmilesBitmap())
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   177
        self.RegisterImage(1, 
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   178
            wx.ArtProvider.GetBitmap(wx.ART_DELETE, size=(16,16)))
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   179
        self.RegisterImage(2, 
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   180
            wx.ArtProvider.GetBitmap(wx.ART_NEW, size=(16,16)))
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   181
        self.RegisterImage(3, 
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   182
            wx.ArtProvider.GetBitmap(wx.ART_COPY, size=(16,16)))
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   183
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   184
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   185
    def OnKeyPressed(self, event):
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   186
        if self.CallTipActive():
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   187
            self.CallTipCancel()
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   188
        key = event.KeyCode()
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   189
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   190
        if key == 32 and event.ControlDown():
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   191
            pos = self.GetCurrentPos()
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   192
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   193
            # Tips
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   194
            if event.ShiftDown():
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   195
                self.CallTipSetBackground("yellow")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   196
                self.CallTipShow(pos, 'lots of of text: blah, blah, blah\n\n'
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   197
                                 'show some suff, maybe parameters..\n\n'
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   198
                                 'fubar(param1, param2)')
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   199
            # Code completion
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   200
            else:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   201
                #lst = []
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   202
                #for x in range(50000):
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   203
                #    lst.append('%05d' % x)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   204
                #st = " ".join(lst)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   205
                #print len(st)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   206
                #self.AutoCompShow(0, st)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   207
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   208
                #kw = keyword.kwlist[:]
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   209
                kw = []
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   210
                """
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   211
                kw.append("zzzzzz?2")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   212
                kw.append("aaaaa?2")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   213
                kw.append("__init__?3")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   214
                kw.append("zzaaaaa?2")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   215
                kw.append("zzbaaaa?2")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   216
                kw.append("this_is_a_longer_value")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   217
                """
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   218
                #kw.append("this_is_a_much_much_much_much_much_much_much_longer_value")
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   219
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   220
                kw.sort()  # Python sorts are case sensitive
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   221
                self.AutoCompSetIgnoreCase(False)  # so this needs to match
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   222
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   223
                # Images are specified with a appended "?type"
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   224
                for i in range(len(kw)):
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   225
                    if kw[i] in keyword.kwlist:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   226
                        kw[i] = kw[i] + "?1"
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   227
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   228
                self.AutoCompShow(0, " ".join(kw))
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   229
        else:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   230
            event.Skip()
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   231
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   232
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   233
    def OnUpdateUI(self, evt):
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   234
        # check for matching braces
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   235
        braceAtCaret = -1
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   236
        braceOpposite = -1
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   237
        charBefore = None
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   238
        caretPos = self.GetCurrentPos()
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   239
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   240
        if caretPos > 0:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   241
            charBefore = self.GetCharAt(caretPos - 1)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   242
            styleBefore = self.GetStyleAt(caretPos - 1)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   243
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   244
        # check before
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   245
        if charBefore and chr(charBefore) in "[]{}()" and styleBefore == stc.STC_P_OPERATOR:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   246
            braceAtCaret = caretPos - 1
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   247
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   248
        # check after
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   249
        if braceAtCaret < 0:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   250
            charAfter = self.GetCharAt(caretPos)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   251
            styleAfter = self.GetStyleAt(caretPos)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   252
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   253
            if charAfter and chr(charAfter) in "[]{}()" and styleAfter == stc.STC_P_OPERATOR:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   254
                braceAtCaret = caretPos
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   255
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   256
        if braceAtCaret >= 0:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   257
            braceOpposite = self.BraceMatch(braceAtCaret)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   258
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   259
        if braceAtCaret != -1  and braceOpposite == -1:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   260
            self.BraceBadLight(braceAtCaret)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   261
        else:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   262
            self.BraceHighlight(braceAtCaret, braceOpposite)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   263
            #pt = self.PointFromPosition(braceOpposite)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   264
            #self.Refresh(True, wxRect(pt.x, pt.y, 5,5))
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   265
            #print pt
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   266
            #self.Refresh(False)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   267
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   268
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   269
    def OnMarginClick(self, evt):
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   270
        # fold and unfold as needed
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   271
        if evt.GetMargin() == 2:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   272
            if evt.GetShift() and evt.GetControl():
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   273
                self.FoldAll()
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   274
            else:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   275
                lineClicked = self.LineFromPosition(evt.GetPosition())
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   276
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   277
                if self.GetFoldLevel(lineClicked) & stc.STC_FOLDLEVELHEADERFLAG:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   278
                    if evt.GetShift():
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   279
                        self.SetFoldExpanded(lineClicked, True)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   280
                        self.Expand(lineClicked, True, True, 1)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   281
                    elif evt.GetControl():
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   282
                        if self.GetFoldExpanded(lineClicked):
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   283
                            self.SetFoldExpanded(lineClicked, False)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   284
                            self.Expand(lineClicked, False, True, 0)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   285
                        else:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   286
                            self.SetFoldExpanded(lineClicked, True)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   287
                            self.Expand(lineClicked, True, True, 100)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   288
                    else:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   289
                        self.ToggleFold(lineClicked)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   290
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   291
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   292
    def FoldAll(self):
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   293
        lineCount = self.GetLineCount()
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   294
        expanding = True
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   295
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   296
        # find out if we are folding or unfolding
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   297
        for lineNum in range(lineCount):
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   298
            if self.GetFoldLevel(lineNum) & stc.STC_FOLDLEVELHEADERFLAG:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   299
                expanding = not self.GetFoldExpanded(lineNum)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   300
                break
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   301
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   302
        lineNum = 0
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   303
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   304
        while lineNum < lineCount:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   305
            level = self.GetFoldLevel(lineNum)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   306
            if level & stc.STC_FOLDLEVELHEADERFLAG and \
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   307
               (level & stc.STC_FOLDLEVELNUMBERMASK) == stc.STC_FOLDLEVELBASE:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   308
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   309
                if expanding:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   310
                    self.SetFoldExpanded(lineNum, True)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   311
                    lineNum = self.Expand(lineNum, True)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   312
                    lineNum = lineNum - 1
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   313
                else:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   314
                    lastChild = self.GetLastChild(lineNum, -1)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   315
                    self.SetFoldExpanded(lineNum, False)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   316
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   317
                    if lastChild > lineNum:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   318
                        self.HideLines(lineNum+1, lastChild)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   319
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   320
            lineNum = lineNum + 1
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   321
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   322
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   323
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   324
    def Expand(self, line, doExpand, force=False, visLevels=0, level=-1):
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   325
        lastChild = self.GetLastChild(line, level)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   326
        line = line + 1
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   327
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   328
        while line <= lastChild:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   329
            if force:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   330
                if visLevels > 0:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   331
                    self.ShowLines(line, line)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   332
                else:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   333
                    self.HideLines(line, line)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   334
            else:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   335
                if doExpand:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   336
                    self.ShowLines(line, line)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   337
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   338
            if level == -1:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   339
                level = self.GetFoldLevel(line)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   340
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   341
            if level & stc.STC_FOLDLEVELHEADERFLAG:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   342
                if force:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   343
                    if visLevels > 1:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   344
                        self.SetFoldExpanded(line, True)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   345
                    else:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   346
                        self.SetFoldExpanded(line, False)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   347
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   348
                    line = self.Expand(line, doExpand, force, visLevels-1)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   349
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   350
                else:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   351
                    if doExpand and self.GetFoldExpanded(line):
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   352
                        line = self.Expand(line, True, force, visLevels-1)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   353
                    else:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   354
                        line = self.Expand(line, False, force, visLevels-1)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   355
            else:
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   356
                line = line + 1
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   357
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   358
        return line
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   359