[MacRuby-devel] windowControllerDidLoadNib strangeness
Tom Jordan
viresh53 at gmail.com
Thu Nov 25 22:12:24 PST 2010
trying to get the code to format right, here it is again (hopefully
better!):
class MyDocument < NSDocument
attr_accessor :loadedmodel, :root #outlet to model field of controller
# Name of nib containing document window
def windowNibName
'MyDocument'
end
# Document data representation for saving (return NSData)
def dataOfType(type, error:outError)
outError.assign(NSError.errorWithDomain(NSOSStatusErrorDomain, code:-4,
userInfo:nil))
NSKeyedArchiver.archivedDataWithRootObject(@root.model)
end
# Read document from data (return non-nil on success)
def readFromData(data, ofType:type, error:outError)
outError.assign(NSError.errorWithDomain(NSOSStatusErrorDomain, code:-4,
userInfo:nil))
@loadedmodel = NSKeyedUnarchiver.unarchiveObjectWithData(data)
end
# Return lowercase 'untitled', to comply with HIG
def displayName
fileURL ? super : super.sub(/^[[:upper:]]/) {|s| s.downcase}
end
def windowControllerDidLoadNib(aController)
super(aController)
@root.model = @loadedmodel
NSLog("model loaded")
end
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20101126/b5d341f9/attachment.html>
More information about the MacRuby-devel
mailing list