Merge branch 'toofar-buffer_completion_delete_item-1443'

This commit is contained in:
Florian Bruhin 2016-04-28 07:09:38 +02:00
commit c39800675e
3 changed files with 53 additions and 10 deletions

View File

@ -36,6 +36,8 @@ Changed
the right. the right.
- `:yank` can now yank the pretty/decoded URL by adding `--pretty` - `:yank` can now yank the pretty/decoded URL by adding `--pretty`
- `:navigate` now clears the URL fragment - `:navigate` now clears the URL fragment
- `:completion-item-del` (`Ctrl-D`) can now be used in `:buffer` completion to
close a tab
Fixed Fixed
~~~~~ ~~~~~

View File

@ -162,12 +162,12 @@ Contributors, sorted by the number of commits in descending order:
* Kevin Velghe * Kevin Velghe
* Austin Anderson * Austin Anderson
* Panagiotis Ktistakis * Panagiotis Ktistakis
* Jimmy
* Alexey "Averrin" Nabrodov * Alexey "Averrin" Nabrodov
* avk * avk
* ZDarian * ZDarian
* Milan Svoboda * Milan Svoboda
* John ShaggyTwoDope Jenkins * John ShaggyTwoDope Jenkins
* Jimmy
* Peter Vilim * Peter Vilim
* Clayton Craft * Clayton Craft
* Oliver Caldwell * Oliver Caldwell

View File

@ -23,7 +23,7 @@ from PyQt5.QtCore import Qt, QTimer, pyqtSlot
from qutebrowser.browser import webview from qutebrowser.browser import webview
from qutebrowser.config import config, configdata from qutebrowser.config import config, configdata
from qutebrowser.utils import objreg, log from qutebrowser.utils import objreg, log, qtutils
from qutebrowser.commands import cmdutils from qutebrowser.commands import cmdutils
from qutebrowser.completion.models import base from qutebrowser.completion.models import base
@ -153,7 +153,7 @@ class TabCompletionModel(base.BaseCompletionModel):
# https://github.com/The-Compiler/qutebrowser/issues/545 # https://github.com/The-Compiler/qutebrowser/issues/545
# pylint: disable=abstract-method # pylint: disable=abstract-method
#IDX_COLUMN = 0 IDX_COLUMN = 0
URL_COLUMN = 1 URL_COLUMN = 1
TEXT_COLUMN = 2 TEXT_COLUMN = 2
@ -201,15 +201,56 @@ class TabCompletionModel(base.BaseCompletionModel):
make sure we handled background loads too ... but iterating over a make sure we handled background loads too ... but iterating over a
few/few dozen/few hundred tabs doesn't take very long at all. few/few dozen/few hundred tabs doesn't take very long at all.
""" """
self.removeRows(0, self.rowCount()) window_count = 0
for win_id in objreg.window_registry: for win_id in objreg.window_registry:
tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=win_id)
if not tabbed_browser.shutting_down:
window_count += 1
if window_count < self.rowCount():
self.removeRows(window_count, self.rowCount() - window_count)
for i, win_id in enumerate(objreg.window_registry):
tabbed_browser = objreg.get('tabbed-browser', scope='window', tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=win_id) window=win_id)
if tabbed_browser.shutting_down: if tabbed_browser.shutting_down:
continue continue
c = self.new_category("{}".format(win_id)) if i >= self.rowCount():
for i in range(tabbed_browser.count()): c = self.new_category("{}".format(win_id))
tab = tabbed_browser.widget(i) else:
self.new_item(c, "{}/{}".format(win_id, i + 1), c = self.item(i, 0)
tab.url().toDisplayString(), c.setData("{}".format(win_id), Qt.DisplayRole)
tabbed_browser.page_title(i)) if tabbed_browser.count() < c.rowCount():
c.removeRows(tabbed_browser.count(),
c.rowCount() - tabbed_browser.count())
for idx in range(tabbed_browser.count()):
tab = tabbed_browser.widget(idx)
if idx >= c.rowCount():
self.new_item(c, "{}/{}".format(win_id, idx + 1),
tab.url().toDisplayString(),
tabbed_browser.page_title(idx))
else:
c.child(idx, 0).setData("{}/{}".format(win_id, idx + 1),
Qt.DisplayRole)
c.child(idx, 1).setData(tab.url().toDisplayString(),
Qt.DisplayRole)
c.child(idx, 2).setData(tabbed_browser.page_title(idx),
Qt.DisplayRole)
def delete_cur_item(self, completion):
"""Delete the selected item.
Args:
completion: The Completion object to use.
"""
index = completion.currentIndex()
qtutils.ensure_valid(index)
category = index.parent()
qtutils.ensure_valid(category)
index = category.child(index.row(), self.IDX_COLUMN)
win_id, tab_index = index.data().split('/')
tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=int(win_id))
tabbed_browser.on_tab_close_requested(int(tab_index) - 1)