Enhanced the autocompletion of templates to observe the language of the current file.

Wed, 27 Apr 2011 12:24:50 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 27 Apr 2011 12:24:50 +0200
changeset 1002
1151d1ea562a
parent 1000
c9f094c33a1d
child 1003
b81a77ac656a

Enhanced the autocompletion of templates to observe the language of the current file.

APIs/Python3/eric5.api file | annotate | diff | comparison | revisions
Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
Documentation/Source/eric5.QScintilla.Editor.html file | annotate | diff | comparison | revisions
Documentation/Source/eric5.Templates.TemplateViewer.html file | annotate | diff | comparison | revisions
QScintilla/Editor.py file | annotate | diff | comparison | revisions
Templates/TemplatePropertiesDialog.py file | annotate | diff | comparison | revisions
Templates/TemplateViewer.py file | annotate | diff | comparison | revisions
changelog file | annotate | diff | comparison | revisions
--- a/APIs/Python3/eric5.api	Tue Apr 26 17:08:08 2011 +0200
+++ b/APIs/Python3/eric5.api	Wed Apr 27 12:24:50 2011 +0200
@@ -5774,14 +5774,15 @@
 eric5.Templates.TemplateViewer.TemplateGroup?1(parent, name, language="All")
 eric5.Templates.TemplateViewer.TemplateViewer.addEntry?4(groupName, name, description, template, quiet=False)
 eric5.Templates.TemplateViewer.TemplateViewer.addGroup?4(name, language="All")
-eric5.Templates.TemplateViewer.TemplateViewer.applyNamedTemplate?4(templateName)
+eric5.Templates.TemplateViewer.TemplateViewer.applyNamedTemplate?4(templateName, groupName=None)
 eric5.Templates.TemplateViewer.TemplateViewer.applyTemplate?4(itm)
 eric5.Templates.TemplateViewer.TemplateViewer.changeEntry?4(itm, name, groupName, description, template)
 eric5.Templates.TemplateViewer.TemplateViewer.changeGroup?4(oldname, newname, language="All")
 eric5.Templates.TemplateViewer.TemplateViewer.getAllGroups?4()
 eric5.Templates.TemplateViewer.TemplateViewer.getGroupNames?4()
-eric5.Templates.TemplateViewer.TemplateViewer.getTemplateNames?4(start)
-eric5.Templates.TemplateViewer.TemplateViewer.hasTemplate?4(entryName)
+eric5.Templates.TemplateViewer.TemplateViewer.getTemplateNames?4(start, groupName=None)
+eric5.Templates.TemplateViewer.TemplateViewer.hasGroup?4(name)
+eric5.Templates.TemplateViewer.TemplateViewer.hasTemplate?4(entryName, groupName=None)
 eric5.Templates.TemplateViewer.TemplateViewer.readTemplates?4(filename=None)
 eric5.Templates.TemplateViewer.TemplateViewer.removeEntry?4(itm)
 eric5.Templates.TemplateViewer.TemplateViewer.removeGroup?4(itm)
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Help/source.qhp	Tue Apr 26 17:08:08 2011 +0200
+++ b/Documentation/Help/source.qhp	Wed Apr 27 12:24:50 2011 +0200
@@ -2334,6 +2334,7 @@
       <keyword name="TemplateViewer.getAllGroups" id="TemplateViewer.getAllGroups" ref="eric5.Templates.TemplateViewer.html#TemplateViewer.getAllGroups" />
       <keyword name="TemplateViewer.getGroupNames" id="TemplateViewer.getGroupNames" ref="eric5.Templates.TemplateViewer.html#TemplateViewer.getGroupNames" />
       <keyword name="TemplateViewer.getTemplateNames" id="TemplateViewer.getTemplateNames" ref="eric5.Templates.TemplateViewer.html#TemplateViewer.getTemplateNames" />
