Hi,

Thank-you very much Watson for your SourceListViewBased example.
As usual, I have few questions:
1) Where did you find "isGroupItem:item" for OutlineView? I search in 
NSOutlineView Class Reference but I didn't find it!
2) I start from your example and I add a column to show a badge for each child. 
It's work, but there is still a small problem I do not understand:
Even if I set the size with interface inspector, the inline button is always 
the same width of the width of the column when I run the program.
For instance, the column's width is 70 and I set the button's width to 25. 

Thanks for reply
François

Some explanation and code:

I use the following method found on internet:
----
"First subclass NSTableCellView and add an IBOutlet for an NSButton and a 
@synthesize/@property statement for it. Then open the NSTableCellView which 
should have a badge in Interface Builder. Set it's class to your newly created 
subclass and add a button to it. Set the button style to "inline" and it's type 
to "switch".

Now select the TableCellView againa and connect the NSButton IBOutlet to your 
added button. That's it. You can now call e.g. [cellView button] 
setTitle@"123"]] to set the rows badge label to 123 or any arbitrary string."
----

So I append to your AppDelegate file the following new class, translated from 
the previous explanation in ruby:
class MaCellule <  NSTableCellView
    attr_accessor :iden
    def initialize
        @iden = NSButton.new
    end
end

and I change one of your method as follow:
    def outlineView(outlineView,
                    viewForTableColumn:tableColumn,
                    item:item)
        if (tableColumn.nil?|(tableColumn == outlineView.outlineTableColumn))
            if item[:type] == "group"
                # group
                view = outlineView.makeViewWithIdentifier("HeaderCell", 
owner:self)
                #puts item['name']
                view.textField.stringValue = item['name']
            else
                # child
                # puts item["name"]
                view = outlineView.makeViewWithIdentifier("DataCell", 
owner:self)
                view.imageView.image = item['icon']
                view.textField.stringValue = item['name']
            end
            return view
        else
            if item[:group] == "group"
            else
                #puts item["name"] + " 2 " + item["badgeValue"].to_s 
                view = outlineView.makeViewWithIdentifier("ButtonCell", 
owner:self)
                #puts view.iden.class
                if item["badgeValue"].empty?
                    view.iden.setTransparent(true)
                else
                    view.iden.setTitle(item["badgeValue"])
                end
            end
        end
    end




Le 2011-12-10 à 02:53, Watson a écrit :

> Hi,
> 
> If you want to display images in NSOutlineView, I think you would use
> the NSOutlineView as View-Based.
> You might use the outlineView:viewForTableColumn:item instead of
> outlineView:objectValueForTableColumn:byItem.
> 
> Look at my sample, you would think it isn't difficult :)
> - 
> https://github.com/Watson1978/MacRuby-Samples/tree/master/SourceListViewBased
> 
> 
> 2011/12/9 François Boone <francois.bo...@usherbrooke.ca>:
>> Hi,
>> 
>> With help of Matt and Watson, I have made a tree using Outline View object 
>> and it works fine.
>> Now I would like to go one step further.
>> 
>> I would like to use the Source List object available in Object Library.  
>> This Source List looks like Outline View with TableColumn Object. In this 
>> Table Object there is two Table Cell objects, the first one for the header 
>> and the second one, divided in two objects, for an image and a text.
>> 
>> My question is: how to build the data to fill the Source List object: I try 
>> something like this:
>> @data = [ [ {:group => 'Title'}],  [:cell => {:image => image1, :name => 
>> 'Test'} ] ] where image1 is a NSImage object.
>> But this doesn't work.
>> 
>> I don't now why it doesn't work:
>> 1) a bad structure for @data
>> 2) a bad binding in xib file
>> 3) a bad definition of outlineView (I kept the same definition than the 
>> previous Outline View project)
>> 
>> Thanks for reply
>> François
>> 
>> 
>> 
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel@lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel@lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
> 

_______________________________________________
MacRuby-devel mailing list
MacRuby-devel@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

Reply via email to