Class: TK::PluginsManagerDialog

Inherits:
BaseDialog show all
Defined in:
lib/wiki_lyrics/gui/gui-tk.rb

Instance Attribute Summary

Attributes inherited from BaseDialog

#accepted, #values

Instance Method Summary collapse

Methods inherited from BaseDialog

#destroy, #exec, #get_position, get_screen_size, #get_size, #set_position, #set_size

Constructor Details

#initialize(values) ⇒ PluginsManagerDialog

Returns a new instance of PluginsManagerDialog.



445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 445

def initialize( values )
	super( values )

	set_size( 400, 230 )

	@shell.title( I18n.get( "gui.pluginsmanager.title", @values["script_name"] ) )

	label = Label.new( @shell, I18n.get( "gui.pluginsmanager.sites" ) )
	label.grid( "row"=>1, "column"=>1, "columnspan"=>4, "sticky"=>"w" )

	frame = TkFrame.new( @shell )
	frame.grid( "row"=>2, "rowspan"=>4, "column"=>2, "sticky"=>"nesw" )
	@used_plugins_list = TkListbox.new( frame, "selectmode" => "single" )
	@values["used_plugins"].each() { |plugin| @used_plugins_list.insert( "end", plugin ) }
	@used_plugins_list.pack( "side"=>"left", "fill"=>"both", "expand"=>true )
	y_scroll_bar = TkScrollbar.new( frame, "orient"=>"ver" )
	y_scroll_bar.command( proc { |*args| @used_plugins_list.yview( *args ) } )
	y_scroll_bar.pack( "side"=>"right", "fill"=>"y" )
	@used_plugins_list.yscrollcommand( proc { |first, last| y_scroll_bar.set( first, last ) } )

	frame = TkFrame.new( @shell )
	frame.grid( "row"=>2, "rowspan"=>4, "column"=>4, "sticky"=>"nesw" )
	@unused_plugins_list = TkListbox.new( frame, "selectmode" => "single" )
	@values["unused_plugins"].each() { |plugin| @unused_plugins_list.insert( "end", plugin ) }
	@unused_plugins_list.pack( "side"=>"left", "fill"=>"both", "expand"=>true )
	y_scroll_bar = TkScrollbar.new( frame, "orient"=>"ver" )
	y_scroll_bar.command( proc { |*args| @unused_plugins_list.yview( *args ) } )
	y_scroll_bar.pack( "side"=>"right", "fill"=>"y" )
	@unused_plugins_list.yscrollcommand( proc { |first, last| y_scroll_bar.set( first, last ) } )

	@move_up_button = Button.new( @shell, I18n.get( "gui.pluginsmanager.sites.moveup" ) )
	@move_up_button.command( proc { move_up() } )
	@move_up_button.grid( "row"=>3, "column"=>1, "sticky"=>"ew" )

	@move_down_button = Button.new( @shell, I18n.get( "gui.pluginsmanager.sites.movedown" ) )
	@move_down_button.command( proc { move_down() } )
	@move_down_button.grid( "row"=>4, "column"=>1, "sticky"=>"ew" )

	@add_button = Button.new( @shell, I18n.get( "gui.pluginsmanager.sites.add" ) )
	@add_button.command( proc { add_plugin() } )
	@add_button.grid( "row"=>3, "column"=>3, "sticky"=>"ew" )

	@remove_button = Button.new( @shell, I18n.get( "gui.pluginsmanager.sites.remove" ) )
	@remove_button.command( proc { remove_plugin() } )
	@remove_button.grid( "row"=>4, "column"=>3, "sticky"=>"ew" )

	@cleanup_lyrics_checkbox = CheckBox.new( @shell, I18n.get( "gui.pluginsmanager.misc.cleanup" ) )
	@cleanup_lyrics_checkbox.set_checked( @values["cleanup_lyrics"].to_s() == "true" )
	@cleanup_lyrics_checkbox.grid( "row"=>6, "column"=>1, "columnspan"=>4, "sticky"=>"w" )

	@single_threaded_checkbox = CheckBox.new( @shell, I18n.get( "gui.pluginsmanager.misc.singlethreaded" ) )
	@single_threaded_checkbox.set_checked( @values["single_threaded"].to_s() == "true" )
	@single_threaded_checkbox.grid( "row"=>7, "column"=>1, "columnspan"=>4, "sticky"=>"w" )

	@write_log_checkbox = CheckBox.new( @shell, I18n.get( "gui.pluginsmanager.misc.writelog", "$HOME/.wikilyrics.log" ) )
	@write_log_checkbox.set_checked( @values["write_log"].to_s() == "true" )
	@write_log_checkbox.grid( "row"=>8, "column"=>1, "columnspan"=>4, "sticky"=>"w" )

	buttons = create_action_buttons()
	buttons.grid( "row"=>9, "column"=>1, "columnspan"=>4, "sticky"=>"ew" )

	update_accept_button()

	@shell.grid_rowconfigure( 2, "weight"=>1 )
	@shell.grid_rowconfigure( 5, "weight"=>1 )
	@shell.grid_columnconfigure( 2, "weight"=>1 )
	@shell.grid_columnconfigure( 4, "weight"=>1 )