+      <keyword name="TemplateViewer.hasGroup" id="TemplateViewer.hasGroup" ref="eric5.Templates.TemplateViewer.html#TemplateViewer.hasGroup" />
       <keyword name="TemplateViewer.hasTemplate" id="TemplateViewer.hasTemplate" ref="eric5.Templates.TemplateViewer.html#TemplateViewer.hasTemplate" />
       <keyword name="TemplateViewer.readTemplates" id="TemplateViewer.readTemplates" ref="eric5.Templates.TemplateViewer.html#TemplateViewer.readTemplates" />
       <keyword name="TemplateViewer.removeEntry" id="TemplateViewer.removeEntry" ref="eric5.Templates.TemplateViewer.html#TemplateViewer.removeEntry" />
--- a/Documentation/Source/eric5.QScintilla.Editor.html	Tue Apr 26 17:08:08 2011 +0200
+++ b/Documentation/Source/eric5.QScintilla.Editor.html	Wed Apr 27 12:24:50 2011 +0200
@@ -1061,13 +1061,17 @@
 </dd>
 </dl><a NAME="Editor.__applyTemplate" ID="Editor.__applyTemplate"></a>
 <h4>Editor.__applyTemplate</h4>
-<b>__applyTemplate</b>(<i>templateName</i>)
+<b>__applyTemplate</b>(<i>templateName, language</i>)
 <p>
         Private method to apply a template by name.
 </p><dl>
 <dt><i>templateName</i></dt>
 <dd>
 name of the template to apply (string)
+</dd><dt><i>language</i></dt>
+<dd>
+name of the language (group) to get the template
+            from (string)
 </dd>
 </dl><a NAME="Editor.__autoSyntaxCheck" ID="Editor.__autoSyntaxCheck"></a>
 <h4>Editor.__autoSyntaxCheck</h4>
--- a/Documentation/Source/eric5.Templates.TemplateViewer.html	Tue Apr 26 17:08:08 2011 +0200
+++ b/Documentation/Source/eric5.Templates.TemplateViewer.html	Wed Apr 27 12:24:50 2011 +0200
@@ -538,6 +538,9 @@
 <td><a href="#TemplateViewer.getTemplateNames">getTemplateNames</a></td>
 <td>Public method to get the names of templates starting with the given string.</td>
 </tr><tr>
+<td><a href="#TemplateViewer.hasGroup">hasGroup</a></td>
+<td>Public method to check, if a group with the given name exists.</td>
+</tr><tr>
 <td><a href="#TemplateViewer.hasTemplate">hasTemplate</a></td>
 <td>Public method to check, if an entry of the given name exists.</td>
 </tr><tr>
@@ -687,13 +690,18 @@
 </dd>
 </dl><a NAME="TemplateViewer.applyNamedTemplate" ID="TemplateViewer.applyNamedTemplate"></a>
 <h4>TemplateViewer.applyNamedTemplate</h4>
-<b>applyNamedTemplate</b>(<i>templateName</i>)
+<b>applyNamedTemplate</b>(<i>templateName, groupName=None</i>)
 <p>
         Public method to apply a template given a template name.
 </p><dl>
 <dt><i>templateName</i></dt>
 <dd>
 name of the template item to apply (string)
+</dd><dt><i>groupName</i></dt>
+<dd>
+name of the group to get the entry from (string).
+            None or empty means to apply the first template found with the
+            given name.
 </dd>
 </dl><a NAME="TemplateViewer.applyTemplate" ID="TemplateViewer.applyTemplate"></a>
 <h4>TemplateViewer.applyTemplate</h4>
@@ -766,28 +774,51 @@
 </dd>
 </dl><a NAME="TemplateViewer.getTemplateNames" ID="TemplateViewer.getTemplateNames"></a>
 <h4>TemplateViewer.getTemplateNames</h4>
-<b>getTemplateNames</b>(<i>start</i>)
+<b>getTemplateNames</b>(<i>start, groupName=None</i>)
 <p>
         Public method to get the names of templates starting with the given string.
 </p><dl>
 <dt><i>start</i></dt>
 <dd>
 start string of the name (string)
