c_ext/CFileEditor.py
changeset 1060 ac9896336b90
parent 920 1499a4d225db
child 1066 b6a5ae4a68d7
equal deleted inserted replaced
1059:50246061d5c6 1060:ac9896336b90
     6 import wx.lib.buttons
     6 import wx.lib.buttons
     7 
     7 
     8 from controls import CustomGrid, CustomTable
     8 from controls import CustomGrid, CustomTable
     9 from editors.ConfTreeNodeEditor import ConfTreeNodeEditor, SCROLLBAR_UNIT
     9 from editors.ConfTreeNodeEditor import ConfTreeNodeEditor, SCROLLBAR_UNIT
    10 from util.BitmapLibrary import GetBitmap
    10 from util.BitmapLibrary import GetBitmap
    11 
    11 from editors.TextViewer import GetCursorPos, faces
    12 if wx.Platform == '__WXMSW__':
       
    13     faces = { 'times': 'Times New Roman',
       
    14               'mono' : 'Courier New',
       
    15               'helv' : 'Arial',
       
    16               'other': 'Comic Sans MS',
       
    17               'size' : 10,
       
    18               'size2': 8,
       
    19              }
       
    20 else:
       
    21     faces = { 'times': 'Times',
       
    22               'mono' : 'Courier',
       
    23               'helv' : 'Helvetica',
       
    24               'other': 'new century schoolbook',
       
    25               'size' : 12,
       
    26               'size2': 10,
       
    27              }
       
    28 
       
    29 
    12 
    30 def AppendMenu(parent, help, id, kind, text):
    13 def AppendMenu(parent, help, id, kind, text):
    31     if wx.VERSION >= (2, 6, 0):
    14     if wx.VERSION >= (2, 6, 0):
    32         parent.Append(help=help, id=id, kind=kind, text=text)
    15         parent.Append(help=help, id=id, kind=kind, text=text)
    33     else:
    16     else:
    44     "namespace", "new", "operator", "private", "protected", "public", "register", 
    27     "namespace", "new", "operator", "private", "protected", "public", "register", 
    45     "reinterpret_cast", "return", "short", "signed", "sizeof", "static", 
    28     "reinterpret_cast", "return", "short", "signed", "sizeof", "static", 
    46     "static_cast", "struct", "switch", "template", "this", "throw", "true", "try",
    29     "static_cast", "struct", "switch", "template", "this", "throw", "true", "try",
    47     "typedef", "typeid", "typename", "union", "unsigned", "using", "virtual", 
    30     "typedef", "typeid", "typename", "union", "unsigned", "using", "virtual", 
    48     "void", "volatile", "wchar_t", "while"]
    31     "void", "volatile", "wchar_t", "while"]
    49 
       
    50 def GetCursorPos(old, new):
       
    51     old_length = len(old)
       
    52     new_length = len(new)
       
    53     common_length = min(old_length, new_length)
       
    54     i = 0
       
    55     for i in xrange(common_length):
       
    56         if old[i] != new[i]:
       
    57             break
       
    58     if old_length < new_length:
       
    59         if common_length > 0 and old[i] != new[i]:
       
    60             return i + new_length - old_length
       
    61         else:
       
    62             return i + new_length - old_length + 1
       
    63     elif old_length > new_length or i < min(old_length, new_length) - 1:
       
    64         if common_length > 0 and old[i] != new[i]:
       
    65             return i
       
    66         else:
       
    67             return i + 1
       
    68     else:
       
    69         return None
       
    70 
    32 
    71 class CppEditor(stc.StyledTextCtrl):
    33 class CppEditor(stc.StyledTextCtrl):
    72 
    34 
    73     fold_symbols = 3
    35     fold_symbols = 3
    74     
    36     
   163         self.StyleSetSpec(stc.STC_STYLE_LINENUMBER,  "back:#C0C0C0,face:%(helv)s,size:%(size2)d" % faces)
   125         self.StyleSetSpec(stc.STC_STYLE_LINENUMBER,  "back:#C0C0C0,face:%(helv)s,size:%(size2)d" % faces)
   164         self.StyleSetSpec(stc.STC_STYLE_CONTROLCHAR, "face:%(other)s" % faces)
   126         self.StyleSetSpec(stc.STC_STYLE_CONTROLCHAR, "face:%(other)s" % faces)
   165         self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT,  "fore:#FFFFFF,back:#0000FF,bold")
   127         self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT,  "fore:#FFFFFF,back:#0000FF,bold")
   166         self.StyleSetSpec(stc.STC_STYLE_BRACEBAD,    "fore:#000000,back:#FF0000,bold")
   128         self.StyleSetSpec(stc.STC_STYLE_BRACEBAD,    "fore:#000000,back:#FF0000,bold")
   167 
   129 
   168         self.StyleSetSpec(stc.STC_C_COMMENT, 'fore:#408060')
   130         self.StyleSetSpec(stc.STC_C_COMMENT, 'fore:#408060,size:%(size)d' % faces)
   169         self.StyleSetSpec(stc.STC_C_COMMENTLINE, 'fore:#408060')
   131         self.StyleSetSpec(stc.STC_C_COMMENTLINE, 'fore:#408060,size:%(size)d' % faces)
   170         self.StyleSetSpec(stc.STC_C_COMMENTDOC, 'fore:#408060')
   132         self.StyleSetSpec(stc.STC_C_COMMENTDOC, 'fore:#408060,size:%(size)d' % faces)
   171         self.StyleSetSpec(stc.STC_C_NUMBER, 'fore:#0076AE')
   133         self.StyleSetSpec(stc.STC_C_NUMBER, 'fore:#0076AE,size:%(size)d' % faces)
   172         self.StyleSetSpec(stc.STC_C_WORD, 'bold,fore:#800056')
   134         self.StyleSetSpec(stc.STC_C_WORD, 'bold,fore:#800056,size:%(size)d' % faces)
   173         self.StyleSetSpec(stc.STC_C_STRING, 'fore:#2a00ff')
   135         self.StyleSetSpec(stc.STC_C_STRING, 'fore:#2a00ff,size:%(size)d' % faces)
   174         self.StyleSetSpec(stc.STC_C_PREPROCESSOR, 'bold,fore:#800056')
   136         self.StyleSetSpec(stc.STC_C_PREPROCESSOR, 'bold,fore:#800056,size:%(size)d' % faces)
   175         self.StyleSetSpec(stc.STC_C_OPERATOR, 'bold')
   137         self.StyleSetSpec(stc.STC_C_OPERATOR, 'bold,size:%(size)d' % faces)
   176         self.StyleSetSpec(stc.STC_C_STRINGEOL, 'back:#FFD5FF')
   138         self.StyleSetSpec(stc.STC_C_STRINGEOL, 'back:#FFD5FF,size:%(size)d' % faces)
   177         
   139         
   178         # register some images for use in the AutoComplete box.
   140         # register some images for use in the AutoComplete box.
   179         #self.RegisterImage(1, images.getSmilesBitmap())
   141         #self.RegisterImage(1, images.getSmilesBitmap())
   180         self.RegisterImage(1, 
   142         self.RegisterImage(1, 
   181             wx.ArtProvider.GetBitmap(wx.ART_DELETE, size=(16,16)))
   143             wx.ArtProvider.GetBitmap(wx.ART_DELETE, size=(16,16)))
   252 
   214 
   253     def RefreshView(self):
   215     def RefreshView(self):
   254         self.ResetBuffer()
   216         self.ResetBuffer()
   255         self.DisableEvents = True
   217         self.DisableEvents = True
   256         old_cursor_pos = self.GetCurrentPos()
   218         old_cursor_pos = self.GetCurrentPos()
       
   219         line = self.GetFirstVisibleLine()
       
   220         column = self.GetXOffset()
   257         old_text = self.GetText()
   221         old_text = self.GetText()
   258         new_text = self.Controler.GetPartText(self.Name)
   222         new_text = self.Controler.GetPartText(self.Name)
   259         self.SetText(new_text)
   223         self.SetText(new_text)
   260         new_cursor_pos = GetCursorPos(old_text, new_text)
   224         if old_text != new_text:
   261         if new_cursor_pos != None:
   225             new_cursor_pos = GetCursorPos(old_text, new_text)
   262             self.GotoPos(new_cursor_pos)
   226             self.LineScroll(column, line)
   263         else:
   227             if new_cursor_pos != None:
   264             self.GotoPos(old_cursor_pos)
   228                 self.GotoPos(new_cursor_pos)
   265         self.ScrollToColumn(0)
   229             else:
   266         self.EmptyUndoBuffer()
   230                 self.GotoPos(old_cursor_pos)
       
   231             self.EmptyUndoBuffer()
   267         self.DisableEvents = False
   232         self.DisableEvents = False
   268         
   233         
   269         self.Colourise(0, -1)
   234         self.Colourise(0, -1)
   270 
   235 
   271     def DoGetBestSize(self):
   236     def DoGetBestSize(self):