Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an extension for opening a symlink's parent directory #32

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions examples/open-symlinks-parent-dirs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os
import os.path
import subprocess
import urllib

from gi.repository import Caja, GObject, Gio


class OpenSymLinksParentDirsExtension(Caja.MenuProvider, GObject.GObject):
def __init__(self):
pass

def _open_parent_dir(self, files_or_directories):
args = ['caja']
for f in files_or_directories:
# find the real location of the file (resolves all symlinks)
path = os.path.realpath(f.get_location().get_path())
parent = os.path.abspath(os.path.join(path, os.pardir))
args.append(parent)
subprocess.Popen(args)

def menu_activate_cb(self, menu, files):
self._open_parent_dir(files)

def get_file_items(self, window, files):
num_files = len(files)
if num_files == 0 or any(not self.is_symbolic_link(f) for f in files):
return

if num_files == 1:
lbl = "Open Link's Parent Directory"
else:
lbl = "Open Links' Parent Directories"

item = Caja.MenuItem(name='CajaPython::open_symlink_parent_dirs_item',
label=lbl,
tip=lbl)
item.connect('activate', self.menu_activate_cb, files)
return item,

def is_symbolic_link(self, f):
f_type = f.get_location().query_file_type(Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS)
return f_type is Gio.FileType.SYMBOLIC_LINK