Prevent empty title when duplicating entry
This commit is contained in:
@@ -954,26 +954,46 @@ class Main(Gtk.Window):
|
||||
game = selected_child.game
|
||||
title = game.title
|
||||
|
||||
# Display duplicate dialog
|
||||
css_provider = Gtk.CssProvider()
|
||||
css = """
|
||||
.entry {
|
||||
border-color: red;
|
||||
}
|
||||
"""
|
||||
css_provider.load_from_data(css.encode("utf-8"))
|
||||
Gtk.StyleContext.add_provider_for_screen(
|
||||
Gdk.Screen.get_default(),
|
||||
css_provider,
|
||||
Gtk.STYLE_PROVIDER_PRIORITY_USER
|
||||
)
|
||||
|
||||
duplicate_dialog = DuplicateDialog(self, title)
|
||||
|
||||
while True:
|
||||
response = duplicate_dialog.run()
|
||||
|
||||
if response == Gtk.ResponseType.OK:
|
||||
new_title = duplicate_dialog.entry_title.get_text()
|
||||
if response != Gtk.ResponseType.OK:
|
||||
break
|
||||
|
||||
new_title = duplicate_dialog.entry_title.get_text().strip()
|
||||
|
||||
if not new_title:
|
||||
duplicate_dialog.entry_title.get_style_context().add_class("entry")
|
||||
continue
|
||||
|
||||
if any(new_title == g.title for g in self.games):
|
||||
duplicate_dialog.show_warning_dialog(
|
||||
duplicate_dialog,
|
||||
_("%s already exists.") % new_title
|
||||
)
|
||||
continue
|
||||
|
||||
if any(new_title == game.title for game in self.games):
|
||||
duplicate_dialog.show_warning_dialog(duplicate_dialog, _("%s already exists.") % title)
|
||||
else:
|
||||
title_formatted_old = format_title(game.title)
|
||||
title_formatted = format_title(new_title)
|
||||
|
||||
icon = f"{icons_dir}/{title_formatted_old}.ico"
|
||||
banner = game.banner
|
||||
|
||||
game.title = new_title
|
||||
title_formatted = format_title(game.title)
|
||||
|
||||
new_icon = f"{icons_dir}/{title_formatted}.ico"
|
||||
new_banner = f"{banners_dir}/{title_formatted}.png"
|
||||
new_addapp_bat = f"{os.path.dirname(game.path)}/faugus-{title_formatted}.bat"
|
||||
@@ -987,6 +1007,7 @@ class Main(Gtk.Window):
|
||||
if os.path.exists(game.addapp_bat):
|
||||
shutil.copyfile(game.addapp_bat, new_addapp_bat)
|
||||
|
||||
game.title = new_title
|
||||
game.banner = new_banner
|
||||
game.addapp_bat = new_addapp_bat
|
||||
|
||||
@@ -1011,7 +1032,6 @@ class Main(Gtk.Window):
|
||||
"lossless_flow": game.lossless_flow,
|
||||
"lossless_performance": game.lossless_performance,
|
||||
"lossless_hdr": game.lossless_hdr,
|
||||
"lossless_present": game.lossless_present,
|
||||
"playtime": game.playtime,
|
||||
"hidden": game.hidden,
|
||||
"prevent_sleep": game.prevent_sleep,
|
||||
@@ -1033,15 +1053,10 @@ class Main(Gtk.Window):
|
||||
self.games.append(game)
|
||||
self.add_item_list(game)
|
||||
self.update_list()
|
||||
|
||||
# Select the added game
|
||||
self.select_game_by_title(new_title)
|
||||
|
||||
break
|
||||
|
||||
else:
|
||||
break
|
||||
|
||||
duplicate_dialog.destroy()
|
||||
|
||||
def on_item_release_event(self, widget, event):
|
||||
|
||||
Reference in New Issue
Block a user