-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from malfisya/add-extension
Add nautilus extension
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import os | ||
import subprocess | ||
from gi.repository import Nautilus, GObject, Gio | ||
|
||
class ClapgrepMenuProvider(GObject.GObject, Nautilus.MenuProvider): | ||
def __init__(self): | ||
pass | ||
|
||
def __open_clapgrep(self, file): | ||
os.system(f"""flatpak run de.leopoldluley.Clapgrep "{file.get_location().get_path()}" &""") | ||
|
||
def menu_activate_cb(self, menu, file): | ||
self.__open_clapgrep(file) | ||
|
||
def menu_background_activate_cb(self, menu, file): | ||
self.__open_clapgrep(file) | ||
|
||
def __create_sub_menu(self, file, additional): | ||
if file.get_file_type()== Gio.FileType.DIRECTORY: | ||
item = Nautilus.MenuItem(name="ClapgrepMenuProvider::Search::" + additional, | ||
label="Clapgrep...", | ||
tip="", | ||
icon="search-symbolic") | ||
item.connect("activate", self.menu_activate_cb, file) | ||
|
||
return item | ||
|
||
def get_file_items(self, files): | ||
if len(files) == 1: | ||
item = self.__create_sub_menu(files[0], "file") | ||
|
||
return item, | ||
|
||
def get_background_items(self, file): | ||
item = self.__create_sub_menu(file, "background") | ||
|
||
return item, |