# -*- coding: utf8 -*- # XML Helper for GEdit # # Copyright (c) 2007 Matej Cepl # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import gedit import gtk import re,sys end_tag_str = """ """ class EndTagPlugin(gedit.Plugin): def __init__(self): gedit.Plugin.__init__(self) def __extract_element(self,tag): buf = "" for char in tag: uc = unicode(char) buf += uc if (uc.isspace() or uc == ">"): ubuf=None break return buf def __find_previous_end_tag(self,buffer,position): # var # buffer: GtkTextBuffer # position, match, match_start: GtkTextIter # tag, element: string # # gtk_text_iter_backward_search (position, ">sys.stderr,inp_mark inp = buffer.get_iter_at_mark(inp_mark) cur = buffer.get_end_iter() line = buffer.get_text(inp, cur) document=window.get_active_document() document.set_search_text("<",0) document.search_backward() tagname=None #find out what is the current tag view.do_insert_at_cursor(view, '' % tagname) def activate(self, window): actions = [ ('EndTag', None, 'End Tag', None, "End Tag", self.end_tag), ] # store per window data in the window object windowdata = dict() window.set_data("EndTagPluginWindowDataKey", windowdata) windowdata["action_group"] = gtk.ActionGroup("GeditEndTagPluginActions") windowdata["action_group"].add_actions(actions, window) manager = window.get_ui_manager() manager.insert_action_group(windowdata["action_group"], -1) windowdata["ui_id"] = manager.add_ui_from_string(end_tag_str) window.set_data("EndTagPluginInfo", windowdata) def deactivate(self, window): windowdata = window.get_data("EndTagPluginWindowDataKey") manager = window.get_ui_manager() manager.remove_ui(windowdata["ui_id"]) manager.remove_action_group(windowdata["action_group"]) def update_ui(self, window): view = window.get_active_view() windowdata = window.get_data("EndTagPluginWindowDataKey") windowdata["action_group"].set_sensitive(bool(view and view.get_editable()))