diff --git a/cardvault/application.py b/cardvault/application.py index a9495f3..e1e3290 100644 --- a/cardvault/application.py +++ b/cardvault/application.py @@ -35,6 +35,7 @@ class Application: self.ui.add_from_file(util.get_ui_filename("search.glade")) self.ui.add_from_file(util.get_ui_filename("library.glade")) self.ui.add_from_file(util.get_ui_filename("wants.glade")) + self.ui.add_from_file(util.get_ui_filename("dialogs.glade")) self.current_page = None self.unsaved_changes = False @@ -184,27 +185,19 @@ class Application: dialog.run() dialog.destroy() - def show_tag_rename_dialog(self, tag): - def rename(button, entry): - self.rename_tag(tag, entry.get_text()) - window.destroy() - self.current_page.emit('show') + def show_rename_dialog(self, name: str) -> str: + dialog = self.ui.get_object("renameDialog") # type: Gtk.Dialog + dialog.set_transient_for(self.ui.get_object("mainWindow")) + entry = self.ui.get_object("renameDialogEntry") + entry.set_text(name) - def eval_key_pressed(widget,event): - key, modifier = Gtk.accelerator_parse('Escape') - keyval = event.keyval - if keyval == key: - window.destroy() + result = dialog.run() + dialog.hide() - builder = Gtk.Builder() - builder.add_from_file(util.get_ui_filename("dialogs.glade")) - window = builder.get_object("renameWindow") - entry = builder.get_object("renameEntry") - entry.set_text(tag) - builder.get_object("renameButton").connect('clicked', rename, entry) - entry.connect('activate', rename, entry) - window.show_all() - window.connect("key-press-event", eval_key_pressed) + if result == Gtk.ResponseType.OK: + return entry.get_text() + else: + return name def save_library(self): # Save library file @@ -301,6 +294,12 @@ class Application: out = {card.multiverse_id: card for card in self.wants[list_name]} return out + def rename_want_list(self, old, new): + self.wants[new] = self.wants[old] + del self.wants[old] + util.log("Want List '" + old + "' renamed to '" + new + "'", util.LogLevel.Info) + self.unsaved_changes = True + def add_want_list(self, name): self.wants[name] = [] util.log("Want list '" + name + "' created", util.LogLevel.Info) diff --git a/cardvault/gui/dialogs.glade b/cardvault/gui/dialogs.glade index 341f521..6573c50 100644 --- a/cardvault/gui/dialogs.glade +++ b/cardvault/gui/dialogs.glade @@ -2,6 +2,77 @@ + + False + False + True + dialog + False + + + False + vertical + 4 + + + False + end + + + gtk-ok + True + True + True + True + + + True + True + 0 + + + + + gtk-cancel + True + True + True + True + + + True + True + 1 + + + + + False + False + 0 + + + + + True + True + + + False + True + 1 + + + + + + okButtonRename + cancelButtonRename + + + + + False Rename @@ -41,7 +112,7 @@ - + diff --git a/cardvault/gui/search.glade b/cardvault/gui/search.glade index e18e5a5..e9c7b97 100644 --- a/cardvault/gui/search.glade +++ b/cardvault/gui/search.glade @@ -16,6 +16,7 @@ + Search True True diff --git a/cardvault/gui/wants.glade b/cardvault/gui/wants.glade index 73df964..020d0a2 100644 --- a/cardvault/gui/wants.glade +++ b/cardvault/gui/wants.glade @@ -34,6 +34,7 @@ True wantsListsStore 0 + @@ -182,4 +183,26 @@ + + True + False + + + True + False + Rename + True + + + + + + True + False + Delete + True + + + + diff --git a/cardvault/handlers.py b/cardvault/handlers.py index 7f350c6..a257080 100644 --- a/cardvault/handlers.py +++ b/cardvault/handlers.py @@ -193,7 +193,10 @@ class Handlers: tree_iter = model.get_iter(path) tag = model.get_value(tree_iter, 0) - self.app.show_tag_rename_dialog(tag) + new_name = self.app.show_rename_dialog(tag) + self.app.rename_tag(tag, new_name) + self.app.current_page.emit('show') + def do_tag_list_delete(self, tree): (model, pathlist) = tree.get_selection().get_selected_rows() @@ -265,6 +268,29 @@ class Handlers: list_name = model.get_value(tree_iter, 0) wants_funct.reload_wants_view(self.app, list_name) + def do_wants_tree_press_event(self, treeview, event): + if event.button == 3: # right click + path = treeview.get_path_at_pos(int(event.x), int(event.y)) + if path: + tree_iter = treeview.get_model().get_iter(path[0]) + tag = treeview.get_model().get_value(tree_iter, 0) + self.app.ui.get_object("wants_wantsListPopup").popup(None, None, None, None, 0, event.time) + return True + + def do_rename_wants_list(self, tree): + (model, pathlist) = tree.get_selection().get_selected_rows() + for path in pathlist: + tree_iter = model.get_iter(path) + tag = model.get_value(tree_iter, 0) + + new_name = self.app.show_rename_dialog(tag) + self.app.rename_want_list(tag, new_name) + self.app.current_page.emit('show') + + def do_delete_wants_list(self, menu_item): + # TODO + pass + def on_want_cards_add_activated(self, menu_item): # TODO pass diff --git a/cardvault/wants_funct.py b/cardvault/wants_funct.py index 310efda..7abd1d5 100644 --- a/cardvault/wants_funct.py +++ b/cardvault/wants_funct.py @@ -36,7 +36,7 @@ def reload_wants_view(app: 'application.Application', selected_list: str = None) # Set Title label = app.ui.get_object("wantsTileLabel") # type: Gtk.Label - label.set_markup("" + selected_list + "") + label.set_markup("" + str(selected_list) + "") def reload_wants_list(app: 'application.Application', preserve=False): tree = app.ui.get_object("wantsListsTree")