def DoOnIdle(self):
        """Check if the file has been modified and prompt a warning"""
        # Don't check while the file is loading
        if self.IsLoading():
            return

        if Profile_Get('CHECKMOD'):
            cfile = self.GetFileName()
            lmod = GetFileModTime(cfile)
            mtime = self.GetModTime()
            if mtime and not lmod and not os.path.exists(cfile):
                # File was deleted since last check
                wx.CallAfter(self.PromptToReSave, cfile)
            elif mtime < lmod:
                # Check if we should automatically reload the file or not
                if Profile_Get('AUTO_RELOAD', default=False) and \
                   not self.GetModify():
                    wx.CallAfter(self.DoReloadFile)
                else:
                    wx.CallAfter(self.AskToReload, cfile)

            # Check for changes to permissions
            readonly = self._nb.ImageIsReadOnly(self.GetTabIndex())
            if self.File.IsReadOnly() != readonly:
                if readonly:
                    # File is no longer read only
                    self._nb.SetPageImage(self.GetTabIndex(),
                                          str(self.GetLangId()))
                else:
                    # File has changed to be readonly
                    self._nb.SetPageImage(self.GetTabIndex(),
                                          ed_glob.ID_READONLY)
            else:
                pass
Exemplo n.º 2
0
    def DoOnIdle(self):
        """Check if the file has been modified and prompt a warning"""
        # Don't check while the file is loading
        if self.IsLoading():
            return

        # Handle hiding and showing the caret when the window gets loses focus
        cfocus = self.FindFocus()
        if not self._focused and cfocus is self:
            # Focus has just returned to the window
            self.SetCaretWidth(self._caret_w)
            self._focused = True
        elif self._focused and cfocus is not self:
            cwidth = self.GetCaretWidth()
            if cwidth > 0:
                self._caret_w = cwidth
            self.SetCaretWidth(0)  # Hide the caret when not active
            self._focused = False

        # Check for changes to on disk file
        if not self._has_dlg and Profile_Get('CHECKMOD'):
            cfile = self.GetFileName()
            lmod = GetFileModTime(cfile)
            mtime = self.GetModTime()
            if mtime and not lmod and not os.path.exists(cfile):
                # File was deleted since last check
                wx.CallAfter(self.PromptToReSave, cfile)
            elif mtime < lmod:
                # Check if we should automatically reload the file or not
                if Profile_Get('AUTO_RELOAD', default=False) and \
                   not self.GetModify():
                    wx.CallAfter(self.DoReloadFile)
                else:
                    wx.CallAfter(self.AskToReload, cfile)

        # Check for changes to permissions
        readonly = self._nb.ImageIsReadOnly(self.GetTabIndex())
        if self.File.IsReadOnly() != readonly:
            if readonly:
                # File is no longer read only
                self._nb.SetPageImage(self.GetTabIndex(),
                                      str(self.GetLangId()))
            else:
                # File has changed to be readonly
                self._nb.SetPageImage(self.GetTabIndex(), ed_glob.ID_READONLY)
            self._nb.Refresh()

        else:
            pass

        # Handle Low(er) priority idle events
        self._lprio += 1
        if self._lprio == 2:
            self._lprio = 0  # Reset counter
            # Do spell checking
            # TODO: Add generic subscriber hook and move spell checking and
            #       and other low priority idle handling there
            if self._spell_data['enabled']:
                self._spell.processCurrentlyVisibleBlock()
Exemplo n.º 3
0
    def DoOnIdle(self):
        """Check if the file has been modified and prompt a warning"""
        # Don't check while the file is loading
        if self.IsLoading():
            return

        # Handle hiding and showing the caret when the window gets loses focus
        cfocus = self.FindFocus()
        if not self._focused and cfocus is self:
            # Focus has just returned to the window
            self.RestoreCaret()
            self._focused = True
        elif self._focused and cfocus is not self:
            self.HideCaret()  # Hide the caret when not active
            self._focused = False
            self.CallTipCancel()

        # Check for changes to on disk file
        if not self._has_dlg and Profile_Get('CHECKMOD'):
            cfile = self.GetFileName()
            lmod = GetFileModTime(cfile)
            mtime = self.GetModTime()
            if mtime and not lmod and not os.path.exists(cfile):
                # File was deleted since last check
                wx.CallAfter(self.PromptToReSave, cfile)
            elif mtime < lmod:
                # Check if we should automatically reload the file or not
                if Profile_Get('AUTO_RELOAD', default=False) and \
                   not self.GetModify():
                    wx.CallAfter(self.DoReloadFile)
                else:
                    wx.CallAfter(self.AskToReload, cfile)

        # Check for changes to permissions
        if self.File.IsReadOnly() != self._ro_img:
            self._nb.SetPageBitmap(self.GetTabIndex(), self.GetTabImage())
            self._nb.Refresh()
        else:
            pass

        # Handle Low(er) priority idle events
        self._lprio += 1
        if self._lprio == 2:
            self._lprio = 0  # Reset counter
            # Do spell checking
            # TODO: Add generic subscriber hook and move spell checking and
            #       and other low priority idle handling there
            if self.IsShown():
                if self._spell_data['enabled']:
                    self._spell.processCurrentlyVisibleBlock()
            else:
                # Ensure calltips are not shown when this is a background tab.
                self.CallTipCancel()
