Improved duplicate-game dialog

Provide a suggested unique name, and also accept 'enter' to close the dialog and make the duplicate.
This commit is contained in:
Daniel Johnson 2023-12-23 10:21:40 -05:00
parent 6cc69c35d3
commit e7109ec65d
2 changed files with 10 additions and 1 deletions

View file

@ -292,6 +292,12 @@ class GameActions(BaseGameActions):
def on_game_duplicate(self, _widget):
for game in self.games:
for num in range(2, 999):
initial_name = game.name + " " + str(num)
if not get_game_by_field(initial_name, "name"):
break
duplicate_game_dialog = InputDialog(
{
"parent": self.window,
@ -301,6 +307,7 @@ class GameActions(BaseGameActions):
"Please enter the new name for the copy:"
) % gtk_safe(game.name),
"title": _("Duplicate game?"),
"initial_value": initial_name
}
)
result = duplicate_game_dialog.run()

View file

@ -315,14 +315,16 @@ class InputDialog(ModalDialog):
self.user_value = ""
self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
self.ok_button = self.add_default_button(Gtk.STOCK_OK, Gtk.ResponseType.OK)
self.set_default_response(Gtk.ResponseType.OK)
self.ok_button.set_sensitive(False)
self.set_title(dialog_settings["title"])
label = Gtk.Label(visible=True)
label.set_markup(dialog_settings["question"])
self.get_content_area().pack_start(label, True, True, 12)
self.entry = Gtk.Entry(visible=True)
self.entry = Gtk.Entry(visible=True, activates_default=True)
self.entry.connect("changed", self.on_entry_changed)
self.get_content_area().pack_start(self.entry, True, True, 12)
self.entry.set_text(dialog_settings.get("initial_value") or "")
def on_entry_changed(self, widget):
self.user_value = widget.get_text()