Class: GTK::PluginsManagerDialog

Inherits:
BaseDialog
  • Object
show all
Defined in:
lib/wiki_lyrics/gui/gui-gtk.rb

Instance Attribute Summary

Attributes inherited from BaseDialog

#accepted, #values

Instance Method Summary collapse

Methods inherited from BaseDialog

#exec

Constructor Details

#initialize(values) ⇒ PluginsManagerDialog

Returns a new instance of PluginsManagerDialog.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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
# File 'lib/wiki_lyrics/gui/gui-gtk.rb', line 108

def initialize( values )
	super( values )

	set_border_width( 5 )
	set_resizable( true )
	set_default_size( 400, 280 )

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

	sites_group = Gtk::Frame.new( I18n.get( "gui.pluginsmanager.sites" ) )

	@move_up_button = Gtk::Button.new( I18n.get( "gui.pluginsmanager.sites.moveup" ) )
	@move_down_button = Gtk::Button.new( I18n.get( "gui.pluginsmanager.sites.movedown" ) )

	@used_plugins_store = Gtk::ListStore.new( String )
	@used_plugins_view = Gtk::TreeView.new( @used_plugins_store )
	column = Gtk::TreeViewColumn.new( I18n.get( "gui.pluginsmanager.sites.inuse" ), Gtk::CellRendererText.new(), :text => 0 )
	@used_plugins_view.append_column( column )
	used_plugins_viewport = Gtk::Viewport.new(
		@used_plugins_view.focus_hadjustment(),
		@used_plugins_view.focus_vadjustment()
	)
	used_plugins_viewport.set_shadow_type( Gtk::SHADOW_IN )
	used_plugins_viewport.add( @used_plugins_view )
	used_plugins_scrolledwindow = Gtk::ScrolledWindow.new()
	used_plugins_scrolledwindow.add( used_plugins_viewport )
	@values["used_plugins"].each() do |plugin|
		iter = @used_plugins_store.append()
		@used_plugins_store.set_value( iter, 0, plugin )
	end

	@add_button = Gtk::Button.new( I18n.get( "gui.pluginsmanager.sites.add" ) )
	@remove_button = Gtk::Button.new( I18n.get( "gui.pluginsmanager.sites.remove" ) )

	@unused_plugins_store = Gtk::ListStore.new( String )
	@unused_plugins_view = Gtk::TreeView.new( @unused_plugins_store )
	column = Gtk::TreeViewColumn.new( I18n.get( "gui.pluginsmanager.sites.available" ), Gtk::CellRendererText.new(), :text=>0 )
	@unused_plugins_view.append_column( column )
	unused_plugins_viewport = Gtk::Viewport.new(
		@unused_plugins_view.focus_hadjustment(),
		@unused_plugins_view.focus_vadjustment()
	)
	unused_plugins_viewport.set_shadow_type( Gtk::SHADOW_IN )
	unused_plugins_viewport.add( @unused_plugins_view )
	unused_plugins_scrolledwindow = Gtk::ScrolledWindow.new()
	unused_plugins_scrolledwindow.add( unused_plugins_viewport )
	@values["unused_plugins"].each() do |plugin|
		iter = @unused_plugins_store.append()
		@unused_plugins_store.set_value( iter, 0, plugin )
	end

	misc_group = Gtk::Frame.new( I18n.get( "gui.pluginsmanager.misc" ) )

	@cleanup_lyrics_checkbox = Gtk::CheckButton.new( I18n.get( "gui.pluginsmanager.misc.cleanup" ) )
	@cleanup_lyrics_checkbox.set_active( values["cleanup_lyrics"].to_s() == "true" )

	@single_threaded_checkbox = Gtk::CheckButton.new( I18n.get( "gui.pluginsmanager.misc.singlethreaded" ) )
	@single_threaded_checkbox.set_active( values["single_threaded"].to_s() == "true" )

	@write_log_checkbox = Gtk::CheckButton.new( I18n.get( "gui.pluginsmanager.misc.writelog", "$HOME/.wikilyrics.log" ) )
	@write_log_checkbox.set_active( values["write_log"].to_s() == "true" )

	buttons = create_action_buttons()

	group_grid = Gtk::Table.new( 4, 4, false )
	group_grid.set_row_spacings( 5 )
	group_grid.set_column_spacings( 5 )
	group_grid.attach( @move_up_button, 0, 1, 1, 2, Gtk::FILL, 0 )
	group_grid.attach( @move_down_button, 0, 1, 2, 3, Gtk::FILL, 0 )
	group_grid.attach( used_plugins_scrolledwindow, 1, 2, 0, 4, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND )
	group_grid.attach( @add_button, 2, 3, 1, 2, Gtk::FILL, 0 )
	group_grid.attach( @remove_button, 2, 3, 2, 3, Gtk::FILL, 0 )
	group_grid.attach( unused_plugins_scrolledwindow, 3, 4, 0, 4, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND )
	sites_group.add( group_grid )

	misc_group_vbox = Gtk::VBox.new( false, 0 );
	misc_group_vbox.add( @cleanup_lyrics_checkbox )
	misc_group_vbox.add( @single_threaded_checkbox )
	misc_group_vbox.add( @write_log_checkbox )
	misc_group.add( misc_group_vbox )

	vbox = Gtk::VBox.new( false, 3 );
	vbox.pack_start( sites_group, true )
	vbox.pack_start( misc_group, false )
	vbox.pack_start( buttons, false )

	add( vbox )

	@move_up_button.signal_connect( "clicked" ) { move_up() }
	@move_down_button.signal_connect( "clicked" ) { move_down() }
	@add_button.signal_connect( "clicked" ) { add_plugin() }
	@remove_button.signal_connect( "clicked" ) { remove_plugin() }

	update_accept_button()
