hotcocoa 0.5.1 → 0.6.0pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. data/.yardopts +14 -0
  2. data/History.txt +21 -0
  3. data/README.markdown +84 -0
  4. data/Rakefile +47 -0
  5. data/bin/hotcocoa +20 -10
  6. data/docs/Contributors.markdown +25 -0
  7. data/docs/Mappings.markdown +352 -0
  8. data/docs/MappingsExplained.markdown +22 -0
  9. data/docs/Overview.markdown +58 -0
  10. data/docs/Resources.markdown +25 -0
  11. data/docs/Tutorial.markdown +3 -0
  12. data/lib/hotcocoa/application/builder.rb +237 -0
  13. data/lib/hotcocoa/application/specification.rb +373 -0
  14. data/lib/hotcocoa/application_builder.rb +338 -242
  15. data/lib/hotcocoa/attributed_string_helpers.rb +128 -0
  16. data/lib/hotcocoa/behaviors.rb +39 -6
  17. data/lib/hotcocoa/core_extensions/kernel.rb +67 -0
  18. data/lib/hotcocoa/core_extensions/nsarray.rb +15 -0
  19. data/lib/hotcocoa/core_extensions/nsmutable_attributed_string.rb +74 -0
  20. data/lib/hotcocoa/core_extensions/nsstring.rb +36 -0
  21. data/lib/hotcocoa/core_extensions/nsurl.rb +6 -0
  22. data/lib/hotcocoa/core_extensions/numeric.rb +9 -0
  23. data/lib/hotcocoa/core_extensions/object.rb +36 -0
  24. data/lib/hotcocoa/core_extensions/range.rb +30 -0
  25. data/lib/hotcocoa/core_extensions.rb +8 -0
  26. data/lib/hotcocoa/data_sources/combo_box_data_source.rb +38 -38
  27. data/lib/hotcocoa/data_sources/outline_view_data_source.rb +33 -0
  28. data/lib/hotcocoa/data_sources/table_data_source.rb +12 -13
  29. data/lib/hotcocoa/data_sources.rb +3 -0
  30. data/lib/hotcocoa/delegate_builder.rb +114 -79
  31. data/lib/hotcocoa/graphics/canvas.rb +211 -214
  32. data/lib/hotcocoa/graphics/color.rb +89 -91
  33. data/lib/hotcocoa/graphics/elements/particle.rb +16 -19
  34. data/lib/hotcocoa/graphics/elements/rope.rb +12 -14
  35. data/lib/hotcocoa/graphics/elements/sandpainter.rb +11 -13
  36. data/lib/hotcocoa/graphics/gradient.rb +13 -14
  37. data/lib/hotcocoa/graphics/image.rb +110 -83
  38. data/lib/hotcocoa/graphics/path.rb +44 -50
  39. data/lib/hotcocoa/graphics/pdf.rb +17 -19
  40. data/lib/hotcocoa/graphics.rb +21 -20
  41. data/lib/hotcocoa/kvo_accessors.rb +10 -11
  42. data/lib/hotcocoa/layout_view.rb +394 -379
  43. data/lib/hotcocoa/mapper.rb +346 -207
  44. data/lib/hotcocoa/mapping_methods.rb +107 -37
  45. data/lib/hotcocoa/mappings/appkit/alert.rb +25 -0
  46. data/lib/hotcocoa/mappings/appkit/application.rb +112 -0
  47. data/lib/hotcocoa/mappings/{array_controller.rb → appkit/array_controller.rb} +33 -35
  48. data/lib/hotcocoa/mappings/appkit/box.rb +37 -0
  49. data/lib/hotcocoa/mappings/appkit/button.rb +88 -0
  50. data/lib/hotcocoa/mappings/appkit/collection_view.rb +42 -0
  51. data/lib/hotcocoa/mappings/appkit/color.rb +40 -0
  52. data/lib/hotcocoa/mappings/appkit/column.rb +19 -0
  53. data/lib/hotcocoa/mappings/appkit/combo_box.rb +22 -0
  54. data/lib/hotcocoa/mappings/appkit/control.rb +31 -0
  55. data/lib/hotcocoa/mappings/appkit/font.rb +58 -0
  56. data/lib/hotcocoa/mappings/appkit/gradient.rb +19 -0
  57. data/lib/hotcocoa/mappings/appkit/image.rb +15 -0
  58. data/lib/hotcocoa/mappings/appkit/image_view.rb +41 -0
  59. data/lib/hotcocoa/mappings/appkit/label.rb +23 -0
  60. data/lib/hotcocoa/mappings/appkit/layout_view.rb +9 -0
  61. data/lib/hotcocoa/mappings/appkit/line.rb +16 -0
  62. data/lib/hotcocoa/mappings/appkit/menu.rb +78 -0
  63. data/lib/hotcocoa/mappings/appkit/menu_item.rb +47 -0
  64. data/lib/hotcocoa/mappings/appkit/outline_view.rb +62 -0
  65. data/lib/hotcocoa/mappings/appkit/popup.rb +106 -0
  66. data/lib/hotcocoa/mappings/appkit/progress_indicator.rb +61 -0
  67. data/lib/hotcocoa/mappings/appkit/scroll_view.rb +28 -0
  68. data/lib/hotcocoa/mappings/appkit/search_field.rb +9 -0
  69. data/lib/hotcocoa/mappings/appkit/secure_text_field.rb +15 -0
  70. data/lib/hotcocoa/mappings/appkit/segmented_control.rb +103 -0
  71. data/lib/hotcocoa/mappings/appkit/slider.rb +23 -0
  72. data/lib/hotcocoa/mappings/appkit/sound.rb +9 -0
  73. data/lib/hotcocoa/mappings/appkit/speech_synthesizer.rb +22 -0
  74. data/lib/hotcocoa/mappings/appkit/split_view.rb +19 -0
  75. data/lib/hotcocoa/mappings/appkit/status_bar.rb +7 -0
  76. data/lib/hotcocoa/mappings/appkit/status_item.rb +9 -0
  77. data/lib/hotcocoa/mappings/appkit/table_view.rb +108 -0
  78. data/lib/hotcocoa/mappings/appkit/text_field.rb +36 -0
  79. data/lib/hotcocoa/mappings/appkit/text_view.rb +13 -0
  80. data/lib/hotcocoa/mappings/appkit/toolbar.rb +99 -0
  81. data/lib/hotcocoa/mappings/appkit/toolbar_item.rb +36 -0
  82. data/lib/hotcocoa/mappings/appkit/tracking_area.rb +24 -0
  83. data/lib/hotcocoa/mappings/appkit/view.rb +65 -0
  84. data/lib/hotcocoa/mappings/appkit/window.rb +124 -0
  85. data/lib/hotcocoa/mappings/foundation/net_service.rb +65 -0
  86. data/lib/hotcocoa/mappings/foundation/net_service_browser.rb +27 -0
  87. data/lib/hotcocoa/mappings/foundation/notification.rb +24 -0
  88. data/lib/hotcocoa/mappings/foundation/sort_descriptor.rb +17 -0
  89. data/lib/hotcocoa/mappings/foundation/timer.rb +38 -0
  90. data/lib/hotcocoa/mappings/foundation/user_defaults.rb +43 -0
  91. data/lib/hotcocoa/mappings/foundation/xml_parser.rb +44 -0
  92. data/lib/hotcocoa/mappings/qtkit/movie.rb +15 -0
  93. data/lib/hotcocoa/mappings/qtkit/movie_view.rb +28 -0
  94. data/lib/hotcocoa/mappings/webkit/web_view.rb +20 -0
  95. data/lib/hotcocoa/mappings.rb +57 -111
  96. data/lib/hotcocoa/mvc.rb +90 -81
  97. data/lib/hotcocoa/notification_listener.rb +135 -58
  98. data/lib/hotcocoa/standard_rake_tasks.rb +17 -9
  99. data/lib/hotcocoa/target_action_convenience.rb +39 -0
  100. data/lib/hotcocoa/template.rb +90 -21
  101. data/lib/hotcocoa/version.rb +3 -0
  102. data/lib/hotcocoa.rb +12 -14
  103. data/template/Rakefile +31 -3
  104. data/template/__APPLICATION_NAME__.appspec +8 -0
  105. data/template/lib/application.rb +14 -17
  106. data/template/lib/menu.rb +11 -11
  107. data/test/application/test_builder.rb +28 -0
  108. data/test/application/test_specification.rb +280 -0
  109. data/test/core_extensions/test_kernel.rb +66 -0
  110. data/test/core_extensions/test_nsarray.rb +9 -0
  111. data/test/core_extensions/test_nsmutable_attributed_string.rb +86 -0
  112. data/test/core_extensions/test_nsstring.rb +20 -0
  113. data/test/core_extensions/test_nsurl.rb +9 -0
  114. data/test/core_extensions/test_numeric.rb +10 -0
  115. data/test/core_extensions/test_object.rb +37 -0
  116. data/test/core_extensions/test_range.rb +28 -0
  117. data/test/helper.rb +30 -0
  118. data/test/mappings/test_bonjour.rb +79 -0
  119. data/test/mappings/test_color.rb +16 -0
  120. data/test/mappings/test_font.rb +21 -0
  121. data/test/mappings/test_tracking_area.rb +18 -0
  122. data/test/test_application_builder.rb +95 -0
  123. data/test/test_attributed_string_helpers.rb +63 -0
  124. data/test/test_behaviours.rb +26 -0
  125. data/test/test_bin.rb +75 -0
  126. data/test/test_mapper.rb +100 -0
  127. data/test/test_mapping_methods.rb +67 -0
  128. data/test/test_mappings.rb +68 -0
  129. data/test/test_notification_listener.rb +19 -0
  130. data/test/test_template.rb +65 -0
  131. metadata +217 -90
  132. data/lib/hotcocoa/attributed_string.rb +0 -143
  133. data/lib/hotcocoa/kernel_ext.rb +0 -14
  134. data/lib/hotcocoa/mappings/alert.rb +0 -25
  135. data/lib/hotcocoa/mappings/application.rb +0 -112
  136. data/lib/hotcocoa/mappings/box.rb +0 -39
  137. data/lib/hotcocoa/mappings/button.rb +0 -92
  138. data/lib/hotcocoa/mappings/collection_view.rb +0 -44
  139. data/lib/hotcocoa/mappings/color.rb +0 -28
  140. data/lib/hotcocoa/mappings/column.rb +0 -21
  141. data/lib/hotcocoa/mappings/combo_box.rb +0 -24
  142. data/lib/hotcocoa/mappings/control.rb +0 -33
  143. data/lib/hotcocoa/mappings/font.rb +0 -44
  144. data/lib/hotcocoa/mappings/gradient.rb +0 -15
  145. data/lib/hotcocoa/mappings/image.rb +0 -15
  146. data/lib/hotcocoa/mappings/image_view.rb +0 -43
  147. data/lib/hotcocoa/mappings/label.rb +0 -25
  148. data/lib/hotcocoa/mappings/layout_view.rb +0 -9
  149. data/lib/hotcocoa/mappings/menu.rb +0 -71
  150. data/lib/hotcocoa/mappings/menu_item.rb +0 -47
  151. data/lib/hotcocoa/mappings/movie.rb +0 -13
  152. data/lib/hotcocoa/mappings/movie_view.rb +0 -27
  153. data/lib/hotcocoa/mappings/notification.rb +0 -17
  154. data/lib/hotcocoa/mappings/popup.rb +0 -110
  155. data/lib/hotcocoa/mappings/progress_indicator.rb +0 -68
  156. data/lib/hotcocoa/mappings/scroll_view.rb +0 -29
  157. data/lib/hotcocoa/mappings/search_field.rb +0 -9
  158. data/lib/hotcocoa/mappings/secure_text_field.rb +0 -17
  159. data/lib/hotcocoa/mappings/segmented_control.rb +0 -97
  160. data/lib/hotcocoa/mappings/slider.rb +0 -25
  161. data/lib/hotcocoa/mappings/sort_descriptor.rb +0 -13
  162. data/lib/hotcocoa/mappings/sound.rb +0 -9
  163. data/lib/hotcocoa/mappings/speech_synthesizer.rb +0 -25
  164. data/lib/hotcocoa/mappings/split_view.rb +0 -21
  165. data/lib/hotcocoa/mappings/status_bar.rb +0 -7
  166. data/lib/hotcocoa/mappings/status_item.rb +0 -9
  167. data/lib/hotcocoa/mappings/table_view.rb +0 -110
  168. data/lib/hotcocoa/mappings/text_field.rb +0 -41
  169. data/lib/hotcocoa/mappings/text_view.rb +0 -13
  170. data/lib/hotcocoa/mappings/timer.rb +0 -25
  171. data/lib/hotcocoa/mappings/toolbar.rb +0 -100
  172. data/lib/hotcocoa/mappings/toolbar_item.rb +0 -36
  173. data/lib/hotcocoa/mappings/view.rb +0 -67
  174. data/lib/hotcocoa/mappings/web_view.rb +0 -22
  175. data/lib/hotcocoa/mappings/window.rb +0 -118
  176. data/lib/hotcocoa/mappings/xml_parser.rb +0 -41
  177. data/lib/hotcocoa/object_ext.rb +0 -22
  178. data/lib/hotcocoa/plist.rb +0 -45
  179. data/template/config/build.yml +0 -8
  180. data/test/test_helper.rb +0 -3
  181. data/test/test_hotcocoa.rb +0 -11
