[macruby-changes] [554] MacRuby/trunk/sample-macruby

source_changes at macosforge.org source_changes at macosforge.org
Thu Sep 4 18:22:45 PDT 2008


Revision: 554
          http://trac.macosforge.org/projects/ruby/changeset/554
Author:   lsansonetti at apple.com
Date:     2008-09-04 18:22:45 -0700 (Thu, 04 Sep 2008)
Log Message:
-----------
s/PhotocastViewer/FlickrDemo/g

Added Paths:
-----------
    MacRuby/trunk/sample-macruby/FlickrDemo/
    MacRuby/trunk/sample-macruby/FlickrDemo/English.lproj/
    MacRuby/trunk/sample-macruby/FlickrDemo/FlickrDemo.xcodeproj/
    MacRuby/trunk/sample-macruby/FlickrDemo/FlickrDemoController.rb
    MacRuby/trunk/sample-macruby/FlickrDemo/Info.plist
    MacRuby/trunk/sample-macruby/FlickrDemo/main.m
    MacRuby/trunk/sample-macruby/FlickrDemo/rb_main.rb

Removed Paths:
-------------
    MacRuby/trunk/sample-macruby/FlickrDemo/English.lproj/
    MacRuby/trunk/sample-macruby/FlickrDemo/Info.plist
    MacRuby/trunk/sample-macruby/FlickrDemo/PhotocastViewer.xcodeproj/
    MacRuby/trunk/sample-macruby/FlickrDemo/PhotocastViewerController.rb
    MacRuby/trunk/sample-macruby/FlickrDemo/main.m
    MacRuby/trunk/sample-macruby/FlickrDemo/rb_main.rb
    MacRuby/trunk/sample-macruby/PhotocastViewer/

