WebBrowser/History/HistoryDialog.py

changeset 5038
df7103c3f2a6
parent 4734
ce0b1f024da9
child 5389
9b1c800daff3
equal deleted inserted replaced
5037:b2b37d7c0791 5038:df7103c3f2a6
23 class HistoryDialog(QDialog, Ui_HistoryDialog): 23 class HistoryDialog(QDialog, Ui_HistoryDialog):
24 """ 24 """
25 Class implementing a dialog to manage history. 25 Class implementing a dialog to manage history.
26 26
27 @signal openUrl(QUrl, str) emitted to open a URL in the current tab 27 @signal openUrl(QUrl, str) emitted to open a URL in the current tab
28 @signal newUrl(QUrl, str) emitted to open a URL in a new tab 28 @signal newTab(QUrl, str) emitted to open a URL in a new tab
29 @signal newBackgroundTab(QUrl, str) emitted to open a URL in a new
30 background tab
31 @signal newWindow(QUrl, str) emitted to open a URL in a new window
32 @signal newPrivateWindow(QUrl, str) emitted to open a URL in a new
33 private window
29 """ 34 """
30 openUrl = pyqtSignal(QUrl, str) 35 openUrl = pyqtSignal(QUrl, str)
31 newUrl = pyqtSignal(QUrl, str) 36 newTab = pyqtSignal(QUrl, str)
37 newBackgroundTab = pyqtSignal(QUrl, str)
38 newWindow = pyqtSignal(QUrl, str)
39 newPrivateWindow = pyqtSignal(QUrl, str)
32 40
33 def __init__(self, parent=None, manager=None): 41 def __init__(self, parent=None, manager=None):
34 """ 42 """
35 Constructor 43 Constructor
36 44
84 @param pos position the context menu was requested (QPoint) 92 @param pos position the context menu was requested (QPoint)
85 """ 93 """
86 menu = QMenu() 94 menu = QMenu()
87 idx = self.historyTree.indexAt(pos) 95 idx = self.historyTree.indexAt(pos)
88 idx = idx.sibling(idx.row(), 0) 96 idx = idx.sibling(idx.row(), 0)
89 if idx.isValid() and not self.historyTree.model().hasChildren(idx): 97 if idx.isValid() and \
98 not self.historyTree.model().hasChildren(idx) and \
99 len(self.historyTree.selectionModel().selectedRows()) == 1:
90 menu.addAction( 100 menu.addAction(
91 self.tr("&Open"), self.__openHistoryInCurrentTab) 101 self.tr("&Open"), self.__openHistoryInCurrentTab)
92 menu.addAction( 102 menu.addAction(
93 self.tr("Open in New &Tab"), self.__openHistoryInNewTab) 103 self.tr("Open in New &Tab"), self.__openHistoryInNewTab)
104 menu.addAction(
105 self.tr("Open in New &Background Tab"),
106 self.__openHistoryInNewBackgroundTab)
107 menu.addAction(
108 self.tr("Open in New &Window"), self.c)
109 menu.addAction(
110 self.tr("Open in New Pri&vate Window"),
111 self.__openHistoryInPrivateWindow)
94 menu.addSeparator() 112 menu.addSeparator()
95 menu.addAction(self.tr("&Copy"), self.__copyHistory) 113 menu.addAction(self.tr("&Copy"), self.__copyHistory)
96 menu.addAction(self.tr("&Remove"), self.historyTree.removeSelected) 114 menu.addAction(self.tr("&Remove"), self.historyTree.removeSelected)
97 menu.exec_(QCursor.pos()) 115 menu.exec_(QCursor.pos())
98 116
100 """ 118 """
101 Private slot to handle the activation of an entry. 119 Private slot to handle the activation of an entry.
102 120
103 @param idx reference to the entry index (QModelIndex) 121 @param idx reference to the entry index (QModelIndex)
104 """ 122 """
105 self.__openHistory( 123 if QApplication.keyboardModifiers() & Qt.ControlModifier:
106 QApplication.keyboardModifiers() & Qt.ControlModifier) 124 self.__openHistoryInNewTab()
125 elif QApplication.keyboardModifiers() & Qt.ShiftModifier:
126 self.__openHistoryInNewWindow()
127 else:
128 self.__openHistoryInCurrentTab()
107 129
108 def __openHistoryInCurrentTab(self): 130 def __openHistoryInCurrentTab(self):
109 """ 131 """
110 Private slot to open a history entry in the current browser tab. 132 Private slot to open a history entry in the current browser tab.
111 """ 133 """
112 self.__openHistory(False) 134 self.__openHistory()
113 135
114 def __openHistoryInNewTab(self): 136 def __openHistoryInNewTab(self):
115 """ 137 """
116 Private slot to open a history entry in a new browser tab. 138 Private slot to open a history entry in a new browser tab.
117 """ 139 """
118 self.__openHistory(True) 140 self.__openHistory(newTab=True)
119 141
120 def __openHistory(self, newTab): 142 def __openHistoryInNewBackgroundTab(self):
143 """
144 Private slot to open a history entry in a new background tab.
145 """
146 self.__openHistory(newTab=True, background=True)
147
148 def __openHistoryInNewWindow(self):
149 """
150 Private slot to open a history entry in a new browser window.
151 """
152 self.__openHistory(newWindow=True)
153
154 def __openHistoryInPrivateWindow(self):
155 """
156 Private slot to open a history entry in a new private browser window.
157 """
158 self.__openHistory(newWindow=True, privateWindow=True)
159
160 def __openHistory(self, newTab=False, background=False,
161 newWindow=False, privateWindow=False):
121 """ 162 """
122 Private method to open a history entry. 163 Private method to open a history entry.
123 164
124 @param newTab flag indicating to open the history entry in a new tab 165 @param newTab flag indicating to open the feed message in a new tab
166 @type bool
167 @param background flag indicating to open the bookmark in a new
168 background tab
169 @type bool
170 @param newWindow flag indicating to open the bookmark in a new window
171 @type bool
172 @param privateWindow flag indicating to open the bookmark in a new
173 private window
174 @type bool
125 (boolean) 175 (boolean)
126 """ 176 """
127 idx = self.historyTree.currentIndex() 177 idx = self.historyTree.currentIndex()
128 if newTab: 178 if newTab:
129 self.newUrl.emit( 179 if background:
130 idx.data(HistoryModel.UrlRole), 180 self.newBackgroundTab.emit(
131 idx.data(HistoryModel.TitleRole)) 181 idx.data(HistoryModel.UrlRole),
182 idx.data(HistoryModel.TitleRole))
183 else:
184 self.newTab.emit(
185 idx.data(HistoryModel.UrlRole),
186 idx.data(HistoryModel.TitleRole))
187 elif newWindow:
188 if privateWindow:
189 self.newPrivateWindow.emit(
190 idx.data(HistoryModel.UrlRole),
191 idx.data(HistoryModel.TitleRole))
192 else:
193 self.newWindow.emit(
194 idx.data(HistoryModel.UrlRole),
195 idx.data(HistoryModel.TitleRole))
132 else: 196 else:
133 self.openUrl.emit( 197 self.openUrl.emit(
134 idx.data(HistoryModel.UrlRole), 198 idx.data(HistoryModel.UrlRole),
135 idx.data(HistoryModel.TitleRole)) 199 idx.data(HistoryModel.TitleRole))
136 200

eric ide

mercurial