@@ -1,40 +1,110 @@
1
- module HotCocoa
2
-
3
- module MappingMethods
4
-
5
- def defaults(defaults=nil)
6
- if defaults
7
- @defaults = defaults
8
- else
9
- @defaults
10
- end
1
+ # -*- coding: utf-8 -*-
2
+
3
+ ##
4
+ # The set of methods that are available when creating a mapping.
5
+ module HotCocoa::MappingMethods
6
+
7
+ ##
8
+ # You can provide a hash of default options in the definition of
9
+ # your mapping. This is very useful for many Cocoa classes, because
10
+ # there are so many options to set at initialization.
11
+ #
12
+ # Details about how defaults are used can be found in the
13
+ # {file:docs/Mappings.markdown Mappings} tutorial.
14
+ #
15
+ # @overload defaults
16
+ # Get the hash of defaults
17
+ # @return [Hash,nil]
18
+ #
19
+ # @overload defaults key1: value1, key2: value2, ...
20
+ # Set the hash of defaults
21
+ # @param [Hash]
22
+ # @return [Hash]
23
+ def defaults defaults = nil
24
+ if defaults
25
+ @defaults = defaults
26
+ else
27
+ @defaults
11
28
  end
12
-
13
- def constant(name, constants)
14
- constants_map[name] = constants
15
- end
16
-
17
- def constants_map
18
- @constants_map ||= {}
19
- end
20
-
21
- def custom_methods(&block)
22
- if block
23
- @custom_methods = Module.new
24
- @custom_methods.module_eval(&block)
25
- else
26
- @custom_methods
27
- end
28
- end
29
-
30
- def delegating(name, options)
31
- delegate_map[name] = options
32
- end
33
-
34
- def delegate_map
35
- @delegate_map ||= {}
29
+ end
30
+
31
+ ##
32
+ # Create a mapping of a constant type to an enumeration of constants.
33
+ #
34
+ # A constant mapping allows the use of short symbol names to be used
35
+ # in place of long constant names in the scope of the wrapped class.
36
+ #
37
+ # Details about using this method are in the
38
+ # {file:docs/Mappings.markdown} tutorial.
39
+ #
40
+ # @param [Symbol] name
41
+ # @param [Hash{Symbol=>Constant}] constants
42
+ def constant name, constants
43
+ constants_map[name] = constants
44
+ end
45
+
46
+ ##
47
+ # A mapping of constant mappings that were created with calls to
48
+ # {#constant}
49
+ #
50
+ # @return [Hash{Symbol=>Hash{Symbol=>Constant}}]
51
+ attr_reader :constants_map
52
+
53
+ ##
54
+ # Custom methods are modules that are mixed into the class being
55
+ # mapped; they provide idiomatic Ruby methods for the mapped
56
+ # Objective-C class instances.
57
+ #
58
+ # Custom methods are meant to be used in conjunction with constant
59
+ # mappings or when the custom method provides something much better
60
+ # than what is offered by plain Cocoa. Examples are available in the
61
+ # {file:docs/Mappings.markdown} tutorial.
62
+ #
63
+ # @yield A block that will be evaluated in the context of a new module
64
+ #
65
+ # @overload custom_methods do ... end
66
+ # Create and cache a new module to mix into the mapped class
67
+ # @return [Module] return the module that caches the custom methods
68
+ #
69
+ # @overload custom_methods
70
+ # @return [Module,nil] return the Module if it exists, otherwise nil
71
+ def custom_methods &block
72
+ if block
73
+ @custom_methods = Module.new &block
74
+ else
75
+ @custom_methods
36
76
  end
