editors/CodeFileEditor.py
author Laurent Bessard
Wed, 08 May 2013 21:37:31 +0200
changeset 1096 c9ace6a881c9
parent 1095 a73fde048749
child 1097 233681f2a00e
permissions -rw-r--r--
Fixed CFileEditor replacing folding panels by variable panel and STC
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
738
413946c04c87 refactoring
laurent
parents: 734
diff changeset
     8
from controls import CustomGrid, CustomTable
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
     9
from editors.ConfTreeNodeEditor import ConfTreeNodeEditor
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 801
diff changeset
    10
from util.BitmapLibrary import GetBitmap
1091
5f612651d227 Fixed bug with margin cursor in StyledTextCtrl on Windows
Laurent Bessard
parents: 1066
diff changeset
    11
from controls.CustomStyledTextCtrl import CustomStyledTextCtrl, faces, GetCursorPos
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
    12
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    13
SECTIONS_NAMES = ["Includes", "Globals", "Init",
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    14
                  "CleanUp", "Retrieve", "Publish"]
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    15
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    16
class CodeEditor(CustomStyledTextCtrl):
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    17
    
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    18
    KEYWORDS = []
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    19
    COMMENT_HEADER = ""
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    20
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    21
    def __init__(self, parent, window, controler):
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    22
        CustomStyledTextCtrl.__init__(self, parent, -1, wx.DefaultPosition, 
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 874
diff changeset
    23
                 wx.Size(-1, 300), 0)
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
    24
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    25
        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
    26
        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
    27
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    28
        self.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    29
        self.CmdKeyAssign(ord('N'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    30
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    31
        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
    32
        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
    33
        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
    34
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    35
        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
    36
        
94855f7b08a9 Improving c_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.SetEdgeMode(stc.STC_EDGE_BACKGROUND)
94855f7b08a9 Improving c_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
        self.SetEdgeColumn(78)
94855f7b08a9 Improving c_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
94855f7b08a9 Improving c_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
        # 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
    41
        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
    42
        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
    43
        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
    44
        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
    45
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    46
        # 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
    47
        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
    48
        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
    49
        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
    50
        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
    51
        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
    52
        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
    53
        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
    54
        
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
    55
        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
    56
        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
    57
        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
    58
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    59
        # 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
    60
        # 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
    61
        # 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
    62
94855f7b08a9 Improving c_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
        # 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
    64
        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
    65
        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
    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
        # 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
    68
        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
    69
        self.StyleSetSpec(stc.STC_STYLE_LINENUMBER,  "back:#C0C0C0,face:%(helv)s,size:%(size)d" % 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
    70
        self.StyleSetSpec(stc.STC_STYLE_CONTROLCHAR, "face:%(other)s" % 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
    71
        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
    72
        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
    73
        
94855f7b08a9 Improving c_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
        # register some images for use in the AutoComplete box.
94855f7b08a9 Improving c_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
        #self.RegisterImage(1, images.getSmilesBitmap())
94855f7b08a9 Improving c_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.RegisterImage(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
    77
            wx.ArtProvider.GetBitmap(wx.ART_DELETE, size=(16,16)))
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    78
        self.RegisterImage(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
    79
            wx.ArtProvider.GetBitmap(wx.ART_NEW, size=(16,16)))
94855f7b08a9 Improving c_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.RegisterImage(3, 
94855f7b08a9 Improving c_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
            wx.ArtProvider.GetBitmap(wx.ART_COPY, size=(16,16)))
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    82
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    83
        # Indentation size
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    84
        self.SetTabWidth(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
    85
        self.SetUseTabs(0)
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    86
        
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    87
        self.SetCodeLexer()
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    88
        self.SetKeyWords(0, " ".join(self.KEYWORDS))
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
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
        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
    91
        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
    92
        
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
    93
        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
    94
        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
    95
        
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    96
        self.SectionsComments = {}
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    97
        for section in SECTIONS_NAMES:
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    98
            section_start_comment = "%s %s section\n" % (self.COMMENT_HEADER, section)
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
    99
            section_end_comment = "\n%s End %s section\n\n" % (self.COMMENT_HEADER, section)
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   100
            self.SectionsComments[section] = {
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   101
                 "start": section_start_comment,
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   102
                 "end": section_end_comment,
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   103
                 "pattern": re.compile(section_start_comment + 
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   104
                                       "(.*)" + 
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   105
                                       section_end_comment,
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   106
                                       re.DOTALL)
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   107
            }
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   108
        
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
   109
        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
   110
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   111
        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
   112
        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
   113
        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
   114
    
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   115
    def SetCodeLexer(self):
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   116
        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
   117
    
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   118
    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
   119
        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
   120
            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
   121
            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
   122
                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
   123
                    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
   124
                        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
   125
                    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
   126
                        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
   127
                        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
   128
                    self.CurrentAction = ("Add", event.GetPosition())
658
94417ab25510 Fixing some issues in c_ext plugin
laurent
parents: 656
diff changeset
   129
                    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
   130
                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
   131
                    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
   132
                        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
   133
                    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
   134
                        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
   135
                        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
   136
                    self.CurrentAction = ("Delete", event.GetPosition())
658
94417ab25510 Fixing some issues in c_ext plugin
laurent
parents: 656
diff changeset
   137
                    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
   138
        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
   139
    
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   140
    def OnDoDrop(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
   141
        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
   142
        wx.CallAfter(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
   143
        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
   144
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   145
    # 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
   146
    def RefreshBuffer(self):
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   147
        self.Controler.BufferCodeFile()
658
94417ab25510 Fixing some issues in c_ext plugin
laurent
parents: 656
diff changeset
   148
        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
   149
            self.ParentWindow.RefreshTitle()
587
c6354f7fe26e Restore RefreshFileMenu in CFileEditor
Edouard Tisserant
parents: 586
diff changeset
   150
            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
   151
            self.ParentWindow.RefreshEditMenu()
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   152
            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
   153
    
94855f7b08a9 Improving c_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
    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
   155
        self.Controler.StartBuffering()
658
94417ab25510 Fixing some issues in c_ext plugin
laurent
parents: 656
diff changeset
   156
        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
   157
            self.ParentWindow.RefreshTitle()
587
c6354f7fe26e Restore RefreshFileMenu in CFileEditor
Edouard Tisserant
parents: 586
diff changeset
   158
            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
   159
            self.ParentWindow.RefreshEditMenu()
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   160
            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
   161
    
94855f7b08a9 Improving c_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
    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
   163
        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
   164
            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
   165
            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
   166
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   167
    def GetCodeText(self):
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   168
        parts = self.Controler.GetTextParts()
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   169
        text = ""
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   170
        for section in SECTIONS_NAMES:
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   171
            section_comments = self.SectionsComments[section]
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   172
            text += section_comments["start"]
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   173
            text += parts[section]
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   174
            text += section_comments["end"]
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   175
        return text
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   176
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
   177
    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
   178
        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
   179
        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
   180
        old_cursor_pos = self.GetCurrentPos()
1060
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   181
        line = self.GetFirstVisibleLine()
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   182
        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
   183
        old_text = self.GetText()
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   184
        new_text = self.GetCodeText()
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
        self.SetText(new_text)
1060
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   186
        if old_text != new_text:
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   187
            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
   188
            self.LineScroll(column, line)
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   189
            if new_cursor_pos != None:
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   190
                self.GotoPos(new_cursor_pos)
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   191
            else:
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   192
                self.GotoPos(old_cursor_pos)
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 920
diff changeset
   193
            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
   194
        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
   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
        self.Colourise(0, -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
   197
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   198
    def DoGetBestSize(self):
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   199
        return self.ParentWindow.GetPanelBestSize()
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   200
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
    def RefreshModel(self):
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   202
        text = self.GetText()
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   203
        parts = {}
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   204
        for section in SECTIONS_NAMES:
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   205
            section_comments = self.SectionsComments[section]
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   206
            result = section_comments["pattern"].search(text)
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   207
            if result is not None:
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   208
                parts[section] = result.group(1)
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   209
            else:
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   210
                parts[section] = ""
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   211
        self.Controler.SetTextParts(parts)
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
   212
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   213
    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
   214
        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
   215
            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
   216
        key = event.GetKeyCode()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   217
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   218
        if key == 32 and event.ControlDown():
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   219
            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
   220
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   221
            # 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
   222
            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
   223
                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
   224
            # 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
   225
            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
   226
                self.AutoCompSetIgnoreCase(False)  # so this needs to match
94855f7b08a9 Improving c_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
94855f7b08a9 Improving c_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
                # Images are specified with a appended "?type"
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   229
                self.AutoCompShow(0, " ".join([word + "?1" for word in self.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
   230
        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
   231
            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
   232
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   233
    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
   234
        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
   235
        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
   236
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   237
    def OnUpdateUI(self, evt):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   238
        # 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
   239
        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
   240
        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
   241
        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
   242
        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
   243
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   244
        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
   245
            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
   246
            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
   247
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   248
        # 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
   249
        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
   250
            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
   251
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   252
        # 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
   253
        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
   254
            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
   255
            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
   256
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   257
            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
   258
                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
   259
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   260
        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
   261
            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
   262
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   263
        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
   264
            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
   265
        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
   266
            self.BraceHighlight(braceAtCaret, braceOpposite)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   267
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   268
    def OnMarginClick(self, evt):
94855f7b08a9 Improving c_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
        # 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
   270
        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
   271
            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
   272
                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
   273
            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
   274
                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
   275
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   276
                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
   277
                    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
   278
                        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
   279
                        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
   280
                    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
   281
                        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
   282
                            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
   283
                            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
   284
                        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
   285
                            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
   286
                            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
   287
                    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
   288
                        self.ToggleFold(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
   289
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   290
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   291
    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
   292
        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
   293
        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
   294
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   295
        # 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
   296
        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
   297
            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
   298
                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
   299
                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
   300
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   301
        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
   302
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   303
        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
   304
            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
   305
            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
   306
               (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
   307
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   308
                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
   309
                    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
   310
                    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
   311
                    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
   312
                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
   313
                    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
   314
                    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
   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
                    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
   317
                        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
   318
94855f7b08a9 Improving c_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
            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
   320
94855f7b08a9 Improving c_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
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   322
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   323
    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
   324
        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
   325
        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
   326
94855f7b08a9 Improving c_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
        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
   328
            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
   329
                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
   330
                    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
   331
                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
   332
                    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
   333
            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
   334
                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
   335
                    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
   336
94855f7b08a9 Improving c_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
            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
   338
                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
   339
94855f7b08a9 Improving c_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
            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
   341
                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
   342
                    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
   343
                        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
   344
                    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
   345
                        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
   346
94855f7b08a9 Improving c_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
                    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
   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
                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
   350
                    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
   351
                        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
   352
                    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
   353
                        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
   354
            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
   355
                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
   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
        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
   358
637
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   359
    def Cut(self):
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   360
        self.ResetBuffer()
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   361
        self.DisableEvents = True
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   362
        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
   363
        self.DisableEvents = False
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   364
        self.RefreshModel()
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   365
        self.RefreshBuffer()
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   366
    
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   367
    def Copy(self):
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   368
        self.CmdKeyExecute(wx.stc.STC_CMD_COPY)
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   369
    
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   370
    def Paste(self):
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   371
        self.ResetBuffer()
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   372
        self.DisableEvents = True
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   373
        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
   374
        self.DisableEvents = False
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   375
        self.RefreshModel()
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   376
        self.RefreshBuffer()
c19557ec2c5a Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 630
diff changeset
   377
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
   378
94855f7b08a9 Improving c_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
#-------------------------------------------------------------------------------
94855f7b08a9 Improving c_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
#                         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
   381
#-------------------------------------------------------------------------------
94855f7b08a9 Improving c_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
651
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 637
diff changeset
   383
class VariablesTable(CustomTable):
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 637
diff changeset
   384
    
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
   385
    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
   386
        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
   387
            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
   388
                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
   389
            else:
651
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 637
diff changeset
   390
                return str(self.data[row].get(self.GetColLabelValue(col, False), ""))
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 637
diff changeset
   391
    
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
   392
    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
   393
        """
94855f7b08a9 Improving c_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
        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
   395
        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
   396
94855f7b08a9 Improving c_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
        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
   398
        """
94855f7b08a9 Improving c_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
        
94855f7b08a9 Improving c_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
        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
   401
        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
   402
        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
   403
            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
   404
                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
   405
                renderer = None
665
aec7aca89f3e Fixing bug in c_ext plugin variable grid cells not editable
laurent
parents: 658
diff changeset
   406
                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
   407
                
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   408
                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
   409
                    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
   410
                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
   411
                    editor = wx.grid.GridCellChoiceEditor()
603
e1ef99c609eb added memory location support to C file pluguin
Edouard Tisserant
parents: 587
diff changeset
   412
                    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
   413
                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
   414
                    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
   415
                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
   416
                    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
   417
                
94855f7b08a9 Improving c_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
                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
   419
                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
   420
                
94855f7b08a9 Improving c_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
                grid.SetCellBackgroundColour(row, col, wx.WHITE)
651
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 637
diff changeset
   422
            self.ResizeRow(grid, row)
848
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   423
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
   424
94855f7b08a9 Improving c_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
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
   426
    
94855f7b08a9 Improving c_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
    def __init__(self, parent, window, controler):
848
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   428
        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
   429
        
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   430
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=4)
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   431
        main_sizer.AddGrowableCol(0)
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   432
        main_sizer.AddGrowableRow(0)
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   433
        
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 874
diff changeset
   434
        self.VariablesGrid = CustomGrid(self, size=wx.Size(-1, 300), style=wx.VSCROLL)
848
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   435
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnVariablesGridCellChange)
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   436
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnVariablesGridCellLeftClick)
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   437
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnVariablesGridEditorShown)
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   438
        main_sizer.AddWindow(self.VariablesGrid, flag=wx.GROW)
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   439
        
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   440
        controls_sizer = wx.BoxSizer(wx.HORIZONTAL)
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   441
        main_sizer.AddSizer(controls_sizer, border=5, flag=wx.TOP|wx.ALIGN_RIGHT)
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   442
        
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   443
        for name, bitmap, help in [
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   444
                ("AddVariableButton", "add_element", _("Add variable")),
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   445
                ("DeleteVariableButton", "remove_element", _("Remove variable")),
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   446
                ("UpVariableButton", "up", _("Move variable up")),
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   447
                ("DownVariableButton", "down", _("Move variable down"))]:
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   448
            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
   449
                  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
   450
            button.SetToolTipString(help)
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   451
            setattr(self, name, button)
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   452
            controls_sizer.AddWindow(button, border=5, flag=wx.LEFT)
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   453
        
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   454
        self.SetSizer(main_sizer)
fe9504c4104e Replacing text buttons by bitmap buttons for variable grid in CFileEditor
laurent
parents: 814
diff changeset
   455
                
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
   456
        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
   457
        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
   458
        
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   459
        self.VariablesDefaultValue = {"Name" : "", "Type" : "", "Initial": ""}
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   460
        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
   461
        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
   462
        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
   463
        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
   464
        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
   465
                                       "Delete": self.DeleteVariableButton,
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   466
                                       "Up": self.UpVariableButton,
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   467
                                       "Down": self.DownVariableButton})
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   468
        
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   469
        def _AddVariable(new_row):
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   470
            self.Table.InsertRow(new_row, self.VariablesDefaultValue.copy())
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   471
            self.RefreshModel()
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   472
            self.RefreshView()
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   473
            return new_row
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   474
        setattr(self.VariablesGrid, "_AddRow", _AddVariable)
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   475
        
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   476
        def _DeleteVariable(row):
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   477
            self.Table.RemoveRow(row)
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   478
            self.RefreshModel()
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   479
            self.RefreshView()
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   480
        setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable)
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   481
        
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   482
        def _MoveVariable(row, move):
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   483
            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
   484
            if new_row != row:
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   485
                self.RefreshModel()
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   486
                self.RefreshView()
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   487
            return new_row
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   488
        setattr(self.VariablesGrid, "_MoveRow", _MoveVariable)
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   489
        
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
   490
        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
   491
        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
   492
            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
   493
            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
   494
            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
   495
            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
   496
        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
   497
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   498
    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
   499
        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
   500
        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
   501
        
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   502
    # 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
   503
    def RefreshBuffer(self):
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   504
        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
   505
        self.ParentWindow.RefreshTitle()
587
c6354f7fe26e Restore RefreshFileMenu in CFileEditor
Edouard Tisserant
parents: 586
diff changeset
   506
        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
   507
        self.ParentWindow.RefreshEditMenu()
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   508
        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
   509
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   510
    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
   511
        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
   512
        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
   513
        self.VariablesGrid.RefreshButtons()
2b9bd5dcf8d2 Adding support for using keyboard to edit cfile interface variables displayed in Grid
laurent
parents: 610
diff changeset
   514
    
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   515
    def DoGetBestSize(self):
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   516
        return self.ParentWindow.GetPanelBestSize()
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   517
    
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
   518
    def OnVariablesGridCellChange(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
   519
        self.RefreshModel()
656
c1792dfc8c7e Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents: 653
diff changeset
   520
        wx.CallAfter(self.RefreshView)
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
   521
        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
   522
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   523
    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
   524
        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
   525
        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
   526
            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
   527
            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
   528
            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
   529
                new_id = wx.NewId()
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   530
                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
   531
                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
   532
            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
   533
            datatype_menu = wx.Menu(title='')
610
00df5b1db283 Disabling definition of enumerated and structure variables for interfacing with PLC in c_ext plug-in
laurent
parents: 603
diff changeset
   534
            for datatype in self.Controler.GetDataTypes(basetypes=False, only_locatables=True):
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
   535
                new_id = wx.NewId()
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   536
                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
   537
                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
   538
            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
   539
            rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col))
708
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 675
diff changeset
   540
            
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
   541
            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
   542
            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
   543
            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
   544
        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
   545
            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
   546
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   547
    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
   548
        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
   549
            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
   550
            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
   551
            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
   552
            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
   553
            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
   554
            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
   555
        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
   556
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   557
    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
   558
        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
   559
            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
   560
            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
   561
            var_name = self.Table.GetValueByName(row, "Name")
1095
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1091
diff changeset
   562
            location = "_".join(map(lambda x:str(x), self.Controler.GetCurrentLocation()))
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1091
diff changeset
   563
            data = wx.TextDataObject(str(("%s_%s" % (var_name, location), 
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1091
diff changeset
   564
                                          "Global", data_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
   565
            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
   566
            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
   567
            dragSource.DoDragDrop()
874
8b24e9312f18 Fix bug when Drag'n Dropping located variables on Windows
Laurent Bessard
parents: 848
diff changeset
   568
            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
   569
        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
   570
    
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   571
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   572
#-------------------------------------------------------------------------------
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   573
#                          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
   574
#-------------------------------------------------------------------------------
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents:
diff changeset
   575
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   576
class CodeFileEditor(ConfTreeNodeEditor):
738
413946c04c87 refactoring
laurent
parents: 734
diff changeset
   577
    
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 874
diff changeset
   578
    CONFNODEEDITOR_TABS = [
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   579
        (_("Variables"), "_create_VariablesPanel")]
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   580
    
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   581
    def _create_VariablesPanel(self, prnt):
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   582
        self.VariablesPanel = VariablesEditor(prnt, self.ParentWindow, self.Controler)
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   583
        
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   584
        return self.VariablesPanel
738
413946c04c87 refactoring
laurent
parents: 734
diff changeset
   585
    
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   586
    def __init__(self, parent, controler, window):
743
4645a3a398ad Fix bugs with ConfigTreeNode
laurent
parents: 738
diff changeset
   587
        ConfTreeNodeEditor.__init__(self, parent, controler, window)
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   588
    
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   589
    def GetBufferState(self):
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   590
        return self.Controler.GetBufferState()
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   591
        
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   592
    def Undo(self):
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   593
        self.Controler.LoadPrevious()
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   594
        self.RefreshView()
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   595
            
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   596
    def Redo(self):
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   597
        self.Controler.LoadNext()
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   598
        self.RefreshView()
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   599
    
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 626
diff changeset
   600
    def RefreshView(self):
751
a8dace95f965 Fixing bug on ConfNodeEditors refresh
laurent
parents: 744
diff changeset
   601
        ConfTreeNodeEditor.RefreshView(self)
a8dace95f965 Fixing bug on ConfNodeEditors refresh
laurent
parents: 744
diff changeset
   602
        
1096
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   603
        self.VariablesPanel.RefreshView()
c9ace6a881c9 Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents: 1095
diff changeset
   604