end

Instance Method Details

#acceptObject



563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 563

def accept()
	@values = {
		"cleanup_lyrics" => @cleanup_lyrics_checkbox.is_checked(),
		"single_threaded" => @single_threaded_checkbox.is_checked(),
		"write_log" => @write_log_checkbox.is_checked(),
		"script_name" => @values["script_name"],
		"used_plugins" => [],
		"unused_plugins" => []
	}
	@used_plugins_list.size.times do |idx|
		@values["used_plugins"].insert( -1, @used_plugins_list.get( idx ) )
	end
	@unused_plugins_list.size.times do |idx|
		@values["unused_plugins"].insert( -1, @unused_plugins_list.get( idx ) )
	end
	super()
end

#add_pluginObject



539
540
541
542
543
544
545
546
547
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 539

def add_plugin()
	active_idx = get_active_index( @unused_plugins_list )
	return if active_idx == nil
	active = @unused_plugins_list.get( active_idx )
	@unused_plugins_list.delete( active_idx )
	@used_plugins_list.insert( "end", active )
	@used_plugins_list.selection_set( "end" )
	update_accept_button()
end

#get_active_index(list_box) ⇒ Object



514
515
516
517
518
519
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 514

def get_active_index( list_box )
	list_box.size.times do |idx|
		return idx if list_box.selection_includes( idx )
	end
	return nil
end

#move_downObject



530
531
532
533
534
535
536
537
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 530

def move_down()
	active_idx = get_active_index( @used_plugins_list )
	return if active_idx == nil || active_idx == @used_plugins_list.size - 1
	active = @used_plugins_list.get( active_idx )
	@used_plugins_list.delete( active_idx )
	@used_plugins_list.insert( active_idx+1, active )
	@used_plugins_list.selection_set( active_idx+1 )
end

#move_upObject



521
522
523
524
525
526
527
528
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 521

def move_up()
	active_idx = get_active_index( @used_plugins_list )
	return if active_idx == nil || active_idx == 0
	active = @used_plugins_list.get( active_idx )
	@used_plugins_list.delete( active_idx )
	@used_plugins_list.insert( active_idx-1, active )
	@used_plugins_list.selection_set( active_idx-1 )
end

#remove_pluginObject



549
550
551
552
553
554
555
556
557
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 549

def remove_plugin()
	active_idx = get_active_index( @used_plugins_list )
	return if active_idx == nil
	active = @used_plugins_list.get( active_idx )
	@used_plugins_list.delete( active_idx )
	@unused_plugins_list.insert( "end", active )
	@unused_plugins_list.selection_set( "end" )
	update_accept_button()
end

#update_accept_buttonObject



559
560
561
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 559

def update_accept_button()
	@accept_button.state = @used_plugins_list.size > 0 ? "normal" : "disabled"
end