Class: Watobo::Gui::TableEditor

Inherits:
FXTable
  • Object
show all
Defined in:
lib/watobo/gui/table_editor.rb

Instance Method Summary collapse

Constructor Details

#initialize(owner, opts) ⇒ TableEditor

Returns a new instance of TableEditor.


157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/watobo/gui/table_editor.rb', line 157

def initialize(owner, opts)
  super(owner, opts)
  @request = nil
  @event_dispatcher_listeners = Hash.new
  initTable()

  self.connect(SEL_COMMAND, method(:onTableClick))

  # KEY_Return
  # KEY_Control_L
  # KEY_Control_R
  # KEY_s
  @ctrl_pressed = false

  addKeyHandler(self)

  self.connect(SEL_DOUBLECLICKED) do |sender, sel, data|
    row = sender.getCurrentRow
    if row >= 0 then
    self.selectRow(row, false)
    # open simple editor
    end
  end

  self.connect(SEL_DOUBLECLICKED) do |sender, sel, data|
    row = sender.getCurrentRow
    return nil unless row >= 0 and row < self.numRows
    transcoder = TranscoderWindow.new(FXApp.instance, self.getItemText(row, 2))
    transcoder.create
    transcoder.show(Fox::PLACEMENT_SCREEN)
  end

  self.connect(SEL_RIGHTBUTTONRELEASE) do |sender, sel, event|
    unless event.moved?
      self.cancelInput()
      ypos = event.click_y
      row = self.rowAtY(ypos)

      next unless row >= 0 and row <= self.numRows

      self.selectRow(row, false) if row < self.numRows
      FXMenuPane.new(self) do |menu_pane|
        if row < self.numRows
          cell_value = self.getItemText(row, 2)
          cell_value.extend Watobo::Mixin::Transcoders

          parm_name = self.getItemText(row, 1)

          FXMenuCaption.new(menu_pane,"- Decoder -")
          FXMenuSeparator.new(menu_pane)
          decodeB64 = FXMenuCommand.new(menu_pane,"Base64: #{cell_value.b64decode}")
          decodeB64.connect(SEL_COMMAND) {
            self.setItemText(row, 2, cell_value.b64decode)
          }
          decodeHex = FXMenuCommand.new(menu_pane,"Hex(A): #{cell_value.hexdecode}")
          decodeHex.connect(SEL_COMMAND) {
            self.setItemText(row, 2, cell_value.hexdecode)
          }
          hex2int = FXMenuCommand.new(menu_pane,"Hex(Int): #{cell_value.hex2int}")
          hex2int.connect(SEL_COMMAND) {
            self.setItemText(row, 2, cell_value.hex2int)
          }
          decodeURL = FXMenuCommand.new(menu_pane,"URL: #{cell_value.url_decode}")
          decodeURL.connect(SEL_COMMAND) {
            self.setItemText(row, 2, cell_value.url_decode)
          }

          FXMenuSeparator.new(menu_pane)
          FXMenuCaption.new(menu_pane,"- Encoder -")
          FXMenuSeparator.new(menu_pane)
          encodeB64 = FXMenuCommand.new(menu_pane,"Base64: #{cell_value.b64encode}")
          encodeB64.connect(SEL_COMMAND) {
            self.setItemText(row, 2, cell_value.b64encode)
          }
          encodeHex = FXMenuCommand.new(menu_pane,"Hex: #{cell_value.hexencode}")
          encodeHex.connect(SEL_COMMAND) {
            self.setItemText(row, 2, cell_value.hexencode)
          }
          encodeURL = FXMenuCommand.new(menu_pane,"URL: #{cell_value.url_encode}")
          encodeURL.connect(SEL_COMMAND) {
            self.setItemText(row, 2, cell_value.url_encode)
          }

          FXMenuSeparator.new(menu_pane)
          remRow = FXMenuCommand.new(menu_pane,"Remove: #{parm_name}")
          remRow.connect(SEL_COMMAND) {
            self.removeRows(row,1, true)
          }
          remRow = FXMenuCommand.new(menu_pane,"Add Parameter..")
          remRow.connect(SEL_COMMAND) { addNewParm() }

        elsif row >= 0
          remRow = FXMenuCommand.new(menu_pane,"Add Parameter..")
          remRow.connect(SEL_COMMAND) { addNewParm() }
        end
        menu_pane.create
        menu_pane.popup(nil, event.root_x, event.root_y)
        app.runModalWhileShown(menu_pane)
      end

    end

  end

  self.columnHeader.connect(SEL_COMMAND) do |sender, sel, index|
    self.fitColumnsToContents(index)
  end
end

Instance Method Details

#parseRequestObject


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/watobo/gui/table_editor.rb', line 101

def parseRequest
  cookies = []
  url = ""
  
  parms = []
  self.numRows.times do |i|
    name = CGI.escape(self.getItemText(i, 1))
    value = self.getItemText(i, 2).strip
    location = self.getItemText(i, 0)
    case location
    when /req/i
      url = self.getItemText(i, 2)
    when /post/i
      @request.set Watobo::WWWFormParameter.new( :name => name, :value => value)            
    when /url/i
      @request.set Watobo::UrlParameter.new( :name => name, :value => value)
    when /cookie2?/i
      cookies << "#{name}=#{value}"
    end
  end
  
  request = @request.copy

  unless cookies.empty?
    # puts cookies
    request.removeHeader("Cookie")
    request.addHeader("Cookie", cookies.join("; "))
  end
  request
end

#rawRequestObject


97
98
99
# File 'lib/watobo/gui/table_editor.rb', line 97

def rawRequest
  parseRequest
end

#setRequest(request) ⇒ Object


132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/watobo/gui/table_editor.rb', line 132

def setRequest(request)
  @request = request.copy

  return false if @request.content_type =~ /(multipart|xml|json)/

  initTable()
  @request = Watobo::Utils.text2request(request) if request.is_a? String
  # addParmList("REQ", ["URL=#{request.url}"])

  if @request.get_parms.length > 0
    addParmList("URL", @request.get_parms)
  end

  if @request.post_parms.length > 0
    addParmList("Post", @request.post_parms)
  end

  if @request.cookies.length > 0
    addParmList("Cookie", @request.cookies)
  end

  true

end