Skip to content

Commit

Permalink
Various improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
maoschanz committed Aug 23, 2019
1 parent a0f6c52 commit c0427d2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 57 deletions.
Empty file modified LICENSE
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

A simple nautilus extension adding a submenu to the right-click, with a list of apps you can use to open the selected files.

Dependency: `python-nautilus`

33 changes: 9 additions & 24 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
#!/bin/bash

echo "Checking if adequate folders exist…"
if (( $EUID == 0 )); then
echo "Checking if adequate folders exist..."

if [ ! -d "/usr/share/nautilus-python" ]; then
mkdir /usr/share/nautilus-python
fi
if [ ! -d "/usr/share/nautilus-python/extensions" ]; then
mkdir /usr/share/nautilus-python/extensions/
fi

echo "Installing plugin files in /usr/share/nautilus-python/extensions/"
cp open-with-menu.py /usr/share/nautilus-python/extensions/open-with-menu.py

dir_pyt_ext="/usr/share/nautilus-python/extensions"
else
echo "Checking if adequate folders exist..."

if [ ! -d "$HOME/.local/share/nautilus-python" ]; then
mkdir ~/.local/share/nautilus-python
fi
if [ ! -d "$HOME/.local/share/nautilus-python/extensions" ]; then
mkdir ~/.local/share/nautilus-python/extensions/
fi

echo "Installing plugin files in ~/.local/share/nautilus-python/extensions"
cp open-with-menu.py ~/.local/share/nautilus-python/extensions/open-with-menu.py

dir_pyt_ext="$HOME/.local/share/nautilus-python/extensions"
fi

mkdir -p "${dir_pyt_ext}"
echo "Installing plugin files in $dir_pyt_ext"
cp open-with-menu.py $dir_pyt_ext/open-with-menu.py

echo "Done."
exit 0

51 changes: 18 additions & 33 deletions open-with-menu.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# "Nautilus Open With Menu" 0.5
# "Nautilus Open With Menu" 0.6
# Copyright (C) 2018 Romain F. T.
#
# "Nautilus Open With Menu" is free software; you can redistribute it and/or modify
Expand All @@ -20,48 +20,29 @@
gi.require_version('Nautilus', '3.0')
from gi.repository import Nautilus, Gtk, GObject, Gio, GLib

BASE_PATH = os.path.dirname(os.path.realpath(__file__))
LOCALE_PATH = os.path.join(BASE_PATH, 'locale')
try:
import gettext
gettext.bindtextdomain('open-with-menu', LOCALE_PATH)
_ = lambda s: gettext.dgettext('open-with-menu', s)
except:
_ = lambda s: s
# TODO translations

class OpenWithMenu(GObject.GObject, Nautilus.MenuProvider):
"""'Open With…' Menu"""
def __init__(self):
pass

def get_file_items(self, window, file_items):
"""Nautilus invoke this function in its startup > Then, create menu entry"""
# Checks
if not self._check_generate_menu(file_items):
"""Nautilus invoke this function when building the menu on files."""
if not len(file_items):
return

# Return menu
return self._generate_menu(file_items)

def get_background_items(self, window, file_items):
"""Nautilus invoke this function when building the menu on the empty
background."""
pass

def _check_generate_menu(self, file_items):
"""Show the menu?"""

# No items selected
if not len(file_items):
return False

return True

def _generate_menu(self, file_items):
"""Generate menu"""
top_menuitem = Nautilus.MenuItem(name='OpenWithMenu', label=_("Open With…"), sensitive=True)
menu = Nautilus.Menu()
"""Generate the menu item and its submenu."""
possible_apps = []
self.files = file_items

for item in file_items:
item_type = item.get_mime_type()
if len(possible_apps) == 0:
Expand All @@ -75,16 +56,19 @@ def _generate_menu(self, file_items):
possible_apps_common.append(app)
possible_apps = possible_apps_common

menu = Nautilus.Menu()
for app in possible_apps:
menu.append_item(self.add_app_item(app, possible_apps.index(app)))

top_menuitem.set_submenu(menu)
return top_menuitem, None

menuitem = Nautilus.MenuItem(name='OpenWithMenu', label="Open With…")
menuitem.set_submenu(menu)
return menuitem, None

def add_app_item(self, app, index):
item_label = app.get_name()
item_name = 'OpenWithMenu' + str(index)
# le constructeur a un paramètre icon mais je ne le pige pas
# according to the documentation, the constructor has an 'icon'
# parameter but i don't understand how it works
item = Nautilus.MenuItem(name=item_name, label=item_label, sensitive=True)
item.connect('activate', self.open_with_app, app)
return item
Expand All @@ -101,5 +85,6 @@ def open_with_app(self, menuitem, app):
files.append(item.get_location())
app.launch(files)


############################################################################
################################################################################

0 comments on commit c0427d2

Please sign in to comment.