<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">

<channel>
  <title>Chandler Kent</title>
  <link>http://www.chandlerkent.com</link>
  <description>Blog of Chandler Kent</description>
  <language>en-us</language>
  
    
    <item>
        <title>Building a Basic App With a Sidebar and Content View</title>
        <link>http://www.chandlerkent.com/2010/01/08/Building-a-Basic-App-With-Sidebar-and-Content-View.html</link>
        <description>&lt;p&gt;In the &lt;a href=&quot;/2009/12/10/Building-a-Sidebar-With-CPOutlineView.html&quot;&gt;last post&lt;/a&gt; I showed you how to build a basic sidebar using &lt;code&gt;CPOutlineView&lt;/code&gt; and all its data source methods. In this post I am going to continue that idea and show you how to update a content view based on the user's selection in the sidebar. You can see a &lt;a href=&quot;/code/SidebarChangingContentView/&quot;&gt;demo&lt;/a&gt; of the final application to get the idea. All the source code created for this post can be found &lt;a href=&quot;http://github.com/chandlerkent/sample-projects/tree/master/SidebarChangingContentView/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Quick Note:&lt;/strong&gt; I am using &lt;a href=&quot;http://www.280atlas.com/&quot;&gt;Atlas&lt;/a&gt; in this post to layout my basic view and make some connections. If you are not part of the Atlas beta, or do not yet have Atlas, the following ideas should still extend to your application.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;Setup the Interface&lt;/h2&gt;

&lt;p&gt;In Atlas, create a new Cib-based project. Then open Resources &gt; MainMenu.cib to begin putting together the view. We are going to create a basic application with a sidebar on the left and a content view on the right. I like to use a Vertical Split View for this. Go ahead and drag a Vertical Split View into your window. Using the Size tab, make the Split View take up the entire window and resize with the window (selecting all the resizing arrows should do the trick). Also, in the &quot;Split View Size&quot; section, select the resizing arrow for the right view. The right view will be our content view, and this arrow tells the right view to resize horizontally as the window resizes. This is the behavior we want.&lt;/p&gt;

&lt;p&gt;Next, we want to create our outline view in the left view of the Split View. Unfortunately, &lt;code&gt;CPOutlineView&lt;/code&gt; isn't supported by Atlas yet, so we need to do this programmatically. However, we can save ourselves some work by creating the &lt;code&gt;CPScrollView&lt;/code&gt; in Atlas that the Outline View will need. Drag out a Scroll View and put it in the left view of the Split View. Again using the Size tab, make the Scroll View take up the entire left view and resize as it resizes (select all the resizing arrows). Also, in the Attributes tab with the Scroll View selected, uncheck &quot;Shows Horizontal Scroller&quot; and check &quot;Autohides Scrollers&quot;. These do exactly what they sound like they do.&lt;/p&gt;

&lt;p&gt;Click &quot;Test&quot; in the toolbar to test your interface. Make sure to resize both the window and the split view to see if your resizing flags are set up correctly.&lt;/p&gt;

&lt;h2&gt;Setup the Sidebar&lt;/h2&gt;

&lt;p&gt;I showed you how to build a sidebar in my &lt;a href=&quot;/2009/12/10/Building-a-Sidebar-With-CPOutlineView.html&quot;&gt;previos post&lt;/a&gt;. I'm not going to repeat that here. However, I want to highlight some different techniques that I am using.&lt;/p&gt;

&lt;p&gt;Last time I just used &lt;code&gt;CPString&lt;/code&gt;s as my items in the sidebar. However, you can use whatever object you like. For this demo, I created a &lt;code&gt;SidebarColorItem&lt;/code&gt; object to wrap all the details of my sidebar items--basically just a name, which the Outline View will display, and a color that will be the background color of the content view when the item is selected. The only thing you need to change from the &lt;a href=&quot;/2009/12/10/Building-a-Sidebar-With-CPOutlineView.html&quot;&gt;previous post&lt;/a&gt;'s code is the&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;- (id)outlineView:(CPOutlineView)outlineView objectValueForTableColumn:(CPTableColumn)tableColumn byItem:(id)item
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;of your data source. Instead of just returning &lt;code&gt;item&lt;/code&gt;, you will want to return &lt;code&gt;[item name]&lt;/code&gt; (the string that will be displayed in the outline view).&lt;/p&gt;

