1 # Copyright (C) 2006 by Aiwota Programmer
2 # aiwotaprog@tetteke.tk
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 from bookmark_core import Bookmark
28 GLADE_FILENAME = "bookmark_editwindow.glade"
31 class BookmarkEditWindow:
33 def __init__(self, on_newbookmark_complete, bookmark=None):
34 glade_path = os.path.join(config.glade_dir, GLADE_FILENAME)
35 self.widget_tree = gtk.glade.XML(glade_path)
36 self.widget_tree.signal_autoconnect(self)
37 self.window = self.widget_tree.get_widget("window_editbookmark")
38 self.entry_name = self.widget_tree.get_widget("entry_name")
39 self.entry_uri = self.widget_tree.get_widget("entry_uri")
40 self.button_ok = self.widget_tree.get_widget("button_ok")
41 self.button_cancel = self.widget_tree.get_widget("button_cancel")
42 self.button_category_add = self.widget_tree.get_widget(
43 "button_category_add")
44 self.button_category_edit = self.widget_tree.get_widget(
45 "button_category_edit")
46 self.button_category_delete = self.widget_tree.get_widget(
47 "button_category_delete")
48 self.treeview_categories = self.widget_tree.get_widget(
49 "treeview_categories")
51 cell = gtk.CellRendererText()
52 cell.set_property("editable", True)
53 cell.connect("edited", self.on_cell_edited)
54 treeviewcolumn = gtk.TreeViewColumn(None, cell, text=0)
55 treeviewcolumn.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
56 self.treeview_categories.append_column(treeviewcolumn)
57 self.treeview_categories.set_fixed_height_mode(True)
58 self.treeview_categories.set_model(gtk.ListStore(str))
60 self.on_newbookmark_complete = on_newbookmark_complete
61 self.bookmark = bookmark
63 self.entry_name.set_text(bookmark.name)
64 self.entry_uri.set_text(bookmark.uri)
65 model = self.treeview_categories.get_model()
66 for category in bookmark.categories:
67 model.append([category])
69 def on_button_ok_clicked(self, widget):
70 bookmark_name = self.entry_name.get_text()
71 bookmark_uri = self.entry_uri.get_text()
72 if not bookmark_name or not bookmark_uri:
74 "Confirmation", self.window,
75 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
76 (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
77 label = gtk.Label("NAME and URL must be set")
78 dialog.vbox.pack_start(label, True, True, 0)
83 bookmark_categories = []
84 for row in self.treeview_categories.get_model():
85 category = row.model.get_value(row.iter, 0)
86 if category and category not in bookmark_categories:
87 bookmark_categories.append(category)
88 bookmark = Bookmark(uri=bookmark_uri, name=bookmark_name,
89 categories=bookmark_categories)
90 self.on_newbookmark_complete(bookmark)
93 def on_button_cancel_clicked(self, widget):
96 def on_button_category_add_clicked(self, widget):
98 "Input Category Name", self.window,
99 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
100 (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
101 gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
102 dialog.set_default_response(gtk.RESPONSE_ACCEPT)
104 entry.set_property("activates-default", True)
105 dialog.vbox.pack_start(entry, True, True, 0)
107 response = dialog.run()
108 if response == gtk.RESPONSE_ACCEPT:
109 text = entry.get_text()
110 model = self.treeview_categories.get_model()
115 def on_button_category_delete_clicked(self, widget):
116 selection = self.treeview_categories.get_selection()
117 model, iter = selection.get_selected()
121 def on_cell_edited(self, cell, path, new_text):
122 model = self.treeview_categories.get_model()
124 iter = model.get_iter(path)
126 model.set_value(iter, 0, new_text)