def import_snippets(self, files): success = True for gfile in files: if not Gedit.utils_location_has_file_scheme(gfile): continue # Remove file:// filename = gfile.get_path() importer = Importer(filename) error = importer.run() if error: message = _( 'The following error occurred while importing: %s') % error success = False message_dialog(self.get_toplevel(), Gtk.MessageType.ERROR, message) self.build_model(True) if success: message = _('Import successfully completed') message_dialog(self.get_toplevel(), Gtk.MessageType.INFO, message)
def on_open_dev_file(self, action): doc = self.window.get_active_document() if doc is None: return None location = doc.get_location() if location is not None and Gedit.utils_location_has_file_scheme(location): self.__lang.evaluate("thisProcess.platform.devLoc(\""+location.get_path()+"\").openTextFile", silent=True)
def get_active_document_directory(self): doc = self.window.get_active_document() if doc is None: return None location = doc.get_location() if location is not None and Gedit.utils_location_has_file_scheme(location): directory = location.get_parent() return directory.get_path() return None
def env_get_documents_path(self, buf): toplevel = self.view.get_toplevel() if isinstance(toplevel, Gedit.Window): documents_location = [doc.get_location() for doc in toplevel.get_documents() if doc.get_location() is not None] documents_path = [location.get_path() for location in documents_location if Gedit.utils_location_has_file_scheme(location)] else: documents_path = [] return ' '.join(documents_path)
def import_snippets(self, files): success = True for gfile in files: if not Gedit.utils_location_has_file_scheme(gfile): continue # Remove file:// filename = gfile.get_path() importer = Importer(filename) error = importer.run() if error: message = _('The following error occurred while importing: %s') % error success = False message_dialog(self.get_toplevel(), Gtk.MessageType.ERROR, message) self.build_model(True) if success: message = _('Import successfully completed') message_dialog(self.get_toplevel(), Gtk.MessageType.INFO, message)
def apply_uri_snippet(self, snippet, mime, uri): # Remove file scheme gfile = Gio.file_new_for_uri(uri) pathname = '' dirname = '' ruri = '' if Gedit.utils_location_has_file_scheme(gfile): pathname = gfile.get_path() dirname = gfile.get_parent().get_path() name = gfile.get_basename() scheme = gfile.get_uri_scheme() os.environ['GEDIT_DROP_DOCUMENT_URI'] = uri os.environ['GEDIT_DROP_DOCUMENT_NAME'] = name os.environ['GEDIT_DROP_DOCUMENT_SCHEME'] = scheme os.environ['GEDIT_DROP_DOCUMENT_PATH'] = pathname os.environ['GEDIT_DROP_DOCUMENT_DIR'] = dirname os.environ['GEDIT_DROP_DOCUMENT_TYPE'] = mime buf = self.view.get_buffer() location = buf.get_location() if location: ruri = location.get_uri() relpath = self.relative_path(ruri, uri, mime) os.environ['GEDIT_DROP_DOCUMENT_RELATIVE_PATH'] = relpath mark = buf.get_mark('gtk_drag_target') if not mark: mark = buf.get_insert() piter = buf.get_iter_at_mark(mark) self.apply_snippet(snippet, piter, piter)