+</dd><dt><i>groupName</i></dt>
+<dd>
+name of the group to get the entry from (string).
+            None or empty means to look in all groups.
 </dd>
 </dl><dl>
 <dt>Returns:</dt>
 <dd>
 sorted list of matching template names (list of strings)
 </dd>
+</dl><a NAME="TemplateViewer.hasGroup" ID="TemplateViewer.hasGroup"></a>
+<h4>TemplateViewer.hasGroup</h4>
+<b>hasGroup</b>(<i>name</i>)
+<p>
+        Public method to check, if a group with the given name exists.
+</p><dl>
+<dt><i>name</i></dt>
+<dd>
+name of the group to be checked for (string)
+</dd>
+</dl><dl>
+<dt>Returns:</dt>
+<dd>
+flag indicating an existing group (boolean)
+</dd>
 </dl><a NAME="TemplateViewer.hasTemplate" ID="TemplateViewer.hasTemplate"></a>
 <h4>TemplateViewer.hasTemplate</h4>
-<b>hasTemplate</b>(<i>entryName</i>)
+<b>hasTemplate</b>(<i>entryName, groupName=None</i>)
 <p>
         Public method to check, if an entry of the given name exists.
 </p><dl>
 <dt><i>entryName</i></dt>
 <dd>
 name of the entry to check for (string)
+</dd><dt><i>groupName</i></dt>
+<dd>
+name of the group to check for the entry (string).
+            None or empty means to check all groups.
 </dd>
 </dl><dl>
 <dt>Returns:</dt>
--- a/QScintilla/Editor.py	Tue Apr 26 17:08:08 2011 +0200
+++ b/QScintilla/Editor.py	Wed Apr 27 12:24:50 2011 +0200
@@ -5524,14 +5524,16 @@
             line, index = self.getCursorPosition()
             tmplName = self.getWordLeft(line, index)
             if tmplName:
-                if e5App().getObject("TemplateViewer").hasTemplate(tmplName):
+                if e5App().getObject("TemplateViewer").hasTemplate(
+                        tmplName, self.getLanguage()):
                     self.__applyTemplate(tmplName)
                     return
                 else:
                     templateNames = \
-                        e5App().getObject("TemplateViewer").getTemplateNames(tmplName)
+                        e5App().getObject("TemplateViewer").getTemplateNames(
+                            tmplName, self.getLanguage())
                     if len(templateNames) == 1:
