Beginning of the editor window title
JSON primitive types (Containers)
All JSON primitive types
The Nodes necessary for the tree representation of a JSON document
Convert the Ruby data structure data into tree model data for Gtk and returns the whole model. If the parameter model wasn’t given a new Gtk::TreeStore is created as the model. The parent parameter specifies the parent node (iter, Gtk:TreeIter instance) to which the data is appended, alternativeley the result of the yielded block is used as iter.
# File lib/json/editor.rb, line 121 121: def Editor.data2model(data, model = nil, parent = nil) 122: model ||= TreeStore.new(Gdk::Pixbuf, String, String) 123: iter = if block_given? 124: yield model 125: else 126: model.append(parent) 127: end 128: case data 129: when Hash 130: iter.type = 'Hash' 131: data.sort.each do |key, value| 132: pair_iter = model.append(iter) 133: pair_iter.type = 'Key' 134: pair_iter.content = key.to_s 135: Editor.data2model(value, model, pair_iter) 136: end 137: when Array 138: iter.type = 'Array' 139: data.each do |value| 140: Editor.data2model(value, model, iter) 141: end 142: when Numeric 143: iter.type = 'Numeric' 144: iter.content = data.to_s 145: when String, true, false, nil 146: iter.type = data.class.name 147: iter.content = data.nil? ? 'null' : data.to_s 148: else 149: iter.type = 'String' 150: iter.content = data.to_s 151: end 152: model 153: end
Edit the string json with encoding encoding in the editor.
# File lib/json/editor.rb, line 1362 1362: def edit(json, encoding = 'utf8') 1363: start(encoding) do |window| 1364: window.edit json 1365: end 1366: end
Opens an error dialog on top of window showing the error message text.
# File lib/json/editor.rb, line 50 50: def Editor.error_dialog(window, text) 51: dialog = MessageDialog.new(window, Dialog::MODAL, 52: MessageDialog::ERROR, 53: MessageDialog::BUTTONS_CLOSE, text) 54: dialog.show_all 55: dialog.run 56: rescue TypeError 57: dialog = MessageDialog.new(Editor.window, Dialog::MODAL, 58: MessageDialog::ERROR, 59: MessageDialog::BUTTONS_CLOSE, text) 60: dialog.show_all 61: dialog.run 62: ensure 63: dialog.destroy if dialog 64: end
Returns the Gdk::Pixbuf of the icon named name from the icon cache.
# File lib/json/editor.rb, line 39 39: def Editor.fetch_icon(name) 40: @icon_cache ||= {} 41: unless @icon_cache.key?(name) 42: path = File.dirname(__FILE__) 43: @icon_cache[name] = Gdk::Pixbuf.new(File.join(path, name + '.xpm')) 44: end 45: @icon_cache[name] 46: end
Convert the tree model starting from Gtk::TreeIter iter into a Ruby data structure and return it.
# File lib/json/editor.rb, line 83 83: def Editor.model2data(iter) 84: return nil if iter.nil? 85: case iter.type 86: when 'Hash' 87: hash = {} 88: iter.each { |c| hash[c.content] = Editor.model2data(c.first_child) } 89: hash 90: when 'Array' 91: array = Array.new(iter.n_children) 92: iter.each_with_index { |c, i| array[i] = Editor.model2data(c) } 93: array 94: when 'Key' 95: iter.content 96: when 'String' 97: iter.content 98: when 'Numeric' 99: content = iter.content 100: if /\./.match(content) 101: content.to_f 102: else 103: content.to_i 104: end 105: when 'TrueClass' 106: true 107: when 'FalseClass' 108: false 109: when 'NilClass' 110: nil 111: else 112: fail "Unknown type found in model: #{iter.type}" 113: end 114: end
Opens a yes/no question dialog on top of window showing the error message text. If yes was answered true is returned, otherwise false.
# File lib/json/editor.rb, line 69 69: def Editor.question_dialog(window, text) 70: dialog = MessageDialog.new(window, Dialog::MODAL, 71: MessageDialog::QUESTION, 72: MessageDialog::BUTTONS_YES_NO, text) 73: dialog.show_all 74: dialog.run do |response| 75: return Gtk::Dialog::RESPONSE_YES === response 76: end 77: ensure 78: dialog.destroy if dialog 79: end
Starts a JSON Editor. If a block was given, it yields to the JSON::Editor::MainWindow instance.
# File lib/json/editor.rb, line 1352 1352: def start(encoding = 'utf8') # :yield: window 1353: Gtk.init 1354: @window = Editor::MainWindow.new(encoding) 1355: @window.icon_list = [ Editor.fetch_icon('json') ] 1356: yield @window if block_given? 1357: @window.show_all 1358: Gtk.main 1359: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.