Parent

Included Modules

Files

JSON::Editor::EditMenu

This class creates the Edit pulldown menu.

Public Instance Methods

copy(item) click to toggle source

Copy data from model into primary clipboard.

     # File lib/json/editor.rb, line 548
548:       def copy(item)
549:         data = Editor.model2data(model.iter_first)
550:         json = JSON.pretty_generate(data, :max_nesting => false)
551:         c = Gtk::Clipboard.get(Gdk::Selection::PRIMARY)
552:         c.text = json
553:       end
create() click to toggle source

Create the menu.

     # File lib/json/editor.rb, line 645
645:       def create
646:         title = MenuItem.new('Edit')
647:         title.submenu = menu
648:         add_item('Copy', cc, &method(:copy))
649:         add_item('Paste', vv, &method(:paste))
650:         add_separator
651:         add_item('Find', ff, &method(:find))
652:         add_item('Find Again', gg, &method(:find_again))
653:         add_separator
654:         add_item('Sort', SS, &method(:sort))
655:         title
656:       end
find(item) click to toggle source

Find a string in all nodes’ contents and select the found node in the treeview.

     # File lib/json/editor.rb, line 570
570:       def find(item)
571:         @search = ask_for_find_term(@search) or return
572:         iter = model.get_iter('0') or return
573:         iter.recursive_each do |i|
574:           if @iter
575:             if @iter != i
576:               next
577:             else
578:               @iter = nil
579:               next
580:             end
581:           elsif @search.match(i[CONTENT_COL])
582:              set_cursor(i.path, nil, false)
583:              @iter = i
584:              break
585:           end
586:         end
587:       end
find_again(item) click to toggle source

Repeat the last search given by #.

     # File lib/json/editor.rb, line 590
590:       def find_again(item)
591:         @search or return
592:         iter = model.get_iter('0')
593:         iter.recursive_each do |i|
594:           if @iter
595:             if @iter != i
596:               next
597:             else
598:               @iter = nil
599:               next
600:             end
601:           elsif @search.match(i[CONTENT_COL])
602:              set_cursor(i.path, nil, false)
603:              @iter = i
604:              break
605:           end
606:         end
607:       end
paste(item) click to toggle source

Copy json text from primary clipboard into model.

     # File lib/json/editor.rb, line 556
556:       def paste(item)
557:         c = Gtk::Clipboard.get(Gdk::Selection::PRIMARY)
558:         if json = c.wait_for_text
559:           window.ask_save if @changed
560:           begin
561:             window.edit json
562:           rescue JSON::ParserError
563:             window.clear
564:           end
565:         end
566:       end
sort(item) click to toggle source

Sort (Reverse sort) all elements of the selected array by the given expression. x is the element in question.

     # File lib/json/editor.rb, line 611
611:       def sort(item)
612:         if current = selection.selected
613:           if current.type == 'Array'
614:             parent = current.parent
615:             ary = Editor.model2data(current)
616:             order, reverse = ask_for_order
617:             order or return
618:             begin
619:               block = eval "lambda { |x| #{order} }"
620:               if reverse
621:                 ary.sort! { |a,b| block[b] <=> block[a] }
622:               else
623:                 ary.sort! { |a,b| block[a] <=> block[b] }
624:               end
625:             rescue => e
626:               Editor.error_dialog(self, "Failed to sort Array with #{order}: #{e}!")
627:             else
628:               Editor.data2model(ary, model, parent) do |m|
629:                 m.insert_before(parent, current)
630:               end
631:               model.remove(current)
632:               expand_collapse(parent)
633:               window.change
634:               toplevel.display_status("Array has been sorted.")
635:             end
636:           else
637:             toplevel.display_status("Only Array nodes can be sorted!")
638:           end
639:         else
640:             toplevel.display_status("Select an Array to sort first!")
641:         end
642:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.