Class: Watobo::Gui::RequestBuilder

Inherits:
FXVerticalFrame
  • Object
show all
Defined in:
lib/watobo/gui/request_builder_frame.rb

Instance Method Summary collapse

Constructor Details

#initialize(owner, opts) ⇒ RequestBuilder

Returns a new instance of RequestBuilder.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/watobo/gui/request_builder_frame.rb', line 72

def initialize(owner, opts)
  super(owner,opts)

  @event_dispatcher_listeners = Hash.new
  @last_editor = nil

  @tab = FXTabBook.new(self, nil, 0, LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_RIGHT)
  @tab.connect(SEL_COMMAND){
    @current = @editors.to_a[@tab.current][1][:editor]
    unless @last_editor.nil?
    last_request = @last_editor.rawRequest
    @current.setRequest(last_request)
    end
    @last_editor = @editors.to_a[@tab.current][1][:editor]
  #puts @current.class
  }
  @editors = {}
  @current = nil

  add_editor("Text") do |frame|
    Watobo::Gui::RequestEditor.new(frame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_THICK, :padding => 0)
  end

  add_editor("Table") do |frame|
    Watobo::Gui::TableEditorFrame.new(frame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_THICK, :padding => 0)
  end

  @current = @editors.first[1][:editor]

end

Instance Method Details

#clearObject



54
55
56
57
58
59
60
61
# File 'lib/watobo/gui/request_builder_frame.rb', line 54

def clear
  puts "* clear tabs"
  @editors.each do |name, item|
    e = item[:editor]
    r = e.clear
    item[:tab_item].disable
  end
end

#clearEvents(event) ⇒ Object



9
10
11
# File 'lib/watobo/gui/request_builder_frame.rb', line 9

def clearEvents(event)
  @event_dispatcher_listener[event].clear
end

#highlight(pattern) ⇒ Object



40
41
42
# File 'lib/watobo/gui/request_builder_frame.rb', line 40

def highlight(pattern)
  # @text_edit.highlight(pattern)
end

#parseRequestObject



48
49
50
51
52
# File 'lib/watobo/gui/request_builder_frame.rb', line 48

def parseRequest

  @current.parseRequest

end

#rawRequestObject



44
45
46
# File 'lib/watobo/gui/request_builder_frame.rb', line 44

def rawRequest
  @current.rawRequest
end

#setRequest(raw_request) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/watobo/gui/request_builder_frame.rb', line 13

def setRequest(raw_request)
  begin
  # request
    if raw_request.is_a? String
      request = Watobo::Utils.text2request(raw_request)
    else
      request = Watobo::Request.new raw_request
    end

    @editors.each do |name, item|
      e = item[:editor]
      r = e.setRequest(request)
      if r
        item[:tab_item].enable
      else
        item[:tab_item].disable
      end

    end

  rescue => bang
    puts bang
    puts bang.backtrace

  end
end

#subscribe(event, &callback) ⇒ Object



5
6
7
# File 'lib/watobo/gui/request_builder_frame.rb', line 5

def subscribe(event, &callback)
  (@event_dispatcher_listeners[event] ||= []) << callback
end

#to_sObject



63
64
65
66
67
68
69
70
# File 'lib/watobo/gui/request_builder_frame.rb', line 63

def to_s
  s = @current.parseRequest
  puts "* [requestBox] .to_s"
#  puts s
# puts s.class
#  puts s.empty?
  s
end