def on_window_active_tab_changed(self, window, tab, state): if log.query(log.INFO): Gedit.debug_plugin_message(log.format("%s, %s", window, tab)) state.save_active_uri(window, tab) self.emit('active-tab-changed', window, tab)
def __init__(self, plugin, window): self.window = window self.plugin = plugin self.document_list = [] self.ui_id = None self.action_toggle_orientation = Gtk.Action(name="ToggleSplitViewOrientation", label="Toggle Split View Orientation", tooltip="Switch between horizontal and vertical splits", stock_id=Gtk.STOCK_REFRESH) self.action_toggle_orientation.connect("activate", self.toggle_orientation) self.action_toggle_orientation.set_visible(False) # 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. We'll # index each dictionary via the tab objects. self.split_views = {} self.tabs_already_using_splitview = [] self.current_orientation = "horizontal" # I hardly even know how this works, but it gets our encoding. try: self.encoding = Gedit.encoding_get_current() except: self.encoding = Gedit.gedit_encoding_get_current()
def __init__(self, window, panel, all_docs, node): self._window = window self._panel = panel self._node = node self._error = False self._signal_ids = {} self._counter = 0 if all_docs: docs = window.get_documents() else: docs = [window.get_active_document()] docs_to_save = [doc for doc in docs if doc.get_modified()] signals = {} for doc in docs_to_save: signals[doc] = doc.connect('saving', self.on_document_saving) if len(docs_to_save) == len(docs) and len(docs) != 0: Gedit.commands_save_all_documents(window) else: for doc in docs_to_save: Gedit.commands_save_document(window, doc) for doc in docs_to_save: doc.disconnect(signals[doc]) self.run_tool()
def debounce(self, obj, fn, *args): if log.query(log.DEBUG): Gedit.debug_plugin_message(log.format("%s", obj)) self.cancel_debounce(obj) self._debounce_ids[obj] = GLib.timeout_add(1000, fn, obj, *args)
def __init__(self, plugin, window): self.window = window self.plugin = plugin self.document_list = [] self.ui_id = None self.action_toggle_orientation = Gtk.Action( name="ToggleSplitViewOrientation", label="Toggle Split View Orientation", tooltip="Switch between horizontal and vertical splits", stock_id=Gtk.STOCK_REFRESH) self.action_toggle_orientation.connect("activate", self.toggle_orientation) self.action_toggle_orientation.set_visible(False) # 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. We'll # index each dictionary via the tab objects. self.split_views = {} self.tabs_already_using_splitview = [] self.current_orientation = "horizontal" # I hardly even know how this works, but it gets our encoding. try: self.encoding = Gedit.encoding_get_current() except: self.encoding = Gedit.gedit_encoding_get_current()
def save_window_state(self, window, window_state=None): if log.query(log.INFO): Gedit.debug_plugin_message( log.format("%s, window_state=%s", window, window_state)) if window_state is None: gdk_window = window.get_window() if not gdk_window: if log.query(log.DEBUG): Gedit.debug_plugin_message( log.format("window not yet realized")) return False window_state = gdk_window.get_state() maximized = bool(window_state & Gdk.WindowState.MAXIMIZED) fullscreen = bool(window_state & Gdk.WindowState.FULLSCREEN) results = [ self.save_property('maximized', maximized), self.save_property('fullscreen', fullscreen) ] return any(results)
def on_tab_notify_name(self, tab, pspec, window, state): if log.query(log.INFO): Gedit.debug_plugin_message(log.format("%s, %s", window, tab)) state.save_uri(window, tab) self.emit('tab-updated', window, tab)
def on_app_shutdown(self, app): if log.query(log.INFO): Gedit.debug_plugin_message(log.format("")) settings = self._settings self.end_quitting(settings, settings.restore_between_sessions)
def apply_window(self, window, is_new_window=False): if log.query(log.INFO): Gedit.debug_plugin_message( log.format("%s, is_new_window=%s", window, is_new_window)) # need to unmaximize/unfullscreen to set size window.unmaximize() window.unfullscreen() self.apply_size(window, is_new_window) self.apply_window_state(window) self.apply_side_panel_page_name(window) self.apply_side_panel_visible(window) self.apply_bottom_panel_page_name(window) self.apply_bottom_panel_visible(window) if is_new_window: window.show() self.apply_side_panel_size(window) self.apply_bottom_panel_size(window) self.apply_uris(window) self.apply_active_uri(window) self.apply_notebook_widths(window)
def on_paned_notify_position(self, paned, pspec, window, state, multi_notebook): if log.query(log.DEBUG): Gedit.debug_plugin_message(log.format("%s, %s", window, paned)) self.debounce(multi_notebook, self.debounce_save_notebook_widths, window, state)
def on_window_tabs_reordered(self, window, state): if log.query(log.INFO): Gedit.debug_plugin_message(log.format("%s", window)) state.update_structure(window) self.emit('tabs-reordered', window)
def setup_window(self, window, is_existing=False): if log.query(log.INFO): Gedit.debug_plugin_message(log.format("%s, is_existing=%s", window, is_existing)) window_manager = self._window_manager settings = self._settings if is_existing: info_bar, quit_response_id = self.add_existing(window) connect_handlers( self, info_bar, ['response'], 'existing_window_info_bar', quit_response_id ) self.show_existing_info_bar(window) connect_handlers( self, window, ['delete-event'], 'window', window_manager ) window_manager.track_window(window) self.setup_restore_window(window_manager, window) if self.is_saving_window_states(): self.bind_window_settings(window_manager, settings, window)
def cancel_debounce(self, obj): if log.query(log.DEBUG): Gedit.debug_plugin_message(log.format("%s", obj)) if obj in self._debounce_ids: GLib.source_remove(self._debounce_ids[obj]) del self._debounce_ids[obj]
def untrack_window(self, window): if log.query(log.INFO): Gedit.debug_plugin_message(log.format("%s", window)) if window not in self._windows: if log.query(log.WARNING): Gedit.debug_plugin_message(log.format("unknown window")) return state, widgets = self._windows[window] multi_notebook = widgets['multi_notebook'] hpaned = widgets['hpaned'] vpaned = widgets['vpaned'] for document in window.get_documents(): self.untrack_tab(window, Gedit.Tab.get_from_document(document), state) for paned in self.find_paneds(multi_notebook): self.untrack_paned(window, paned, state, multi_notebook) self.cancel_debounce(window) self.cancel_debounce(multi_notebook) self.cancel_debounce(hpaned) self.cancel_debounce(vpaned) disconnect_handlers(self, window) disconnect_handlers(self, multi_notebook) disconnect_handlers(self, widgets['side_panel']) disconnect_handlers(self, widgets['bottom_panel']) disconnect_handlers(self, hpaned) disconnect_handlers(self, vpaned) del self._windows[window]
def restore_windows(self, window_manager, window, tab): if log.query(log.INFO): Gedit.debug_plugin_message(log.format("%s, %s", window, tab)) active_tab = window.get_active_tab() num_tabs = len(active_tab.get_parent().get_children()) is_single_empty_tab = (num_tabs == 1 and tab == active_tab and tab.get_document().is_untouched() and tab.get_state() == Gedit.TabState.STATE_NORMAL) # if there is only one empty tab, let gedit reuse it when opening files # otherwise, open a new tab to be (re)used # this protects the new tab that was added if gedit was run with # --new-document and one or more files to open if log.query(log.DEBUG): Gedit.debug_plugin_message( log.format("is_single_empty_tab=%s", is_single_empty_tab)) if not is_single_empty_tab: window.create_tab(True) state = self._restore_states.pop() window_manager.import_window_state(window, state) for state in self._restore_states: window_manager.open_new_window_with_window_state(state) self._restore_states = None if not is_single_empty_tab: window.set_active_tab(active_tab) window.present()
def __default__(filename, view): """Edit file: edit <filename>""" doc = view.get_buffer() cwd = os.getcwd() if not doc.is_untitled(): cwd = doc.get_location().get_parent().get_path() else: cwd = os.path.expanduser('~/') if not os.path.isabs(filename): filename = os.path.join(cwd, filename) matches = glob.glob(filename) files = [] if matches: for match in matches: files.append(Gio.file_new_for_path(match)) else: files.append(Gio.file_new_for_path(filename)) if files: window = view.get_toplevel() Gedit.commands_load_locations(window, files, None, 0, 0) return commander.commands.result.HIDE
def do_create_configure_widget(self): if log.query(log.INFO): Gedit.debug_plugin_message(log.format("")) app = Gedit.App.get_default() is_primary = not (app.get_flags() & Gio.ApplicationFlags.NON_UNIQUE) settings = ExMortisSettings() if settings.can_save: widget = Gtk.CheckButton.new_with_label( _("Restore windows between sessions") ) if not is_primary: widget.set_sensitive(False) create_bindings( self, settings, widget, {'restore_between_sessions': 'active'}, GObject.BindingFlags.BIDIRECTIONAL ) widget.set_active(settings.restore_between_sessions) widget._settings = settings else: widget = Gtk.Label.new(_("Could not load settings schema")) box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) box.set_border_width(5) box.add(widget) return box
def __default__(filename, view): """Edit file: edit <filename>""" doc = view.get_buffer() cwd = os.getcwd() if not doc.is_untitled(): cwd = doc.get_file().get_location().get_parent().get_path() else: cwd = os.path.expanduser('~/') if not os.path.isabs(filename): filename = os.path.join(cwd, filename) matches = glob.glob(filename) files = [] if matches: for match in matches: files.append(Gio.file_new_for_path(match)) else: files.append(Gio.file_new_for_path(filename)) if files: window = view.get_toplevel() Gedit.commands_load_locations(window, files, None, 0, 0) return commander.commands.result.HIDE
def save_file(self): """ Trigger the 'Save' action (used by ToolAction before tool run) """ tab = self._active_tab_decorator.tab Gedit.commands_save_document(tab.get_toplevel(), tab.get_document())
def save_to_window_state(self, window): if log.query(log.INFO): Gedit.debug_plugin_message(log.format("%s", window)) state = self.get_window_state(window) if state: state.save_window(window)
def __init__(self): GObject.Object.__init__(self) if log.query(log.INFO): Gedit.debug_plugin_message(log.format("")) self._windows = {} self._debounce_ids = {}
def save_side_panel_size(self, window): if log.query(log.INFO): Gedit.debug_plugin_message(log.format("%s", window)) hpaned = window.get_template_child(Gedit.Window, 'hpaned') position = hpaned.get_position() return self.save_property('side-panel-size', position)
def restore_from_window_state(self, window): if log.query(log.INFO): Gedit.debug_plugin_message(log.format("%s", window)) state = self.get_window_state(window) if state: state.apply_window(window)
def notebook_widths_changed(self): if log.query(log.INFO): Gedit.debug_plugin_message(log.format("")) zipped = zip(self._restore_filter, self._notebook_widths) self._restore_notebook_widths = [ width for can_restore, width in zipped if can_restore ]
def on_window_manager_tab_removed(self, window_manager, window, tab): if log.query(log.INFO): Gedit.debug_plugin_message(log.format("%s, %s", window, tab)) if not self.is_existing(window): self.update_closing(window, tab) self.update_quitting(window, tab)
def on_window_manager_tabs_reordered(self, window_manager, window): if log.query(log.INFO): Gedit.debug_plugin_message(log.format("%s", window)) if not self.is_existing(window): self.cancel_closing(window) self.cancel_quitting()
def save_bottom_panel_visible(self, window): if log.query(log.INFO): Gedit.debug_plugin_message(log.format("%s", window)) bottom_panel = window.get_bottom_panel() visible = bottom_panel.get_visible() return self.save_property('bottom-panel-visible', visible)
def cleanup(self): if log.query(log.INFO): Gedit.debug_plugin_message(log.format("")) for window in list(self._windows.keys()): self.untrack_window(window) self._windows = None self._debounce_ids = None
def debounce_save_bottom_panel_size(self, vpaned, window, state): if log.query(log.INFO): Gedit.debug_plugin_message(log.format("%s", window)) state.save_bottom_panel_size(window) self.done_debounce(vpaned) return False
def debounce_save_notebook_widths(self, multi_notebook, window, state): if log.query(log.INFO): Gedit.debug_plugin_message(log.format("%s", window)) state.save_notebook_widths(window) self.done_debounce(multi_notebook) return False
def track_window(self, window): if log.query(log.INFO): Gedit.debug_plugin_message(log.format("%s", window)) if window in self._windows: if log.query(log.WARNING): Gedit.debug_plugin_message( log.format("window already being tracked")) return state = ExMortisWindowState() state.save_window(window) multi_notebook = window.get_template_child(Gedit.Window, 'multi_notebook') side_panel = window.get_side_panel() bottom_panel = window.get_bottom_panel() hpaned = window.get_template_child(Gedit.Window, 'hpaned') vpaned = window.get_template_child(Gedit.Window, 'vpaned') connect_handlers(self, window, [ 'tab-added', 'tab-removed', 'tabs-reordered', 'active-tab-changed', 'configure-event', 'window-state-event', ], 'window', state) connect_handlers(self, multi_notebook, ['notebook-added', 'notebook-removed'], 'multi_notebook', window, state) connect_handlers(self, side_panel, ['notify::visible-child-name', 'notify::visible'], 'side_panel', window, state) connect_handlers(self, bottom_panel, ['notify::visible-child-name', 'notify::visible'], 'bottom_panel', window, state) connect_handlers(self, hpaned, ['notify::position'], 'hpaned', window, state) connect_handlers(self, vpaned, ['notify::position'], 'vpaned', window, state) self._windows[window] = (state, { 'multi_notebook': multi_notebook, 'side_panel': side_panel, 'bottom_panel': bottom_panel, 'hpaned': hpaned, 'vpaned': vpaned }) for paned in self.find_paneds(multi_notebook): self.track_paned(window, paned, state, multi_notebook) for document in window.get_documents(): self.track_tab(window, Gedit.Tab.get_from_document(document), state)
def forget_tab(self, tab): if log.query(log.INFO): Gedit.debug_plugin_message(log.format("%s", tab)) if tab == self._active_tab: self._active_tab = None if tab in self._tab_map: del self._tab_map[tab]
def on_tool_manager_dialog_response(self, dialog, response): if response == Gtk.ResponseType.HELP: Gedit.app_get_default().show_help(self.dialog, "gedit", "gedit-plugins-external-tools") return self.on_tool_manager_dialog_focus_out(dialog, None) self.dialog.destroy() self.dialog = None self.tools = None
def _load_session(self, session, window): # Note: a session has to stand on its own window. tab = window.get_active_tab() if tab is not None and \ not (tab.get_document().is_untouched() and \ tab.get_state() == Gedit.TabState.STATE_NORMAL): # Create a new gedit window window = Gedit.App.get_default().create_window(None) window.show() Gedit.commands_load_locations(window, session.files, None, 0, 0)
def on_focus_out_event(self, widget, focus): for n, doc in enumerate(self.window.get_unsaved_documents()): if doc.is_untouched(): # nothing to do continue if doc.is_untitled(): # provide a default filename now = datetime.datetime.now() assure_path_exists(dirname) filename = now.strftime(dirname + "%Y%m%d-%H%M%S-%%d.txt") % (n + 1) doc.set_location(Gio.file_parse_name(filename)) # save the document Gedit.commands_save_document(self.window, doc)
def _on_row_activated(self, tree, path, column): model = tree.get_model() i = model.get_iter(path) if model.iter_has_child(i): if tree.row_expanded(path): tree.collapse_row(path) else: tree.expand_row(path, False) else: info = model.get(i, 2, 3) if info[1] != Gio.FileType.DIRECTORY: Gedit.commands_load_location(self.window, info[0], None, -1, -1)
def on_focus_out_event(self, widget, focus): for doc in self.window.get_unsaved_documents(): if doc.is_untouched(): # nothing to do continue if doc.is_untitled(): # provide a default filename now = datetime.datetime.now() filename = now.strftime("/tmp/gedit.unsaved.%Y%m%d-%H%M%S.txt") doc.set_location(Gio.file_parse_name(filename)) # save the document Gedit.commands_save_document(self.window, doc)
def save_next_document(self): if len(self._docs_to_save) == 0: # The documents are saved, we can run the tool. run_external_tool(self._window, self._panel, self._node) else: next_doc = self._docs_to_save[0] self._docs_to_save.remove(next_doc) Gedit.commands_save_document_async(next_doc, self._window, None, self.on_document_saved, None)
def on_view_button_press_event(self, view, event): if event.button != 1 or event.type != Gdk.BUTTON_PRESS or \ event.window != view.get_window(Gtk.TextWindowType.TEXT): return False link = self.get_link_at_location(view, int(event.x), int(event.y)) if link is None: return False gfile = self.file_lookup.lookup(link.path) if gfile: Gedit.commands_load_location(self.window, gfile, None, link.line_nr, -1) GObject.idle_add(self.idle_grab_focus)
def _setup(self, tab): notebooks = self._notebooks multi = self._get_multi_notebook(tab) if multi: self._connect_handlers(multi, ('notebook-added', 'notebook-removed', 'tab-added', 'tab-removed'), 'multi_notebook', notebooks) self._multi = multi for doc in self.window.get_documents(): self.on_multi_notebook_notebook_added(multi, Gedit.Tab.get_from_document(doc).get_parent(), notebooks) self._connect_handlers(self.window, ('tabs-reordered', 'active-tab-changed', 'key-press-event', 'key-release-event', 'focus-out-event'), 'window', notebooks) elif hasattr(Gedit, 'debug_plugin_message'): Gedit.debug_plugin_message("cannot find multi notebook from %s", tab)
def activate_tab(self, file): """ Activate the GeditTab containing the given File or open a new tab for it (this is called by the WindowContext) @param file: a File object """ for tab, tab_decorator in self._tab_decorators.items(): if tab_decorator.file and tab_decorator.file == file: self.window.set_active_tab(tab) return # not found, open file in a new tab... uri = file.uri gfile = Gio.file_new_for_uri(uri) if Gedit.utils_is_valid_location(gfile): LOG.debug("GeditWindow.create_tab_from_uri(%s)" % uri) try: view = self.window.get_active_view() encoding = view.get_buffer().get_encoding() except AttributeError: # No document open encoding = None self.window.create_tab_from_location( gfile, encoding, 1, 1, False, True) else: LOG.error("Gedit.utils.uri_is_valid(%s) = False" % uri)
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 __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) Gedit.commands_save_document(window, doc) doc.disconnect(signals[doc])
def on_navigation_request(self, page, frame, request): file_uri = None uri = request.get_uri() gp = self.mt.search(uri) if gp: file_uri = "file://%s" % gp.group("file") line_number = gp.group("line") if file_uri: # Test if document is already open for doc in self.window.get_documents(): doc_uri = "file://%s" % doc.get_uri_for_display() if doc_uri == file_uri: tab = Gedit.Tab.get_from_document(doc) view = tab.get_view() self.window.set_active_tab(tab) doc.goto_line(int(line_number)) view.scroll_to_cursor() self.todo_window.hide() return 1 # Document isn't open, create a new tab from uri file_uri = Gio.file_new_for_uri(file_uri) self.window.create_tab_from_location( file_uri, Gedit.encoding_get_current(), int(line_number), 0, False, True ) self.todo_window.hide() return 1 else: # self.todo_window.hide() return 0
def __init__(self): GObject.Object.__init__(self) self.uri = "" self.window = None self.id_name = 'OpenURIContextMenuPluginID' self.encoding = Gedit.encoding_get_from_charset("UTF-8")
def _update_window_menu_idle(self, window, data): self._clear_window_menu(window, data) closed_files = self._closed_files ui_manager = window.get_ui_manager() if closed_files: reopen_ui_id = ui_manager.new_merge_id() action_group = data['reopen_action_group'] max_items = self._max_reopen_items num = 0 for f in closed_files: if num >= max_items: break location = f['location'] content_type = Gio.content_type_from_mime_type(f['mime_type']) name = 'NecronomiconPluginReopenFile_%d' % num label = Gedit.utils_escape_underscores(location.get_basename(), -1) # Translators: %s is a URI tooltip = _("Reopen '%s'") % Gedit.utils_replace_home_dir_with_tilde(location.get_parse_name()) action = Gtk.Action(name, label, tooltip, None) action.set_always_show_image(True) if content_type: action.set_gicon(Gio.content_type_get_icon(content_type)) connect_handlers(self, action, ('activate',), 'reopen_action', window, f) if num == 0: action_group.add_action_with_accel(action, self.REOPEN_ACCELERATOR) else: action_group.add_action(action) ui_manager.add_ui(reopen_ui_id, self.REOPEN_MENU_PATH, name, name, Gtk.UIManagerItemType.MENUITEM, False) num += 1 ui_manager.insert_action_group(action_group, -1) data['menu_action'].set_sensitive(True) data['reopen_ui_id'] = reopen_ui_id ui_manager.ensure_update() data['update_menu_id'] = 0 return False
def _direct_file(self): uri = self._entry.get_text() gfile = Gio.file_new_for_uri(uri) if Gedit.utils_is_valid_location(gfile) or (os.path.isabs(uri) and gfile.query_exists()): return gfile else: return None
def _edit_command(view, mod, func=None): try: location = Gio.file_new_for_path(inspect.getsourcefile(mod)) except: return False if not func: Gedit.commands_load_location(view.get_toplevel(), location, None, 0, 0) else: try: lines = inspect.getsourcelines(func) line = lines[-1] except: line = 0 Gedit.commands_load_location(view.get_toplevel(), location, None, line, 0) return True
def open_uri(self, uri): doc = self.get_document_by_uri(uri) if doc != None : tab = Gedit.tab_get_from_document(doc) self.window.set_active_tab(tab) else: self.window.create_tab_from_location(Gio.file_new_for_uri(uri), self.encoding, 0, 0, False, True) status = self.window.get_statusbar() status_id = status.push(status.get_context_id(self.id_name), _("Loading file '%s'...") % (uri)) GObject.timeout_add(4000, self.on_statusbar_timeout, status, status.get_context_id(self.id_name), status_id)
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 Gedit.utils_drop_get_uris(data)] ), -1, ) Gtk.drag_finish(drag_context, True, False, time) else: Vte.Terminal.do_drag_data_received(self, drag_context, x, y, data, info, time)
def make_popup(self, event = None): menu = self.create_popup_menu() menu.attach_to_widget(self, None) if event is not None: menu.popup(None, None, None, None, event.button, event.time) else: menu.popup(None, None, lambda m: Gedit.utils_menu_position_under_widget(m, self), None, 0, Gtk.get_current_event_time()) menu.select_first(False)
def click(self, eventbox, event): for doc in self.window.get_documents(): if 'file://'+doc.get_uri_for_display() == self.file: tab = Gedit.Tab.get_from_document(doc) view = tab.get_view() self.window.set_active_tab(tab) doc.goto_line(self.line) view.scroll_to_cursor() return file_uri = Gio.file_new_for_uri(self.file) self.window.create_tab_from_location(file_uri, Gedit.encoding_get_current(), self.line, 0, False, True)
def add_open_project(self, titer, projectpath): open_project_name = [] while titer: open_project_name.insert(0, self.model[titer][0]) titer = self.model.iter_parent(titer) open_project_name = '/'.join(open_project_name) for row in self.model_open: if projectpath == row[1]: break else: self.model_open.append( [open_project_name, projectpath, Pango.Weight.NORMAL, projectpath.lower(), Gedit.utils_replace_home_dir_with_tilde(projectpath)])
def _get_tab_name(self, tab): doc = tab.get_document() name = doc.get_short_name_for_display() docname = Gedit.utils_str_middle_truncate(name, self.MAX_DOC_NAME_LENGTH) if doc.get_modified(): tab_name = "<i>%s</i>" % escape(docname) else: tab_name = escape(docname) if doc.get_readonly(): tab_name += " [<i>%s</i>]" % escape(_("Read Only")) return tab_name
def __init__(self, plugin): self._window = plugin.window self._plugin = plugin self._encoding = Gedit.encoding_get_current() self._rootpath = os.getcwd() self._rootdir = "file://" + self._rootpath self._show_hidden = False self._suggestion = None self._git = True self._liststore = None self._last_pattern = "" self._init_glade() self._insert_menu() self.connect_to_fb_bus()
def _update_recent_menu(self): max_recents = self.app_data.config.max_recents for action in self.actiongroup_recent.list_actions(): i = int(action.props.name.rsplit('_', 1)[1]) if i >= max_recents: action.props.visible = False continue try: projectpath = self.app_data.config.recent_projects[i] except IndexError: projectpath = None if projectpath: action.props.label = Gedit.utils_replace_home_dir_with_tilde(projectpath) action.props.visible = bool(projectpath)
def activate_tab(self, file): """ Activate the GeditTab containing the given File or open a new tab for it (this is called by the WindowContext) @param file: a File object """ for tab, tab_decorator in self._tab_decorators.iteritems(): if tab_decorator.file and tab_decorator.file == file: self.window.set_active_tab(tab) return # not found, open file in a new tab... uri = file.uri gfile = Gio.file_new_for_uri(uri) if Gedit.utils_is_valid_location(gfile): LOG.debug("GeditWindow.create_tab_from_uri(%s)" % uri) self.window.create_tab_from_location( gfile, Gedit.encoding_get_current(), 1, 1, False, True) else: LOG.error("Gedit.utils.uri_is_valid(%s) = False" % uri)
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)