Copied: MacRuby/trunk/sample-macruby/FlickrDemo/FlickrDemoController.rb (from rev 553, MacRuby/trunk/sample-macruby/PhotocastViewer/FlickrDemoController.rb)
===================================================================
--- MacRuby/trunk/sample-macruby/FlickrDemo/FlickrDemoController.rb	                        (rev 0)
+++ MacRuby/trunk/sample-macruby/FlickrDemo/FlickrDemoController.rb	2008-09-05 01:22:45 UTC (rev 554)
@@ -0,0 +1,139 @@
+class FlickrDemoController < NSWindowController
+  
+  attr_accessor :sourcesTableView, :imageBrowserView
+  
+  def awakeFromNib
+    @cache = []
+    @imageBrowserView.animates = true
+    @imageBrowserView.dataSource = self
+    @imageBrowserView.delegate = self
+    
+    @sources = []
+    @sources << Source.new('cat')
+    @sourcesTableView.reloadData
+    @sourcesTableView.selectRowIndexes(NSIndexSet.indexSetWithIndex(0), byExtendingSelection:false)
+    
+    NSNotificationCenter.defaultCenter.addObserver self,
+      selector:'feedRefreshed:',
+      name:PSFeedRefreshingNotification,
+      object:nil
+  end
+  
+  # Actions
+  
+  def addSource(sender)
+    row = @sources.size
+    @sources << Source.new('dog')
+    @sourcesTableView.reloadData
+    @sourcesTableView.selectRowIndexes(NSIndexSet.indexSetWithIndex(row), byExtendingSelection:false)
+    @sourcesTableView.editColumn(0, row:row, withEvent:nil, select:true)
+  end
+  
+  def removeSource(sender)
+    @sources.delete_at @sourcesTableView.selectedRow
+    @sourcesTableView.reloadData
+    tableViewSelectionDidChange(nil)
+  end
+  
+  def zoomChanged(sender)
+    @imageBrowserView.zoomValue = sender.floatValue
+  end
+  
+  def feedRefreshed(notification)
+    feed = notification.object
+    @results = feed.entryEnumeratorSortedBy(nil).allObjects
+    @cache.clear
+    @imageBrowserView.reloadData
+  end
+  
+  # table view datasource/delegate
+  
+  def numberOfRowsInTableView(table)
+    @sources ? @sources.size : 0
+  end
+  
+  def tableView(table, objectValueForTableColumn:column, row:row)
+    @sources[row].tag
+  end
+
+  def tableView(table, setObjectValue:object, forTableColumn:column, row:row)
+    source = @sources[row]
+    source.tag = object
+    refreshImageView(source)
+  end
+
+  def tableViewSelectionDidChange(notification)
+    refreshImageView @sources[@sourcesTableView.selectedRow]
+  end
+  
+  # Image browser datasource/delegate
+
+  def numberOfItemsInImageBrowser(browser)
+    @results ? @results.size : 0
+  end
+  
+  def imageBrowser(browser, itemAtIndex:index)
+    photo = @cache[index]
+    if photo.nil? 
+      entry = @results[index]
+      url = entry.content.HTMLString.scan(/<img\s+src="([^"]+)"/)[0][0] # " stupid Xcode
+      photo = Photo.new(url)
+      @cache[index] = photo
+    end
+    return photo
+  end
+
+  def imageBrowser(browser, cellWasDoubleClickedAtIndex:index)
+    NSWorkspace.sharedWorkspace.openURL @cache[index].url
+  end
+  
+  private
+  
+  def refreshImageView(source)
+    if source
+      url = NSURL.URLWithString(source.url)
+      feed = PSFeed.alloc.initWithURL(url)
+      feed.refresh(nil)
+    else
+      @cache.clear
+      @results.clear
+      @imageBrowserView.reloadData
+    end
+  end
+end
+
+class Photo
+  attr_reader :url
+  
+  def initialize(url)
+    @urlString = url
+    @url = NSURL.alloc.initWithString url
+  end
+  
+  # IKImageBrowserItem protocol conformance
+  
+  def imageUID
+    @urlString
+  end
+    
+  def imageRepresentationType
+    :IKImageBrowserNSImageRepresentationType
+  end
+  
+  def imageRepresentation    
+    @image ||= NSImage.alloc.initByReferencingURL @url
+  end
+end
+
+class Source
+  attr_reader :tag, :url
+  
+  def initialize(tag)
+    self.tag = tag
+  end
+  
+  def tag=(tag)
+    @tag = tag
+    @url = "http://api.flickr.com/services/feeds/photos_public.gne?tags=#{tag}&lang=en-us&format=rss_200"
+  end
+end
\ No newline at end of file

Deleted: MacRuby/trunk/sample-macruby/FlickrDemo/Info.plist
===================================================================
--- MacRuby/trunk/sample-macruby/PhotocastViewer/Info.plist	2008-09-03 23:51:00 UTC (rev 550)
+++ MacRuby/trunk/sample-macruby/FlickrDemo/Info.plist	2008-09-05 01:22:45 UTC (rev 554)
@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
-	<key>CFBundleDevelopmentRegion</key>
-	<string>English</string>
-	<key>CFBundleExecutable</key>
-	<string>${EXECUTABLE_NAME}</string>
-	<key>CFBundleIconFile</key>
-	<string></string>
-	<key>CFBundleIdentifier</key>
-	<string>com.yourcompany.PhotocastViewer</string>
-	<key>CFBundleInfoDictionaryVersion</key>
-	<string>6.0</string>
-	<key>CFBundleName</key>
-	<string>${PRODUCT_NAME}</string>
-	<key>CFBundlePackageType</key>
-	<string>APPL</string>
-	<key>CFBundleSignature</key>
-	<string>????</string>
-	<key>CFBundleVersion</key>
-	<string>1.0</string>
-	<key>NSMainNibFile</key>
-	<string>MainMenu</string>
-	<key>NSPrincipalClass</key>
-	<string>NSApplication</string>
-</dict>
-</plist>

