mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-27 17:35:07 +01:00
Fix file browser to not add empty line when no file/dir selected
- When no file selected in file browser an empty line/entry gets added to input entries list - Bug got introduced due to insufficient update on change to add instead of insert - Update is_none_or_empty helper method to also check for empty string
This commit is contained in:
parent
8098b8c3a8
commit
5e6625ac68
2 changed files with 7 additions and 11 deletions
|
@ -4,10 +4,11 @@ from PyQt6.QtCore import QDir
|
|||
|
||||
# Internal Packages
|
||||
from src.utils.config import SearchType
|
||||
from src.utils.helpers import is_none_or_empty
|
||||
|
||||
|
||||
class FileBrowser(QtWidgets.QWidget):
|
||||
def __init__(self, title, search_type: SearchType=None, default_files=[]):
|
||||
def __init__(self, title, search_type: SearchType=None, default_files:list=[]):
|
||||
QtWidgets.QWidget.__init__(self)
|
||||
layout = QtWidgets.QHBoxLayout()
|
||||
self.setLayout(layout)
|
||||
|
@ -57,16 +58,11 @@ class FileBrowser(QtWidgets.QWidget):
|
|||
filter=self.filter_name)[0])
|
||||
self.setFiles(filepaths)
|
||||
|
||||
def setFiles(self, paths):
|
||||
self.filepaths = paths
|
||||
if not self.filepaths or len(self.filepaths) == 0:
|
||||
return
|
||||
elif len(self.filepaths) == 1:
|
||||
self.lineEdit.setPlainText(self.filepaths[0])
|
||||
else:
|
||||
def setFiles(self, paths:list):
|
||||
self.filepaths = [path for path in paths if not is_none_or_empty(path)]
|
||||
self.lineEdit.setPlainText("\n".join(self.filepaths))
|
||||
|
||||
def getPaths(self):
|
||||
def getPaths(self) -> list:
|
||||
if self.lineEdit.toPlainText() == '':
|
||||
return []
|
||||
else:
|
||||
|
|
|
@ -5,7 +5,7 @@ from os.path import join
|
|||
|
||||
|
||||
def is_none_or_empty(item):
|
||||
return item == None or (hasattr(item, '__iter__') and len(item) == 0)
|
||||
return item == None or (hasattr(item, '__iter__') and len(item) == 0) or item == ''
|
||||
|
||||
|
||||
def to_snake_case_from_dash(item: str):
|
||||
|
|
Loading…
Reference in a new issue