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

« back to all changes in this revision

Viewing changes to wxPython/wx/tools/Editra/src/ed_editv.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:
14
14
"""
15
15
 
16
16
__author__ = "Cody Precord <cprecord@editra.org>"
17
 
__svnid__ = "$Id: ed_editv.py 64304 2010-05-13 16:44:35Z CJP $"
18
 
__revision__ = "$Revision: 64304 $"
 
17
__svnid__ = "$Id: ed_editv.py 67834 2011-06-02 02:39:41Z CJP $"
 
18
__revision__ = "$Revision: 67834 $"
19
19
 
20
20
#--------------------------------------------------------------------------#
21
21
# Imports
31
31
from doctools import DocPositionMgr
32
32
from profiler import Profile_Get
33
33
from util import Log, SetClipboardText
34
 
from ebmlib import GetFileModTime, ContextMenuManager
 
34
import syntax.synglob as synglob
 
35
from ebmlib import GetFileModTime, ContextMenuManager, GetFileName
35
36
 
36
37
# External libs
37
38
from extern.stcspellcheck import STCSpellCheck
65
66
class EdEditorView(ed_stc.EditraStc, ed_tab.EdTabBase):
66
67
    """Tab editor view for main notebook control."""
67
68
    ID_NO_SUGGEST = wx.NewId()
 
69
    ID_CLOSE_TAB = wx.NewId()
 
70
    ID_CLOSE_ALL_TABS = wx.NewId()
68
71
    DOCMGR = DocPositionMgr()
69
72
 
70
73
    def __init__(self, parent, id_=wx.ID_ANY, pos=wx.DefaultPosition,
74
77
        ed_tab.EdTabBase.__init__(self)
75
78
 
76
79
        # Attributes
 
80
        self._ro_img = False
77
81
        self._ignore_del = False
78
82
        self._has_dlg = False
79
83
        self._lprio = 0     # Idle event priority counter
80
84
        self._menu = ContextMenuManager()
81
85
        self._spell = STCSpellCheck(self, check_region=self.IsNonCode)
 
86
        self._caret_w = 1
 
87
        self._focused = True
82
88
        spref = Profile_Get('SPELLCHECK', default=dict())
83
89
        self._spell_data = dict(choices=list(),
84
90
                                word=('', -1, -1),
105
111
        # TODO: decide on whether this belongs in base class or not
106
112
        self.Bind(wx.EVT_KILL_FOCUS, lambda evt: self.HidePopups())
107
113
        self.Bind(wx.EVT_LEFT_UP, self.OnSetFocus)
 
114
        self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy, self)
108
115
 
109
116
        ed_msg.Subscribe(self.OnConfigMsg,
110
117
                         ed_msg.EDMSG_PROFILE_CHANGE + ('SPELLCHECK',))
115
122
        ed_msg.Subscribe(self.OnConfigMsg,
116
123
                         ed_msg.EDMSG_PROFILE_CHANGE + ('SYNTAX',))
117
124
 
118
 
    def __del__(self):
119
 
        ed_msg.Unsubscribe(self.OnConfigMsg)
120
 
        super(EdEditorView, self).__del__()
 
125
    def OnDestroy(self, evt):
 
126
        if evt.GetId() == self.GetId():
 
127
            ed_msg.Unsubscribe(self.OnConfigMsg)
 
128
        evt.Skip()
121
129
 
122
130
    #---- EdTab Methods ----#
123
131
 
135
143
        if self.IsLoading():
136
144
            return
137
145
 
 
146
        # Handle hiding and showing the caret when the window gets loses focus
 
147
        cfocus = self.FindFocus()
 
148
        if not self._focused and cfocus is self:
 
149
            # Focus has just returned to the window
 
150
            self.SetCaretWidth(self._caret_w)
 
151
            self._focused = True
 
152
        elif self._focused and cfocus is not self:
 
153
            cwidth = self.GetCaretWidth()
 
154
            if cwidth > 0:
 
155
                self._caret_w = cwidth
 
156
            self.SetCaretWidth(0) # Hide the caret when not active
 
157
            self._focused = False
 
158
            self.CallTipCancel()
 
159
 
 
160
        # Check for changes to on disk file
138
161
        if not self._has_dlg and Profile_Get('CHECKMOD'):
139
162
            cfile = self.GetFileName()
140
163
            lmod = GetFileModTime(cfile)
151
174
                    wx.CallAfter(self.AskToReload, cfile)
152
175
 
153
176
        # Check for changes to permissions
154
 
        readonly = self._nb.ImageIsReadOnly(self.GetTabIndex())
155
 
        if self.File.IsReadOnly() != readonly:
156
 
            if readonly:
157
 
                # File is no longer read only
158
 
                self._nb.SetPageImage(self.GetTabIndex(),
159
 
                                      str(self.GetLangId()))
160
 
            else:
161
 
                # File has changed to be readonly
162
 
                self._nb.SetPageImage(self.GetTabIndex(),
163
 
                                      ed_glob.ID_READONLY)
 
177
        if self.File.IsReadOnly() != self._ro_img:
 
178
            self._nb.SetPageBitmap(self.GetTabIndex(), self.GetTabImage())
164
179
            self._nb.Refresh()
165
 
 
166
180
        else:
167
181
            pass
168
182
 
173
187
            # Do spell checking
174
188
            # TODO: Add generic subscriber hook and move spell checking and
175
189
            #       and other low priority idle handling there
176
 
            if self._spell_data['enabled']:
177
 
                self._spell.processCurrentlyVisibleBlock()
 
190
            if self.IsShown():
 
191
                if self._spell_data['enabled']:
 
192
                    self._spell.processCurrentlyVisibleBlock()
 
193
            else:
 
194
                # Ensure calltips are not shown when this is a background tab.
 
195
                self.CallTipCancel()
178
196
 
179
197
    @modalcheck
180
198
    def DoReloadFile(self):
213
231
        """
