~ubuntu-branches/ubuntu/raring/wxwidgets2.8/raring

« back to all changes in this revision

Viewing changes to wxPython/wx/tools/Editra/src/autocomp/htmlcomp.py

  • Committer: Package Import Robot
  • Author(s): Stéphane Graber
  • Date: 2012-01-07 13:59:25 UTC
  • mfrom: (1.1.9) (5.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20120107135925-2601miy9ullcon9j
Tags: 2.8.12.1-6ubuntu1
* Resync from Debian, changes that were kept:
  - debian/rules: re-enable mediactrl. This allows libwx_gtk2u_media-2.8 to be
    built, as this is required by some applications (LP: #632984)
  - debian/control: Build-dep on libxt-dev for mediactrl.
  - Patches
    + fix-bashism-in-example
* Add conflict on python-wxgtk2.8 (<< 2.8.12.1-6ubuntu1~) to python-wxversion
  to guarantee upgrade ordering when moving from pycentral to dh_python2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
"""
13
13
 
14
14
__author__ = "Cody Precord <cprecord@editra.org>"
15
 
__cvsid__ = "$Id: htmlcomp.py 63476 2010-02-13 06:20:53Z CJP $"
16
 
__revision__ = "$Revision: 63476 $"
 
15
__cvsid__ = "$Id: htmlcomp.py 67123 2011-03-04 00:02:35Z CJP $"
 
16
__revision__ = "$Revision: 67123 $"
17
17
 
18
18
#--------------------------------------------------------------------------#
19
19
# Imports
90
90
#--------------------------------------------------------------------------#
91
91
 
92
92
class Completer(completer.BaseCompleter):
93
 
    """Code completer provider"""
 
93
    """HTML/XML Code completion provider"""
94
94
    def __init__(self, stc_buffer):
95
 
        completer.BaseCompleter.__init__(self, stc_buffer)
 
95
        super(Completer, self).__init__(stc_buffer)
96
96
 
97
97
        # Setup
98
98
        self.SetAutoCompKeys([ord('>'), ord('<')])
103
103
        """Returns the list of possible completions for a
104
104
        command string. If namespace is not specified the lookup
105
105
        is based on the locals namespace
106
 
        @param command: commadn lookup is done on
 
106
        @param command: command lookup is done on
107
107
        @keyword namespace: namespace to do lookup in
108
108
 
109
109
        """
117
117
        if buff.GetStyleAt(cpos) not in HTML_AREA:
118
118
            return list()
119
119
 
 
120
        # Get current context
120
121
        cline = buff.GetCurrentLine()
121
 
 
 
122
        ccol = buff.GetColumn(cpos)
122
123
        tmp = buff.GetLine(cline).rstrip()
 
124
        if ccol < len(tmp):
 
125
            tmp = tmp[:ccol].rstrip()
123
126
 
124
 
        # Check if we are completing an open tag
 
127
        # Check if we are completing an open tag (i.e < was typed)
125
128
        if tmp.endswith('<'):
126
129
            if buff.GetLexer() == wx.stc.STC_LEX_XML:
127
130
                taglst = _FindXmlTags(buff.GetText())
129
132
                taglst = TAGS
130
133
            return completer.CreateSymbols(taglst, completer.TYPE_ELEMENT)
131
134
 
 
135
        # Check for a self closing tag (i.e />)
 
136
        endchk = tmp.strip().replace(u" ", u"").replace(u"\t", u"")
 
137
        if endchk.endswith(u"/>"):
 
138
            return list()
 
139
 
 
140
        # Try to autocomplete a closing tag (if necessary)
132
141
        tmp = tmp.rstrip('>').rstrip()
133
142
        if len(tmp) and (tmp[-1] in '"\' \t' or tmp[-1].isalpha()):
 
143
            # Walk backwards from the current line
134
144
            for line in range(cline, -1, -1):
135
145
                txt = buff.GetLine(line)
136
146
                if line == cline:
145
155
                           tag not in ('img', 'br', '?php', '?xml', '?') and \
146
156
                           not tag[0] in ('!', '/'):
147
157
                            rtag = u"</" + tag + u">"
148
 
                            if tag in NLINE_TAGS:
149
 
                                rtag = buff.GetEOLChar() + rtag
150
158
 
151
159
                            if not parts[-1].endswith('>'):
152
160
                                rtag = u">" + rtag
162
170
 
163
171
        """
164
172
        buff = self.GetBuffer()
165
 
        if text.startswith(u"</"):
 
173
        if text.strip().startswith(u"</"):
166
174
            buff.SetCurrentPos(pos) # move caret back between the tags
167
175
            # HACK: SetCurrentPos causes text to be selected
168
176
            buff.SetSelection(pos, pos)