mirror of
https://codeberg.org/privacy1st/xournalpp-relative-background
synced 2024-12-03 22:15:02 +01:00
add support for Nemo file manager
This commit is contained in:
parent
abf2e31f83
commit
5cb1d82a7a
@ -52,6 +52,7 @@ def main():
|
||||
|
||||
|
||||
NAUTILUS_SELECTION = 'NAUTILUS_SCRIPT_SELECTED_FILE_PATHS'
|
||||
NEMO_SELECTION = 'NEMO_SCRIPT_SELECTED_FILE_PATHS'
|
||||
SCRIPT_NAME = 'relative-xopp-background'
|
||||
|
||||
|
||||
@ -64,14 +65,10 @@ def parse_args() -> List[Path]:
|
||||
|
||||
# get list of selected paths
|
||||
selected_paths: List[Path] = []
|
||||
selected_files_str = getenv(NAUTILUS_SELECTION)
|
||||
if selected_files_str:
|
||||
selected_files = selected_files_str.split('\n')
|
||||
# if last filename is empty, remove it
|
||||
if len(selected_files[-1]) < 1:
|
||||
selected_files = selected_files[:-1]
|
||||
selected_paths = [Path(file) for file in selected_files]
|
||||
else:
|
||||
selected_paths += selection_from_env(NAUTILUS_SELECTION)
|
||||
selected_paths += selection_from_env(NEMO_SELECTION)
|
||||
# if no selected files from NAUTILUS or NEMO were added
|
||||
if len(selected_paths) == 0:
|
||||
selected_paths = [Path(file) for file in argv[1:]]
|
||||
|
||||
# for each selected path
|
||||
@ -91,7 +88,22 @@ def parse_args() -> List[Path]:
|
||||
if path.suffix == '.xopp':
|
||||
xopp_files.append(path.absolute())
|
||||
|
||||
return xopp_files
|
||||
# don't return duplicates
|
||||
return list(set(xopp_files))
|
||||
|
||||
|
||||
def selection_from_env(key: str) -> List[Path]:
|
||||
"""
|
||||
Splits the value of environment key "key" by newlines and returns each element as Path object.
|
||||
"""
|
||||
newline_delimited_selection = getenv(key)
|
||||
if newline_delimited_selection:
|
||||
selected_files = newline_delimited_selection.split('\n')
|
||||
# if last filename is empty, remove it
|
||||
if len(selected_files[-1]) < 1:
|
||||
selected_files = selected_files[:-1]
|
||||
return [Path(file) for file in selected_files]
|
||||
return []
|
||||
|
||||
|
||||
def usage():
|
||||
|
Loading…
Reference in New Issue
Block a user