Skip to content

Commit

Permalink
add ui shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed May 30, 2013
1 parent 8b8f1e5 commit 7811f57
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 36 deletions.
37 changes: 1 addition & 36 deletions src/ruby/ycp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,40 +38,5 @@
require "ycp/path"
require "ycp/scr"
require "ycp/term"
require "ycp/ui"
require "ycp/wfm"

#--------------------------------------
#
# YCP::Ui
#

module YCP
module Ui

# Define symbols for the UI
ui_terms = [ :BarGraph, :Bottom, :CheckBox, :ColoredLabel, :ComboBox, :Date,
:DownloadProgress, :DumbTab, :DummySpecialWidget, :Empty, :Frame, :HBox, :HBoxvHCenter,
:HMultiProgressMeter, :HSpacing, :HSquash, :HStretch, :HVCenter, :HVSquash,
:HVStretch, :HWeight, :Heading, :IconButton, :Image, :IntField, :Label, :Left, :LogView,
:MarginBox, :MenuButton, :MinHeight, :MinSize, :MinWidth, :MultiLineEdit,
:MultiSelectionBox, :PackageSelector, :PatternSelector, :PartitionSplitter,
:Password, :PkgSpecial, :ProgressBar, :PushButton, :RadioButton,
:RadioButtonGroup, :ReplacePoint, :RichText, :Right, :SelectionBox, :Slider, :Table,
:TextEntry, :Time, :Top, :Tree, :VBox, :VCenter, :VMultiProgressMeter, :VSpacing,
:VSquash, :VStretch, :VWeight, :Wizard,
:id, :opt ]

# for each symbol define a util function that will create a term
ui_terms.each do | term_name |
define_method(term_name) do | *args |
t = YaST::Term.new(term_name.to_s)
args.each do |arg|
t.add(arg)
end
return t
end
alias_method term_name.to_s.downcase, term_name
end

end # end Ui module
end
2 changes: 2 additions & 0 deletions src/ruby/ycp/client_base.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
require "ycp/ycp"
require "ycp/i18n"
require "ycp/exportable"
require "ycp/ui"

module YCP
class ClientBase
include I18n
extend Exportable
include YCP
include UI
end
end
2 changes: 2 additions & 0 deletions src/ruby/ycp/module_base.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
require "ycp/ycp"
require "ycp/i18n"
require "ycp/exportable"
require "ycp/ui"

module YCP
class ModuleBase
include I18n
extend Exportable
include YCP
include UI
end
end
26 changes: 26 additions & 0 deletions src/ruby/ycp/ui.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require "ycp/term"

module YCP
module UI

# Define symbols for the UI
UI_TERMS = [ :BarGraph, :Bottom, :CheckBox, :ColoredLabel, :ComboBox, :Date,
:DownloadProgress, :DumbTab, :DummySpecialWidget, :Empty, :Frame, :HBox, :HBoxvHCenter,
:HMultiProgressMeter, :HSpacing, :HSquash, :HStretch, :HVCenter, :HVSquash,
:HVStretch, :HWeight, :Heading, :IconButton, :Image, :IntField, :Label, :Left, :LogView,
:MarginBox, :MenuButton, :MinHeight, :MinSize, :MinWidth, :MultiLineEdit,
:MultiSelectionBox, :PackageSelector, :PatternSelector, :PartitionSplitter,
:Password, :PkgSpecial, :ProgressBar, :PushButton, :RadioButton,
:RadioButtonGroup, :ReplacePoint, :RichText, :Right, :SelectionBox, :Slider, :Table,
:TextEntry, :Time, :Top, :Tree, :VBox, :VCenter, :VMultiProgressMeter, :VSpacing,
:VSquash, :VStretch, :VWeight, :Wizard,
:id, :opt ]

# for each symbol define a util function that will create a term
UI_TERMS.each do | term_name |
define_method(term_name) do | *args |
YCP::Term.new(term_name, *args)
end
end
end
end
13 changes: 13 additions & 0 deletions tests/ruby/ui_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$LOAD_PATH << File.dirname(__FILE__)
require "test_helper"

require "ycp/ui"

class UITest < YCP::TestCase
include YCP::UI

def test_shortcuts
assert_equal YCP::Term.new(:HBox), HBox()
assert_equal YCP::Term.new(:HBox, "test"), HBox("test")
end
end

0 comments on commit 7811f57

Please sign in to comment.