diff options
author | Andrew MacFie <amacfie@sent.com> | 2021-01-14 15:38:07 -0500 |
---|---|---|
committer | Andrew MacFie <amacfie@sent.com> | 2021-01-14 15:38:07 -0500 |
commit | 0b38303ee72c567804bbd60496fc585e9e34057a (patch) | |
tree | ca3ac5fd785be2b173c208ba69a071a15c7a7576 /qutebrowser/completion/models/filepathcategory.py | |
parent | 4b7d52ae7cdf52ebef038b4a90b9fe95ab002105 (diff) | |
download | qutebrowser-0b38303ee72c567804bbd60496fc585e9e34057a.tar.gz qutebrowser-0b38303ee72c567804bbd60496fc585e9e34057a.zip |
Add file path completion
Diffstat (limited to 'qutebrowser/completion/models/filepathcategory.py')
-rw-r--r-- | qutebrowser/completion/models/filepathcategory.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/qutebrowser/completion/models/filepathcategory.py b/qutebrowser/completion/models/filepathcategory.py new file mode 100644 index 000000000..530e90294 --- /dev/null +++ b/qutebrowser/completion/models/filepathcategory.py @@ -0,0 +1,55 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# 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/>. + +"""Completion category for filesystem paths.""" + +import glob +import os + +from PyQt5.QtCore import (QAbstractListModel, QModelIndex) + +class FilePathCategory(QAbstractListModel): + """Represent filesystem paths matching a pattern.""" + + def __init__(self, name: str, *args, **kwargs): + super().__init__(*args, **kwargs) + self._paths: list = [] + self.name = name + self.columns_to_filter = [0] + + def set_pattern(self, val): + """Setter for pattern. + + Args: + val: The value to set. + """ + glob_str = os.path.expanduser(glob.escape(val)) + '*' + self._paths = sorted(glob.glob(glob_str)) + + def data(self, index: QModelIndex): + """Implement abstract method in QAbstractListModel. + """ + if index.column() == 0: + return self._paths[index.row()] + else: + return '' + + def rowCount(self, *_args): + """Implement abstract method in QAbstractListModel. + """ + return len(self._paths) + |