214
232
        return u"EditraTextCtrl"
215
233
 
 
234
    def GetTabImage(self):
 
235
        """Get the Bitmap to use for the tab
 
236
        @return: wx.Bitmap (16x16)
 
237
 
 
238
        """
 
239
        if self.GetDocument().ReadOnly:
 
240
            self._ro_img = True
 
241
            bmp = wx.ArtProvider.GetBitmap(str(ed_glob.ID_READONLY), wx.ART_MENU)
 
242
        else:
 
243
            self._ro_img = False
 
244
            lang_id = str(self.GetLangId())
 
245
            bmp = wx.ArtProvider.GetBitmap(lang_id, wx.ART_MENU)
 
246
            if bmp.IsNull():
 
247
                bmp = wx.ArtProvider.GetBitmap(str(synglob.ID_LANG_TXT), wx.ART_MENU)
 
248
        return bmp
 
249
 
216
250
    def GetTabMenu(self):
217
251
        """Get the tab menu
218
252
        @return: wx.Menu
227
261
        menu.Append(ed_glob.ID_MOVE_TAB, _("Move Tab to New Window"))
228
262
        menu.AppendSeparator()
229
263
        menu.Append(ed_glob.ID_SAVE, _("Save \"%s\"") % ptxt)
230
 
        menu.Append(ed_glob.ID_CLOSE, _("Close \"%s\"") % ptxt)
 
264
        menu.Append(EdEditorView.ID_CLOSE_TAB, _("Close \"%s\"") % ptxt)
231
265
        menu.Append(ed_glob.ID_CLOSE_OTHERS, _("Close Other Tabs"))
232
 
        menu.Append(ed_glob.ID_CLOSEALL, _("Close All"))
 
266
        menu.Append(EdEditorView.ID_CLOSE_ALL_TABS, _("Close All"))
233
267
        menu.AppendSeparator()
 
268
        menu.Append(ed_glob.ID_COPY_FILE, _("Copy Filename"))
234
269
        menu.Append(ed_glob.ID_COPY_PATH, _("Copy Full Path"))
235
270
        return menu
236
271
 
298
333
    def OnTabMenu(self, evt):
299
334
        """Tab menu event handler"""
300
335
        e_id = evt.GetId()
301
 
        if e_id == ed_glob.ID_COPY_PATH:
 
336
        if e_id in (ed_glob.ID_COPY_PATH, ed_glob.ID_COPY_FILE):
302
337
            path = self.GetFileName()
303
338
            if path is not None:
 
339
                if e_id == ed_glob.ID_COPY_FILE:
 
340
                    path = GetFileName(path)
304
341
                SetClipboardText(path)
305
342
        elif e_id == ed_glob.ID_MOVE_TAB:
306
343
            frame = wx.GetApp().OpenNewWindow()
315
352
            parent = self.GetParent()
316
353
            if hasattr(parent, 'CloseOtherPages'):
317
354
                parent.CloseOtherPages()
318
 
        elif wx.Platform == '__WXGTK__' and \
319
 
             e_id in (ed_glob.ID_CLOSE, ed_glob.ID_CLOSEALL):
 
355
        elif e_id in (EdEditorView.ID_CLOSE_TAB, EdEditorView.ID_CLOSE_ALL_TABS):
320
356
            # Need to relay events up to toplevel window on GTK for them to
321
 
            # be processed. On other platforms the propagate by them selves.
 
357
            # be processed. On other platforms the propagate by themselves.
 
358
            evt.SetId({ EdEditorView.ID_CLOSE_TAB : ed_glob.ID_CLOSE,
 
359
                        EdEditorView.ID_CLOSE_ALL_TABS : ed_glob.ID_CLOSEALL}.get(e_id))
322
360
            wx.PostEvent(self.GetTopLevelParent(), evt)
323
361
        else:
324
362
            evt.Skip()
345
383
        elif mtype == 'AUTOBACKUP':
346
384
            self.EnableAutoBackup(Profile_Get('AUTOBACKUP'))
347
385
        elif mtype == 'SYNTHEME':
348
 
            self.UpdateAllStyles()
 
386
            self.UpdateAllStyles(Profile_Get('SYNTHEME'))
349
387
        elif mtype == 'SYNTAX':
350
388
            self.SyntaxOnOff(Profile_Get('SYNTAX'))
351
389
        elif mtype == 'AUTO_COMP_EX':