# -*- coding: utf-8 -*- import os import urllib import customJava from gi.repository import Nautilus, GObject def get_translation(text): translations = {} translations["Java Runner"] = {} translations["Java Runner"]["es"] = "Ejecuta con el Java..." translations["Java Runner"]["qcv"] = "Executa amb el Java..." translations["Set as default"] = {} translations["Set as default"]["es"] = "Establece como predeterminado" translations["Set as default"]["qcv"] = "Establix com a predeterminat" lng = os.getenv("LANG") if text in translations: if "qcv" in lng or "ca_ES" in lng: return translations[text]["qcv"] if "es_" in lng or "es." in lng: return translations[text]["es"] return text #def get_translation _ = get_translation class JavaRunnerExtension(GObject.GObject, Nautilus.MenuProvider): def __init__(self): print("Initializing java-custom-runner extension") def _run_java(self, javavm, file): filename = urllib.unquote(file.get_uri()[7:])#.replace(" ","\ ").replace("(","\(").replace(")","\)") cmd='java-custom-runner --java "%s" "%s" &' % (javavm, filename.decode("utf-8")) print(cmd) os.system(cmd.encode("utf-8")) def menu_activate_cb(self, menu, javavm,file): self._run_java( javavm ,file) def _run_java_selector(self, javavm, file): filename = urllib.unquote(file.get_uri()[7:]) cmd='java-custom-runner --set "%s" "%s" &' % (javavm, filename.decode("utf-8")) print(cmd) os.system(cmd.encode("utf-8")) def menu_activate_cb_selector(self, menu, javavm,file): self._run_java_selector( javavm ,file) def menu_background_activate_cb(self, menu, file): self._run_java(file) def get_file_items(self, window, files): if len(files) != 1: return if os.path.isdir(str(files[0])): return file = files[0] path_dir = "" line = str(file.get_parent_uri()) if not line.startswith("file://"): return path_dir = line[7:] path_to_file = path_dir + "/" + str(file.get_name()) try: aux_file = open(path_to_file) except IOError as e: return ext = os.path.splitext(path_to_file)[-1].lower() # TOP MENU AdvancedTopMenu = Nautilus.MenuItem(name='TopMenuItem::Advanced', label=_('Java Runner'), tip='Advanced Menu', icon='java-custom-runner', ) AdvancedSubMenu = Nautilus.Menu() AdvancedTopMenu.set_submenu(AdvancedSubMenu) list_of_javas = customJava.CustomRunner.list_java_available() default_java = customJava.CustomRunner.get_java_version_default_on_system() if ext == ".jar": for javavm in list_of_javas: if default_java != "Unknown" and javavm[0] == default_java: etiq = _(javavm[0]) +" "+ _(" (System)") else: etiq = _(javavm[0]) current_icon ="java-custom-runner" # Get the icon icons_list = {"open":{"1.5":"openjdk15","1.6":"openjdk16","1.7":"openjdk17","1.8":"openjdk18"},"oracle":{"-5-":"java15","-6-":"java16","-7-":"java17","-8-":"java18"}} for key,value in icons_list.items(): if key in etiq: for key1,value1 in value.items(): if key1 in etiq: current_icon = value1 item = Nautilus.MenuItem(name='NautilusPython::run_java_runner_'+javavm[0].replace("-","_"), label=etiq, tip='%s %s' % (etiq, file.get_name().decode("utf-8")), icon=current_icon) item.connect('activate', self.menu_activate_cb, javavm[0],file) AdvancedSubMenu.append_item(item) MenuAdmin = Nautilus.MenuItem(name="MenuItem::AdminSubMenu", label=_("Set as default"), tip="Only admins", icon="java-custom-runner", ) MenuAdminSubmenu = Nautilus.Menu() MenuAdmin.set_submenu(MenuAdminSubmenu) for javavm in list_of_javas: if default_java != "Unknown" and javavm[0] == default_java: etiq = _(javavm[0]) +" "+ _(" (System)") else: etiq = _(javavm[0]) current_icon ="java-custom-runner" # Get the icon icons_list = {"open":{"1.5":"openjdk15","1.6":"openjdk16","1.7":"openjdk17","1.8":"openjdk18"},"oracle":{"-5-":"java15","-6-":"java16","-7-":"java17","-8-":"java18"}} for key,value in icons_list.items(): if key in etiq: for key1,value1 in value.items(): if key1 in etiq: current_icon = value1 item = Nautilus.MenuItem(name='NautilusPython::run_java_runner_selector'+javavm[0].replace("-","_"), label=etiq, tip='%s %s' % (etiq, file.get_name().decode("utf-8")), icon=current_icon) item.connect('activate', self.menu_activate_cb_selector, javavm[0],file) MenuAdminSubmenu.append_item(item) AdvancedSubMenu.append_item(MenuAdmin) return AdvancedTopMenu,