From 071e688351791f2bcc8d0d6fefdb0036346119ff Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Tue, 13 May 2003 14:59:20 +0000 Subject: [PATCH] Can add and remove namespaces. git-svn-id: http://dom-editor.googlecode.com/svn/branches/Gtk2@480 ef21e15d-ca94-4315-9c45-0d95b1b2e117 --- Dome/Namespaces.py | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/Dome/Namespaces.py b/Dome/Namespaces.py index ccddd13..445a530 100644 --- a/Dome/Namespaces.py +++ b/Dome/Namespaces.py @@ -42,6 +42,11 @@ class Namespaces(g.GenericTreeModel): if iter < len(self.list) - 1: return iter + 1 + def add_new(self): + x = 1 + while ('ns%d' % x) in self.dict: x += 1 + self['ns%d' % x] = 'http://example.com' + def __setitem__(self, prefix, uri): if prefix in self.dict and self.dict[prefix] == uri: return @@ -50,19 +55,41 @@ class Namespaces(g.GenericTreeModel): assert prefix not in fixed_ns self.dict[prefix] = uri + self.update_list() + path = (self.list.index(prefix),) + self.emit('row-inserted', path, self.get_iter(path)) + + def __delitem__(self, iter): + prefix = self[iter][0] + if prefix in fixed_ns: + raise Exception('This is a built-in namespace and cannot be deleted') + path = (self.list.index(prefix),) + del self.dict[prefix] + self.update_list() + self.emit('row-deleted', path) class GUI(rox.Dialog): def __init__(self, model): rox.Dialog.__init__(self) self.model = model + + self.add_button(g.STOCK_ADD, 1) + self.add_button(g.STOCK_DELETE, 2) self.add_button(g.STOCK_CLOSE, g.RESPONSE_OK) + + tree = g.TreeView(model.namespaces) + def response(dialog, resp): - self.destroy() + if resp == 1: + model.namespaces.add_new() + elif resp == 2: + self.delete_selected(tree.get_selection()) + else: + self.destroy() self.connect('response', response) self.set_position(g.WIN_POS_MOUSE) self.set_title('Namespaces for ' + `model.uri`) - tree = g.TreeView(model.namespaces) frame = g.Frame() frame.add(tree) frame.set_shadow_type(g.SHADOW_IN) @@ -80,3 +107,13 @@ class GUI(rox.Dialog): self.set_default_size(400, 200) self.set_has_separator(False) + + def delete_selected(self, sel): + model, iter = sel.get_selected() + if not iter: + rox.alert('Select a namespace binding to delete') + return + try: + del model[iter] + except: + rox.report_exception() -- 2.11.4.GIT