Migrated the shortcuts handler to shortcuts reader.

Sun, 12 Sep 2010 15:02:07 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 12 Sep 2010 15:02:07 +0200
changeset 595
7d2c8346021c
parent 594
cded89ee3e30
child 597
86d4732c5084

Migrated the shortcuts handler to shortcuts reader.

Documentation/Source/eric5.E5XML.ShortcutsHandler.html file | annotate | diff | comparison | revisions
E5XML/ShortcutsHandler.py file | annotate | diff | comparison | revisions
E5XML/ShortcutsWriter.py file | annotate | diff | comparison | revisions
PluginManager/PluginRepositoryDialog.py file | annotate | diff | comparison | revisions
Preferences/Shortcuts.py file | annotate | diff | comparison | revisions
UI/UserInterface.py file | annotate | diff | comparison | revisions
eric5.e4p file | annotate | diff | comparison | revisions
--- a/Documentation/Source/eric5.E5XML.ShortcutsHandler.html	Sun Sep 12 13:56:03 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,164 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
-'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
-<html><head>
-<title>eric5.E5XML.ShortcutsHandler</title>
-<style>
-body {
-    background: #EDECE6;
-    margin: 0em 1em 10em 1em;
-    color: black;
-}
-
-h1 { color: white; background: #85774A; }
-h2 { color: white; background: #85774A; }
-h3 { color: white; background: #9D936E; }
-h4 { color: white; background: #9D936E; }
-    
-a { color: #BA6D36; }
-
-</style>
-</head>
-<body><a NAME="top" ID="top"></a>
-<h1>eric5.E5XML.ShortcutsHandler</h1>
-<p>
-Module implementing the handler class for reading a keyboard shortcuts file.
-</p>
-<h3>Global Attributes</h3>
-<table>
-<tr><td>None</td></tr>
-</table>
-<h3>Classes</h3>
-<table>
-<tr>
-<td><a href="#ShortcutsHandler">ShortcutsHandler</a></td>
-<td>Class implementing a sax handler to read a keyboard shortcuts file.</td>
-</tr>
-</table>
-<h3>Functions</h3>
-<table>
-<tr><td>None</td></tr>
-</table>
-<hr /><hr />
-<a NAME="ShortcutsHandler" ID="ShortcutsHandler"></a>
-<h2>ShortcutsHandler</h2>
-<p>
-    Class implementing a sax handler to read a keyboard shortcuts file.
-</p>
-<h3>Derived from</h3>
-XMLHandlerBase
-<h3>Class Attributes</h3>
-<table>
-<tr><td>None</td></tr>
-</table>
-<h3>Methods</h3>
-<table>
-<tr>
-<td><a href="#ShortcutsHandler.__init__">ShortcutsHandler</a></td>
-<td>Constructor</td>
-</tr><tr>
-<td><a href="#ShortcutsHandler.endAccel">endAccel</a></td>
-<td>Handler method for the "Accel" end tag.</td>
-</tr><tr>
-<td><a href="#ShortcutsHandler.endAltAccel">endAltAccel</a></td>
-<td>Handler method for the "AltAccel" end tag.</td>
-</tr><tr>
-<td><a href="#ShortcutsHandler.endName">endName</a></td>
-<td>Handler method for the "Name" end tag.</td>
-</tr><tr>
-<td><a href="#ShortcutsHandler.endShortcut">endShortcut</a></td>
-<td>Handler method for the "Shortcut" end tag.</td>
-</tr><tr>
-<td><a href="#ShortcutsHandler.getShortcuts">getShortcuts</a></td>
-<td>Public method to retrieve the shortcuts.</td>
-</tr><tr>
-<td><a href="#ShortcutsHandler.getVersion">getVersion</a></td>
-<td>Public method to retrieve the version of the shortcuts.</td>
-</tr><tr>
-<td><a href="#ShortcutsHandler.startDocumentShortcuts">startDocumentShortcuts</a></td>
-<td>Handler called, when the document parsing is started.</td>
-</tr><tr>
-<td><a href="#ShortcutsHandler.startShortcut">startShortcut</a></td>
-<td>Handler method for the "Shortcut" start tag.</td>
-</tr><tr>
-<td><a href="#ShortcutsHandler.startShortcuts">startShortcuts</a></td>
-<td>Handler method for the "Shortcuts" start tag.</td>
-</tr>
-</table>
-<a NAME="ShortcutsHandler.__init__" ID="ShortcutsHandler.__init__"></a>
-<h4>ShortcutsHandler (Constructor)</h4>
-<b>ShortcutsHandler</b>(<i></i>)
-<p>
-        Constructor
-</p><a NAME="ShortcutsHandler.endAccel" ID="ShortcutsHandler.endAccel"></a>
-<h4>ShortcutsHandler.endAccel</h4>
-<b>endAccel</b>(<i></i>)
-<p>
-        Handler method for the "Accel" end tag.
-</p><a NAME="ShortcutsHandler.endAltAccel" ID="ShortcutsHandler.endAltAccel"></a>
-<h4>ShortcutsHandler.endAltAccel</h4>
-<b>endAltAccel</b>(<i></i>)
-<p>
-        Handler method for the "AltAccel" end tag.
-</p><a NAME="ShortcutsHandler.endName" ID="ShortcutsHandler.endName"></a>
-<h4>ShortcutsHandler.endName</h4>
-<b>endName</b>(<i></i>)
-<p>
-        Handler method for the "Name" end tag.
-</p><a NAME="ShortcutsHandler.endShortcut" ID="ShortcutsHandler.endShortcut"></a>
-<h4>ShortcutsHandler.endShortcut</h4>
-<b>endShortcut</b>(<i></i>)
-<p>
-        Handler method for the "Shortcut" end tag.
-</p><a NAME="ShortcutsHandler.getShortcuts" ID="ShortcutsHandler.getShortcuts"></a>
-<h4>ShortcutsHandler.getShortcuts</h4>
-<b>getShortcuts</b>(<i></i>)
-<p>
-        Public method to retrieve the shortcuts.
-</p><dl>
-<dt>Returns:</dt>
-<dd>
-Dictionary of dictionaries of shortcuts. The keys of the
-            dictionary are the categories, the values are dictionaries.
-            These dictionaries have the shortcut name as their key and
-            a tuple of accelerators as their value.
-</dd>
-</dl><a NAME="ShortcutsHandler.getVersion" ID="ShortcutsHandler.getVersion"></a>
-<h4>ShortcutsHandler.getVersion</h4>
-<b>getVersion</b>(<i></i>)
-<p>
-        Public method to retrieve the version of the shortcuts.
-</p><dl>
-<dt>Returns:</dt>
-<dd>
-String containing the version number.
-</dd>
-</dl><a NAME="ShortcutsHandler.startDocumentShortcuts" ID="ShortcutsHandler.startDocumentShortcuts"></a>
-<h4>ShortcutsHandler.startDocumentShortcuts</h4>
-<b>startDocumentShortcuts</b>(<i></i>)
-<p>
-        Handler called, when the document parsing is started.
-</p><a NAME="ShortcutsHandler.startShortcut" ID="ShortcutsHandler.startShortcut"></a>
-<h4>ShortcutsHandler.startShortcut</h4>
-<b>startShortcut</b>(<i>attrs</i>)
-<p>
-        Handler method for the "Shortcut" start tag.
-</p><dl>
-<dt><i>attrs</i></dt>
-<dd>
-list of tag attributes
-</dd>
-</dl><a NAME="ShortcutsHandler.startShortcuts" ID="ShortcutsHandler.startShortcuts"></a>
-<h4>ShortcutsHandler.startShortcuts</h4>
-<b>startShortcuts</b>(<i>attrs</i>)
-<p>
-        Handler method for the "Shortcuts" start tag.
-</p><dl>
-<dt><i>attrs</i></dt>
-<dd>
-list of tag attributes
-</dd>
-</dl>
-<div align="right"><a href="#top">Up</a></div>
-<hr />
-</body></html>
\ No newline at end of file
--- a/E5XML/ShortcutsHandler.py	Sun Sep 12 13:56:03 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,107 +0,0 @@
-# -*- coding: utf-8 -*-
-
-# Copyright (c) 2003 - 2010 Detlev Offenbach <detlev@die-offenbachs.de>
-#
-
-"""
-Module implementing the handler class for reading a keyboard shortcuts file.
-"""
-
-from .Config import shortcutsFileFormatVersion
-from .XMLHandlerBase import XMLHandlerBase
-
-class ShortcutsHandler(XMLHandlerBase):
-    """
-    Class implementing a sax handler to read a keyboard shortcuts file.
-    """
-    def __init__(self):
-        """
-        Constructor
-        """
-        XMLHandlerBase.__init__(self)
-        
-        self.startDocumentSpecific = self.startDocumentShortcuts
-        
-        self.elements.update({
-            'Shortcuts' : (self.startShortcuts, self.defaultEndElement),
-            'Shortcut' : (self.startShortcut, self.endShortcut),
-            'Name' : (self.defaultStartElement, self.endName),
-            'Accel' : (self.defaultStartElement, self.endAccel),
-            'AltAccel' : (self.defaultStartElement, self.endAltAccel),
-        })
-        
-    def startDocumentShortcuts(self):
-        """
-        Handler called, when the document parsing is started.
-        """
-        self.shortcuts = {}     # dictionary for storing the shortcuts
-        self.version = ''
-        
-    ###################################################
-    ## below follow the individual handler functions
-    ###################################################
-    
-    def endName(self):
-        """
-        Handler method for the "Name" end tag.
-        """
-        self.name = self.buffer
-        
-    def endAccel(self):
-        """
-        Handler method for the "Accel" end tag.
-        """
-        self.accel = self.unescape(self.buffer)
-        
-    def endAltAccel(self):
-        """
-        Handler method for the "AltAccel" end tag.
-        """
-        self.altAccel = self.unescape(self.buffer)
-        
-    def startShortcut(self, attrs):
-        """
-        Handler method for the "Shortcut" start tag.
-        
-        @param attrs list of tag attributes
-        """
-        self.name = ''
-        self.accel = ''
-        self.altAccel = ''
-        self.category = attrs.get('category', '')
-        
-    def endShortcut(self):
-        """
-        Handler method for the "Shortcut" end tag.
-        """
-        if self.category:
-            if self.category not in self.shortcuts:
-                self.shortcuts[self.category] = {}
-            self.shortcuts[self.category][self.name] = (self.accel, self.altAccel)
-        
-    def startShortcuts(self, attrs):
-        """
-        Handler method for the "Shortcuts" start tag.
-        
-        @param attrs list of tag attributes
-        """
-        self.version = attrs.get('version', shortcutsFileFormatVersion)
-        
-    def getShortcuts(self):
-        """
-        Public method to retrieve the shortcuts.
-        
-        @return Dictionary of dictionaries of shortcuts. The keys of the
-            dictionary are the categories, the values are dictionaries.
-            These dictionaries have the shortcut name as their key and
-            a tuple of accelerators as their value.
-        """
-        return self.shortcuts
-        
-    def getVersion(self):
-        """
-        Public method to retrieve the version of the shortcuts.
-        
-        @return String containing the version number.
-        """
-        return self.version
--- a/E5XML/ShortcutsWriter.py	Sun Sep 12 13:56:03 2010 +0200
+++ b/E5XML/ShortcutsWriter.py	Sun Sep 12 15:02:07 2010 +0200
@@ -11,22 +11,22 @@
 
 from E5Gui.E5Application import e5App
 
-from .XMLWriterBase import XMLWriterBase
+from .XMLStreamWriterBase import XMLStreamWriterBase
 from .Config import shortcutsFileFormatVersion
 
 import Preferences
 
-class ShortcutsWriter(XMLWriterBase):
+class ShortcutsWriter(XMLStreamWriterBase):
     """
     Class implementing the writer class for writing an XML shortcuts file.
     """
-    def __init__(self, file):
+    def __init__(self, device):
         """
         Constructor
         
-        @param file open file (like) object for writing
+        @param device reference to the I/O device to write to (QIODevice)
         """
-        XMLWriterBase.__init__(self, file)
+        XMLStreamWriterBase.__init__(self, device)
         
         self.email = Preferences.getUser("Email")
         
@@ -34,151 +34,69 @@
         """
         Public method to write the XML to the file.
         """
-        XMLWriterBase.writeXML(self)
+        XMLStreamWriterBase.writeXML(self)
         
-        self._write('<!DOCTYPE Shortcuts SYSTEM "Shortcuts-{0}.dtd">'.format(
+        self.writeDTD('<!DOCTYPE Shortcuts SYSTEM "Shortcuts-{0}.dtd">'.format(
             shortcutsFileFormatVersion))
         
         # add some generation comments
-        self._write("<!-- Eric5 keyboard shortcuts -->")
-        self._write("<!-- Saved: {0} -->".format(time.strftime('%Y-%m-%d, %H:%M:%S')))
-        self._write("<!-- Author: {0} -->".format(self.escape("{0}".format(self.email))))
+        self.writeComment(" Eric5 keyboard shortcuts ")
+        self.writeComment(" Saved: {0}".format(time.strftime('%Y-%m-%d, %H:%M:%S')))
+        self.writeComment(" Author: {0} ".format(self.email))
         
         # add the main tag
-        self._write('<Shortcuts version="{0}">'.format(shortcutsFileFormatVersion))
-        
-        for act in e5App().getObject("Project").getActions():
-            self._write('  <Shortcut category="Project">')
-            self._write('    <Name>{0}</Name>'.format(act.objectName()))
-            self._write('    <Accel>{0}</Accel>'.format(
-                self.escape("{0}".format(act.shortcut().toString()))))
-            self._write('    <AltAccel>{0}</AltAccel>' \
-               .format(self.escape("{0}".format(act.alternateShortcut().toString()))))
-            self._write('  </Shortcut>')
-        
-        for act in e5App().getObject("UserInterface").getActions('ui'):
-            self._write('  <Shortcut category="General">')
-            self._write('    <Name>{0}</Name>'.format(act.objectName()))
-            self._write('    <Accel>{0}</Accel>'.format(
-                self.escape("{0}".format(act.shortcut().toString()))))
-            self._write('    <AltAccel>{0}</AltAccel>'.format(
-                self.escape("{0}".format(act.alternateShortcut().toString()))))
-            self._write('  </Shortcut>')
-        
-        for act in e5App().getObject("UserInterface").getActions('wizards'):
-            self._write('  <Shortcut category="Wizards">')
-            self._write('    <Name>{0}</Name>'.format(act.objectName()))
-            self._write('    <Accel>{0}</Accel>'.format(
-                self.escape("{0}".format(act.shortcut().toString()))))
-            self._write('    <AltAccel>{0}</AltAccel>'.format(
-                self.escape("{0}".format(act.alternateShortcut().toString()))))
-            self._write('  </Shortcut>')
-        
-        for act in e5App().getObject("DebugUI").getActions():
-            self._write('  <Shortcut category="Debug">')
-            self._write('    <Name>{0}</Name>'.format(act.objectName()))
-            self._write('    <Accel>{0}</Accel>'.format(
-                self.escape("{0}".format(act.shortcut().toString()))))
-            self._write('    <AltAccel>{0}</AltAccel>'.format(
-                self.escape("{0}".format(act.alternateShortcut().toString()))))
-            self._write('  </Shortcut>')
-        
-        for act in e5App().getObject("ViewManager").getActions('edit'):
-            self._write('  <Shortcut category="Edit">')
-            self._write('    <Name>{0}</Name>'.format(act.objectName()))
-            self._write('    <Accel>{0}</Accel>'.format(
-                self.escape("{0}".format(act.shortcut().toString()))))
-            self._write('    <AltAccel>{0}</AltAccel>'.format(
-                self.escape("{0}".format(act.alternateShortcut().toString()))))
-            self._write('  </Shortcut>')
+        self.writeStartElement("Shortcuts")
+        self.writeAttribute("version", shortcutsFileFormatVersion)
         
-        for act in e5App().getObject("ViewManager").getActions('file'):
-            self._write('  <Shortcut category="File">')
-            self._write('    <Name>{0}</Name>'.format(act.objectName()))
-            self._write('    <Accel>{0}</Accel>'.format(
-                self.escape("{0}".format(act.shortcut().toString()))))
-            self._write('    <AltAccel>{0}</AltAccel>'.format(
-                self.escape("{0}".format(act.alternateShortcut().toString()))))
-            self._write('  </Shortcut>')
-        
-        for act in e5App().getObject("ViewManager").getActions('search'):
-            self._write('  <Shortcut category="Search">')
-            self._write('    <Name>{0}</Name>'.format(act.objectName()))
-            self._write('    <Accel>{0}</Accel>'.format(
-                self.escape("{0}".format(act.shortcut().toString()))))
-            self._write('    <AltAccel>{0}</AltAccel>'.format(
-                self.escape("{0}".format(act.alternateShortcut().toString()))))
-            self._write('  </Shortcut>')
-        
-        for act in e5App().getObject("ViewManager").getActions('view'):
-            self._write('  <Shortcut category="View">')
-            self._write('    <Name>{0}</Name>'.format(act.objectName()))
-            self._write('    <Accel>{0}</Accel>'.format(
-                self.escape("{0}".format(act.shortcut().toString()))))
-            self._write('    <AltAccel>{0}</AltAccel>'.format(
-                self.escape("{0}".format(act.alternateShortcut().toString()))))
-            self._write('  </Shortcut>')
-        
-        for act in e5App().getObject("ViewManager").getActions('macro'):
-            self._write('  <Shortcut category="Macro">')
-            self._write('    <Name>{0}</Name>'.format(act.objectName()))
-            self._write('    <Accel>{0}</Accel>'.format(
-                self.escape("{0}".format(act.shortcut().toString()))))
-            self._write('    <AltAccel>{0}</AltAccel>'.format(
-                self.escape("{0}".format(act.alternateShortcut().toString()))))
-            self._write('  </Shortcut>')
-        
-        for act in e5App().getObject("ViewManager").getActions('bookmark'):
-            self._write('  <Shortcut category="Bookmarks">')
-            self._write('    <Name>{0}</Name>'.format(act.objectName()))
-            self._write('    <Accel>{0}</Accel>'.format(
-                self.escape("{0}".format(act.shortcut().toString()))))
-            self._write('    <AltAccel>{0}</AltAccel>'.format(
-                self.escape("{0}".format(act.alternateShortcut().toString()))))
-            self._write('  </Shortcut>')
-        
-        for act in e5App().getObject("ViewManager").getActions('spelling'):
-            self._write('  <Shortcut category="Spelling">')
-            self._write('    <Name>{0}</Name>'.format(act.objectName()))
-            self._write('    <Accel>{0}</Accel>'.format(
-                self.escape("{0}".format(act.shortcut().toString()))))
-            self._write('    <AltAccel>{0}</AltAccel>'.format(
-                self.escape("{0}".format(act.alternateShortcut().toString()))))
-            self._write('  </Shortcut>')
-        
-        actions = e5App().getObject("ViewManager").getActions('window')
-        for act in actions:
-            self._write('  <Shortcut category="Window">')
-            self._write('    <Name>{0}</Name>'.format(act.objectName()))
-            self._write('    <Accel>{0}</Accel>'.format(
-                self.escape("{0}".format(act.shortcut().toString()))))
-            self._write('    <AltAccel>{0}</AltAccel>'.format(
-                self.escape("{0}".format(act.alternateShortcut().toString()))))
-            self._write('  </Shortcut>')
+        self.__writeActions("Project", 
+            e5App().getObject("Project").getActions())
+        self.__writeActions("General", 
+            e5App().getObject("UserInterface").getActions('ui'))
+        self.__writeActions("Wizards", 
+            e5App().getObject("UserInterface").getActions('wizards'))
+        self.__writeActions("Debug", 
+            e5App().getObject("DebugUI").getActions())
+        self.__writeActions("Edit", 
+            e5App().getObject("ViewManager").getActions('edit'))
+        self.__writeActions("File", 
+            e5App().getObject("ViewManager").getActions('file'))
+        self.__writeActions("Search", 
+            e5App().getObject("ViewManager").getActions('search'))
+        self.__writeActions("View", 
+            e5App().getObject("ViewManager").getActions('view'))
+        self.__writeActions("Macro", 
+            e5App().getObject("ViewManager").getActions('macro'))
+        self.__writeActions("Bookmarks", 
+            e5App().getObject("ViewManager").getActions('bookmark'))
+        self.__writeActions("Spelling", 
+            e5App().getObject("ViewManager").getActions('spelling'))
+        self.__writeActions("Window", 
+            e5App().getObject("ViewManager").getActions('window'))
         
         for category, ref in e5App().getPluginObjects():
             if hasattr(ref, "getActions"):
-                actions = ref.getActions()
-                for act in actions:
-                    if act.objectName():
-                        # shortcuts are only exported, if their objectName is set
-                        self._write('  <Shortcut category="{0}">'.format(category))
-                        self._write('    <Name>{0}</Name>'.format(act.objectName()))
-                        self._write('    <Accel>{0}</Accel>'.format(
-                            self.escape("{0}".format(act.shortcut().toString()))))
-                        self._write('    <AltAccel>{0}</AltAccel>'\
-                            .format(self.escape("{0}".format(
-                                act.alternateShortcut().toString()))))
-                        self._write('  </Shortcut>')
+                self.__writeActions(category, ref.getActions())
     
-        for act in e5App().getObject("DummyHelpViewer").getActions():
-            self._write('  <Shortcut category="HelpViewer">')
-            self._write('    <Name>{0}</Name>'.format(act.objectName()))
-            self._write('    <Accel>{0}</Accel>'.format(
-                self.escape("{0}".format(act.shortcut().toString()))))
-            self._write('    <AltAccel>{0}</AltAccel>' \
-               .format(self.escape("{0}".format(act.alternateShortcut().toString()))))
-            self._write('  </Shortcut>')
+        self.__writeActions("HelpViewer", 
+            e5App().getObject("DummyHelpViewer").getActions())
     
         # add the main end tag
-        self._write("</Shortcuts>", newline = False)
+        self.writeEndElement()
+        self.writeEndDocument()
+    
+    def __writeActions(self, category, actions):
+        """
+        Private method to write the shortcuts for the given actions.
+        
+        @param category category the actions belong to (string)
+        @param actions list of actions to write (E5Action)
+        """
+        for act in actions:
+            if act.objectName():
+                # shortcuts are only exported, if their objectName is set
+                self.writeStartElement("Shortcut")
+                self.writeAttribute("category", category)
+                self.writeTextElement("Name", act.objectName())
+                self.writeTextElement("Accel", act.shortcut().toString())
+                self.writeTextElement("AltAccel", act.alternateShortcut().toString())
+                self.writeEndElement()
--- a/PluginManager/PluginRepositoryDialog.py	Sun Sep 12 13:56:03 2010 +0200
+++ b/PluginManager/PluginRepositoryDialog.py	Sun Sep 12 15:02:07 2010 +0200
@@ -269,7 +269,6 @@
                     self.trUtf8("<p>The plugins repository file <b>{0}</b> "
                                 "could not be read. Select Update</p>")\
                         .format(self.pluginRepositoryFile))
-                return
         else:
             self.__repositoryMissing = True
             QTreeWidgetItem(self.repositoryList, 
--- a/Preferences/Shortcuts.py	Sun Sep 12 13:56:03 2010 +0200
+++ b/Preferences/Shortcuts.py	Sun Sep 12 15:02:07 2010 +0200
@@ -7,8 +7,6 @@
 Module implementing functions dealing with keyboard shortcuts.
 """
 
-import io
-
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
 
@@ -17,11 +15,8 @@
 
 from Preferences import Prefs, syncPreferences
 
-from E5XML.XMLUtilities import make_parser
-from E5XML.XMLErrorHandler import XMLErrorHandler, XMLFatalParseError
-from E5XML.ShortcutsHandler import ShortcutsHandler
+from E5XML.ShortcutsReader import ShortcutsReader
 from E5XML.ShortcutsWriter import ShortcutsWriter
-from E5XML.XMLEntityResolver import XMLEntityResolver
 
 def __readShortcut(act, category, prefClass):
     """
@@ -189,136 +184,49 @@
     Module function to export the keyboard shortcuts for the defined QActions.
     
     @param fn filename of the export file (string)
-    @return flag indicating success
     """
-    try:
-        if fn.lower().endswith("e4kz"):
-            try:
-                import gzip
-            except ImportError:
-                E5MessageBox.critical(None,
-                    QApplication.translate("Shortcuts", "Export Keyboard Shortcuts"),
-                    QApplication.translate("Shortcuts", 
-                        """Compressed keyboard shortcut files"""
-                        """ not supported. The compression library is missing."""))
-                return 0
-            f = io.StringIO()
-        else:
-            f = open(fn, "w", encoding = "utf-8")
-        
+    # let the plugin manager create on demand plugin objects
+    pm = e5App().getObject("PluginManager")
+    pm.initOnDemandPlugins()
+    
+    f = QFile(fn)
+    if f.open(QIODevice.WriteOnly):
         ShortcutsWriter(f).writeXML()
-        
-        if fn.lower().endswith("e4kz"):
-            g = gzip.open(fn, "wb")
-            g.write(f.getvalue().encode("utf-8"))
-            g.close()
         f.close()
-        return True
-    except IOError:
-        return False
+    else:
+        E5MessageBox.critical(None,
+            QApplication.translate("Shortcuts", "Export Keyboard Shortcuts"),
+            QApplication.translate("Shortcuts", 
+                "<p>The keyboard shortcuts could not be written to file <b>{0}</b>.</p>")
+                .format(fn))
 
 def importShortcuts(fn):
     """
     Module function to import the keyboard shortcuts for the defined E5Actions.
     
     @param fn filename of the import file (string)
-    @return flag indicating success
     """
-    try:
-        if fn.lower().endswith("kz"):
-            try:
-                import gzip
-            except ImportError:
-                E5MessageBox.critical(None,
-                    QApplication.translate("Shortcuts", "Import Keyboard Shortcuts"),
-                    QApplication.translate("Shortcuts", 
-                        """Compressed keyboard shortcut files"""
-                        """ not supported. The compression library is missing."""))
-                return False
-            g = gzip.open(fn, "rb")
-            f = io.StringIO(g.read().decode("utf-8"))
-            g.close()
-        else:
-            f = open(fn, "r", encoding = "utf-8")
-        try:
-            f.readline()
-            dtdLine = f.readline()
-        finally:
-            f.close()
-    except IOError:
+    # let the plugin manager create on demand plugin objects
+    pm = e5App().getObject("PluginManager")
+    pm.initOnDemandPlugins()
+    
+    f = QFile(fn)
+    if f.open(QIODevice.ReadOnly):
+        reader = ShortcutsReader(f)
+        reader.readXML()
+        f.close()
+        if not reader.hasError():
+            shortcuts = reader.getShortcuts()
+            setActions(shortcuts)
+            saveShortcuts()
+            syncPreferences()
+    else:
         E5MessageBox.critical(None,
             QApplication.translate("Shortcuts", "Import Keyboard Shortcuts"),
             QApplication.translate("Shortcuts", 
                 "<p>The keyboard shortcuts could not be read from file <b>{0}</b>.</p>")
                 .format(fn))
-        return False
-    
-    if fn.lower().endswith("kz"):
-        # work around for a bug in xmlproc
-        validating = False
-    else:
-        validating = dtdLine.startswith("<!DOCTYPE")
-    parser = make_parser(validating)
-    handler = ShortcutsHandler()
-    er = XMLEntityResolver()
-    eh = XMLErrorHandler()
-    
-    parser.setContentHandler(handler)
-    parser.setEntityResolver(er)
-    parser.setErrorHandler(eh)
-    
-    try:
-        if fn.lower().endswith("kz"):
-            try:
-                import gzip
-            except ImportError:
-                E5MessageBox.critical(None,
-                    QApplication.translate("Shortcuts", "Import Keyboard Shortcuts"),
-                    QApplication.translate("Shortcuts", 
-                        """Compressed keyboard shortcut files"""
-                        """ not supported. The compression library is missing."""))
-                return False
-            g = gzip.open(fn, "rb")
-            f = io.StringIO(g.read().decode("utf-8"))
-            g.close()
-        else:
-            f = open(fn, "r", encoding = "utf-8")
-        try:
-            try:
-                parser.parse(f)
-            except UnicodeEncodeError:
-                f.seek(0)
-                buf = io.StringIO(f.read())
-                parser.parse(buf)
-        finally:
-            f.close()
-    except IOError:
-        E5MessageBox.critical(None,
-            QApplication.translate("Shortcuts", "Import Keyboard Shortcuts"),
-            QApplication.translate("Shortcuts", 
-                "<p>The keyboard shortcuts could not be read from file <b>{0}</b>.</p>")
-                .format(fn))
-        return False
-        
-    except XMLFatalParseError:
-        E5MessageBox.critical(None,
-            QApplication.translate("Shortcuts", "Import Keyboard Shortcuts"),
-            QApplication.translate("Shortcuts", 
-                "<p>The keyboard shortcuts file <b>{0}</b> has invalid contents.</p>")
-                .format(fn))
-        eh.showParseMessages()
-        return False
-        
-    eh.showParseMessages()
-    
-    shortcuts = handler.getShortcuts()
-    
-    setActions(shortcuts)
-    
-    saveShortcuts()
-    syncPreferences()
-    
-    return True
+        return
 
 def __setAction(actions, sdict):
     """
@@ -399,4 +307,4 @@
     
     if "HelpViewer" in shortcuts:
         __setAction(e5App().getObject("DummyHelpViewer").getActions(), 
-            shortcuts["HelpViewer"])
\ No newline at end of file
+            shortcuts["HelpViewer"])
--- a/UI/UserInterface.py	Sun Sep 12 13:56:03 2010 +0200
+++ b/UI/UserInterface.py	Sun Sep 12 15:02:07 2010 +0200
@@ -4903,12 +4903,7 @@
             if ex:
                 fn += ex
         
-        res = Shortcuts.exportShortcuts(fn)
-        if not res:
-            E5MessageBox.critical(self,
-                self.trUtf8("Export Keyboard Shortcuts"),
-                self.trUtf8("<p>The keyboard shortcuts could not be written to file"
-                    " <b>{0}</b>.</p>").format(fn))
+        Shortcuts.exportShortcuts(fn)
 
     def __importShortcuts(self):
         """
@@ -5053,6 +5048,7 @@
         if f.open(QIODevice.ReadOnly):
             reader = TasksReader(f, viewer = self.taskViewer)
             reader.readXML()
+            f.close()
         else:
             E5MessageBox.critical(self,
                 self.trUtf8("Read tasks"),
--- a/eric5.e4p	Sun Sep 12 13:56:03 2010 +0200
+++ b/eric5.e4p	Sun Sep 12 15:02:07 2010 +0200
@@ -715,7 +715,6 @@
     <Source>E5XML/DebuggerPropertiesWriter.py</Source>
     <Source>E5XML/TemplatesWriter.py</Source>
     <Source>E5XML/DebuggerPropertiesHandler.py</Source>
-    <Source>E5XML/ShortcutsHandler.py</Source>
     <Source>E5XML/Config.py</Source>
     <Source>E5XML/__init__.py</Source>
     <Source>E5XML/TasksWriter.py</Source>
@@ -821,6 +820,7 @@
     <Source>E5XML/TasksReader.py</Source>
     <Source>E5XML/TemplatesReader.py</Source>
     <Source>E5XML/HighlightingStylesReader.py</Source>
+    <Source>E5XML/ShortcutsReader.py</Source>
   </Sources>
   <Forms>
     <Form>PyUnit/UnittestDialog.ui</Form>

eric ide

mercurial