def on_dialog_snippets_response(self, dlg, resp): alloc = dlg.get_allocation() self.default_size = [alloc.width, alloc.height] if resp == Gtk.ResponseType.HELP: Pluma.help_display(self, 'pluma', 'pluma-snippets-plugin') return self.dlg.destroy()
def on_dialog_snippets_response(self, dlg, resp): alloc = dlg.get_allocation() self.default_size = [alloc.width, alloc.height] if resp == Gtk.ResponseType.HELP: Pluma.help_display(self, 'pluma', 'pluma-snippets-plugin') return self.dlg.destroy()
def on_tool_manager_dialog_response(self, dialog, response): if response == Gtk.ResponseType.HELP: Pluma.help_display(self.dialog, 'pluma', 'pluma-external-tools-plugin') return self.on_tool_manager_dialog_focus_out(dialog, None) self.dialog.destroy() self.dialog = None self.tools = None
def open_file(self, file_view, path, column, window): model = file_view.get_model() try: iter_ = model.get_iter(path) except ValueError: pass else: location = model.get_value(iter_, Column.LOCATION) Pluma.commands_load_uri(window, location.get_uri(), None, -1) self.destroy()
def __init__(self, window, panel, docs, node): self._window = window self._panel = panel self._node = node self._error = False self._counter = len(docs) self._signal_ids = {} self._counter = 0 signals = {} for doc in docs: signals[doc] = doc.connect('saving', self.on_document_saving) Pluma.commands_save_document(window, doc) doc.disconnect(signals[doc])
def import_snippets(self, filenames): success = True for filename in filenames: if not Pluma.utils_uri_has_file_scheme(filename): continue # Remove file:// gfile = Gio.file_new_for_uri(filename) 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.dlg, Gtk.MessageType.ERROR, message) self.build_model(True) if success: message = _('Import successfully completed') message_dialog(self.dlg, Gtk.MessageType.INFO, message)
def __init__(self, window, panel, docs, node): self._window = window self._panel = panel self._node = node self._error = False self._counter = len(docs) self._signal_ids = {} self._counter = 0 signals = {} for doc in docs: signals[doc] = doc.connect('saving', self.on_document_saving) Pluma.commands_save_document(window, doc) doc.disconnect(signals[doc])
def load_other_file(self, source): current_tab = self.window.get_active_tab() self.same_document[current_tab] = False self.split_views[current_tab].remove( self.split_views[current_tab].get_children()[1]) new_document = Pluma.Document() #.Pluma_document_new() new_document.load("file://" + source.replace(" ", "%20"), self.encoding, 1, True) new_view = Pluma.View.new_with_buffer( new_document) #.Pluma_view_new(new_document) new_document.connect("mark-set", self.update_line_column_data) new_document.save(0) self.alt_views[current_tab] = new_document sw = Gtk.ScrolledWindow() sw.add(new_view) self.split_views[current_tab].add2(sw) self.label_other_document.set_label( os.path.basename(source).replace("%20", " ")) self.window.get_active_tab().show_all()
def do_drag_data_received(self, drag_context, x, y, data, info, time): if info == self.TARGET_URI_LIST: self.feed_child(' '.join([ "'" + Gio.file_new_for_uri(item).get_path() + "'" for item in Pluma.utils_drop_get_uris(data) ]).encode('utf-8')) Gtk.drag_finish(drag_context, True, False, time) else: Vte.Terminal.do_drag_data_received(self, drag_context, x, y, data, info, time)
def get_bookmark_dirs(self): filename = Path(GLib.get_user_config_dir()) / 'gtk-3.0' / 'bookmarks' if not filename.is_file(): filename = Path.home() / '.gtk-bookmarks' try: with filename.open() as bookmarks: for bookmark in bookmarks: uri = bookmark.strip().split(' ')[0] if Pluma.utils_uri_has_file_scheme(uri): yield GLib.filename_from_uri(uri)[0] except FileNotFoundError: pass
def _direct_file(self): uri = self._entry.get_text() gfile = None if Pluma.utils_is_valid_uri(uri): gfile = Gio.file_new_for_uri(uri) elif os.path.isabs(uri): f = Gio.file_new_for_uri(uri) if f.query_exists(): gfile = f return gfile
def env_get_documents_path(self, buf): toplevel = self.view.get_toplevel() if isinstance(toplevel, Pluma.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 Pluma.utils_uri_has_file_scheme(location.get_uri())] else: documents_path = [] return ' '.join(documents_path)
def do_get_info_widget(self, proposal): if not self.info_widget: view = Pluma.View.new_with_buffer(Pluma.Document()) manager = get_language_manager() lang = manager.get_language('snippets') view.get_buffer().set_language(lang) sw = Gtk.ScrolledWindow() sw.add(view) self.info_view = view self.info_widget = sw return self.info_widget
def __init__(self, plugin, window): self.window = window self.plugin = plugin self.ui_id = None # Add a "toggle split view" item to the View menu self.insert_menu_item(window) # We're going to keep track of each tab's split view # and, if used, ALT view -- the view of a separate # document -- with a couple of dictionaries. We'll # index each dictionary via the tab objects. self.split_views = {} self.alt_views = {} # This keeps track of whether the user is viewing an ALT document. self.same_document = {} # I hardly even know how this works, but it gets our encoding. try: self.encoding = Pluma.encoding_get_current() except: self.encoding = Pluma.Pluma_encoding_get_current()
def fill(self): manager = Gtk.RecentManager.get_default() items = manager.get_items() items.sort(key=lambda i: i.get_visited(), reverse=True) count = 0 for item in items: if item.has_group('pluma'): uri = item.get_uri() if Pluma.utils_uri_exists(uri): self.append(GLib.filename_from_uri(uri)[0]) count += 1 if count >= self.max_recents: break
def apply_uri_snippet(self, snippet, mime, uri): # Remove file scheme gfile = Gio.file_new_for_uri(uri) pathname = '' dirname = '' ruri = '' if Pluma.utils_uri_has_file_scheme(uri): pathname = gfile.get_path() dirname = gfile.get_parent().get_path() name = os.path.basename(uri) scheme = gfile.get_uri_scheme() os.environ['PLUMA_DROP_DOCUMENT_URI'] = uri os.environ['PLUMA_DROP_DOCUMENT_NAME'] = name os.environ['PLUMA_DROP_DOCUMENT_SCHEME'] = scheme os.environ['PLUMA_DROP_DOCUMENT_PATH'] = pathname os.environ['PLUMA_DROP_DOCUMENT_DIR'] = dirname os.environ['PLUMA_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['PLUMA_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)
def import_snippets(self, filenames): success = True for filename in filenames: if not Pluma.utils_uri_has_file_scheme(filename): continue # Remove file:// gfile = Gio.file_new_for_uri(filename) 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.dlg, Gtk.MessageType.ERROR, message) self.build_model(True) if success: message = _('Import successfully completed') message_dialog(self.dlg, Gtk.MessageType.INFO, message)
def on_activated(self, gfile): Pluma.commands_load_uri(self._window, gfile.get_uri(), None, -1) return True
def on_dialog_snippets_response(self, dlg, resp): if resp == Gtk.ResponseType.HELP: Pluma.help_display(self, 'pluma', 'pluma-snippets-plugin') return self.dlg.destroy()
def run_external_tool(window, panel, node): # Configure capture environment try: cwd = os.getcwd() except OSError: cwd = os.getenv('HOME'); capture = Capture(node.command, cwd) capture.env = os.environ.copy() capture.set_env(PLUMA_CWD = cwd) view = window.get_active_view() if view is not None: # Environment vars relative to current document document = view.get_buffer() uri = document.get_uri() # Current line number piter = document.get_iter_at_mark(document.get_insert()) capture.set_env(PLUMA_CURRENT_LINE_NUMBER=str(piter.get_line() + 1)) # Current line text piter.set_line_offset(0) end = piter.copy() if not end.ends_line(): end.forward_to_line_end() capture.set_env(PLUMA_CURRENT_LINE=piter.get_text(end)) # Selected text (only if input is not selection) if node.input != 'selection' and node.input != 'selection-document': bounds = document.get_selection_bounds() if bounds: capture.set_env(PLUMA_SELECTED_TEXT=bounds[0].get_text(bounds[1])) bounds = current_word(document) capture.set_env(PLUMA_CURRENT_WORD=bounds[0].get_text(bounds[1])) capture.set_env(PLUMA_CURRENT_DOCUMENT_TYPE=document.get_mime_type()) if uri is not None: gfile = Gio.file_new_for_uri(uri) scheme = gfile.get_uri_scheme() name = os.path.basename(uri) capture.set_env(PLUMA_CURRENT_DOCUMENT_URI = uri, PLUMA_CURRENT_DOCUMENT_NAME = name, PLUMA_CURRENT_DOCUMENT_SCHEME = scheme) if Pluma.utils_uri_has_file_scheme(uri): path = gfile.get_path() cwd = os.path.dirname(path) capture.set_cwd(cwd) capture.set_env(PLUMA_CURRENT_DOCUMENT_PATH = path, PLUMA_CURRENT_DOCUMENT_DIR = cwd) documents_uri = [doc.get_uri() for doc in window.get_documents() if doc.get_uri() is not None] documents_path = [Gio.file_new_for_uri(uri).get_path() for uri in documents_uri if Pluma.utils_uri_has_file_scheme(uri)] capture.set_env(PLUMA_DOCUMENTS_URI = ' '.join(documents_uri), PLUMA_DOCUMENTS_PATH = ' '.join(documents_path)) flags = capture.CAPTURE_BOTH if not node.has_hash_bang(): flags |= capture.CAPTURE_NEEDS_SHELL capture.set_flags(flags) # Get input text input_type = node.input output_type = node.output # Clear the panel panel.clear() if output_type == 'output-panel': panel.show() # Assign the error output to the output panel panel.set_process(capture) if input_type != 'nothing' and view is not None: if input_type == 'document': start, end = document.get_bounds() elif input_type == 'selection' or input_type == 'selection-document': try: start, end = document.get_selection_bounds() print start, end except ValueError: if input_type == 'selection-document': start, end = document.get_bounds() if output_type == 'replace-selection': document.select_range(start, end) else: start = document.get_iter_at_mark(document.get_insert()) end = start.copy() elif input_type == 'line': start = document.get_iter_at_mark(document.get_insert()) end = start.copy() if not start.starts_line(): start.set_line_offset(0) if not end.ends_line(): end.forward_to_line_end() elif input_type == 'word': start = document.get_iter_at_mark(document.get_insert()) end = start.copy() if not start.inside_word(): panel.write(_('You must be inside a word to run this command'), panel.command_tag) return if not start.starts_word(): start.backward_word_start() if not end.ends_word(): end.forward_word_end() input_text = document.get_text(start, end, False) capture.set_input(input_text) # Assign the standard output to the chosen "file" if output_type == 'new-document': tab = window.create_tab(True) view = tab.get_view() document = tab.get_document() pos = document.get_start_iter() capture.connect('stdout-line', capture_stdout_line_document, document, pos) document.begin_user_action() view.set_editable(False) view.set_cursor_visible(False) elif output_type != 'output-panel' and output_type != 'nothing' and view is not None: document.begin_user_action() view.set_editable(False) view.set_cursor_visible(False) if output_type == 'insert': pos = document.get_iter_at_mark(document.get_mark('insert')) elif output_type == 'replace-selection': document.delete_selection(False, False) pos = document.get_iter_at_mark(document.get_mark('insert')) elif output_type == 'replace-document': document.set_text('') pos = document.get_end_iter() else: pos = document.get_end_iter() capture.connect('stdout-line', capture_stdout_line_document, document, pos) elif output_type != 'nothing': capture.connect('stdout-line', capture_stdout_line_panel, panel) document.begin_user_action() capture.connect('stderr-line', capture_stderr_line_panel, panel) capture.connect('begin-execute', capture_begin_execute_panel, panel, view, node.name) capture.connect('end-execute', capture_end_execute_panel, panel, view, output_type) # Run the command capture.execute() if output_type != 'nothing': document.end_user_action()
def run_external_tool(window, panel, node): # Configure capture environment try: cwd = os.getcwd() except OSError: cwd = os.getenv('HOME') capture = Capture(node.command, cwd) capture.env = os.environ.copy() capture.set_env(PLUMA_CWD=cwd) view = window.get_active_view() if view is not None: # Environment vars relative to current document document = view.get_buffer() uri = document.get_uri() # Current line number piter = document.get_iter_at_mark(document.get_insert()) capture.set_env(PLUMA_CURRENT_LINE_NUMBER=str(piter.get_line() + 1)) # Current line text piter.set_line_offset(0) end = piter.copy() if not end.ends_line(): end.forward_to_line_end() capture.set_env(PLUMA_CURRENT_LINE=piter.get_text(end)) # Selected text (only if input is not selection) if node.input != 'selection' and node.input != 'selection-document': bounds = document.get_selection_bounds() if bounds: capture.set_env( PLUMA_SELECTED_TEXT=bounds[0].get_text(bounds[1])) bounds = current_word(document) capture.set_env(PLUMA_CURRENT_WORD=bounds[0].get_text(bounds[1])) capture.set_env(PLUMA_CURRENT_DOCUMENT_TYPE=document.get_mime_type()) if uri is not None: gfile = Gio.file_new_for_uri(uri) scheme = gfile.get_uri_scheme() name = os.path.basename(uri) capture.set_env(PLUMA_CURRENT_DOCUMENT_URI=uri, PLUMA_CURRENT_DOCUMENT_NAME=name, PLUMA_CURRENT_DOCUMENT_SCHEME=scheme) if Pluma.utils_uri_has_file_scheme(uri): path = gfile.get_path() cwd = os.path.dirname(path) capture.set_cwd(cwd) capture.set_env(PLUMA_CURRENT_DOCUMENT_PATH=path, PLUMA_CURRENT_DOCUMENT_DIR=cwd) documents_uri = [ doc.get_uri() for doc in window.get_documents() if doc.get_uri() is not None ] documents_path = [ Gio.file_new_for_uri(uri).get_path() for uri in documents_uri if Pluma.utils_uri_has_file_scheme(uri) ] capture.set_env(PLUMA_DOCUMENTS_URI=' '.join(documents_uri), PLUMA_DOCUMENTS_PATH=' '.join(documents_path)) flags = capture.CAPTURE_BOTH if not node.has_hash_bang(): flags |= capture.CAPTURE_NEEDS_SHELL capture.set_flags(flags) # Get input text input_type = node.input output_type = node.output # Clear the panel panel.clear() if output_type == 'output-panel': panel.show() # Assign the error output to the output panel panel.set_process(capture) if input_type != 'nothing' and view is not None: if input_type == 'document': start, end = document.get_bounds() elif input_type == 'selection' or input_type == 'selection-document': try: start, end = document.get_selection_bounds() except ValueError: if input_type == 'selection-document': start, end = document.get_bounds() if output_type == 'replace-selection': document.select_range(start, end) else: start = document.get_iter_at_mark(document.get_insert()) end = start.copy() elif input_type == 'line': start = document.get_iter_at_mark(document.get_insert()) end = start.copy() if not start.starts_line(): start.set_line_offset(0) if not end.ends_line(): end.forward_to_line_end() elif input_type == 'word': start = document.get_iter_at_mark(document.get_insert()) end = start.copy() if not start.inside_word(): panel.write(_('You must be inside a word to run this command'), panel.command_tag) return if not start.starts_word(): start.backward_word_start() if not end.ends_word(): end.forward_word_end() input_text = document.get_text(start, end, False) capture.set_input(input_text) # Assign the standard output to the chosen "file" if output_type == 'new-document': tab = window.create_tab(True) view = tab.get_view() document = tab.get_document() pos = document.get_start_iter() capture.connect('stdout-line', capture_stdout_line_document, document, pos) document.begin_user_action() view.set_editable(False) view.set_cursor_visible(False) elif output_type != 'output-panel' and output_type != 'nothing' and view is not None: document.begin_user_action() view.set_editable(False) view.set_cursor_visible(False) if output_type == 'insert': pos = document.get_iter_at_mark(document.get_mark('insert')) elif output_type == 'replace-selection': document.delete_selection(False, False) pos = document.get_iter_at_mark(document.get_mark('insert')) elif output_type == 'replace-document': document.set_text('') pos = document.get_end_iter() else: pos = document.get_end_iter() capture.connect('stdout-line', capture_stdout_line_document, document, pos) elif output_type != 'nothing': capture.connect('stdout-line', capture_stdout_line_panel, panel) document.begin_user_action() capture.connect('stderr-line', capture_stderr_line_panel, panel) capture.connect('begin-execute', capture_begin_execute_panel, panel, view, node.name) capture.connect('end-execute', capture_end_execute_panel, panel, view, output_type) # Run the command capture.execute() if output_type != 'nothing': document.end_user_action()
def restore_open_files(self, window): if self.is_only_window(): settings = Gio.Settings.new(SCHEMA_ID) for uri in settings.get_value('uris'): if Pluma.utils_uri_exists(uri): Pluma.commands_load_uri(window, uri, None, -1)