&lt;p&gt;Also, I wanted my Outline View to show all of its top-level items as expanded when it is first loaded. I used the following method for that:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;- (void)expandAllItems
{
    var allItems = [items allKeys];
    for (var i = 0; i &amp;lt; [allItems count]; i++)
    {
        [outlineView expandItem:[allItems objectAtIndex:i]];
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Finally, since I am using Atlas, I want Atlas to instantiate my &lt;code&gt;SidebarController&lt;/code&gt; for me. To do that, go back to MainMenu.cib, drag a &quot;Custom Object&quot; into the object section (the area along the bottom of the window). With the new object selected, change its class in the Class tab to &lt;code&gt;SidebarController&lt;/code&gt;. Also, connect the outlet &lt;code&gt;sidebarScrollView&lt;/code&gt; of the SidebarController to the Scroll View in the left view.&lt;/p&gt;

&lt;p&gt;This won't work on its own because our project doesn't know where that file is coming from. So in the &lt;code&gt;AppController&lt;/code&gt;, &lt;code&gt;@import&lt;/code&gt; the class file.&lt;/p&gt;

&lt;p&gt;I kind of breezed over most of the implementation details of the &lt;code&gt;SidebarController&lt;/code&gt;, so you may want to take a look at the full &lt;a href=&quot;http://github.com/chandlerkent/sample-projects/blob/master/SidebarChangingContentView/SidebarController.j&quot;&gt;SidebarController&lt;/a&gt; and &lt;a href=&quot;http://github.com/chandlerkent/sample-projects/blob/master/SidebarChangingContentView/SidebarColorItem.j&quot;&gt;SidebarColorItem&lt;/a&gt; source.&lt;/p&gt;

&lt;h2&gt;Create the Content View Controller&lt;/h2&gt;

&lt;p&gt;Now it is time to create the &lt;code&gt;ContentViewController&lt;/code&gt;. For this demo, all it will do is change its background color based on the selection in the sidebar. You can probably imagine a more complex application that will swap out the content view instead. But this should help you get the idea.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;ContentViewController&lt;/code&gt; will have an outlet which references the right view of the Split View. This is the view whose background color will be changed.&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;- (void)awakeFromCib&lt;/code&gt; method (which will be called when our object is instantiated from MainMenu.cib), all we need to do is register our object to receive notifications when the Outline View's selection changed, specifically we want to know about the &lt;code&gt;CPOutlineViewSelectionDidChangeNotification&lt;/code&gt; notification. This is done like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[[CPNotificationCenter defaultCenter]
        addObserver:self
        selector:@selector(outlineViewSelectionDidChange:)
        name:CPOutlineViewSelectionDidChangeNotification
        object:nil];
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you pass it a non-&lt;code&gt;nil&lt;/code&gt; object, your selector will only be called when the notification is posted from that specific object. Also, you can specify whatever selector you want, but in this case I called it &lt;code&gt;- (void)outlineViewSelectionDidChange:&lt;/code&gt;. This method will be called with the &lt;code&gt;CPNotification&lt;/code&gt; object that was posted by the &lt;code&gt;CPNotificationCenter&lt;/code&gt;. The implementation of this method may look like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;- (void)outlineViewSelectionDidChange:(CPNotification)notification
{
    var outlineView = [notification object];
    var selectedRow = [[outlineView selectedRowIndexes] firstIndex];
    var item = [outlineView itemAtRow:selectedRow];

    if ([item color])
    {
        [contentView setBackgroundColor:[item color]];
    }
    else
    {
        [contentView setBackgroundColor:[CPColor clearColor]];
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In the method you will notice that you can get the outline view through the method &lt;code&gt;[notification object]&lt;/code&gt;. Then, you get the selected row of the outline view and finally the selected item. In your application you can do what you like with this item; I just change the background color of the content view.&lt;/p&gt;

&lt;p&gt;Now go back in MainMenu.cib, drag out a new &quot;Custom Object&quot; and set its class to be &lt;code&gt;ContentViewController&lt;/code&gt;. Now connect the &lt;code&gt;contentView&lt;/code&gt; outlet to the right view of the Split View. Also, don't forget to &lt;code&gt;@import&lt;/code&gt; the class file in your &lt;code&gt;AppController&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;Putting it All Together&lt;/h2&gt;

&lt;p&gt;As a quick recap, you have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Used Atlas to setup a simple interface with a sidebar and a content view, wrapped with a split view&lt;/li&gt;
&lt;li&gt;Created a &lt;code&gt;SidebarController&lt;/code&gt; that is in charge of creating and managing the items in an outline view&lt;/li&gt;
&lt;li&gt;Also created a small &lt;code&gt;SidebarColorItem&lt;/code&gt; for the items in the sidebar&lt;/li&gt;
&lt;li&gt;Finally, created a &lt;code&gt;ContentViewController&lt;/code&gt; that responds to the &lt;code&gt;CPOutlineViewSelectionDidChangeNotification&lt;/code&gt; sent by the outline view&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Now when you load the final application you should be able to select items from the sidebar and see the background color of the content view change. &lt;a href=&quot;/code/SidebarChangingContentView/&quot;&gt;Here&lt;/a&gt; is the demo of my finished application.&lt;/p&gt;

&lt;p&gt;As you can see, it is relatively easy to create a simple application with a sidebar and a content view. While this example is fairly contrived, I'm sure you can envision how you can extend it for your own applications.&lt;/p&gt;

&lt;p&gt;As always, the full source code for this application is available at &lt;a href=&quot;http://www.github.com/chandlerkent/sample-projects/&quot;&gt;my GitHub account&lt;/a&gt;: &lt;a href=&quot;http://github.com/chandlerkent/sample-projects/tree/master/SidebarChangingContentView/&quot;&gt;here&lt;/a&gt;. If you have any questions, please post them in the comments section.&lt;/p&gt;

&lt;p&gt;Stay tuned for my next post on how to style your Outline View to be a little less bland!&lt;/p&gt;
</description>
        <pubDate>2010-01-08T00:00:00-05:00</pubDate>
        <guid>http://www.chandlerkent.com/2010/01/08/Building-a-Basic-App-With-Sidebar-and-Content-View</guid>
    </item>        
    
    <item>
        <title>Moving The Blog To Jekyll</title>
        <link>http://www.chandlerkent.com/2009/12/23/Moving-the-Blog-To-Jekyll.html</link>
        <description>&lt;p&gt;I started chandlerkent.com about four years ago as a way to learn how to create a website, including a backend powered by PHP and MySQL. At that time I created really basic blog software. This had many obvious problems, mainly it became impossible for me to maintain and add the features I needed. So the blog became stagnant. But from the experience I gained while building the site, I was able to create and deploy &lt;a href=&quot;http://www.iphlickr.com/&quot;&gt;iPhlickr&lt;/a&gt;, which was also backed by PHP and MySQL. This site has basically been used for iPhlickr since then. About a year ago I deleted the blog altogether as the information was simply out-of-date and the site was an eyesore. I didn't want to associate myself with that work.&lt;/p&gt;

&lt;p&gt;This year I decided I wanted to start blogging again. But I wanted to do it in such a way that would be more sustainable for me in the future. This meant it would need to be drop-dead simple for me to update, maintain, and add features. So I started looking into my options. I looked at &lt;a href=&quot;http://wordpress.org/&quot;&gt;WordPress&lt;/a&gt;, but it seemed like a lot of overhead. I've also heard that WordPress had some &lt;a href=&quot;http://daringfireball.net/2009/09/regarding_wordpress_and_security&quot;&gt;security issues&lt;/a&gt; in the past, as well as being a notorious &lt;a href=&quot;http://www.codinghorror.com/blog/archives/001105.html&quot;&gt;CPU hog&lt;/a&gt;. I wanted a little more control over my content that WordPress also didn't offer. So I kept looking. Google's &lt;a href=&quot;http://www.blogger.com/&quot;&gt;Blogger&lt;/a&gt; seemed to offer more benefits. It was very simple to set-up, offered an API that allowed me to use other tools to blog instead of the crappy web interface, and allowed me to host it on my own domain.&lt;/p&gt;

&lt;p&gt;I decided to give Blogger a try, and last month I created the first post on the new blog. But I was immediately underwhelmed with what I could do. I wanted more control over my users' experience than what Blogger offered, and the templates provided were downright ugly. So I started to look for another solution. Enter &lt;a href=&quot;http://github.com/mojombo/jekyll&quot;&gt;Jekyll&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Jekyll gives me a lot of the benefits I was looking for. It is drop-dead simple to use. I can write using &lt;a href=&quot;http://daringfireball.net/projects/markdown/&quot;&gt;Markdown&lt;/a&gt;, &lt;a href=&quot;http://en.wikipedia.org/wiki/Textile_(markup_language)&quot;&gt;Textile&lt;/a&gt;, or just HTML if I wanted to. I have complete control over the content, including layout and final HTML markup that will be served to the users. I can easily use source control for my writing like I do for code. And since it just generates static HTML pages, deployment is simple and flexible, and the final product is as fast as the server can deliver simple HTML files. Perfect.&lt;/p&gt;

&lt;p&gt;I spent today setting up and configuring Jekyll. Following the &lt;a href=&quot;http://wiki.github.com/mojombo/jekyll&quot;&gt;Jekyll-wiki&lt;/a&gt; was simple and the documentation is detailed. It took me less than an hour to get a simple blog setup. Next, I threw on some simple CSS (powered by &lt;a href=&quot;http://sass-lang.com/&quot;&gt;Sass&lt;/a&gt;--I never want to write straight CSS again!) for style and layout, added a few features like an &lt;a href=&quot;/archive.html&quot;&gt;Archive&lt;/a&gt; page and a &lt;a href=&quot;/rss.xml&quot;&gt;RSS&lt;/a&gt; feed, and uploaded it to my GoDaddy hosting. It was really a joy.&lt;/p&gt;

&lt;p&gt;After spending the day with Jekyll, I'm fairly confident I will be using it moving forward. I was surprised with its simplicity and flexibility which work together to allow for a lot of power and control. While I'm not sure when I will next get to work on the site, I do have many features in mind, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;comments (possibly through &lt;a href=&quot;http://disqus.com/&quot;&gt;Disqus&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;better archives&lt;/li&gt;
&lt;li&gt;tags&lt;/li&gt;
&lt;li&gt;related posts&lt;/li&gt;
&lt;li&gt;better front-page&lt;/li&gt;
&lt;li&gt;better layout&lt;/li&gt;
&lt;li&gt;easier deployment (eventually through a git push)&lt;/li&gt;
&lt;li&gt;ads?&lt;/li&gt;
&lt;li&gt;and more...&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;If you're interested, the source code for this site is up on &lt;a href=&quot;http://www.github.com/chandlerkent/chandlerkent.com&quot;&gt;GitHub&lt;/a&gt;. I look forward to any feedback you have as well as suggestions in ways I can improve the experience of this site.&lt;/p&gt;
</description>
        <pubDate>2009-12-23T00:00:00-05:00</pubDate>
        <guid>http://www.chandlerkent.com/2009/12/23/Moving-the-Blog-To-Jekyll</guid>
    </item>        
    
    <item>
        <title>Building a Sidebar With CPOutlineView</title>
        <link>http://www.chandlerkent.com/2009/12/10/Building-a-Sidebar-With-CPOutlineView.html</link>
        <description>&lt;p&gt;This past week I was tasked with converting our &lt;code&gt;CPCollectionView&lt;/code&gt;-backed sidebar to one using a &lt;code&gt;CPOutlineView&lt;/code&gt;. The reason for doing this was threefold. First, a collection view could not support all of the project's requirements going forward (at least not easily). Most notably, we wanted to support quick and easy navigation to common items like projects, glossaries, and some community links. Second, an outline view is more Mac-like in that most desktop Mac applications with a sidebar have some sort of outline view. This would move us closer to a Mac desktop experience on the web and lower the learning curve for new users. Finally, we just could.&lt;/p&gt;

&lt;p&gt;Since the release of &lt;a href=&quot;http://280atlas.com&quot;&gt;Atlas&lt;/a&gt;, the team has been trying to use Cibs to build our interface as much as possible. But &lt;code&gt;CPTableView&lt;/code&gt; and its brethren &lt;code&gt;CPOutlineView&lt;/code&gt; are not yet supported in Atlas. So that means I had to do this in straight code. This isn't a big deal (most of our interface is still built programmatically at this time), but it just means I have to be extra careful with configuring the view.&lt;/p&gt;

&lt;h2&gt;Setting Up the View&lt;/h2&gt;

&lt;p&gt;Setting up a &lt;code&gt;CPOutlineView&lt;/code&gt; is not much different from any other &lt;code&gt;CPView&lt;/code&gt; with two exceptions. The first is since &lt;code&gt;CPOutlineView&lt;/code&gt; inherits from &lt;code&gt;CPTableView&lt;/code&gt;, the column of data is actually a &lt;code&gt;CPTableColumn&lt;/code&gt;. So I had to create a &lt;code&gt;CPTableColumn&lt;/code&gt; and add it to the &lt;code&gt;CPOutlineView&lt;/code&gt;, just like in a &lt;code&gt;CPTableView&lt;/code&gt;. Simple enough. The second pitfall is again related to &lt;code&gt;CPOutlineView&lt;/code&gt; inheriting from &lt;code&gt;CPTableView&lt;/code&gt;. In order to correctly support scrolling, the outline view must be the documentView of a &lt;code&gt;CPScrollView&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To get the scroll view and outline view to actually look like an outline view, some additional configuration must be done. First, make sure to autohide the scroll view's scrollers. Again, an outline view is just a very specific table view, so it has a header view and a corner view. But in a sidebar, those views don't really make since, so I just set them both to nil. You probably also want to set the background color of the scroll view to look like a sidebar. I used &lt;code&gt;e0ecfa&lt;/code&gt;, but you may choose any color you wish.&lt;/p&gt;

&lt;h2&gt;DataSource&lt;/h2&gt;

&lt;p&gt;If you are coding along, and you're like me and like to refresh your project to see the effects of your changes, you are probably disappointed at this point. All you should see is a nice blue rectangle. That is because we haven't told the outline view what to display yet. This is what the dataSource is for.&lt;/p&gt;

&lt;p&gt;After setting the dataSource on the outline view to some object, we must implement the correct dataSource methods. There are four required methods:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;- (id)outlineView:child:ofItem:
- (BOOL)outlineView:isItemExpandable:
- (int)outlineView:numberOfChildrenOfItem:
- (id)outlineView:objectValueForTableColumn:byItem:
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Most of these methods are pretty self explanatory and I'm not going to go into much detail about them here (you can see &lt;a href=&quot;http://developer.apple.com/mac/library/documentation/cocoa/Reference/ApplicationKit/Protocols/NSOutlineViewDataSource_Protocol/Reference/Reference.html#//apple_ref/doc/uid/20000457&quot;&gt;&lt;code&gt;NSOutlineView&lt;/code&gt;'s documentation&lt;/a&gt; for more information) . I just want to note a few of the hangups that I had. First, these methods will be called with a &lt;code&gt;nil&lt;/code&gt; item for the root object in the outline view. Second, if &lt;code&gt;- (id)outlineView:objectValueForTableColumn:byItem:&lt;/code&gt; doesn't get called, you haven't added your table column to the outline view. Finally, if you mysteriously can't get anything beyond the first level of data to display (&lt;a href=&quot;http://groups.google.com/group/objectivej/browse_thread/thread/64b3209423502341&quot;&gt;like me&lt;/a&gt;), you haven't actually told the outline view which table column is the outline view's table column. So you need to use &lt;code&gt;- (void)setOutlineTableColumn:&lt;/code&gt;, passing in your table column.&lt;/p&gt;

&lt;p&gt;That's basically it. The final piece is to actually back your dataSource with some object or objects. Since I only need two levels of data, I am using a &lt;code&gt;CPDictionary&lt;/code&gt; where the keys are the top level and the values are arrays of data for the second level.&lt;/p&gt;

&lt;p&gt;You can see the code for my finished AppController at &lt;a href=&quot;http://gist.github.com/251323&quot;&gt;http://gist.github.com/251323&lt;/a&gt;. I included a bunch of debug statements in the dataSource methods to help understand what exactly is going on. You can see a running version of this project at &lt;a href=&quot;http://www.chandlerkent.com/code/OutlineView/&quot;&gt;http://www.chandlerkent.com/code/OutlineView/&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;What's Next&lt;/h2&gt;

&lt;p&gt;My next step is to implement &lt;code&gt;CPOutlineView&lt;/code&gt;'s delegate methods to be able to tell when the selection changes and which item is selected. Also, I want to have all my items expanded at startup like in Atlas, but just haven't gotten around to figuring that out yet.&lt;/p&gt;

&lt;p&gt;I hope this post helps you if you are struggling to get a &lt;code&gt;CPOutlineView&lt;/code&gt; in your interface or if you wanted to create a somewhat Mac-like sidebar. Leave a comment below if you have any questions, comments, or suggestions.&lt;/p&gt;
</description>
        <pubDate>2009-12-10T00:00:00-05:00</pubDate>
        <guid>http://www.chandlerkent.com/2009/12/10/Building-a-Sidebar-With-CPOutlineView</guid>
    </item>        
    
    <item>
        <title>First Post</title>
        <link>http://www.chandlerkent.com/2009/11/24/First-Post.html</link>
        <description>&lt;p&gt;I finally got the blog setup again. I am still using Blogger because I don't feel like fussing with installing my own solution. We'll see how far this takes me.&lt;/p&gt;

&lt;p&gt;I have a few things I want to write up in the next few days, so stay tuned!&lt;/p&gt;

&lt;p&gt;Also, I can't seem to find a good Blogger template, so if anybody has any suggestions, let me know.&lt;/p&gt;
</description>
        <pubDate>2009-11-24T00:00:00-05:00</pubDate>
        <guid>http://www.chandlerkent.com/2009/11/24/First-Post</guid>
    </item>        
    
</channel>

</rss>