Class EditMenu
In: lib/json/editor.rb
Parent: Object
OptionsMenu EditMenu PopUpMenu FileMenu JSONTreeView MainWindow ParserError NestingError GeneratorError CircularDatastructure StandardError JSONError MissingUnicodeSupport StringScanner Parser State Enumerable TreeIter Gtk::TreeView Gtk::Window MenuExtension lib/json/common.rb Ext Editor lib/json/pure/parser.rb lib/json/pure/generator.rb Integer FalseClass Array Hash Float NilClass Object TrueClass Extend String GeneratorMethods Generator Pure JSON Editor lib/json/editor.rb Gtk dot/f_8.png

This class creates the Edit pulldown menu.

Methods

create   find   find_again   sort  

Included Modules

MenuExtension

Public Instance methods

Create the menu.

[Source]

     # File lib/json/editor.rb, line 630
630:       def create
631:         title = MenuItem.new('Edit')
632:         title.submenu = menu
633:         add_item('Find', ?f, &method(:find))
634:         add_item('Find Again', ?g, &method(:find_again))
635:         add_separator
636:         add_item('Sort', ?S, &method(:sort))
637:         title
638:       end

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

[Source]

     # File lib/json/editor.rb, line 549
549:       def find(item)
550:         search = ask_for_find_term or return
551:         begin
552:           @search = Regexp.new(search)
553:         rescue => e
554:           Editor.error_dialog(self, "Evaluation of regex /#{search}/ failed: #{e}!")
555:           return
556:         end
557:         iter = model.get_iter('0')
558:         iter.recursive_each do |i|
559:           if @iter
560:             if @iter != i
561:               next
562:             else
563:               @iter = nil
564:               next
565:             end
566:           elsif @search.match(i[CONTENT_COL])
567:              set_cursor(i.path, nil, false)
568:              @iter = i
569:              break
570:           end
571:         end
572:       end

Repeat the last search given by find.

[Source]

     # File lib/json/editor.rb, line 575
575:       def find_again(item)
576:         @search or return
577:         iter = model.get_iter('0')
578:         iter.recursive_each do |i|
579:           if @iter
580:             if @iter != i
581:               next
582:             else
583:               @iter = nil
584:               next
585:             end
586:           elsif @search.match(i[CONTENT_COL])
587:              set_cursor(i.path, nil, false)
588:              @iter = i
589:              break
590:           end
591:         end
592:       end

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

[Source]

     # File lib/json/editor.rb, line 596
596:       def sort(item)
597:         if current = selection.selected
598:           if current.type == 'Array'
599:             parent = current.parent
600:             ary = Editor.model2data(current)
601:             order, reverse = ask_for_order
602:             order or return
603:             begin
604:               block = eval "lambda { |x| #{order} }"
605:               if reverse
606:                 ary.sort! { |a,b| block[b] <=> block[a] }
607:               else
608:                 ary.sort! { |a,b| block[a] <=> block[b] }
609:               end
610:             rescue => e
611:               Editor.error_dialog(self, "Failed to sort Array with #{order}: #{e}!")
612:             else
613:               Editor.data2model(ary, model, parent) do |m|
614:                 m.insert_before(parent, current)
615:               end
616:               model.remove(current)
617:               expand_collapse(parent)
618:               window.change
619:               toplevel.display_status("Array has been sorted.")
620:             end
621:           else
622:             toplevel.display_status("Only Array nodes can be sorted!")
623:           end
624:         else
625:             toplevel.display_status("Select an Array to sort first!")
626:         end
627:       end

[Validate]