Project/ProjectBrowserModel.py

branch
Py2 comp.
changeset 2791
a9577f248f04
parent 2677
3d4277929fb3
parent 2769
8cbebde7a984
child 3057
10516539f238
--- a/Project/ProjectBrowserModel.py	Mon Jul 08 21:47:26 2013 +0200
+++ b/Project/ProjectBrowserModel.py	Mon Jul 08 22:36:10 2013 +0200
@@ -437,7 +437,7 @@
 
     def findParentItemByName(self, type_, name, dontSplit=False):
         """
-        Public method to find an item given it's name.
+        Public method to find an item given its name.
         
         <b>Note</b>: This method creates all necessary parent items, if they
         don't exist.
@@ -556,7 +556,7 @@
     
     def findItem(self, name):
         """
-        Public method to find an item given it's name.
+        Public method to find an item given its name.
         
         @param name name of the item (string)
         @return reference to the item found
@@ -577,7 +577,7 @@
     
     def itemIndexByName(self, name):
         """
-        Public method to find an item's index given it's name.
+        Public method to find an item's index given its name.
         
         @param name name of the item (string)
         @return index of the item found (QModelIndex)
@@ -589,6 +589,44 @@
             index = self.createIndex(itm.row(), 0, itm)
         return index
     
+    def itemIndexByNameAndLine(self, name, lineno):
+        """
+        Public method to find an item's index given its name.
+        
+        @param name name of the item (string)
+        @param lineno one based line number of the item (integer)
+        @return index of the item found (QModelIndex)
+        """
+        index = QModelIndex()
+        itm = self.findItem(name)
+        if itm is not None and \
+           isinstance(itm, ProjectBrowserFileItem):
+            olditem = itm
+            autoPopulate = Preferences.getProject("AutoPopulateItems")
+            while itm is not None:
+                if not itm.isPopulated():
+                    if itm.isLazyPopulated() and autoPopulate:
+                        self.populateItem(itm)
+                    else:
+                        break
+                for child in itm.children():
+                    try:
+                        start, end = child.boundaries()
+                        if end == -1:
+                            end = 1000000   # assume end of file
+                        if start <= lineno <= end:
+                            itm = child
+                            break
+                    except AttributeError:
+                        pass
+                else:
+                    itm = None
+                if itm:
+                    olditem = itm
+            index = self.createIndex(olditem.row(), 0, olditem)
+        
+        return index
+    
     def directoryChanged(self, path):
         """
         Public slot to handle the directoryChanged signal of the watcher.

eric ide

mercurial