2015-03-11 23:07:58 +01:00
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
|
|
|
|
2017-05-09 21:37:03 +02:00
|
|
|
# Copyright 2014-2017 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
2015-03-11 23:07:58 +01:00
|
|
|
#
|
|
|
|
# This file is part of qutebrowser.
|
|
|
|
#
|
|
|
|
# qutebrowser is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# qutebrowser is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-09-16 21:41:54 +02:00
|
|
|
"""Functions that return miscellaneous completion models."""
|
2015-03-11 23:07:58 +01:00
|
|
|
|
Move bind completion to configmodels.
When in miscmodels, the config module was unable to find the function.
It appears to be some sort of circular import issue:
```
File "/home/rcorre/projects/contrib/qutebrowser/qutebrowser/app.py", line 44, in <module>
from qutebrowser.completion.models import miscmodels
File "/home/rcorre/projects/contrib/qutebrowser/qutebrowser/completion/models/miscmodels.py", line 24, in <module>
from qutebrowser.completion.models import completionmodel, listcategory, util
File "/home/rcorre/projects/contrib/qutebrowser/qutebrowser/completion/models/util.py", line 24, in <module>
from qutebrowser.config import config
File "/home/rcorre/projects/contrib/qutebrowser/qutebrowser/config/config.py", line 223, in <module>
class ConfigCommands:
File "/home/rcorre/projects/contrib/qutebrowser/qutebrowser/config/config.py", line 314, in ConfigCommands
@cmdutils.argument('command', completion=miscmodels.bind)
AttributeError: module 'qutebrowser.completion.models.miscmodels' has no attribute 'bind'
```
As configmodel imports util (and thereby config as well) it is unclear
to me why moving bind() to configmodel actually fixes this, but it does.
2017-08-19 23:37:04 +02:00
|
|
|
from qutebrowser.config import configdata
|
2017-06-21 05:04:03 +02:00
|
|
|
from qutebrowser.utils import objreg, log
|
Move bind completion to configmodels.
When in miscmodels, the config module was unable to find the function.
It appears to be some sort of circular import issue:
```
File "/home/rcorre/projects/contrib/qutebrowser/qutebrowser/app.py", line 44, in <module>
from qutebrowser.completion.models import miscmodels
File "/home/rcorre/projects/contrib/qutebrowser/qutebrowser/completion/models/miscmodels.py", line 24, in <module>
from qutebrowser.completion.models import completionmodel, listcategory, util
File "/home/rcorre/projects/contrib/qutebrowser/qutebrowser/completion/models/util.py", line 24, in <module>
from qutebrowser.config import config
File "/home/rcorre/projects/contrib/qutebrowser/qutebrowser/config/config.py", line 223, in <module>
class ConfigCommands:
File "/home/rcorre/projects/contrib/qutebrowser/qutebrowser/config/config.py", line 314, in ConfigCommands
@cmdutils.argument('command', completion=miscmodels.bind)
AttributeError: module 'qutebrowser.completion.models.miscmodels' has no attribute 'bind'
```
As configmodel imports util (and thereby config as well) it is unclear
to me why moving bind() to configmodel actually fixes this, but it does.
2017-08-19 23:37:04 +02:00
|
|
|
from qutebrowser.completion.models import completionmodel, listcategory, util
|
2015-03-11 23:07:58 +01:00
|
|
|
|
|
|
|
|
2016-09-16 21:41:54 +02:00
|
|
|
def command():
|
2016-08-01 18:30:12 +02:00
|
|
|
"""A CompletionModel filled with non-hidden commands and descriptions."""
|
2017-02-23 04:25:11 +01:00
|
|
|
model = completionmodel.CompletionModel(column_widths=(20, 60, 20))
|
Move bind completion to configmodels.
When in miscmodels, the config module was unable to find the function.
It appears to be some sort of circular import issue:
```
File "/home/rcorre/projects/contrib/qutebrowser/qutebrowser/app.py", line 44, in <module>
from qutebrowser.completion.models import miscmodels
File "/home/rcorre/projects/contrib/qutebrowser/qutebrowser/completion/models/miscmodels.py", line 24, in <module>
from qutebrowser.completion.models import completionmodel, listcategory, util
File "/home/rcorre/projects/contrib/qutebrowser/qutebrowser/completion/models/util.py", line 24, in <module>
from qutebrowser.config import config
File "/home/rcorre/projects/contrib/qutebrowser/qutebrowser/config/config.py", line 223, in <module>
class ConfigCommands:
File "/home/rcorre/projects/contrib/qutebrowser/qutebrowser/config/config.py", line 314, in ConfigCommands
@cmdutils.argument('command', completion=miscmodels.bind)
AttributeError: module 'qutebrowser.completion.models.miscmodels' has no attribute 'bind'
```
As configmodel imports util (and thereby config as well) it is unclear
to me why moving bind() to configmodel actually fixes this, but it does.
2017-08-19 23:37:04 +02:00
|
|
|
cmdlist = util.get_cmd_completions(include_aliases=True,
|
|
|
|
include_hidden=False)
|
2017-03-03 14:31:28 +01:00
|
|
|
model.add_category(listcategory.ListCategory("Commands", cmdlist))
|
2016-09-16 21:41:54 +02:00
|
|
|
return model
|
2015-03-11 23:07:58 +01:00
|
|
|
|
|
|
|
|
2016-09-16 21:41:54 +02:00
|
|
|
def helptopic():
|
2015-03-11 23:07:58 +01:00
|
|
|
"""A CompletionModel filled with help topics."""
|
2017-02-23 04:25:11 +01:00
|
|
|
model = completionmodel.CompletionModel()
|
2016-09-16 21:41:54 +02:00
|
|
|
|
Move bind completion to configmodels.
When in miscmodels, the config module was unable to find the function.
It appears to be some sort of circular import issue:
```
File "/home/rcorre/projects/contrib/qutebrowser/qutebrowser/app.py", line 44, in <module>
from qutebrowser.completion.models import miscmodels
File "/home/rcorre/projects/contrib/qutebrowser/qutebrowser/completion/models/miscmodels.py", line 24, in <module>
from qutebrowser.completion.models import completionmodel, listcategory, util
File "/home/rcorre/projects/contrib/qutebrowser/qutebrowser/completion/models/util.py", line 24, in <module>
from qutebrowser.config import config
File "/home/rcorre/projects/contrib/qutebrowser/qutebrowser/config/config.py", line 223, in <module>
class ConfigCommands:
File "/home/rcorre/projects/contrib/qutebrowser/qutebrowser/config/config.py", line 314, in ConfigCommands
@cmdutils.argument('command', completion=miscmodels.bind)
AttributeError: module 'qutebrowser.completion.models.miscmodels' has no attribute 'bind'
```
As configmodel imports util (and thereby config as well) it is unclear
to me why moving bind() to configmodel actually fixes this, but it does.
2017-08-19 23:37:04 +02:00
|
|
|
cmdlist = util.get_cmd_completions(include_aliases=False,
|
|
|
|
include_hidden=True, prefix=':')
|
2017-08-12 21:07:17 +02:00
|
|
|
settings = ((opt.name, opt.description)
|
|
|
|
for opt in configdata.DATA.values())
|
2015-03-11 23:07:58 +01:00
|
|
|
|
2017-03-03 14:31:28 +01:00
|
|
|
model.add_category(listcategory.ListCategory("Commands", cmdlist))
|
2017-08-12 21:07:17 +02:00
|
|
|
model.add_category(listcategory.ListCategory("Settings", sorted(settings)))
|
2016-09-16 21:41:54 +02:00
|
|
|
return model
|
2015-03-11 23:07:58 +01:00
|
|
|
|
|
|
|
|
2016-09-16 21:41:54 +02:00
|
|
|
def quickmark():
|
2015-03-11 23:07:58 +01:00
|
|
|
"""A CompletionModel filled with all quickmarks."""
|
2017-07-28 15:02:15 +02:00
|
|
|
def delete(data):
|
|
|
|
"""Delete a quickmark from the completion menu."""
|
|
|
|
name = data[0]
|
|
|
|
quickmark_manager = objreg.get('quickmark-manager')
|
|
|
|
log.completion.debug('Deleting quickmark {}'.format(name))
|
|
|
|
quickmark_manager.delete(name)
|
2015-03-11 23:07:58 +01:00
|
|
|
|
2017-02-23 04:25:11 +01:00
|
|
|
model = completionmodel.CompletionModel(column_widths=(30, 70, 0))
|
2017-03-03 14:31:28 +01:00
|
|
|
marks = objreg.get('quickmark-manager').marks.items()
|
2017-07-28 15:02:15 +02:00
|
|
|
model.add_category(listcategory.ListCategory('Quickmarks', marks,
|
|
|
|
delete_func=delete))
|
2016-09-16 21:41:54 +02:00
|
|
|
return model
|
2015-03-11 23:07:58 +01:00
|
|
|
|
|
|
|
|
2016-09-16 21:41:54 +02:00
|
|
|
def bookmark():
|
2015-05-22 01:38:30 +02:00
|
|
|
"""A CompletionModel filled with all bookmarks."""
|
2017-07-28 15:02:15 +02:00
|
|
|
def delete(data):
|
|
|
|
"""Delete a bookmark from the completion menu."""
|
|
|
|
urlstr = data[0]
|
|
|
|
log.completion.debug('Deleting bookmark {}'.format(urlstr))
|
|
|
|
bookmark_manager = objreg.get('bookmark-manager')
|
|
|
|
bookmark_manager.delete(urlstr)
|
2015-05-22 01:38:30 +02:00
|
|
|
|
2017-02-23 04:25:11 +01:00
|
|
|
model = completionmodel.CompletionModel(column_widths=(30, 70, 0))
|
2017-03-03 14:31:28 +01:00
|
|
|
marks = objreg.get('bookmark-manager').marks.items()
|
2017-07-28 15:02:15 +02:00
|
|
|
model.add_category(listcategory.ListCategory('Bookmarks', marks,
|
|
|
|
delete_func=delete))
|
2016-09-16 21:41:54 +02:00
|
|
|
return model
|
2015-05-22 01:38:30 +02:00
|
|
|
|
2015-03-11 23:07:58 +01:00
|
|
|
|
2016-09-16 21:41:54 +02:00
|
|
|
def session():
|
2015-03-11 23:07:58 +01:00
|
|
|
"""A CompletionModel filled with session names."""
|
2017-02-23 04:25:11 +01:00
|
|
|
model = completionmodel.CompletionModel()
|
2016-09-16 21:41:54 +02:00
|
|
|
try:
|
2017-02-23 04:25:11 +01:00
|
|
|
manager = objreg.get('session-manager')
|
|
|
|
sessions = ((name,) for name in manager.list_sessions()
|
|
|
|
if not name.startswith('_'))
|
2017-03-03 14:31:28 +01:00
|
|
|
model.add_category(listcategory.ListCategory("Sessions", sessions))
|
2016-09-16 21:41:54 +02:00
|
|
|
except OSError:
|
|
|
|
log.completion.exception("Failed to list sessions!")
|
|
|
|
return model
|
|
|
|
|
|
|
|
|
|
|
|
def buffer():
|
2016-02-18 07:01:30 +01:00
|
|
|
"""A model to complete on open tabs across all windows.
|
|
|
|
|
2016-04-08 07:35:53 +02:00
|
|
|
Used for switching the buffer command.
|
|
|
|
"""
|
2017-06-21 05:04:03 +02:00
|
|
|
def delete_buffer(data):
|
2016-09-16 21:41:54 +02:00
|
|
|
"""Close the selected tab."""
|
2017-06-21 05:04:03 +02:00
|
|
|
win_id, tab_index = data[0].split('/')
|
2016-04-22 12:43:25 +02:00
|
|
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
2016-04-28 07:07:49 +02:00
|
|
|
window=int(win_id))
|
|
|
|
tabbed_browser.on_tab_close_requested(int(tab_index) - 1)
|
2016-08-01 18:30:12 +02:00
|
|
|
|
2017-06-21 05:04:03 +02:00
|
|
|
model = completionmodel.CompletionModel(column_widths=(6, 40, 54))
|
2016-08-01 18:30:12 +02:00
|
|
|
|
2016-09-16 21:41:54 +02:00
|
|
|
for win_id in objreg.window_registry:
|
|
|
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
|
|
|
window=win_id)
|
|
|
|
if tabbed_browser.shutting_down:
|
|
|
|
continue
|
2017-02-23 04:25:11 +01:00
|
|
|
tabs = []
|
2016-09-16 21:41:54 +02:00
|
|
|
for idx in range(tabbed_browser.count()):
|
|
|
|
tab = tabbed_browser.widget(idx)
|
2017-02-23 04:25:11 +01:00
|
|
|
tabs.append(("{}/{}".format(win_id, idx + 1),
|
|
|
|
tab.url().toDisplayString(),
|
|
|
|
tabbed_browser.page_title(idx)))
|
2017-05-30 04:58:11 +02:00
|
|
|
cat = listcategory.ListCategory("{}".format(win_id), tabs,
|
2017-06-21 05:04:03 +02:00
|
|
|
delete_func=delete_buffer)
|
2017-03-03 14:31:28 +01:00
|
|
|
model.add_category(cat)
|
2017-05-30 04:58:11 +02:00
|
|
|
|
2016-09-16 21:41:54 +02:00
|
|
|
return model
|