37
-
38
77
  end
39
-
40
- end
78
+
79
+ ##
80
+ # Delegation is a pattern that is used pervasively in Cocoa to
81
+ # facilitate customization of controls; it is a powerful tool, but
82
+ # is a little more complex to setup than custom methods.
83
+ #
84
+ # You should read the {file:docs/Mappings.markdown Mappings} tutorial
85
+ # to get an in depth understanding on how to setup delegates in
86
+ # HotCocoa.
87
+ #
88
+ # @param [String,Symbol] name
89
+ # @param [Hash{:to=>:ruby_name, :parameters=>Array<String>}] options
90
+ # the `:to` key must be included, but `:parameters` is optional
91
+ def delegating name, options
92
+ delegate_map[name] = options
93
+ end
94
+
95
+ ##
96
+ # A mapping of delegate mappings that were created with calls to
97
+ # {#delegating}
98
+ #
99
+ # @return [Hash{Symbol=>Hash{Symbol=>SEL}}]
100
+ attr_reader :delegate_map
101
+
102
+ ##
103
+ # A small hack so that we can have {#delegate_map} and {#constants} as
104
+ # attributes instead of methods that memoize instance variables.
105
+ def self.extended klass
106
+ klass.instance_variable_set :@constants_map, {}
107
+ klass.instance_variable_set :@delegate_map, {}
108
+ end
109
+
110
+ end
@@ -0,0 +1,25 @@
1
+ ##
2
+ # @note Alerts are shown immediately
3
+ HotCocoa::Mappings.map alert: NSAlert do
4
+
5
+ defaults default: 'OK', alternate: nil, other: nil, info: '', show: true
6
+
7
+ def alloc_with_options options
8
+ if options[:message]
9
+ alert = NSAlert.alertWithMessageText options.delete(:message),
10
+ defaultButton: options.delete(:default),
11
+ alternateButton: options.delete(:alternate),
12
+ otherButton: options.delete(:other),
13
+ informativeTextWithFormat: options.delete(:info)
14
+ end
15
+ end
16
+
17
+ custom_methods do
18
+ def show
19
+ runModal
20
+ end
21
+ end
22
+
23
+ delegating 'alertShowHelp:', to: :show_help?
24
+
25
+ end
@@ -0,0 +1,112 @@
1
+ HotCocoa::Mappings.map application: NSApplication do
2
+
3
+ def alloc_with_options opts
4
+ NSApplication.sharedApplication
5
+ end
6
+
7
+ def handle_block app
8
+ app.load_application_menu
9
+ yield app
10
+ app.run
11
+ end
12
+
13
+ custom_methods do
14
+ # @todo Should we really be hardcoded to require lib/menu and should
15
+ # it done here?
16
+ def load_application_menu
17
+ require 'lib/menu' # hmmm...
18
+
19
+ obj = Object.new
20
+ obj.extend HotCocoa
21
+
22
+ setMainMenu obj.application_menu
23
+ rescue LoadError => e
24
+ end
25
+
26
+ attr_accessor :name
27
+
28
+ # @todo What is this about?
29
+ =begin
30
+ def menu(path=nil)
31
+ if path
32
+ find_menu(mainMenu, path)
33
+ else
34
+ mainMenu
35
+ end
36
+ end
37
+ =end
38
+
39
+ def menu
40
+ mainMenu
41
+ end
42
+
43
+ def menu= menu
44
+ setMainMenu menu
45
+ end
46
+
47
+ def on_hide menu
48
+ hide menu
49
+ end
50
+
51
+ def on_about menu
52
+ orderFrontStandardAboutPanel menu
53
+ end
54
+
55
+ def on_hide_others menu
56
+ hideOtherApplications menu
57
+ end
58
+
59
+ def on_show_all menu
60
+ unhideAllApplications menu
61
+ end
62
+
63
+ def on_quit menu
64
+ terminate menu
65
+ end
66
+
67
+
68
+ private
69
+
70
+ def find_menu menu, path
71
+ key = path.keys.first
72
+ value = path.values.first
73
+ menu = menu[key]
74
+
75
+ if value.kind_of? Array
76
+ find_menu menu, value.first
77
+ else
78
+ menu[value]
79
+ end
80
+ end
81
+ end
82
+
83
+ delegating 'application:delegateHandlesKey:', to: :delegate_handles_key?, parameters: [:delegateHandlesKey]
84
+ delegating 'application:openFile:', to: :open_file, parameters: [:openFile]
85
+ delegating 'application:openFiles:', to: :open_files, parameters: [:openFiles]
86
+ delegating 'application:openFileWithoutUI:', to: :open_file_without_ui, parameters: [:openFileWithoutUI]
87
+ delegating 'application:openTempFile:', to: :open_temp_file, parameters: [:openTempFile]
88
+ delegating 'application:printFile:', to: :print_file
89
+ delegating 'application:printFiles:withSettings:showPrintPanels:', to: :print_files
90
+ delegating 'application:willPresentError:', to: :will_present_error
91
+ delegating 'applicationDidBecomeActive:', to: :did_become_active
92
+ delegating 'applicationDidChangeScreenParameters:', to: :did_change_screen_parameters
93
+ delegating 'applicationDidFinishLaunching:', to: :did_finish_launching
94
+ delegating 'applicationDidHide:', to: :did_hide
95
+ delegating 'applicationDidResignActive:', to: :resign_active
96
+ delegating 'applicationDidUnhide:', to: :did_unhide
97
+ delegating 'applicationDidUpdate:', to: :did_update
98
+ delegating 'applicationDockMenu:', to: :dock_menu
99
+ delegating 'applicationOpenUntitledFile:', to: :open_untitled_file
100
+ delegating 'applicationShouldHandleReopen:hasVisibleWindows:', to: :should_handle_reopen?, parameters: [:hasVisibleWindows]
101
+ delegating 'applicationShouldOpenUntitledFile:', to: :should_open_untitled_file?
102
+ delegating 'applicationShouldTerminate:', to: :should_terminate?
103
+ delegating 'applicationShouldTerminateAfterLastWindowClosed:', to: :should_terminate_after_last_window_closed?
104
+ delegating 'applicationWillBecomeActive:', to: :will_become_active
105
+ delegating 'applicationWillFinishLaunching:', to: :will_finish_launching
106
+ delegating 'applicationWillHide:', to: :will_hide
107
+ delegating 'applicationWillResignActive:', to: :will_resign_active
108
+ delegating 'applicationWillTerminate:', to: :will_terminate
109
+ delegating 'applicationWillUnhide:', to: :will_unhide
110
+ delegating 'applicationWillUpdate:', to: :will_update
111
+
112
+ end
@@ -1,77 +1,75 @@
1
- HotCocoa::Mappings.map :array_controller => :NSArrayController do
1
+ HotCocoa::Mappings.map array_controller: NSArrayController do
2
2
 
