lib/json/editor.rb in json_pure-1.1.0 vs lib/json/editor.rb in json_pure-1.1.1
- old
+ new
@@ -50,18 +50,16 @@
def Editor.error_dialog(window, text)
dialog = MessageDialog.new(window, Dialog::MODAL,
MessageDialog::ERROR,
MessageDialog::BUTTONS_CLOSE, text)
dialog.show_all
- window.focus = dialog
dialog.run
rescue TypeError
dialog = MessageDialog.new(Editor.window, Dialog::MODAL,
MessageDialog::ERROR,
MessageDialog::BUTTONS_CLOSE, text)
dialog.show_all
- window.focus = dialog
dialog.run
ensure
dialog.destroy if dialog
end
@@ -71,11 +69,10 @@
def Editor.question_dialog(window, text)
dialog = MessageDialog.new(window, Dialog::MODAL,
MessageDialog::QUESTION,
MessageDialog::BUTTONS_YES_NO, text)
dialog.show_all
- window.focus = dialog
dialog.run do |response|
return Gtk::Dialog::RESPONSE_YES === response
end
ensure
dialog.destroy if dialog
@@ -1100,13 +1097,15 @@
end
# Quit this editor, that is, leave this editor's main loop.
def quit
ask_save if @changed
- destroy
- Gtk.main_quit
- true
+ if Gtk.main_level > 0
+ destroy
+ Gtk.main_quit
+ end
+ nil
end
# Display the new title according to the editor's current state.
def display_title
title = TITLE.dup
@@ -1183,24 +1182,25 @@
# Load the file named _filename_ into the editor as a JSON document.
def load_file(filename)
if filename
if File.directory?(filename)
Editor.error_dialog(self, "Try to select a JSON file!")
- return
+ nil
else
- data = read_data(filename)
@filename = filename
- toplevel.display_status("Loaded data from '#@filename'.")
+ if data = read_data(filename)
+ toplevel.display_status("Loaded data from '#@filename'.")
+ end
display_title
- return data
+ data
end
end
end
# Load the data at location _uri_ into the editor as a JSON document.
def load_location(uri)
- data = read_data(uri)
+ data = read_data(uri) or return
@filename = nil
toplevel.display_status("Loaded data from '#{uri}'.")
display_title
data
end
@@ -1215,14 +1215,12 @@
iconverter = Iconv.new('utf8', @encoding)
json = iconverter.iconv(json)
end
return JSON::parse(json, :max_nesting => false)
end
- rescue JSON::JSONError => e
+ rescue => e
Editor.error_dialog(self, "Failed to parse JSON file: #{e}!")
return
- rescue SystemCallError => e
- quit
end
# Open a file selecton dialog, displaying _message_, and return the
# selected filename or nil, if no file was selected.
def select_file(message)