# HG changeset patch
# User Yuki KODAMA <endflow.net@gmail.com>
# Date 1254068037 -32400
# Node ID 3af7e75877aaf8ac1373463628b3851d159e2588
# Parent  30246dc350e4890214b2e6b3b1f6d8f97edfcfe7
gdialog: catch ValueError occurred in CustomPrompt

In case of the choice string doesn't have '&' char, 'str.index()'
raises ValueError.  In general, choice string was wrapped with
gettext '_' function, so translated string doesn't always have
'&' char in some languages.

diff --git a/tortoisehg/hgtk/gdialog.py b/tortoisehg/hgtk/gdialog.py
--- a/tortoisehg/hgtk/gdialog.py
+++ b/tortoisehg/hgtk/gdialog.py
@@ -58,10 +58,13 @@
         accel_group = gtk.AccelGroup()
         self.add_accel_group(accel_group)
         for i, s in enumerate(choices):
-            char = s[s.index('&')+1].lower()
             button = self.add_button(s.replace('&', '_'), i)
-            button.add_accelerator('clicked', accel_group, ord(char), 0,
-                    gtk.ACCEL_VISIBLE)
+            try:
+                char = s[s.index('&')+1].lower()
+                button.add_accelerator('clicked', accel_group, ord(char), 0,
+                        gtk.ACCEL_VISIBLE)
+            except ValueError:
+                pass
         if default:
             self.set_default_response(default)
         self.esc = esc