3
- def init_with_options(array_controller, options)
3
+ def init_with_options array_controller, options
4
4
  result = array_controller.init
5
- if options.has_key?(:for)
6
- result.addObjects(options.delete(:for))
5
+ if options.has_key? :for
6
+ result.addObjects(options.delete :for)
7
7
  end
8
8
  result
9
9
  end
10
10
 
11
11
  custom_methods do
12
-
13
12
  def avoids_empty_selection?
14
13
  avoidsEmptySelection
15
14
  end
16
-
15
+
17
16
  def preserves_selection?
18
17
  preservesSelection
19
18
  end
20
-
21
- def rearrange_automatically=(value)
22
- setAutomaticallyRearrangesObjects(value)
19
+
20
+ def rearrange_automatically= value
21
+ setAutomaticallyRearrangesObjects value
23
22
  end
24
-
23
+
25
24
  def rearrange_automatically?
26
25
  automaticallyRearrangesObjects
27
26
  end
28
-
29
- def selects_inserted=(value)
30
- setSelectsInsertedObjects(value)
27
+
28
+ def selects_inserted= value
29
+ setSelectsInsertedObjects value
31
30
  end
32
-
31
+
33
32
  def selects_inserted?
34
33
  selectsInsertedObjects
35
34
  end
36
-
37
- def <<(object)
38
- addObject(object)
35
+
36
+ def << object
37
+ addObject object
39
38
  end