Exemplo n.º 4
0
 def DoReloadFile(self):
     """Reload the current file"""
     cfile = self.GetFileName()
     ret = True
     rmsg = u""
     try:
         ret, rmsg = self.ReloadFile()
     except Exception, msg:
         # Unexpected error
         wx.MessageBox(_("Failed to reload file\n\nError:\n%s") % msg,
                       _("File read error"), wx.ICON_ERROR|wx.OK|wx.CENTER)
         # Set modtime to prevent re-prompting of dialog regardless of error cases
         self.SetModTime(GetFileModTime(cfile))
         return
Exemplo n.º 5
0
    def AskToReload(self, cfile):
        """Show a dialog asking if the file should be reloaded
        @param cfile: the file to prompt for a reload of

        """
        mdlg = wx.MessageDialog(self,
                                _("%s has been modified by another "
                                  "application.\n\nWould you like "
                                  "to reload it?") % cfile,
                                  _("Reload File?"),
                                  wx.YES_NO | wx.ICON_INFORMATION)
        mdlg.CenterOnParent()
        result = mdlg.ShowModal()
        mdlg.Destroy()
        if result == wx.ID_YES:
            self.DoReloadFile()
        else:
            self.SetModTime(GetFileModTime(cfile))
Exemplo n.º 6
0
class EdEditorView(ed_stc.EditraStc, ed_tab.EdTabBase):
    """Tab editor view for main notebook control."""
    ID_NO_SUGGEST = wx.NewId()
    ID_ADD_TO_DICT = wx.NewId()
    ID_IGNORE = wx.NewId()
    ID_SPELLING_MENU = wx.NewId()
    ID_CLOSE_TAB = wx.NewId()
    ID_CLOSE_ALL_TABS = wx.NewId()
    DOCMGR = DocPositionMgr()

    def __init__(self,
                 parent,
                 id_=wx.ID_ANY,
                 pos=wx.DefaultPosition,
                 size=wx.DefaultSize,
                 style=0,
                 use_dt=True):
        """Initialize the editor view"""
        ed_stc.EditraStc.__init__(self, parent, id_, pos, size, style, use_dt)
        ed_tab.EdTabBase.__init__(self)

        # Attributes
        self._ro_img = False
        self._ignore_del = False
        self._has_dlg = False
        self._lprio = 0  # Idle event priority counter
        self._menu = ContextMenuManager()
        self._spell = STCSpellCheck(self, check_region=self.IsNonCode)
        self._caret_w = 1
        self._focused = True
        spref = Profile_Get('SPELLCHECK', default=dict())
        self._spell_data = dict(choices=list(),
                                word=('', -1, -1),
                                enabled=spref.get('auto', False))

        # Initialize the classes position manager for the first control
        # that is created only.
        if not EdEditorView.DOCMGR.IsInitialized():
            EdEditorView.DOCMGR.InitPositionCache(ed_glob.CONFIG['CACHE_DIR'] + \
                                                  os.sep + u'positions')

        self._spell.clearAll()
        self._spell.setDefaultLanguage(spref.get('dict', 'en_US'))
        self._spell.startIdleProcessing()

        # Context Menu Events
        self.Bind(wx.EVT_CONTEXT_MENU, self.OnContextMenu)

        # Need to relay the menu events from the context menu to the top level
        # window to be handled on gtk. Other platforms don't require this.
        self.Bind(wx.EVT_MENU, self.OnMenuEvent)

        # Hide autocomp/calltips when window looses focus
        # TODO: decide on whether this belongs in base class or not
        self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
        self.Bind(wx.EVT_LEFT_UP, self.OnSetFocus)
        self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy, self)

        # Subscribe for configuration updates
        for opt in ('AUTOBACKUP', 'SYNTHEME', 'SYNTAX', 'BRACKETHL', 'GUIDES',
                    'SHOW_EDGE', 'EDGE', 'CODE_FOLD', 'AUTO_COMP',
                    'AUTO_INDENT', 'HLCARETLINE', 'SPELLCHECK', 'VI_EMU',
                    'VI_NORMAL_DEFAULT', 'USETABS', 'TABWIDTH', 'INDENTWIDTH',
                    'BSUNINDENT', 'EOL_MODE', 'AALIASING', 'SHOW_EOL',
                    'SHOW_LN', 'SHOW_WS', 'WRAP', 'VIEWVERTSPACE'):
            ed_msg.Subscribe(self.OnConfigMsg,
                             ed_msg.EDMSG_PROFILE_CHANGE + (opt, ))

    def OnDestroy(self, evt):
        """Cleanup message handlers on destroy"""
        if evt.Id == self.Id:
            ed_msg.Unsubscribe(self.OnConfigMsg)
        evt.Skip()

    #---- EdTab Methods ----#

    def DoDeactivateTab(self):
        """Deactivate any active popups when the tab is no longer
        the active tab.

        """
        self._menu.Clear()
        self.HidePopups()

    def DoOnIdle(self):
        """Check if the file has been modified and prompt a warning"""
        # Don't check while the file is loading
        if self.IsLoading():
            return

        # Handle hiding and showing the caret when the window gets loses focus
        cfocus = self.FindFocus()
        if not self._focused and cfocus is self:
            # Focus has just returned to the window
            self.RestoreCaret()
            self._focused = True
        elif self._focused and cfocus is not self:
            self.HideCaret()  # Hide the caret when not active
            self._focused = False
            self.CallTipCancel()

        # Check for changes to on disk file
        if not self._has_dlg and Profile_Get('CHECKMOD'):
            cfile = self.GetFileName()
            lmod = GetFileModTime(cfile)
            mtime = self.GetModTime()
            if mtime and not lmod and not os.path.exists(cfile):
                # File was deleted since last check
                wx.CallAfter(self.PromptToReSave, cfile)
            elif mtime < lmod:
                # Check if we should automatically reload the file or not
                if Profile_Get('AUTO_RELOAD', default=False) and \
                   not self.GetModify():
                    wx.CallAfter(self.DoReloadFile)
                else:
                    wx.CallAfter(self.AskToReload, cfile)

        # Check for changes to permissions
        if self.File.IsReadOnly() != self._ro_img:
            self._nb.SetPageBitmap(self.GetTabIndex(), self.GetTabImage())
            self._nb.Refresh()
        else:
            pass

        # Handle Low(er) priority idle events
        self._lprio += 1
        if self._lprio == 2:
            self._lprio = 0  # Reset counter
            # Do spell checking
            # TODO: Add generic subscriber hook and move spell checking and
            #       and other low priority idle handling there
            if self.IsShown():
                if self._spell_data['enabled']:
                    self._spell.processCurrentlyVisibleBlock()
            else:
                # Ensure calltips are not shown when this is a background tab.
                self.CallTipCancel()

    @modalcheck
    def DoReloadFile(self):
        """Reload the current file"""
        cfile = self.GetFileName()
        ret = True
        rmsg = u""
        try:
            ret, rmsg = self.ReloadFile()
        except Exception, msg:
            # Unexpected error
            wx.MessageBox(
                _("Failed to reload file\n\nError:\n%s") % msg,
                _("File read error"), wx.ICON_ERROR | wx.OK | wx.CENTER)
            # Set modtime to prevent re-prompting of dialog regardless of error cases
            self.SetModTime(GetFileModTime(cfile))
            return

        # Check for expected errors
        if not ret:
            errmap = dict(filename=cfile, errmsg=rmsg)
            mdlg = wx.MessageDialog(
                self,
                _("Failed to reload %(filename)s:\n"
                  "Error: %(errmsg)s") % errmap, _("Error"),
                wx.OK | wx.ICON_ERROR)
            mdlg.ShowModal()
            mdlg.Destroy()

        # Set modtime to prevent re-prompting of dialog regardless of error cases
        self.SetModTime(GetFileModTime(cfile))