Class: Watobo::Gui::DefineScopeFrame

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

Instance Method Summary collapse

Constructor Details

#initialize(owner, sites, scope, opts) ⇒ DefineScopeFrame

Returns a new instance of DefineScopeFrame.



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/watobo/gui/define_scope_frame.rb', line 255

def initialize(owner, sites, scope, opts)
  super(owner, :opts => opts, :padding => 0)
  
  @dummy_scope = Hash.new
  @dummy_scope = YAML.load(YAML.dump(scope)) if scope.is_a? Hash
  
  @cb_sites = Hash.new
  @edit_btns = Hash.new
  
  title = FXLabel.new(self, "Target Scope")
  info_frame = FXVerticalFrame.new(self, :opts => LAYOUT_FILL_X|FRAME_GROOVE)
  title.setFont(FXFont.new(getApp(), "helvetica", 12, FONTWEIGHT_BOLD, FONTSLANT_ITALIC, FONTENCODING_DEFAULT))
  
  scope_text =<<'EOF'
The target scopes affects primarly the 
behaviour all WATOBO scanner tools. 
Click the appropriate edit-button for more 
 detailed settings.
EOF
  btn = FXButton.new(info_frame, scope_text,
                     :opts => LAYOUT_FILL_X|LAYOUT_FIX_HEIGHT, :height => 90)
  #btn.font = @font
  #btn.backColor = FXColor::White
  btn.justify = JUSTIFY_LEFT
  quickSelectFrame = FXHorizontalFrame.new(self, LAYOUT_FILL_X)
  @sel_all_btn = FXButton.new(quickSelectFrame, "Select All", nil, nil, 0, FRAME_RAISED|FRAME_THICK|LAYOUT_FILL_X)
  @sel_all_btn.connect(SEL_COMMAND, method(:onSelectAll))
  
  @sel_all_btn.setFocus()
  @sel_all_btn.setDefault()
  
  @desel_all_btn = FXButton.new(quickSelectFrame, "Deselect All", nil, nil, 0, FRAME_RAISED|FRAME_THICK|LAYOUT_FILL_X)
  @desel_all_btn.connect(SEL_COMMAND, method(:onDeselectAll)) 
    frame = FXVerticalFrame.new(self, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_GROOVE, :padding => 0)
  sitesArea = FXScrollWindow.new(frame, SCROLLERS_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_Y)
  sitesFrame = FXVerticalFrame.new(sitesArea, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y, :padding => 0)
  
  sites.sort.each do |site|         
    site_frame = FXHorizontalFrame.new(sitesFrame, :opts => LAYOUT_FILL_X)
    b = FXCheckButton.new(site_frame, site, nil, 0, ICON_BEFORE_TEXT|LAYOUT_SIDE_LEFT)
    eb = FXButton.new(site_frame, "edit..", nil, nil, 0, FRAME_RAISED|FRAME_THICK|LAYOUT_RIGHT)
    @edit_btns[site] = eb
    
    b.connect(SEL_COMMAND){
      b.checked? ? @edit_btns[site].enable : @edit_btns[site].disable
      @dummy_scope[site][:enabled] = true
    }
    
    
    @cb_sites[site] = b  
    b.setCheck(false)
    scope_details = {
      :site => site,
      :enabled => false,
      :root_path => '',
      :excluded_paths => [],
      #:exclude_pattern => []
    }
    
    if !@dummy_scope[site]
    @dummy_scope[site] = scope_details 
  else
    @dummy_scope[site][:enabled] = true
    end
    
    
    eb.connect(SEL_COMMAND){
      editSiteDetails(site)            
    }
    
  end
  updateFrame()
end

Instance Method Details

#editSiteDetails(site) ⇒ Object



220
221
222
223
224
225
226
227
# File 'lib/watobo/gui/define_scope_frame.rb', line 220

def editSiteDetails(site)
  dlg = EditScopeDetailsDialog.new(self, @dummy_scope[site])
  
  if dlg.execute != 0
    @dummy_scope[site].update dlg.details
    puts dlg.details.to_yaml
  end
end

#getScopeObject



229
230
231
232
233
234
235
236
# File 'lib/watobo/gui/define_scope_frame.rb', line 229

def getScope()
  scope = Hash.new
  @cb_sites.keys.each do |site|
    @dummy_scope.delete(site) if !@cb_sites[site].checked?
    # scope[site] = @dummy_scope[site] if @cb_sites[site].checked?
  end
  return @dummy_scope
end

#onDeselectAll(sender, sel, item) ⇒ Object



200
201
202
203
204
205
206
207
208
# File 'lib/watobo/gui/define_scope_frame.rb', line 200

def onDeselectAll(sender, sel, item)        
  @dummy_scope.each do |site, val|        
    @cb_sites[site].setCheck(false)  
    @edit_btns[site].disable
  end
  @sel_all_btn.setFocus()
  @sel_all_btn.setDefault()
  
end

#onSelectAll(sender, sel, item) ⇒ Object



210
211
212
213
214
215
216
217
218
# File 'lib/watobo/gui/define_scope_frame.rb', line 210

def onSelectAll(sender, sel, item)
  sites = []
  @dummy_scope.each do |site, scope|
    @cb_sites[site].setCheck(true)
    @edit_btns[site].enable
  end
  @desel_all_btn.setFocus()
  @desel_all_btn.setDefault()
end

#setScope(scope) ⇒ Object



247
248
249
250
251
252
253
# File 'lib/watobo/gui/define_scope_frame.rb', line 247

def setScope(scope)
  @scope = scope
  @dummy_scope.keys.each do |site|         
    @dummy_scope[site].update @scope[site] if !@scope[site].nil?         
  end
  updateFrame()
end

#updateFrameObject



238
239
240
241
242
243
244
245
# File 'lib/watobo/gui/define_scope_frame.rb', line 238

def updateFrame()
  @dummy_scope.each do |site, scope|
    next if @cb_sites[site].nil? 
    @cb_sites[site].setCheck(scope[:enabled])
    @cb_sites[site].checked? ? @edit_btns[site].enable : @edit_btns[site].disable
  end
  
end