Copied: MacRuby/trunk/sample-macruby/FlickrDemo/Info.plist (from rev 553, MacRuby/trunk/sample-macruby/PhotocastViewer/Info.plist)
===================================================================
--- MacRuby/trunk/sample-macruby/FlickrDemo/Info.plist	                        (rev 0)
+++ MacRuby/trunk/sample-macruby/FlickrDemo/Info.plist	2008-09-05 01:22:45 UTC (rev 554)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>CFBundleDevelopmentRegion</key>
+	<string>English</string>
+	<key>CFBundleExecutable</key>
+	<string>${EXECUTABLE_NAME}</string>
+	<key>CFBundleIconFile</key>
+	<string></string>
+	<key>CFBundleIdentifier</key>
+	<string>com.yourcompany.PhotocastViewer</string>
+	<key>CFBundleInfoDictionaryVersion</key>
+	<string>6.0</string>
+	<key>CFBundleName</key>
+	<string>${PRODUCT_NAME}</string>
+	<key>CFBundlePackageType</key>
+	<string>APPL</string>
+	<key>CFBundleSignature</key>
+	<string>????</string>
+	<key>CFBundleVersion</key>
+	<string>1.0</string>
+	<key>NSMainNibFile</key>
+	<string>MainMenu</string>
+	<key>NSPrincipalClass</key>
+	<string>NSApplication</string>
+</dict>
+</plist>

Deleted: MacRuby/trunk/sample-macruby/FlickrDemo/PhotocastViewerController.rb
===================================================================
--- MacRuby/trunk/sample-macruby/PhotocastViewer/PhotocastViewerController.rb	2008-09-03 23:51:00 UTC (rev 550)
+++ MacRuby/trunk/sample-macruby/FlickrDemo/PhotocastViewerController.rb	2008-09-05 01:22:45 UTC (rev 554)
@@ -1,80 +0,0 @@
-class PhotocastViewerController < NSWindowController
-  
-  attr_accessor :imageBrowserView
-  
-  def awakeFromNib
-    @cache = []
-    @imageBrowserView.animates = true
-    @imageBrowserView.dataSource = self
-    @imageBrowserView.delegate = self
-    
-    NSNotificationCenter.defaultCenter.addObserver self,
-      selector:'feedRefreshed:',
-      name:PSFeedRefreshingNotification,
-      object:nil
-  end
-  
-  # Actions
-  
-  def zoomChanged(sender)
-    @imageBrowserView.zoomValue = sender.floatValue
-  end
-  
-  def parse(sender)
-    urlString = sender.stringValue
-    url = NSURL.URLWithString(urlString)
-    feed = PSFeed.alloc.initWithURL(url)
-    feed.refresh(nil)
-  end
-
-  def feedRefreshed(notification)
-    feed = notification.object
-    @results = feed.entryEnumeratorSortedBy(nil).allObjects
-    @cache.clear
-    @imageBrowserView.reloadData
-  end
-  
-  # Image browser datasource/delegate
-
-  def numberOfItemsInImageBrowser(browser)
-    @results ? @results.size : 0
-  end
-  
-  def imageBrowser(browser, itemAtIndex:index)
-    photo = @cache[index]
-    if photo.nil? 
-      entry = @results[index]
-      url = entry.content.HTMLString.scan(/<img\s+src="([^"]+)"/)[0][0]
-      photo = RSSPhoto.new(url)
-      @cache[index] = photo
-    end
-    return photo
-  end
-
-  def imageBrowser(browser, cellWasDoubleClickedAtIndex:index)
-    NSWorkspace.sharedWorkspace.openURL @cache[index].url
-  end
-end
-
-class RSSPhoto
-  attr_reader :url
-  
-  def initialize(url)
-    @urlString = url
-    @url = NSURL.alloc.initWithString url
-  end
-  
-  # IKImageBrowserItem protocol conformance
-  
-  def imageUID
-    @urlString
-  end
-    
-  def imageRepresentationType
-    :IKImageBrowserNSImageRepresentationType
-  end
-  
-  def imageRepresentation    
-    @image ||= NSImage.alloc.initByReferencingURL @url
-  end
-end