-                        self.__applyTemplate(templateNames[0])
+                        self.__applyTemplate(templateNames[0], self.getLanguage())
                         return
                     elif len(templateNames) > 1:
                         self.showUserList(TemplateCompletionListID,
@@ -5549,17 +5551,21 @@
         @param txt the selected text (string)
         """
         if id == TemplateCompletionListID:
-            self.__applyTemplate(txt)
+            self.__applyTemplate(txt, self.getLanguage())
     
-    def __applyTemplate(self, templateName):
+    def __applyTemplate(self, templateName, language):
         """
         Private method to apply a template by name.
         
         @param templateName name of the template to apply (string)
-        """
-        if e5App().getObject("TemplateViewer").hasTemplate(templateName):
+        @param language name of the language (group) to get the template
+            from (string)
+        """
+        if e5App().getObject("TemplateViewer").hasTemplate(
+                templateName, self.getLanguage()):
             self.extendSelectionWordLeft()
-            e5App().getObject("TemplateViewer").applyNamedTemplate(templateName)
+            e5App().getObject("TemplateViewer").applyNamedTemplate(
+                templateName, self.getLanguage())
     
     #######################################################################
     ## Project related methods
--- a/Templates/TemplatePropertiesDialog.py	Tue Apr 26 17:08:08 2011 +0200
+++ b/Templates/TemplatePropertiesDialog.py	Wed Apr 27 12:24:50 2011 +0200
@@ -156,7 +156,8 @@
                 """<tr><td>cur_select</td>"""
                 """<td>the currently selected text</td></tr>"""
                 """<tr><td>insertion</td>"""
-                """<td>Sets insertion point for cursor after template is inserted.</td></tr>"""
+                """<td>Sets insertion point for cursor after template is inserted.</td>"""
+                """</tr>"""
                 """<tr><td>select_start</td>"""
                 """<td>Sets span of selected text in template after template is """
                 """inserted (used together with 'select_end').</td></tr>"""
--- a/Templates/TemplateViewer.py	Tue Apr 26 17:08:08 2011 +0200
+++ b/Templates/TemplateViewer.py	Wed Apr 27 12:24:50 2011 +0200
@@ -725,13 +725,23 @@
             editor.endUndoAction()
             editor.setFocus()
 
-    def applyNamedTemplate(self, templateName):
+    def applyNamedTemplate(self, templateName, groupName=None):
         """
         Public method to apply a template given a template name.
         
         @param templateName name of the template item to apply (string)
+        @param groupName name of the group to get the entry from (string).
+            None or empty means to apply the first template found with the
+            given name.
         """
-        for group in list(self.groups.values()):
+        if groupName:
+            if self.hasGroup(groupName):
+                groups = [self.groups[groupName]]
+            else:
+                return
+        else:
+            groups = list(self.groups.values())
+        for group in groups:
             template = group.getEntry(templateName)
             if template is not None:
                 self.applyTemplate(template)
@@ -749,7 +759,16 @@
         """
         self.groups[groupName].addEntry(name, description, template, quiet=quiet)
         self.__resort()
+    
+    def hasGroup(self, name):
+        """
+        Public method to check, if a group with the given name exists.
         
+        @param name name of the group to be checked for (string)
+        @return flag indicating an existing group (boolean)
+        """
+        return name in self.groups
+    
     def addGroup(self, name, language="All"):
         """
         Public method to add a group.
@@ -899,27 +918,45 @@
         """
         e5App().getObject("UserInterface").showPreferences("templatesPage")
     
-    def hasTemplate(self, entryName):
+    def hasTemplate(self, entryName, groupName=None):
         """
         Public method to check, if an entry of the given name exists.
         
         @param entryName name of the entry to check for (string)
+        @param groupName name of the group to check for the entry (string).
+            None or empty means to check all groups.
         @return flag indicating the existence (boolean)
         """
-        for group in list(self.groups.values()):
+        if groupName:
+            if self.hasGroup(groupName):
+                groups = [self.groups[groupName]]
+            else:
+                groups = []
+        else:
+            groups = list(self.groups.values())
+        for group in groups:
             if group.hasEntry(entryName):
                 return True
         
         return False
     
-    def getTemplateNames(self, start):
+    def getTemplateNames(self, start, groupName=None):
         """
         Public method to get the names of templates starting with the given string.
         
         @param start start string of the name (string)
+        @param groupName name of the group to get the entry from (string).
+            None or empty means to look in all groups.
         @return sorted list of matching template names (list of strings)
         """
         names = []
-        for group in list(self.groups.values()):
+        if groupName:
+            if self.hasGroup(groupName):
+                groups = [self.groups[groupName]]
+            else:
+                groups = []
+        else:
+            groups = list(self.groups.values())
+        for group in groups:
             names.extend(group.getEntryNames(start))
         return sorted(names)
--- a/changelog	Tue Apr 26 17:08:08 2011 +0200
+++ b/changelog	Wed Apr 27 12:24:50 2011 +0200
@@ -24,6 +24,8 @@
 - changed algorithm to determine the debugger backend type to be used by
   analysing a first line starting with '#!'
 - added support for the Matlab and Octave lexers for QScintilla >= 2.5.1
+- enhanced the autocompletion of templates to observe the language of the
+  current file
 
 Version 5.1-snapshot-20110123:
 - bug fixes

eric ide

mercurial