Permalink
Browse files

use Cocoa Binding

  • Loading branch information...
1 parent ff52ad7 commit 8e7c6533e76d7b10a8e6e40e6c1b187557d0d4d7 @Watson1978 committed Nov 20, 2011
Showing with 142 additions and 193 deletions.
  1. +7 −23 PodCreator/AppDelegate.rb
  2. +10 −25 PodCreator/PodList.rb
  3. +48 −110 PodCreator/en.lproj/MainMenu.xib
  4. +77 −35 PodCreator/en.lproj/PodList.xib
View
@@ -8,11 +8,11 @@ class AppDelegate
attr_accessor :platformButton
attr_accessor :addButton, :removeButton, :createButton
attr_accessor :tableView
+ attr_accessor :arrayController
PLATFORM = {'iOS' => ":ios", 'Mac' => ":osx" }
def applicationDidFinishLaunching(a_notification)
- @depend = []
@podList = PodList.alloc.init
@podList.delegate = self
end
@@ -21,18 +21,6 @@ def windowWillClose(a_notification)
NSApp.terminate(self)
end
- #----------------------------------------
- def numberOfRowsInTableView(aTableView)
- return 0 if @depend.nil?
- return @depend.size
- end
-
- def tableView(aTableView,
- objectValueForTableColumn:aTableColumn,
- row:rowIndex)
- return @depend[rowIndex]
- end
-
#----------------------------------------
def showList(sender)
NSApp.beginSheet(@podList.window,
@@ -45,12 +33,8 @@ def showList(sender)
end
def remove(sender)
- index = tableView.selectedRow
-
- if index >= 0
- @depend.delete_at(index)
- tableView.reloadData
- end
+ index = arrayController.selectionIndexes
+ arrayController.removeObjectsAtArrangedObjectIndexes(index)
end
def create(sender)
@@ -64,8 +48,9 @@ def create(sender)
File.open(path, "w") {|f|
f.puts "platform #{PLATFORM[plat]}"
- @depend.each do |item|
- f.puts "dependency '#{item}'"
+ ary = arrayController.arrangedObjects
+ ary.each do |item|
+ f.puts "dependency '#{item['name']}'"
end
}
system "open -a TextEdit '#{path}'"
@@ -74,8 +59,7 @@ def create(sender)
#----------------------------------------
def addPod(pod)
- @depend << pod.name.dup
- tableView.reloadData
+ arrayController.addObject(pod.dup)
end
end
View
@@ -6,9 +6,10 @@
class PodList < NSWindowController
attr_accessor :delegate
attr_accessor :tableView
+ attr_accessor :arrayController
def init
- @pods ||= Pod::Source::search_by_name("", true)
+ @pods = Pod::Source::search_by_name("", true)
super
self.initWithWindowNibName("PodList")
@@ -17,35 +18,19 @@ def init
def awakeFromNib
tableView.setTarget(self)
tableView.setDoubleAction("selectPods:")
- end
-
- #----------------------------------------
- def numberOfRowsInTableView(aTableView)
- return 0 if @pods.nil?
- return @pods.size
- end
-
- def tableView(aTableView,
- objectValueForTableColumn:aTableColumn,
- row:rowIndex)
- case aTableColumn.identifier
- when 'name'
- @pods[rowIndex].name
- when 'version'
- @pods[rowIndex].versions.reverse.join(", ")
- when 'description'
- @pods[rowIndex].specification.summary
+ @pods.each do |pod|
+ arrayController.addObject({'name' => pod.name,
+ 'version' => pod.versions.join(", "),
+ 'description' => pod.specification.summary
+ })
end
end
#----------------------------------------
def selectPods(sender)
- index = tableView.selectedRow
-
- if index >= 0
- delegate.addPod(@pods[index])
- self.window.orderOut(self)
- end
+ obj = arrayController.selectedObjects.first
+ delegate.addPod(obj)
+ self.window.orderOut(self)
end
end
Oops, something went wrong.

0 comments on commit 8e7c653

Please sign in to comment.