25 |
30 |
26 |
31 |
27 class HistoryMenuModel(QAbstractProxyModel): |
32 class HistoryMenuModel(QAbstractProxyModel): |
28 """ |
33 """ |
29 Class implementing a model for the history menu. |
34 Class implementing a model for the history menu. |
30 |
35 |
31 It maps the first bunch of items of the source model to the root. |
36 It maps the first bunch of items of the source model to the root. |
32 """ |
37 """ |
|
38 |
33 MOVEDROWS = 15 |
39 MOVEDROWS = 15 |
34 |
40 |
35 def __init__(self, sourceModel, parent=None): |
41 def __init__(self, sourceModel, parent=None): |
36 """ |
42 """ |
37 Constructor |
43 Constructor |
38 |
44 |
39 @param sourceModel reference to the source model (QAbstractItemModel) |
45 @param sourceModel reference to the source model (QAbstractItemModel) |
40 @param parent reference to the parent object (QObject) |
46 @param parent reference to the parent object (QObject) |
41 """ |
47 """ |
42 super().__init__(parent) |
48 super().__init__(parent) |
43 |
49 |
44 self.__treeModel = sourceModel |
50 self.__treeModel = sourceModel |
45 |
51 |
46 self.setSourceModel(sourceModel) |
52 self.setSourceModel(sourceModel) |
47 |
53 |
48 def bumpedRows(self): |
54 def bumpedRows(self): |
49 """ |
55 """ |
50 Public method to determine the number of rows moved to the root. |
56 Public method to determine the number of rows moved to the root. |
51 |
57 |
52 @return number of rows moved to the root (integer) |
58 @return number of rows moved to the root (integer) |
53 """ |
59 """ |
54 first = self.__treeModel.index(0, 0) |
60 first = self.__treeModel.index(0, 0) |
55 if not first.isValid(): |
61 if not first.isValid(): |
56 return 0 |
62 return 0 |
57 return min(self.__treeModel.rowCount(first), self.MOVEDROWS) |
63 return min(self.__treeModel.rowCount(first), self.MOVEDROWS) |
58 |
64 |
59 def columnCount(self, parent=None): |
65 def columnCount(self, parent=None): |
60 """ |
66 """ |
61 Public method to get the number of columns. |
67 Public method to get the number of columns. |
62 |
68 |
63 @param parent index of parent (QModelIndex) |
69 @param parent index of parent (QModelIndex) |
64 @return number of columns (integer) |
70 @return number of columns (integer) |
65 """ |
71 """ |
66 if parent is None: |
72 if parent is None: |
67 parent = QModelIndex() |
73 parent = QModelIndex() |
68 |
74 |
69 return self.__treeModel.columnCount(self.mapToSource(parent)) |
75 return self.__treeModel.columnCount(self.mapToSource(parent)) |
70 |
76 |
71 def rowCount(self, parent=None): |
77 def rowCount(self, parent=None): |
72 """ |
78 """ |
73 Public method to determine the number of rows. |
79 Public method to determine the number of rows. |
74 |
80 |
75 @param parent index of parent (QModelIndex) |
81 @param parent index of parent (QModelIndex) |
76 @return number of rows (integer) |
82 @return number of rows (integer) |
77 """ |
83 """ |
78 if parent is None: |
84 if parent is None: |
79 parent = QModelIndex() |
85 parent = QModelIndex() |
80 |
86 |
81 if parent.column() > 0: |
87 if parent.column() > 0: |
82 return 0 |
88 return 0 |
83 |
89 |
84 if not parent.isValid(): |
90 if not parent.isValid(): |
85 folders = self.sourceModel().rowCount() |
91 folders = self.sourceModel().rowCount() |
86 bumpedItems = self.bumpedRows() |
92 bumpedItems = self.bumpedRows() |
87 if ( |
93 if ( |
88 bumpedItems <= self.MOVEDROWS and |
94 bumpedItems <= self.MOVEDROWS |
89 bumpedItems == self.sourceModel().rowCount( |
95 and bumpedItems |
90 self.sourceModel().index(0, 0)) |
96 == self.sourceModel().rowCount(self.sourceModel().index(0, 0)) |
91 ): |
97 ): |
92 folders -= 1 |
98 folders -= 1 |
93 return bumpedItems + folders |
99 return bumpedItems + folders |
94 |
100 |
95 if ( |
101 if parent.internalId() == sys.maxsize and parent.row() < self.bumpedRows(): |
96 parent.internalId() == sys.maxsize and |
|
97 parent.row() < self.bumpedRows() |
|
98 ): |
|
99 return 0 |
102 return 0 |
100 |
103 |
101 idx = self.mapToSource(parent) |
104 idx = self.mapToSource(parent) |
102 defaultCount = self.sourceModel().rowCount(idx) |
105 defaultCount = self.sourceModel().rowCount(idx) |
103 if idx == self.sourceModel().index(0, 0): |
106 if idx == self.sourceModel().index(0, 0): |
104 return defaultCount - self.bumpedRows() |
107 return defaultCount - self.bumpedRows() |
105 |
108 |
106 return defaultCount |
109 return defaultCount |
107 |
110 |
108 def mapFromSource(self, sourceIndex): |
111 def mapFromSource(self, sourceIndex): |
109 """ |
112 """ |
110 Public method to map an index to the proxy model index. |
113 Public method to map an index to the proxy model index. |
111 |
114 |
112 @param sourceIndex reference to a source model index (QModelIndex) |
115 @param sourceIndex reference to a source model index (QModelIndex) |
113 @return proxy model index (QModelIndex) |
116 @return proxy model index (QModelIndex) |
114 """ |
117 """ |
115 sourceRow = self.__treeModel.mapToSource(sourceIndex).row() |
118 sourceRow = self.__treeModel.mapToSource(sourceIndex).row() |
116 return self.createIndex( |
119 return self.createIndex(sourceIndex.row(), sourceIndex.column(), sourceRow) |
117 sourceIndex.row(), sourceIndex.column(), sourceRow) |
120 |
118 |
|
119 def mapToSource(self, proxyIndex): |
121 def mapToSource(self, proxyIndex): |
120 """ |
122 """ |
121 Public method to map an index to the source model index. |
123 Public method to map an index to the source model index. |
122 |
124 |
123 @param proxyIndex reference to a proxy model index (QModelIndex) |
125 @param proxyIndex reference to a proxy model index (QModelIndex) |
124 @return source model index (QModelIndex) |
126 @return source model index (QModelIndex) |
125 """ |
127 """ |
126 if not proxyIndex.isValid(): |
128 if not proxyIndex.isValid(): |
127 return QModelIndex() |
129 return QModelIndex() |
128 |
130 |
129 if proxyIndex.internalId() == sys.maxsize: |
131 if proxyIndex.internalId() == sys.maxsize: |
130 bumpedItems = self.bumpedRows() |
132 bumpedItems = self.bumpedRows() |
131 if proxyIndex.row() < bumpedItems: |
133 if proxyIndex.row() < bumpedItems: |
132 return self.__treeModel.index( |
134 return self.__treeModel.index( |
133 proxyIndex.row(), proxyIndex.column(), |
135 proxyIndex.row(), proxyIndex.column(), self.__treeModel.index(0, 0) |
134 self.__treeModel.index(0, 0)) |
136 ) |
135 if ( |
137 if ( |
136 bumpedItems <= self.MOVEDROWS and |
138 bumpedItems <= self.MOVEDROWS |
137 bumpedItems == self.sourceModel().rowCount( |
139 and bumpedItems |
138 self.__treeModel.index(0, 0)) |
140 == self.sourceModel().rowCount(self.__treeModel.index(0, 0)) |
139 ): |
141 ): |
140 bumpedItems -= 1 |
142 bumpedItems -= 1 |
141 return self.__treeModel.index(proxyIndex.row() - bumpedItems, |
143 return self.__treeModel.index( |
142 proxyIndex.column()) |
144 proxyIndex.row() - bumpedItems, proxyIndex.column() |
143 |
145 ) |
|
146 |
144 historyIndex = self.__treeModel.sourceModel().index( |
147 historyIndex = self.__treeModel.sourceModel().index( |
145 proxyIndex.internalId(), proxyIndex.column()) |
148 proxyIndex.internalId(), proxyIndex.column() |
|
149 ) |
146 treeIndex = self.__treeModel.mapFromSource(historyIndex) |
150 treeIndex = self.__treeModel.mapFromSource(historyIndex) |
147 return treeIndex |
151 return treeIndex |
148 |
152 |
149 def index(self, row, column, parent=None): |
153 def index(self, row, column, parent=None): |
150 """ |
154 """ |
151 Public method to create an index. |
155 Public method to create an index. |
152 |
156 |
153 @param row row number for the index (integer) |
157 @param row row number for the index (integer) |
154 @param column column number for the index (integer) |
158 @param column column number for the index (integer) |
155 @param parent index of the parent item (QModelIndex) |
159 @param parent index of the parent item (QModelIndex) |
156 @return requested index (QModelIndex) |
160 @return requested index (QModelIndex) |
157 """ |
161 """ |
158 if parent is None: |
162 if parent is None: |
159 parent = QModelIndex() |
163 parent = QModelIndex() |
160 |
164 |
161 if ( |
165 if ( |
162 row < 0 or |
166 row < 0 |
163 column < 0 or |
167 or column < 0 |
164 column >= self.columnCount(parent) or |
168 or column >= self.columnCount(parent) |
165 parent.column() > 0 |
169 or parent.column() > 0 |
166 ): |
170 ): |
167 return QModelIndex() |
171 return QModelIndex() |
168 |
172 |
169 if not parent.isValid(): |
173 if not parent.isValid(): |
170 return self.createIndex(row, column, sys.maxsize) |
174 return self.createIndex(row, column, sys.maxsize) |
171 |
175 |
172 treeIndexParent = self.mapToSource(parent) |
176 treeIndexParent = self.mapToSource(parent) |
173 |
177 |
174 bumpedItems = 0 |
178 bumpedItems = 0 |
175 if treeIndexParent == self.sourceModel().index(0, 0): |
179 if treeIndexParent == self.sourceModel().index(0, 0): |
176 bumpedItems = self.bumpedRows() |
180 bumpedItems = self.bumpedRows() |
177 treeIndex = self.__treeModel.index( |
181 treeIndex = self.__treeModel.index(row + bumpedItems, column, treeIndexParent) |
178 row + bumpedItems, column, treeIndexParent) |
|
179 historyIndex = self.__treeModel.mapToSource(treeIndex) |
182 historyIndex = self.__treeModel.mapToSource(treeIndex) |
180 historyRow = historyIndex.row() |
183 historyRow = historyIndex.row() |
181 if historyRow == -1: |
184 if historyRow == -1: |
182 historyRow = treeIndex.row() |
185 historyRow = treeIndex.row() |
183 return self.createIndex(row, column, historyRow) |
186 return self.createIndex(row, column, historyRow) |
184 |
187 |
185 def parent(self, index): |
188 def parent(self, index): |
186 """ |
189 """ |
187 Public method to get the parent index. |
190 Public method to get the parent index. |
188 |
191 |
189 @param index index of item to get parent (QModelIndex) |
192 @param index index of item to get parent (QModelIndex) |
190 @return index of parent (QModelIndex) |
193 @return index of parent (QModelIndex) |
191 """ |
194 """ |
192 offset = index.internalId() |
195 offset = index.internalId() |
193 if offset == sys.maxsize or not index.isValid(): |
196 if offset == sys.maxsize or not index.isValid(): |
194 return QModelIndex() |
197 return QModelIndex() |
195 |
198 |
196 historyIndex = self.__treeModel.sourceModel().index( |
199 historyIndex = self.__treeModel.sourceModel().index(index.internalId(), 0) |
197 index.internalId(), 0) |
|
198 treeIndex = self.__treeModel.mapFromSource(historyIndex) |
200 treeIndex = self.__treeModel.mapFromSource(historyIndex) |
199 treeIndexParent = treeIndex.parent() |
201 treeIndexParent = treeIndex.parent() |
200 |
202 |
201 sourceRow = self.sourceModel().mapToSource(treeIndexParent).row() |
203 sourceRow = self.sourceModel().mapToSource(treeIndexParent).row() |
202 bumpedItems = self.bumpedRows() |
204 bumpedItems = self.bumpedRows() |
203 if ( |
205 if bumpedItems <= self.MOVEDROWS and bumpedItems == self.sourceModel().rowCount( |
204 bumpedItems <= self.MOVEDROWS and |
206 self.sourceModel().index(0, 0) |
205 bumpedItems == self.sourceModel().rowCount( |
|
206 self.sourceModel().index(0, 0)) |
|
207 ): |
207 ): |
208 bumpedItems -= 1 |
208 bumpedItems -= 1 |
209 |
209 |
210 return self.createIndex(bumpedItems + treeIndexParent.row(), |
210 return self.createIndex( |
211 treeIndexParent.column(), |
211 bumpedItems + treeIndexParent.row(), treeIndexParent.column(), sourceRow |
212 sourceRow) |
212 ) |
213 |
213 |
214 def mimeData(self, indexes): |
214 def mimeData(self, indexes): |
215 """ |
215 """ |
216 Public method to return the mime data. |
216 Public method to return the mime data. |
217 |
217 |
218 @param indexes list of indexes (QModelIndexList) |
218 @param indexes list of indexes (QModelIndexList) |
219 @return mime data (QMimeData) |
219 @return mime data (QMimeData) |
220 """ |
220 """ |
221 urls = [] |
221 urls = [] |
222 for index in indexes: |
222 for index in indexes: |
223 url = index.data(HistoryModel.UrlRole) |
223 url = index.data(HistoryModel.UrlRole) |
224 urls.append(url) |
224 urls.append(url) |
225 |
225 |
226 mdata = QMimeData() |
226 mdata = QMimeData() |
227 mdata.setUrls(urls) |
227 mdata.setUrls(urls) |
228 return mdata |
228 return mdata |
229 |
229 |
230 |
230 |
231 class HistoryMostVisitedMenuModel(QSortFilterProxyModel): |
231 class HistoryMostVisitedMenuModel(QSortFilterProxyModel): |
232 """ |
232 """ |
233 Class implementing a model to show the most visited history entries. |
233 Class implementing a model to show the most visited history entries. |
234 """ |
234 """ |
|
235 |
235 def __init__(self, sourceModel, parent=None): |
236 def __init__(self, sourceModel, parent=None): |
236 """ |
237 """ |
237 Constructor |
238 Constructor |
238 |
239 |
239 @param sourceModel reference to the source model (QAbstractItemModel) |
240 @param sourceModel reference to the source model (QAbstractItemModel) |
240 @param parent reference to the parent object (QObject) |
241 @param parent reference to the parent object (QObject) |
241 """ |
242 """ |
242 super().__init__(parent) |
243 super().__init__(parent) |
243 |
244 |
244 self.setDynamicSortFilter(True) |
245 self.setDynamicSortFilter(True) |
245 self.setSourceModel(sourceModel) |
246 self.setSourceModel(sourceModel) |
246 |
247 |
247 def lessThan(self, left, right): |
248 def lessThan(self, left, right): |
248 """ |
249 """ |
249 Public method used to sort the displayed items. |
250 Public method used to sort the displayed items. |
250 |
251 |
251 @param left index of left item (QModelIndex) |
252 @param left index of left item (QModelIndex) |
252 @param right index of right item (QModelIndex) |
253 @param right index of right item (QModelIndex) |
253 @return true, if left is less than right (boolean) |
254 @return true, if left is less than right (boolean) |
254 """ |
255 """ |
255 from .HistoryFilterModel import HistoryFilterModel |
256 from .HistoryFilterModel import HistoryFilterModel |
256 frequency_L = self.sourceModel().data( |
257 |
257 left, HistoryFilterModel.FrequencyRole) |
258 frequency_L = self.sourceModel().data(left, HistoryFilterModel.FrequencyRole) |
258 dateTime_L = self.sourceModel().data( |
259 dateTime_L = self.sourceModel().data(left, HistoryModel.DateTimeRole) |
259 left, HistoryModel.DateTimeRole) |
260 frequency_R = self.sourceModel().data(right, HistoryFilterModel.FrequencyRole) |
260 frequency_R = self.sourceModel().data( |
261 dateTime_R = self.sourceModel().data(right, HistoryModel.DateTimeRole) |
261 right, HistoryFilterModel.FrequencyRole) |
262 |
262 dateTime_R = self.sourceModel().data( |
|
263 right, HistoryModel.DateTimeRole) |
|
264 |
|
265 # Sort results in descending frequency-derived score. If frequencies |
263 # Sort results in descending frequency-derived score. If frequencies |
266 # are equal, sort on most recently viewed |
264 # are equal, sort on most recently viewed |
267 if frequency_R == frequency_L: |
265 if frequency_R == frequency_L: |
268 return dateTime_R < dateTime_L |
266 return dateTime_R < dateTime_L |
269 |
267 |
270 return frequency_R < frequency_L |
268 return frequency_R < frequency_L |
271 |
269 |
272 |
270 |
273 class HistoryMenu(EricModelMenu): |
271 class HistoryMenu(EricModelMenu): |
274 """ |
272 """ |
275 Class implementing the history menu. |
273 Class implementing the history menu. |
276 |
274 |
277 @signal openUrl(QUrl, str) emitted to open a URL in the current tab |
275 @signal openUrl(QUrl, str) emitted to open a URL in the current tab |
278 @signal newTab(QUrl, str) emitted to open a URL in a new tab |
276 @signal newTab(QUrl, str) emitted to open a URL in a new tab |
279 @signal newBackgroundTab(QUrl, str) emitted to open a URL in a new |
277 @signal newBackgroundTab(QUrl, str) emitted to open a URL in a new |
280 background tab |
278 background tab |
281 @signal newWindow(QUrl, str) emitted to open a URL in a new window |
279 @signal newWindow(QUrl, str) emitted to open a URL in a new window |
282 @signal newPrivateWindow(QUrl, str) emitted to open a URL in a new |
280 @signal newPrivateWindow(QUrl, str) emitted to open a URL in a new |
283 private window |
281 private window |
284 """ |
282 """ |
|
283 |
285 openUrl = pyqtSignal(QUrl, str) |
284 openUrl = pyqtSignal(QUrl, str) |
286 newTab = pyqtSignal(QUrl, str) |
285 newTab = pyqtSignal(QUrl, str) |
287 newBackgroundTab = pyqtSignal(QUrl, str) |
286 newBackgroundTab = pyqtSignal(QUrl, str) |
288 newWindow = pyqtSignal(QUrl, str) |
287 newWindow = pyqtSignal(QUrl, str) |
289 newPrivateWindow = pyqtSignal(QUrl, str) |
288 newPrivateWindow = pyqtSignal(QUrl, str) |
290 |
289 |
291 def __init__(self, parent=None, tabWidget=None): |
290 def __init__(self, parent=None, tabWidget=None): |
292 """ |
291 """ |
293 Constructor |
292 Constructor |
294 |
293 |
295 @param parent reference to the parent widget (QWidget) |
294 @param parent reference to the parent widget (QWidget) |
296 @param tabWidget reference to the tab widget managing the browser |
295 @param tabWidget reference to the tab widget managing the browser |
297 tabs (HelpTabWidget |
296 tabs (HelpTabWidget |
298 """ |
297 """ |
299 EricModelMenu.__init__(self, parent) |
298 EricModelMenu.__init__(self, parent) |
300 |
299 |
301 self.__tabWidget = tabWidget |
300 self.__tabWidget = tabWidget |
302 self.__mw = parent |
301 self.__mw = parent |
303 |
302 |
304 self.__historyManager = None |
303 self.__historyManager = None |
305 self.__historyMenuModel = None |
304 self.__historyMenuModel = None |
306 self.__initialActions = [] |
305 self.__initialActions = [] |
307 self.__mostVisitedMenu = None |
306 self.__mostVisitedMenu = None |
308 |
307 |
309 self.__closedTabsMenu = QMenu(self.tr("Closed Tabs")) |
308 self.__closedTabsMenu = QMenu(self.tr("Closed Tabs")) |
310 self.__closedTabsMenu.aboutToShow.connect( |
309 self.__closedTabsMenu.aboutToShow.connect(self.__aboutToShowClosedTabsMenu) |
311 self.__aboutToShowClosedTabsMenu) |
|
312 self.__tabWidget.closedTabsManager().closedTabAvailable.connect( |
310 self.__tabWidget.closedTabsManager().closedTabAvailable.connect( |
313 self.__closedTabAvailable) |
311 self.__closedTabAvailable |
314 |
312 ) |
|
313 |
315 self.setMaxRows(7) |
314 self.setMaxRows(7) |
316 |
315 |
317 self.activated.connect(self.__activated) |
316 self.activated.connect(self.__activated) |
318 self.setStatusBarTextRole(HistoryModel.UrlStringRole) |
317 self.setStatusBarTextRole(HistoryModel.UrlStringRole) |
319 |
318 |
320 def __activated(self, idx): |
319 def __activated(self, idx): |
321 """ |
320 """ |
322 Private slot handling the activated signal. |
321 Private slot handling the activated signal. |
323 |
322 |
324 @param idx index of the activated item (QModelIndex) |
323 @param idx index of the activated item (QModelIndex) |
325 """ |
324 """ |
326 if self._keyboardModifiers & Qt.KeyboardModifier.ControlModifier: |
325 if self._keyboardModifiers & Qt.KeyboardModifier.ControlModifier: |
327 self.newTab.emit( |
326 self.newTab.emit( |
328 idx.data(HistoryModel.UrlRole), |
327 idx.data(HistoryModel.UrlRole), idx.data(HistoryModel.TitleRole) |
329 idx.data(HistoryModel.TitleRole)) |
328 ) |
330 elif self._keyboardModifiers & Qt.KeyboardModifier.ShiftModifier: |
329 elif self._keyboardModifiers & Qt.KeyboardModifier.ShiftModifier: |
331 self.newWindow.emit( |
330 self.newWindow.emit( |
332 idx.data(HistoryModel.UrlRole), |
331 idx.data(HistoryModel.UrlRole), idx.data(HistoryModel.TitleRole) |
333 idx.data(HistoryModel.TitleRole)) |
332 ) |
334 else: |
333 else: |
335 self.openUrl.emit( |
334 self.openUrl.emit( |
336 idx.data(HistoryModel.UrlRole), |
335 idx.data(HistoryModel.UrlRole), idx.data(HistoryModel.TitleRole) |
337 idx.data(HistoryModel.TitleRole)) |
336 ) |
338 |
337 |
339 def prePopulated(self): |
338 def prePopulated(self): |
340 """ |
339 """ |
341 Public method to add any actions before the tree. |
340 Public method to add any actions before the tree. |
342 |
341 |
343 @return flag indicating if any actions were added (boolean) |
342 @return flag indicating if any actions were added (boolean) |
344 """ |
343 """ |
345 if self.__historyManager is None: |
344 if self.__historyManager is None: |
346 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
345 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
|
346 |
347 self.__historyManager = WebBrowserWindow.historyManager() |
347 self.__historyManager = WebBrowserWindow.historyManager() |
348 self.__historyMenuModel = HistoryMenuModel( |
348 self.__historyMenuModel = HistoryMenuModel( |
349 self.__historyManager.historyTreeModel(), self) |
349 self.__historyManager.historyTreeModel(), self |
|
350 ) |
350 self.setModel(self.__historyMenuModel) |
351 self.setModel(self.__historyMenuModel) |
351 |
352 |
352 # initial actions |
353 # initial actions |
353 for act in self.__initialActions: |
354 for act in self.__initialActions: |
354 self.addAction(act) |
355 self.addAction(act) |
355 if len(self.__initialActions) != 0: |
356 if len(self.__initialActions) != 0: |
356 self.addSeparator() |
357 self.addSeparator() |
357 self.setFirstSeparator(self.__historyMenuModel.bumpedRows()) |
358 self.setFirstSeparator(self.__historyMenuModel.bumpedRows()) |
358 |
359 |
359 return False |
360 return False |
360 |
361 |
361 def postPopulated(self): |
362 def postPopulated(self): |
362 """ |
363 """ |
363 Public method to add any actions after the tree. |
364 Public method to add any actions after the tree. |
364 """ |
365 """ |
365 if len(self.__historyManager.history()) > 0: |
366 if len(self.__historyManager.history()) > 0: |
366 self.addSeparator() |
367 self.addSeparator() |
367 |
368 |
368 if self.__mostVisitedMenu is None: |
369 if self.__mostVisitedMenu is None: |
369 self.__mostVisitedMenu = HistoryMostVisitedMenu(10, self) |
370 self.__mostVisitedMenu = HistoryMostVisitedMenu(10, self) |
370 self.__mostVisitedMenu.setTitle(self.tr("Most Visited")) |
371 self.__mostVisitedMenu.setTitle(self.tr("Most Visited")) |
371 self.__mostVisitedMenu.openUrl.connect(self.openUrl) |
372 self.__mostVisitedMenu.openUrl.connect(self.openUrl) |
372 self.__mostVisitedMenu.newTab.connect(self.newTab) |
373 self.__mostVisitedMenu.newTab.connect(self.newTab) |
373 self.__mostVisitedMenu.newBackgroundTab.connect( |
374 self.__mostVisitedMenu.newBackgroundTab.connect(self.newBackgroundTab) |
374 self.newBackgroundTab) |
|
375 self.__mostVisitedMenu.newWindow.connect(self.newWindow) |
375 self.__mostVisitedMenu.newWindow.connect(self.newWindow) |
376 self.__mostVisitedMenu.newPrivateWindow.connect( |
376 self.__mostVisitedMenu.newPrivateWindow.connect(self.newPrivateWindow) |
377 self.newPrivateWindow) |
|
378 self.addMenu(self.__mostVisitedMenu) |
377 self.addMenu(self.__mostVisitedMenu) |
379 act = self.addMenu(self.__closedTabsMenu) |
378 act = self.addMenu(self.__closedTabsMenu) |
380 act.setIcon(UI.PixmapCache.getIcon("trash")) |
379 act.setIcon(UI.PixmapCache.getIcon("trash")) |
381 act.setEnabled(self.__tabWidget.canRestoreClosedTab()) |
380 act.setEnabled(self.__tabWidget.canRestoreClosedTab()) |
382 self.addSeparator() |
381 self.addSeparator() |
383 |
382 |
384 act = self.addAction(UI.PixmapCache.getIcon("history"), |
383 act = self.addAction( |
385 self.tr("Show All History...")) |
384 UI.PixmapCache.getIcon("history"), self.tr("Show All History...") |
|
385 ) |
386 act.triggered.connect(self.showHistoryDialog) |
386 act.triggered.connect(self.showHistoryDialog) |
387 act = self.addAction(UI.PixmapCache.getIcon("historyClear"), |
387 act = self.addAction( |
388 self.tr("Clear History...")) |
388 UI.PixmapCache.getIcon("historyClear"), self.tr("Clear History...") |
|
389 ) |
389 act.triggered.connect(self.__clearHistoryDialog) |
390 act.triggered.connect(self.__clearHistoryDialog) |
390 |
391 |
391 def setInitialActions(self, actions): |
392 def setInitialActions(self, actions): |
392 """ |
393 """ |
393 Public method to set the list of actions that should appear first in |
394 Public method to set the list of actions that should appear first in |
394 the menu. |
395 the menu. |
395 |
396 |
396 @param actions list of initial actions (list of QAction) |
397 @param actions list of initial actions (list of QAction) |
397 """ |
398 """ |
398 self.__initialActions = actions[:] |
399 self.__initialActions = actions[:] |
399 for act in self.__initialActions: |
400 for act in self.__initialActions: |
400 self.addAction(act) |
401 self.addAction(act) |
401 |
402 |
402 def showHistoryDialog(self): |
403 def showHistoryDialog(self): |
403 """ |
404 """ |
404 Public slot to show the history dialog. |
405 Public slot to show the history dialog. |
405 """ |
406 """ |
406 from .HistoryDialog import HistoryDialog |
407 from .HistoryDialog import HistoryDialog |
|
408 |
407 dlg = HistoryDialog(self.__mw) |
409 dlg = HistoryDialog(self.__mw) |
408 dlg.openUrl.connect(self.openUrl) |
410 dlg.openUrl.connect(self.openUrl) |
409 dlg.newTab.connect(self.newTab) |
411 dlg.newTab.connect(self.newTab) |
410 dlg.newBackgroundTab.connect(self.newBackgroundTab) |
412 dlg.newBackgroundTab.connect(self.newBackgroundTab) |
411 dlg.newWindow.connect(self.newWindow) |
413 dlg.newWindow.connect(self.newWindow) |
412 dlg.newPrivateWindow.connect(self.newPrivateWindow) |
414 dlg.newPrivateWindow.connect(self.newPrivateWindow) |
413 dlg.show() |
415 dlg.show() |
414 |
416 |
415 def __clearHistoryDialog(self): |
417 def __clearHistoryDialog(self): |
416 """ |
418 """ |
417 Private slot to clear the history. |
419 Private slot to clear the history. |
418 """ |
420 """ |
419 if self.__historyManager is not None and EricMessageBox.yesNo( |
421 if self.__historyManager is not None and EricMessageBox.yesNo( |
420 self, |
422 self, |
421 self.tr("Clear History"), |
423 self.tr("Clear History"), |
422 self.tr("""Do you want to clear the history?""")): |
424 self.tr("""Do you want to clear the history?"""), |
|
425 ): |
423 self.__historyManager.clear() |
426 self.__historyManager.clear() |
424 self.__tabWidget.clearClosedTabsList() |
427 self.__tabWidget.clearClosedTabsList() |
425 |
428 |
426 def __aboutToShowClosedTabsMenu(self): |
429 def __aboutToShowClosedTabsMenu(self): |
427 """ |
430 """ |
428 Private slot to populate the closed tabs menu. |
431 Private slot to populate the closed tabs menu. |
429 """ |
432 """ |
430 fm = self.__closedTabsMenu.fontMetrics() |
433 fm = self.__closedTabsMenu.fontMetrics() |
431 try: |
434 try: |
432 maxWidth = fm.horizontalAdvance('m') * 40 |
435 maxWidth = fm.horizontalAdvance("m") * 40 |
433 except AttributeError: |
436 except AttributeError: |
434 maxWidth = fm.width('m') * 40 |
437 maxWidth = fm.width("m") * 40 |
435 |
438 |
436 import WebBrowser.WebBrowserWindow |
439 import WebBrowser.WebBrowserWindow |
|
440 |
437 self.__closedTabsMenu.clear() |
441 self.__closedTabsMenu.clear() |
438 for index, tab in enumerate( |
442 for index, tab in enumerate( |
439 self.__tabWidget.closedTabsManager().allClosedTabs() |
443 self.__tabWidget.closedTabsManager().allClosedTabs() |
440 ): |
444 ): |
441 title = fm.elidedText(tab.title, Qt.TextElideMode.ElideRight, |
445 title = fm.elidedText(tab.title, Qt.TextElideMode.ElideRight, maxWidth) |
442 maxWidth) |
|
443 act = self.__closedTabsMenu.addAction( |
446 act = self.__closedTabsMenu.addAction( |
444 WebBrowser.WebBrowserWindow.WebBrowserWindow.icon(tab.url), |
447 WebBrowser.WebBrowserWindow.WebBrowserWindow.icon(tab.url), title |
445 title) |
448 ) |
446 act.setData(index) |
449 act.setData(index) |
447 act.triggered.connect( |
450 act.triggered.connect( |
448 functools.partial(self.__tabWidget.restoreClosedTab, act)) |
451 functools.partial(self.__tabWidget.restoreClosedTab, act) |
|
452 ) |
449 self.__closedTabsMenu.addSeparator() |
453 self.__closedTabsMenu.addSeparator() |
450 self.__closedTabsMenu.addAction( |
454 self.__closedTabsMenu.addAction( |
451 self.tr("Restore All Closed Tabs"), |
455 self.tr("Restore All Closed Tabs"), self.__tabWidget.restoreAllClosedTabs |
452 self.__tabWidget.restoreAllClosedTabs) |
456 ) |
453 self.__closedTabsMenu.addAction( |
457 self.__closedTabsMenu.addAction( |
454 self.tr("Clear List"), |
458 self.tr("Clear List"), self.__tabWidget.clearClosedTabsList |
455 self.__tabWidget.clearClosedTabsList) |
459 ) |
456 |
460 |
457 def __closedTabAvailable(self, avail): |
461 def __closedTabAvailable(self, avail): |
458 """ |
462 """ |
459 Private slot to handle changes of the availability of closed tabs. |
463 Private slot to handle changes of the availability of closed tabs. |
460 |
464 |
461 @param avail flag indicating the availability of closed tabs (boolean) |
465 @param avail flag indicating the availability of closed tabs (boolean) |
462 """ |
466 """ |
463 self.__closedTabsMenu.setEnabled(avail) |
467 self.__closedTabsMenu.setEnabled(avail) |
464 |
468 |
465 |
469 |
466 class HistoryMostVisitedMenu(EricModelMenu): |
470 class HistoryMostVisitedMenu(EricModelMenu): |
467 """ |
471 """ |
468 Class implementing the most visited history menu. |
472 Class implementing the most visited history menu. |
469 |
473 |
470 @signal openUrl(QUrl, str) emitted to open a URL in the current tab |
474 @signal openUrl(QUrl, str) emitted to open a URL in the current tab |
471 @signal newTab(QUrl, str) emitted to open a URL in a new tab |
475 @signal newTab(QUrl, str) emitted to open a URL in a new tab |
472 @signal newBackgroundTab(QUrl, str) emitted to open a URL in a new |
476 @signal newBackgroundTab(QUrl, str) emitted to open a URL in a new |
473 background tab |
477 background tab |
474 @signal newWindow(QUrl, str) emitted to open a URL in a new window |
478 @signal newWindow(QUrl, str) emitted to open a URL in a new window |
475 @signal newPrivateWindow(QUrl, str) emitted to open a URL in a new |
479 @signal newPrivateWindow(QUrl, str) emitted to open a URL in a new |
476 private window |
480 private window |
477 """ |
481 """ |
|
482 |
478 openUrl = pyqtSignal(QUrl, str) |
483 openUrl = pyqtSignal(QUrl, str) |
479 newTab = pyqtSignal(QUrl, str) |
484 newTab = pyqtSignal(QUrl, str) |
480 newBackgroundTab = pyqtSignal(QUrl, str) |
485 newBackgroundTab = pyqtSignal(QUrl, str) |
481 newWindow = pyqtSignal(QUrl, str) |
486 newWindow = pyqtSignal(QUrl, str) |
482 newPrivateWindow = pyqtSignal(QUrl, str) |
487 newPrivateWindow = pyqtSignal(QUrl, str) |
483 |
488 |
484 def __init__(self, count, parent=None): |
489 def __init__(self, count, parent=None): |
485 """ |
490 """ |
486 Constructor |
491 Constructor |
487 |
492 |
488 @param count maximum number of entries to be shown (integer) |
493 @param count maximum number of entries to be shown (integer) |
489 @param parent reference to the parent widget (QWidget) |
494 @param parent reference to the parent widget (QWidget) |
490 """ |
495 """ |
491 EricModelMenu.__init__(self, parent) |
496 EricModelMenu.__init__(self, parent) |
492 |
497 |
493 self.__historyMenuModel = None |
498 self.__historyMenuModel = None |
494 |
499 |
495 self.setMaxRows(count + 1) |
500 self.setMaxRows(count + 1) |
496 |
501 |
497 self.setStatusBarTextRole(HistoryModel.UrlStringRole) |
502 self.setStatusBarTextRole(HistoryModel.UrlStringRole) |
498 |
503 |
499 def __activated(self, idx): |
504 def __activated(self, idx): |
500 """ |
505 """ |
501 Private slot handling the activated signal. |
506 Private slot handling the activated signal. |
502 |
507 |
503 @param idx index of the activated item (QModelIndex) |
508 @param idx index of the activated item (QModelIndex) |
504 """ |
509 """ |
505 if self._keyboardModifiers & Qt.KeyboardModifier.ControlModifier: |
510 if self._keyboardModifiers & Qt.KeyboardModifier.ControlModifier: |
506 self.newTab.emit( |
511 self.newTab.emit( |
507 idx.data(HistoryModel.UrlRole), |
512 idx.data(HistoryModel.UrlRole), idx.data(HistoryModel.TitleRole) |
508 idx.data(HistoryModel.TitleRole)) |
513 ) |
509 elif self._keyboardModifiers & Qt.KeyboardModifier.ShiftModifier: |
514 elif self._keyboardModifiers & Qt.KeyboardModifier.ShiftModifier: |
510 self.newWindow.emit( |
515 self.newWindow.emit( |
511 idx.data(HistoryModel.UrlRole), |
516 idx.data(HistoryModel.UrlRole), idx.data(HistoryModel.TitleRole) |
512 idx.data(HistoryModel.TitleRole)) |
517 ) |
513 else: |
518 else: |
514 self.openUrl.emit( |
519 self.openUrl.emit( |
515 idx.data(HistoryModel.UrlRole), |
520 idx.data(HistoryModel.UrlRole), idx.data(HistoryModel.TitleRole) |
516 idx.data(HistoryModel.TitleRole)) |
521 ) |
517 |
522 |
518 def prePopulated(self): |
523 def prePopulated(self): |
519 """ |
524 """ |
520 Public method to add any actions before the tree. |
525 Public method to add any actions before the tree. |
521 |
526 |
522 @return flag indicating if any actions were added (boolean) |
527 @return flag indicating if any actions were added (boolean) |
523 """ |
528 """ |
524 if self.__historyMenuModel is None: |
529 if self.__historyMenuModel is None: |
525 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
530 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
|
531 |
526 historyManager = WebBrowserWindow.historyManager() |
532 historyManager = WebBrowserWindow.historyManager() |
527 self.__historyMenuModel = HistoryMostVisitedMenuModel( |
533 self.__historyMenuModel = HistoryMostVisitedMenuModel( |
528 historyManager.historyFilterModel(), self) |
534 historyManager.historyFilterModel(), self |
|
535 ) |
529 self.setModel(self.__historyMenuModel) |
536 self.setModel(self.__historyMenuModel) |
530 self.__historyMenuModel.sort(0) |
537 self.__historyMenuModel.sort(0) |
531 |
538 |
532 return False |
539 return False |