Class: JSON::Editor::FileMenu
- Inherits:
-
Object
- Object
- JSON::Editor::FileMenu
- Includes:
- MenuExtension
- Defined in:
- lib/json/editor.rb
Overview
This class creates the File pulldown menu.
Instance Attribute Summary
Attributes included from MenuExtension
Instance Method Summary collapse
-
#create ⇒ Object
Create the menu.
-
#new(item) ⇒ Object
Clear the model and filename, but ask to save the JSON document, if unsaved changes have occured.
-
#open(item) ⇒ Object
Open a file and load it into the editor.
-
#quit(item) ⇒ Object
Quit the editor, after asking to save any unsaved changes first.
-
#revert(item) ⇒ Object
Revert the current JSON document in the editor to the saved version.
-
#save(item) ⇒ Object
Save the current JSON document.
-
#save_as(item) ⇒ Object
Save the current JSON document under the given filename.
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
#create ⇒ Object
Create the menu.
492 493 494 495 496 497 498 499 500 501 502 503 504 |
# File 'lib/json/editor.rb', line 492 def create title = MenuItem.new('File') title. = add_item('New', &method(:new)) add_item('Open', &method(:open)) add_item('Revert', &method(:revert)) add_separator add_item('Save', &method(:save)) add_item('Save As', &method(:save_as)) add_separator add_item('Quit', &method(:quit)) title end |
#new(item) ⇒ Object
Clear the model and filename, but ask to save the JSON document, if unsaved changes have occured.
459 460 461 |
# File 'lib/json/editor.rb', line 459 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.
465 466 467 |
# File 'lib/json/editor.rb', line 465 def open(item) window.file_open end |
#quit(item) ⇒ Object
Quit the editor, after asking to save any unsaved changes first.
487 488 489 |
# File 'lib/json/editor.rb', line 487 def quit(item) window.quit end |
#revert(item) ⇒ Object
Revert the current JSON document in the editor to the saved version.
470 471 472 473 474 |
# File 'lib/json/editor.rb', line 470 def revert(item) window.instance_eval do @filename and file_open(@filename) end end |
#save(item) ⇒ Object
Save the current JSON document.
477 478 479 |
# File 'lib/json/editor.rb', line 477 def save(item) window.file_save end |
#save_as(item) ⇒ Object
Save the current JSON document under the given filename.
482 483 484 |
# File 'lib/json/editor.rb', line 482 def save_as(item) window.file_save_as end |