Skip to content

Commit

Permalink
Merge pull request #44 from malfisya/add-extension
Browse files Browse the repository at this point in the history
Add nautilus extension
  • Loading branch information
luleyleo authored Nov 21, 2024
2 parents 65d3af6 + 9fd8654 commit cff2840
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions extension/clapgrep.py
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,

0 comments on commit cff2840

Please sign in to comment.