[macruby-changes] [604] MacRuby/trunk/lib/hotcocoa/mappings
source_changes at macosforge.org
source_changes at macosforge.org
Thu Sep 18 18:17:08 PDT 2008
Revision: 604
http://trac.macosforge.org/projects/ruby/changeset/604
Author: rich at infoether.com
Date: 2008-09-18 18:17:07 -0700 (Thu, 18 Sep 2008)
Log Message:
-----------
use delegate mappings for mapping delegate methods with display= and allowed=
Modified Paths:
--------------
MacRuby/trunk/lib/hotcocoa/mappings/toolbar.rb
MacRuby/trunk/lib/hotcocoa/mappings/toolbar_item.rb
Modified: MacRuby/trunk/lib/hotcocoa/mappings/toolbar.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mappings/toolbar.rb 2008-09-18 00:35:31 UTC (rev 603)
+++ MacRuby/trunk/lib/hotcocoa/mappings/toolbar.rb 2008-09-19 01:17:07 UTC (rev 604)
@@ -1,16 +1,16 @@
HotCocoa::Mappings.map :toolbar => :NSToolbar do
constant :size, {
- :default => NSToolbarSizeModeDefault,
- :regular => NSToolbarSizeModeRegular,
- :small => NSToolbarSizeModeSmall
+ :default => NSToolbarSizeModeDefault,
+ :regular => NSToolbarSizeModeRegular,
+ :small => NSToolbarSizeModeSmall
}
constant :display, {
- :default => NSToolbarDisplayModeDefault,
+ :default => NSToolbarDisplayModeDefault,
:icon_and_label => NSToolbarDisplayModeIconAndLabel,
- :icon => NSToolbarDisplayModeIconOnly,
- :label => NSToolbarDisplayModeLabelOnly
+ :icon => NSToolbarDisplayModeIconOnly,
+ :label => NSToolbarDisplayModeLabelOnly
}
defaults :identifier => 'DefaultToolbarIdentifier',
@@ -21,55 +21,11 @@
:size => :default
def init_with_options(toolbar, options)
- toolbar.initWithIdentifier options.delete(:identifier)
-
- allowed = options.delete(:allowed).dup
- default = options.delete(:default).dup
-
- ary = default.select { |x| x.is_a?(NSToolbarItem) }
- default -= ary
- custom_items = {}
- ary.each { |x| custom_items[x.itemIdentifier] = x }
- allowed.concat(custom_items.keys)
- default.concat(custom_items.keys)
-
- [allowed, default].each do |a|
- a.map! do |i|
- case i
- when :separator
- NSToolbarSeparatorItemIdentifier
- when :space
- NSToolbarSpaceItemIdentifier
- when :flexible_space
- NSToolbarFlexibleSpaceItemIdentifier
- when :show_colors
- NSToolbarShowColorsItemIdentifier
- when :show_fonts
- NSToolbarShowFontsItemIdentifier
- when :customize
- NSToolbarCustomizeToolbarItemIdentifier
- when :print
- NSToolbarPrintItemIdentifier
- else
- i
- end
- end
- end
- o = Object.new
- o.instance_variable_set(:@allowed, allowed)
- o.instance_variable_set(:@default, default)
- o.instance_variable_set(:@custom_items, custom_items)
- def o.toolbarAllowedItemIdentifiers(sender); @allowed; end
- def o.toolbarDefaultItemIdentifiers(sender); @default; end
- def o.toolbar(sender, itemForItemIdentifier:identifier,
- willBeInsertedIntoToolbar:flag)
- @custom_items[identifier]
- end
- toolbar.delegate = o
+ toolbar = toolbar.initWithIdentifier options.delete(:identifier)
toolbar.allowsUserCustomization = options.delete(:allow_customization)
toolbar
end
-
+
custom_methods do
def size=(mode)
@@ -79,7 +35,63 @@
def display=(mode)
setDisplayMode(mode)
end
+
+ def default=(list)
+ @default = list.dup
+ build_custom_items
+ end
+
+ def allowed=(list)
+ @allowed = list.dup
+ build_custom_items
+ end
+
+ private
+
+ def build_custom_items
+ if @allowed && @default
+ ary = @default.select { |x| x.is_a?(NSToolbarItem) }
+ @default -= ary
+ @custom_items = {}
+ ary.each { |x| @custom_items[x.itemIdentifier] = x }
+ @allowed.concat(@custom_items.keys)
+ @default.concat(@custom_items.keys)
+ [@allowed, @default].each do |a|
+ a.map! do |i|
+ case i
+ when :separator
+ NSToolbarSeparatorItemIdentifier
+ when :space
+ NSToolbarSpaceItemIdentifier
+ when :flexible_space
+ NSToolbarFlexibleSpaceItemIdentifier
+ when :show_colors
+ NSToolbarShowColorsItemIdentifier
+ when :show_fonts
+ NSToolbarShowFontsItemIdentifier
+ when :customize
+ NSToolbarCustomizeToolbarItemIdentifier
+ when :print
+ NSToolbarPrintItemIdentifier
+ else
+ i
+ end
+ end
+ end
+ allowed_items { @allowed }
+ default_items { @default }
+ item_for_identifier { |identifier, will_be_inserted| @custom_items[identifier] }
+ end
+ end
+
end
+ delegating "toolbar:itemForItemIdentifier:willBeInsertedIntoToolbar:", :to => :item_for_identifier, :parameters => [:itemForItemIdentifier, :willBeInsertedIntoToolbar], :required => true
+ delegating "toolbarAllowedItemIdentifiers:", :to => :allowed_items, :required => true
+ delegating "toolbarDefaultItemIdentifiers:", :to => :default_items, :required => true
+ delegating "toolbarSelectableItemIdentifiers:", :to => :selectable_items
+ delegating "toolbarDidRemoveItem:", :to => :did_remove_item, :parameters => ["toolbarDidRemoveItem.userInfo['item']"]
+ delegating "toolbarWillAddItem:", :to => :will_add_item, :parameters => ["toolbarWillAddItem.userInfo['item']"]
+
end
Modified: MacRuby/trunk/lib/hotcocoa/mappings/toolbar_item.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mappings/toolbar_item.rb 2008-09-18 00:35:31 UTC (rev 603)
+++ MacRuby/trunk/lib/hotcocoa/mappings/toolbar_item.rb 2008-09-19 01:17:07 UTC (rev 604)
@@ -1,24 +1,36 @@
HotCocoa::Mappings.map :toolbar_item => :NSToolbarItem do
+
+ defaults :priority => :standard
+
+ constant :priority, {
+ :standard => NSToolbarItemVisibilityPriorityStandard,
+ :low => NSToolbarItemVisibilityPriorityLow,
+ :high => NSToolbarItemVisibilityPriorityHigh,
+ :user => NSToolbarItemVisibilityPriorityUser
+ }
def init_with_options(toolbar_item, options)
- identifier = options.delete(:identifier)
- label = options[:label]
- unless identifier
- if label
- identifier = label.tr(' ', '_')
- else
- raise ArgumentError, ":identifier or :label required"
- end
+ if !options.has_key?(:label) && !options.has_key?(:identifier)
+ raise ArgumentError, ":identifier or :label required"
end
- toolbar_item.initWithItemIdentifier identifier
- if label
- toolbar_item.paletteLabel = label
- end
+ label = options.delete(:label)
+ toolbar_item.initWithItemIdentifier(options.delete(:identifier) || label.tr(' ', '_'))
+ toolbar_item.paletteLabel = label if label
toolbar_item
end
custom_methods do
+
include TargetActionConvenience
+
+ def priority=(value)
+ setVisibilityPriority(value)
+ end
+
+ def priority
+ visibilityPriority
+ end
+
end
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080918/e3b27beb/attachment.html
More information about the macruby-changes
mailing list