40
-
41
- def [](index)
39
+
40
+ def [] index
42
41
  arrangedObjects[index]
43
42
  end
44
-
45
- def each(&block)
46
- arrangedObjects.each(&block)
43
+
44
+ def each &block
45
+ arrangedObjects.each &block
47
46
  end
48
-
47
+
49
48
  def selected
50
49
  selectedObjects.first
51
50
  end
52
-
53
- def sort_by=(sort_descriptors)
54
- sort_descriptors = [sort_descriptors] if sort_descriptors.kind_of?(Hash)
51
+
52
+ def sort_by= sort_descriptors
53
+ sort_descriptors = [sort_descriptors] if sort_descriptors.kind_of? Hash
55
54
  descriptors = sort_descriptors.collect do |descriptor|
56
- selector = descriptor.delete(:selector)
55
+ selector = descriptor.delete :selector
57
56
  ascending = (descriptor.values.first == :ascending)
58
57
  if selector
59
- NSSortDescriptor.alloc.initWithKey(descriptor.keys.first.to_s, ascending: ascending, selector: selector)
58
+ NSSortDescriptor.alloc.initWithKey(descriptor.keys.first.to_s, ascending:ascending, selector:selector)
60
59
  else
61
- NSSortDescriptor.alloc.initWithKey(descriptor.keys.first.to_s, ascending: ascending)
60
+ NSSortDescriptor.alloc.initWithKey(descriptor.keys.first.to_s, ascending:ascending)
62
61
  end
