From e2d63293cf7b2b6831ddf9db69af8db1c4448e21 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 9 Mar 2003 18:55:49 +0000 Subject: [PATCH] Started edit globs box. git-svn-id: https://rox.svn.sourceforge.net/svnroot/rox/trunk/MIME-Editor@2543 66de3db3-b00d-0410-b41b-f4738ad19bea --- editor.py | 4 +++- type.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/editor.py b/editor.py index 68a1e06..f8a10fa 100644 --- a/editor.py +++ b/editor.py @@ -232,8 +232,10 @@ class EditBox(rox.Dialog): self.model.set(f, 0, str(field), 1, field) field.add_subtree(self.model, f) - def add_new_field(self, type): + def add_new_field(self, klass): rox.alert("TODO: Add field of type '%s'" % type) + new = klass() + new.edit() def add_field(self, view): model, iter = view.get_selection().get_selected() diff --git a/type.py b/type.py index a900a3e..22a6c80 100644 --- a/type.py +++ b/type.py @@ -11,6 +11,9 @@ user_override = os.path.join(home_mime, 'packages', 'Override.xml') FREE_NS='http://www.freedesktop.org/standards/shared-mime-info' +class Invalid(Exception): + pass + def get_type(name): if name not in types: types[name] = MIME_Type(name) @@ -76,14 +79,37 @@ class Field: def __cmp__(self, b): return cmp(str(self), str(b)) - def edit(self): - rox.alert('Sorry, MIME-Editor does not support editing fields of this type') - def delete(self): rox.alert('TODO') - def create(self): - rox.alert("Sorry, can't create fields of this type yet") + def edit(self): + if not hasattr(self, 'add_edit_widgets'): + rox.alert('Sorry, MIME-Editor does not support editing fields of this type') + return + box = rox.Dialog() + self.box = box + box.set_has_separator(False) + vbox = g.VBox(False, 4) + vbox.set_border_width(4) + box.vbox.pack_start(vbox, True, True, 0) + self.add_edit_widgets(vbox) + box.add_button(g.STOCK_CANCEL, g.RESPONSE_CANCEL) + box.add_button(g.STOCK_OK, g.RESPONSE_OK) + box.set_default_response(g.RESPONSE_OK) + box.vbox.show_all() + while 1: + resp = box.run() + if resp == g.RESPONSE_OK: + try: + self.commit_edit(box) + except Invalid, e: + rox.alert(str(e)) + continue + box.destroy() + break + + def commit_edit(self, box): + raise Invalid('TODO: Not implemented') class Comment(Field): def __str__(self): @@ -98,6 +124,26 @@ class Glob(Field): def __str__(self): return "Match '%s'" % self.item + def add_edit_widgets(self, vbox): + vbox.pack_start( + g.Label("Enter a glob pattern which matches files of this type.\n" + "Special characters are:\n" + "? - any one character\n" + "* - zero or more characters\n" + "[abc] - any character between the brackets\n" + "Example: '*.html' matches all files ending in '.html'"), + False, True, 0) + self.entry = g.Entry() + self.entry.set_text(self.item) + vbox.pack_start(self.entry, False, True, 0) + self.entry.set_activates_default(True) + + def commit_edit(self, box): + new = self.entry.get_text() + if not new: + raise Invalid("Pattern can't be empty") + raise Invalid('TODO') + class Magic(Field): def __str__(self): prio, match = self.item -- 2.11.4.GIT