Skip to content

Commit

Permalink
config
Browse files Browse the repository at this point in the history
  • Loading branch information
chr314 committed Mar 31, 2021
1 parent 516996c commit 36aeed0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
install:
mkdir -p ~/.local/share/nautilus-python/extensions/nautilus-copy-path
cp nautilus-copy-path.py ~/.local/share/nautilus-python/extensions
cp nautilus_copy_path.py translation.py ~/.local/share/nautilus-python/extensions/nautilus-copy-path
cp nautilus_copy_path.py translation.py config.json ~/.local/share/nautilus-python/extensions/nautilus-copy-path
cp -rf translations ~/.local/share/nautilus-python/extensions/nautilus-copy-path

uninstall:
Expand Down
11 changes: 11 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"items": {
"path": true,
"uri": true,
"name": true
},
"selections": {
"clipboard": true,
"primary": true
}
}
55 changes: 36 additions & 19 deletions nautilus_copy_path.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import json
from translation import Translation
from gi.repository import Nautilus, GObject, Gtk, Gdk
from gi import require_version
Expand All @@ -13,6 +14,9 @@ def __init__(self):
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
self.clipboard_primary = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY)

with open(os.path.join(os.path.dirname(__file__), 'config.json')) as json_file:
self.config = json.load(json_file)

def get_file_items(self, window, files):
return self._create_menu_items(files, "File")

Expand All @@ -21,23 +25,34 @@ def get_background_items(self, window, file):

def _create_menu_items(self, files, group):
plural = len(files) > 1
item_path = Nautilus.MenuItem(
name="NautilusCopyPath::CopyPath" + group,
label=Translation.t("copy_paths") if plural else Translation.t("copy_path"),
)
item_uri = Nautilus.MenuItem(
name="NautilusCopyPath::CopyUri" + group,
label=Translation.t("copy_uris") if plural else Translation.t("copy_uri"),
)
item_name = Nautilus.MenuItem(
name="NautilusCopyPath::CopyName" + group,
label=Translation.t("copy_names") if plural else Translation.t("copy_name"),
)

item_path.connect("activate", self._copy_paths, files)
item_uri.connect("activate", self._copy_uris, files)
item_name.connect("activate", self._copy_names, files)
return [item_path, item_uri, item_name]
config_items = self.config["items"]
active_items = []

if config_items["path"]:
item_path = Nautilus.MenuItem(
name="NautilusCopyPath::CopyPath" + group,
label=Translation.t("copy_paths" if plural else "copy_path"),
)
item_path.connect("activate", self._copy_paths, files)
active_items.append(item_path)

if config_items["uri"]:
item_uri = Nautilus.MenuItem(
name="NautilusCopyPath::CopyUri" + group,
label=Translation.t("copy_uris" if plural else "copy_uri"),
)
item_uri.connect("activate", self._copy_uris, files)
active_items.append(item_uri)

if config_items["name"]:
item_name = Nautilus.MenuItem(
name="NautilusCopyPath::CopyName" + group,
label=Translation.t("copy_names" if plural else "copy_name"),
)
item_name.connect("activate", self._copy_names, files)
active_items.append(item_name)

return active_items

def _copy_paths(self, menu, files):
self._copy_value(list(map(lambda f: f.get_location().get_path(), files)))
Expand All @@ -51,5 +66,7 @@ def _copy_names(self, menu, files):
def _copy_value(self, value):
if len(value) > 0:
new_value = ", ".join(value)
self.clipboard.set_text(new_value, -1)
self.clipboard_primary.set_text(new_value, -1)
if self.config["selections"]["clipboard"]:
self.clipboard.set_text(new_value, -1)
if self.config["selections"]["primary"]:
self.clipboard_primary.set_text(new_value, -1)

0 comments on commit 36aeed0

Please sign in to comment.