Class: JSON::Editor::FileMenu

Inherits:
Object
  • Object
show all
Includes:
MenuExtension
Defined in:
lib/json/editor.rb

Overview

This class creates the File pulldown menu.

Instance Attribute Summary

Attributes included from MenuExtension

#menu, #treeview

Instance Method Summary collapse

Methods included from MenuExtension

#add_item, #add_separator, #initialize, #method_missing

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class JSON::Editor::MenuExtension

Instance Method Details

#createObject

Create the menu.



526
527
528
529
530
531
532
533
534
535
536
537
538
539
# File 'lib/json/editor.rb', line 526

def create
  title = MenuItem.new('File')
  title.submenu = menu
  add_item('New', &method(:new))
  add_item('Open', ?o, &method(:open))
  add_item('Open location', ?l, &method(:open_location))
  add_item('Revert', &method(:revert))
  add_separator
  add_item('Save', ?s, &method(:save))
  add_item('Save As', ?S, &method(:save_as))
  add_separator
  add_item('Quit', ?q, &method(:quit))
  title
end

#new(item) ⇒ Object

Clear the model and filename, but ask to save the JSON document, if unsaved changes have occured.



489
490
491
# File 'lib/json/editor.rb', line 489

def new(item)
  window.clear
end

#open(item) ⇒ Object

Open a file and load it into the editor. Ask to save the JSON document first, if unsaved changes have occured.



495
496
497
# File 'lib/json/editor.rb', line 495

def open(item)
  window.file_open
end

#open_location(item) ⇒ Object



499
500
501
# File 'lib/json/editor.rb', line 499

def open_location(item)
  window.location_open
end

#quit(item) ⇒ Object

Quit the editor, after asking to save any unsaved changes first.



521
522
523
# File 'lib/json/editor.rb', line 521

def quit(item)
  window.quit
end

#revert(item) ⇒ Object

Revert the current JSON document in the editor to the saved version.



504
505
506
507
508
# File 'lib/json/editor.rb', line 504

def revert(item)
  window.instance_eval do
    @filename and file_open(@filename)
  end
end

#save(item) ⇒ Object

Save the current JSON document.



511
512
513
# File 'lib/json/editor.rb', line 511

def save(item)
  window.file_save
end

#save_as(item) ⇒ Object

Save the current JSON document under the given filename.



516
517
518
# File 'lib/json/editor.rb', line 516

def save_as(item)
  window.file_save_as
end