From: gc Date: Mon, 2 Jan 2006 18:08:17 +0000 (+0000) Subject: when save fail, rescue errors; try to save in UTF8 if user entered chars which defaul... X-Git-Tag: 0.9.0~291 X-Git-Url: http://git.zarb.org/?p=booh;a=commitdiff_plain;h=89527f29abd1f07071c92efdc4e7f1c78d07de4b when save fail, rescue errors; try to save in UTF8 if user entered chars which default encoding cannot encode --- diff --git a/bin/booh b/bin/booh index f59d3da..c9f9a92 100755 --- a/bin/booh +++ b/bin/booh @@ -1549,16 +1549,36 @@ def save_current_file save_changes if $filename - ios = File.open($filename, "w") - $xmldoc.write(ios, 0) - ios.close + begin + begin + ios = File.open($filename, "w") + $xmldoc.write(ios, 0) + ios.close + rescue Iconv::IllegalSequence + #- user might have entered text which cannot be encoded in his default encoding. retry in UTF-8. + if ! ios.nil? && ! ios.closed? + ios.close + end + $xmldoc.xml_decl.encoding = 'UTF-8' + ios = File.open($filename, "w") + $xmldoc.write(ios, 0) + ios.close + end + return true + rescue Exception + return false + end end end def save_current_file_user save_tempfilename = $filename $filename = $orig_filename - save_current_file + if ! save_current_file + show_popup($main_window, utf8(_("Save failed! Try another location/name."))) + $filename = save_tempfilename + return + end $modified = false $generated_outofline = false $filename = save_tempfilename @@ -1602,7 +1622,9 @@ def ask_save_modifications(msg1, msg2, *options) dialog.run { |response| dialog.destroy if response == Gtk::Dialog::RESPONSE_YES - save_current_file_user + if ! save_current_file_user + return ask_save_modifications(msg1, msg2, options) + end else #- if we have generated an album but won't save modifications, we must remove #- already-generated markers in original file @@ -3090,7 +3112,10 @@ def save_as_do fc.filename = $orig_filename if fc.run == Gtk::Dialog::RESPONSE_ACCEPT $orig_filename = fc.filename - save_current_file_user + if ! save_current_file_user + fc.destroy + return save_as_do + end $config['last-opens'] ||= [] $config['last-opens'] << $orig_filename end