63
62
  end
64
- setSortDescriptors(descriptors)
63
+ setSortDescriptors descriptors
65
64
  end
66
-
67
65
  end
68
66
 
69
67
  end
70
68
 
71
69
  =begin
72
- array :avoids_empty_selection => true,
73
- :preserves_selection => false,
74
- :selects_inserted => false,
70
+ array :avoids_empty_selection => true,
71
+ :preserves_selection => false,
72
+ :selects_inserted => false,
75
73
  :rearrange_automatically => true,
76
74
  :sort_by => {:name => :ascending}
77
75
 
@@ -84,4 +82,4 @@ array_controller.setAutomaticallyRearrangesObjects(true)
84
82
 
85
83
  array_controller.setSortDescriptors(NSArray.arrayWithObject(NSSortDescriptor.alloc.initWithKey("name", ascending: false)))
86
84
  array_controller.addObject Icon.new("Rich", image(:file => "rich.jpg"))
87
- =end
85
+ =end
@@ -0,0 +1,37 @@
1
+ HotCocoa::Mappings.map box: NSBox do
2
+
3
+ defaults frame: CGRectZero, layout: {}
4
+
5
+ constant :title_position, {
6
+ none: NSNoTitle,
7
+ above_top: NSAboveTop,
8
+ top: NSAtTop,
9
+ below_top: NSBelowTop,
10
+ above_bottom: NSAboveBottom,
11
+ bottom: NSAtBottom,
12
+ below_bottom: NSBelowBottom
13
+ }
14
+
15
+ constant :type, {
16
+ primary: NSBoxPrimary,
17
+ secondary: NSBoxSecondary,
18
+ separator: NSBoxSeparator,
19
+ old: NSBoxOldStyle,
20
+ custom: NSBoxCustom
21
+ }
22
+
23
+ def init_with_options box, options
24
+ box.initWithFrame options.delete :frame
25
+ end
26
+
27
+ custom_methods do
28
+ def type= value
29
+ setBoxType value
30
+ end
31
+
32
+ def border= value
33
+ setBorderType value
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,88 @@
1
+ HotCocoa::Mappings.map button: NSButton do
2
+
3
+ defaults bezel: :rounded,
4
+ frame: CGRectZero,
5
+ layout: {}
6
+
7
+ constant :bezel, {
8
+ rounded: NSRoundedBezelStyle,
9
+ regular_square: NSRegularSquareBezelStyle,
10
+ thick_square: NSThickSquareBezelStyle,
11
+ thicker_square: NSThickerSquareBezelStyle,
12
+ disclosure: NSDisclosureBezelStyle,
13
+ shadowless_square: NSShadowlessSquareBezelStyle,
14
+ circular: NSCircularBezelStyle,
15
+ textured_square: NSTexturedSquareBezelStyle,
16
+ help_button: NSHelpButtonBezelStyle,
17
+ small_square: NSSmallSquareBezelStyle,
18
+ textured_rounded: NSTexturedRoundedBezelStyle,
19
+ round_rect: NSRoundRectBezelStyle,
20
+ recessed: NSRecessedBezelStyle,
21
+ rounded_disclosure: NSRoundedDisclosureBezelStyle
22
+ }
23
+
24
+ constant :type, {
25
+ momentary_light: NSMomentaryLightButton,
26
+ push_on_push_off: NSPushOnPushOffButton,
27
+ toggle: NSToggleButton,
28
+ switch: NSSwitchButton,
29
+ radio: NSRadioButton,
30
+ momentary_change: NSMomentaryChangeButton,
31
+ on_off: NSOnOffButton,
32
+ momentary_push_in: NSMomentaryPushInButton,
33
+ momentary_push: NSMomentaryPushButton
34
+ }
35
+
36
+ constant :state, {
37
+ on: NSOnState,
38
+ off: NSOffState,
39
+ mixed: NSMixedState
40
+ }
41
+
42
+ constant :image_position, {
43
+ text_only: NSNoImage,
44
+ image_only: NSImageOnly,
45
+ overlaps: NSImageOverlaps,
46
+ left: NSImageLeft,
47
+ right: NSImageRight,
48
+ below: NSImageBelow,
49
+ above: NSImageAbove
50
+ }
51
+
52
+ def init_with_options button, options
53
+ button.initWithFrame options.delete :frame
54
+ end
55
+
56
+ custom_methods do
57
+ def bezel= value
58
+ setBezelStyle value
59
+ end
60
+
61
+ def type= value
62
+ setButtonType value
63
+ end
64
+
65
+ def state= value
66
+ value = case value
67
+ when :on then NSOnState
68
+ when :off then NSOffState
69
+ when :mixed then NSMixedState
70
+ else value
71
+ end
72
+ setState value
73
+ end
74
+
75
+ def on?
76
+ state == NSOnState
77
+ end
78
+
79
+ def off?
80
+ state == NSOffState
81
+ end
82
+
83
+ def mixed?
84
+ state == NSMixedState
85
+ end
86
+ end
87
+
88
+ end
@@ -0,0 +1,42 @@
1
+ HotCocoa::Mappings.map collection_view: NSCollectionView do
2
+
3
+ defaults layout: {}, frame: [0,0,100,100]
4
+
5
+ def init_with_options collection_view, options
6
+ collection_view.initWithFrame options.delete :frame
7
+ end
8
+
9
+ custom_methods do
10
+ def item_prototype
11
+ itemPrototype
12
+ end
13
+
14
+ def item_view
15
+ item_prototype if item_prototype.view
16
+ end
17
+
18
+ def item_view= view
19
+ item = NSCollectionViewItem.alloc.init
20
+ item.setView view
21
+ view.collection_item = item if view.respond_to? :collection_item=
22
+ setItemPrototype item
23
+ end
24
+
25
+ def rows= value
26
+ setMaxNumberOfRows value
27
+ end
28
+
29
+ def rows
30
+ maxNumberOfRows
31
+ end
32
+
33
+ def columns= value
34
+ setMaxNumberOfColumns value
35
+ end
36
+
37
+ def columns
38
+ maxNumberOfColumns
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,40 @@
1
+ ##
2
+ # @todo Allow aliasing of mappings (so we can have :coloUr as well)
3
+ #
4
+ # @cocoa NSColor
5
+ #
6
+ HotCocoa::Mappings.map color: NSColor do
7
+
8
+ def alloc_with_options options
9
+ if options.has_key? :name
10
+ color = NSColor.send "#{options.delete :name}Color"
11
+ color = color.colorWithAlphaComponent(options.delete :alpha) if options.has_key? :alpha
12
+ return color
13
+
14
+ elsif options.has_key? :rgb
15
+ calibrated = !options.delete(:device)
16
+
17
+ rgb = options.delete :rgb
18
+ red = ((rgb >> 16) & 0xff) / 255.0
19
+ green = ((rgb >> 8) & 0xff) / 255.0
20
+ blue = (rgb & 0xff) / 255.0
21
+ alpha = options.delete(:alpha) || 1.0
22
+
23
+ if calibrated
24
+ return NSColor.colorWithCalibratedRed red, green: green, blue: blue, alpha: alpha
25
+ else
26
+ return NSColor.colorWithDeviceRed red, green: green, blue: blue, alpha: alpha
27
+ end
28
+
29
+ elsif (options.keys & [:red, :green, :blue]).size == 3
30
+ alpha = (options.delete(:alpha) or 1.0)
31
+ return NSColor.colorWithCalibratedRed options.delete(:red),
32
+ green: options.delete(:green),
33
+ blue: options.delete(:blue),
34
+ alpha: alpha
35
+ else
36
+ raise 'Cannot create color with the provided options'
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,19 @@
1
+ HotCocoa::Mappings.map column: NSTableColumn do
2
+
3
+ defaults title: 'Column'
4
+
5
+ def init_with_options column, options
6
+ column.initWithIdentifier options.delete :id
7
+ end
8
+
9
+ custom_methods do
10
+ def title
11
+ headerCell.stringValue
12
+ end
13
+
14
+ def title= newTitle
15
+ headerCell.stringValue = newTitle
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,22 @@
1
+ HotCocoa::Mappings.map combo_box: NSComboBox do
2
+
3
+ defaults selectable: true, editable: true, completes: true, layout: {}
4
+
5
+ def init_with_options combo_box, options
6
+ combo_box.initWithFrame options.delete :frame
7
+ end
8
+
9
+ custom_methods do
10
+ def data= data_source
11
+ setUsesDataSource true
12
+ data_source = HotCocoa::ComboBoxDataSource.new data_source if data_source.kind_of? Array
13
+ setDataSource data_source
14
+ end
15
+ end
16
+
17
+ delegating 'comboBoxSelectionDidChange:', to: :selection_did_change
18
+ delegating 'comboBoxSelectionIsChanging:', to: :selection_is_changing
19
+ delegating 'comboBoxWillDismiss:', to: :will_dismiss
20
+ delegating 'comboBoxWillPopUp:', to: :will_pop_up
21
+
22
+ end
@@ -0,0 +1,31 @@
1
+ HotCocoa::Mappings.map control: NSControl do
2
+
3
+ constant :alignment, {
4
+ left: NSLeftTextAlignment,
5
+ right: NSRightTextAlignment,
6
+ center: NSCenterTextAlignment,
7
+ justified: NSJustifiedTextAlignment,
8
+ natural: NSNaturalTextAlignment
9
+ }
10
+
11
+ custom_methods do
12
+ include HotCocoa::Mappings::TargetActionConvenience
13
+
14
+ def text= text
15
+ setStringValue text
16
+ end
17
+
18
+ def to_i
19
+ intValue
20
+ end
21
+
22
+ def to_f
23
+ doubleValue
24
+ end
25
+
26
+ def to_s
27
+ stringValue
28
+ end
29
+ end
30
+
31
+ end