public
Description: Watches the ether for the handy *jour scripts.
Homepage:
Clone URL: git://github.com/lachie/starjour.git
Click here to lend your support to: starjour and make a donation at www.pledgie.com !
starjour / Jour.rb
100644 89 lines (70 sloc) 1.732 kb
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#
# Jour.rb
# starjour
#
# Created by Lachie Cox on 21/06/08.
# Copyright (c) 2008 __MyCompanyName__. All rights reserved.
#
 
require 'osx/cocoa'
 
module Jour
  
  def self.included(base)
    base.extend ClassMethods
    base.class_eval do
      kvc_accessor :text
    end
  end
  
  def initWithService(service)
    if init
      puts "starting #{self.class} with #{service.oc_type}"
      @service = service
      setup if respond_to?(:setup)
    end
    self
  end
  
  module ClassMethods
    def service_name(name=nil)
      @service_name = name if name
      @service_name
    end
    
    def nib_name(nib_name=nil)
      self.nib_path OSX::NSBundle.mainBundle.pathForResource_ofType(nib_name,'nib')
    end
    
    def nib_path(nib_path=nil)
      if nib_path
        @nib_path = nib_path
      else
        @nib_path
      end
    end
    
  end
  
  def view?
    begin
      view
      true
    rescue
      false
    end
  end
  
  def view
    unless @view
      raise "no nib path set... set the class nib path first" unless self.class.nib_path
      
      @vc = OSX::NSViewController.alloc.initWithNibName_bundle(nil,nil)
      nib = OSX::NSNib.alloc.initWithContentsOfURL(OSX::NSURL.fileURLWithPath(self.class.nib_path))
      
      nib.instantiateNibWithOwner_topLevelObjects(@vc, nil)
      
      puts "nib... #{@vc}"
      
      @vc.representedObject = self
      @view = @vc.view
    end
    
    @view
  end
  
  def children; [] end
  def leaf; true end
  
  # service resolution
def netServiceDidResolveAddress(service)
resolved! if respond_to?(:resolved!)
  end
  
  def netService_didNotResolve(service,reason)
    puts "netService_didNotResolve #{service_key(service)}"
    p reason
  end
end