end

Instance Method Details

#acceptObject



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/wiki_lyrics/gui/gui-gtk.rb', line 256

def accept()
	@values = {
		"cleanup_lyrics" => @cleanup_lyrics_checkbox.active?(),
		"single_threaded" => @single_threaded_checkbox.active?(),
		"write_log" => @write_log_checkbox.active?(),
		"used_plugins" => [],
		"script_name" => @values["script_name"],
		"unused_plugins" => []
	}
	iter = @used_plugins_store.iter_first()
	while ( iter )
		@values["used_plugins"].insert( -1, iter.get_value( 0 ) )
		break if ! iter.next!()
	end
	iter = @unused_plugins_store.iter_first()
	while ( iter )
		@values["unused_plugins"].insert( -1, iter.get_value( 0 ) )
		break if ! iter.next!()
	end
	super()
end

#add_pluginObject



230
231
232
233
234
235
236
237
238
239
# File 'lib/wiki_lyrics/gui/gui-gtk.rb', line 230

def add_plugin()
	unused_sel_iter = @unused_plugins_view.selection().selected()
	return if unused_sel_iter == nil
	plugin = unused_sel_iter.get_value( 0 )
	@unused_plugins_store.remove( unused_sel_iter )
	iter = @used_plugins_store.append()
	@used_plugins_store.set_value( iter, 0, plugin )
	@used_plugins_view.selection().select_iter( iter )
	update_accept_button()
end

#move_downObject



217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/wiki_lyrics/gui/gui-gtk.rb', line 217

def move_down()
	sel_iter = @used_plugins_view.selection().selected()
	return if sel_iter == nil
	plugin = sel_iter.get_value( 0 )
	sel_path = sel_iter.path()
	return if ! sel_iter.next!()
	next_iter = sel_iter
	iter = @used_plugins_store.insert_after( next_iter )
	@used_plugins_store.set_value( iter, 0, plugin )
	@used_plugins_store.remove( @used_plugins_store.get_iter( sel_path ) )
	@used_plugins_view.selection().select_iter( iter )
end

#move_upObject



204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/wiki_lyrics/gui/gui-gtk.rb', line 204

def move_up()
	sel_iter = @used_plugins_view.selection().selected()
	return if sel_iter == nil || sel_iter == @used_plugins_store.iter_first()
	sel_path = sel_iter.path()
	plugin = sel_iter.get_value( 0 )
	@used_plugins_store.remove( sel_iter )
	sel_path.prev!()
	prev_iter = @used_plugins_store.get_iter( sel_path )
	iter = @used_plugins_store.insert_before( prev_iter )
	@used_plugins_store.set_value( iter, 0, plugin )
	@used_plugins_view.selection().select_iter( iter )
end

#remove_pluginObject



241
242
243
244
245
246
247
248
249
250
# File 'lib/wiki_lyrics/gui/gui-gtk.rb', line 241

def remove_plugin()
	used_sel_iter = @used_plugins_view.selection().selected()
	return if used_sel_iter == nil
	plugin = used_sel_iter.get_value( 0 )
	@used_plugins_store.remove( used_sel_iter )
	iter = @unused_plugins_store.append()
	@unused_plugins_store.set_value( iter, 0, plugin )
	@unused_plugins_view.selection().select_iter( iter )
	update_accept_button()
end

#update_accept_buttonObject



252
253
254
# File 'lib/wiki_lyrics/gui/gui-gtk.rb', line 252

def update_accept_button()
	@accept_button.set_sensitive( @used_plugins_store.iter_first() )
end