Helpviewer/AdBlock/AdBlockDialog.py

changeset 1963
9c5b3235abf9
parent 1854
191efdc54c62
child 1970
02cf3bac079b
--- a/Helpviewer/AdBlock/AdBlockDialog.py	Sun Jul 29 13:40:11 2012 +0200
+++ b/Helpviewer/AdBlock/AdBlockDialog.py	Sun Jul 29 15:41:58 2012 +0200
@@ -7,7 +7,7 @@
 Module implementing the AdBlock configuration dialog.
 """
 
-from PyQt4.QtCore import pyqtSlot, QUrl
+from PyQt4.QtCore import pyqtSlot, Qt, QUrl
 from PyQt4.QtGui import QDialog, QMenu, QToolButton, QApplication, QDesktopServices
 
 from E5Gui.E5TreeSortFilterProxyModel import E5TreeSortFilterProxyModel
@@ -113,7 +113,7 @@
         manager = Helpviewer.HelpWindow.HelpWindow.adblockManager()
         subscription = manager.customRules()
         assert subscription is not None
-        subscription.addRule(AdBlockRule(rule))
+        subscription.addRule(AdBlockRule(rule, subscription))
         QApplication.processEvents()
         
         parent = self.__adBlockModel.subscriptionIndex(subscription)
@@ -172,3 +172,31 @@
             manager = Helpviewer.HelpWindow.HelpWindow.adblockManager()
             for subscription in manager.subscriptions():
                 subscription.checkForUpdate()
+    
+    def showRule(self, rule):
+        """
+        Public slot to show the given rule.
+        
+        @param rule rule to be shown (AdBlockRule)
+        """
+        if rule is None:
+            return
+        
+        subscription = rule.subscription()
+        if subscription is None:
+            return
+        
+        self.searchEdit.clear()
+        
+        subscriptionIndex = self.__adBlockModel.subscriptionIndex(subscription)
+        subscriptionProxyIndex = self.__proxyModel.mapFromSource(subscriptionIndex)
+        filter = rule.filter()
+        if filter:
+            indexes = self.__proxyModel.match(
+                subscriptionProxyIndex, Qt.DisplayRole, filter, 1,
+                Qt.MatchStartsWith | Qt.MatchRecursive)
+            if indexes:
+                self.subscriptionsTree.expand(subscriptionProxyIndex)
+                self.subscriptionsTree.scrollTo(indexes[0])
+                self.subscriptionsTree.setCurrentIndex(indexes[0])
+                self.raise_()

eric ide

mercurial