Report abuse
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
require 'osx/cocoa'
include OSX
class Connection
def self.id_label_map
@id_label_map ||= {}
end
def initialize(source_id)
@source_id = source_id
@connections = Hash.new { |k, v| k[v] = [] }
end
def add_connection(destination_id, label)
@connections[destination_id] << label
end
def inspect
if @connections.keys.empty?
connected = "\t No Connections"
else
connected = @connections.map do |id, label|
"\t#{self.class.id_label_map[id]}: #{label}"
end
end
"\n#{self.class.id_label_map[@source_id]}:\n" << connected.join("\n")
end
end
plist = `ibtool --connections misc/English.lproj/MainMenu.nib`
plist_data = NSData.alloc.initWithBytes_length(plist, plist.size)
connections, format, error = NSPropertyListSerialization.propertyListFromData_mutabilityOption_format_errorDescription(plist_data, NSPropertyListMutableContainersAndLeaves)
id_label_map = {}
connection_map = {}
connections['com.apple.ibtool.document.connections'].each do |key, value|
source_id = value['source-id'].to_i
source_label = value['source-label'].to_s
destination_id = value['destination-id'].to_i
destination_label = value['destination-label'].to_s
Connection.id_label_map[source_id] ||= source_label
Connection.id_label_map[destination_id] ||= destination_label
(connection_map[source_id] ||= Connection.new(source_id)).add_connection(destination_id, value['label'].to_s)
end
connection_map.each { |source_id, connections| puts connections.inspect }
|