Deleted: MacRuby/trunk/sample-macruby/FlickrDemo/main.m
===================================================================
--- MacRuby/trunk/sample-macruby/PhotocastViewer/main.m	2008-09-03 23:51:00 UTC (rev 550)
+++ MacRuby/trunk/sample-macruby/FlickrDemo/main.m	2008-09-05 01:22:45 UTC (rev 554)
@@ -1,14 +0,0 @@
-//
-//  main.m
-//  PhotocastViewer
-//
-//  Created by Laurent Sansonetti on 6/5/08.
-//  Copyright __MyCompanyName__ 2008. All rights reserved.
-//
-
-#import <MacRuby/MacRuby.h>
-
-int main(int argc, char *argv[])
-{
-    return macruby_main("rb_main.rb", argc, argv);
-}

Copied: MacRuby/trunk/sample-macruby/FlickrDemo/main.m (from rev 553, MacRuby/trunk/sample-macruby/PhotocastViewer/main.m)
===================================================================
--- MacRuby/trunk/sample-macruby/FlickrDemo/main.m	                        (rev 0)
+++ MacRuby/trunk/sample-macruby/FlickrDemo/main.m	2008-09-05 01:22:45 UTC (rev 554)
@@ -0,0 +1,14 @@
+//
+//  main.m
+//  PhotocastViewer
+//
+//  Created by Laurent Sansonetti on 6/5/08.
+//  Copyright __MyCompanyName__ 2008. All rights reserved.
+//
+
+#import <MacRuby/MacRuby.h>
+
+int main(int argc, char *argv[])
+{
+    return macruby_main("rb_main.rb", argc, argv);
+}

Deleted: MacRuby/trunk/sample-macruby/FlickrDemo/rb_main.rb
===================================================================
--- MacRuby/trunk/sample-macruby/PhotocastViewer/rb_main.rb	2008-09-03 23:51:00 UTC (rev 550)
+++ MacRuby/trunk/sample-macruby/FlickrDemo/rb_main.rb	2008-09-05 01:22:45 UTC (rev 554)
@@ -1,24 +0,0 @@
-#
-# rb_main.rb
-# PhotocastViewer
-#
-# Created by Laurent Sansonetti on 6/5/08.
-# Copyright __MyCompanyName__ 2008. All rights reserved.
-#
-
-# Loading the Cocoa framework. If you need to load more frameworks, you can
-# do that here too.
-framework 'Cocoa'
-framework 'Quartz'
-framework 'PubSub'
-
-# Loading all the Ruby project files.
-dir_path = NSBundle.mainBundle.resourcePath.fileSystemRepresentation
-Dir.entries(dir_path).each do |path|
-  if path != File.basename(__FILE__) and path[-3..-1] == '.rb'
-    require(path)
-  end
-end
-
-# Starting the Cocoa main loop.
-NSApplicationMain(0, nil)

Copied: MacRuby/trunk/sample-macruby/FlickrDemo/rb_main.rb (from rev 553, MacRuby/trunk/sample-macruby/PhotocastViewer/rb_main.rb)
===================================================================
--- MacRuby/trunk/sample-macruby/FlickrDemo/rb_main.rb	                        (rev 0)
+++ MacRuby/trunk/sample-macruby/FlickrDemo/rb_main.rb	2008-09-05 01:22:45 UTC (rev 554)
@@ -0,0 +1,24 @@
+#
+# rb_main.rb
+# PhotocastViewer
+#
+# Created by Laurent Sansonetti on 6/5/08.
+# Copyright __MyCompanyName__ 2008. All rights reserved.
+#
+
+# Loading the Cocoa framework. If you need to load more frameworks, you can
+# do that here too.
+framework 'Cocoa'
+framework 'Quartz'
+framework 'PubSub'
+
+# Loading all the Ruby project files.
+dir_path = NSBundle.mainBundle.resourcePath.fileSystemRepresentation
+Dir.entries(dir_path).each do |path|
+  if path != File.basename(__FILE__) and path[-3..-1] == '.rb'
+    require(path)
+  end
+end
+
+# Starting the Cocoa main loop.
+NSApplicationMain(0, nil)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080904/31d7d71e/attachment-0001.html 


More information about the macruby-changes mailing list