Skip to content

Commit

Permalink
Lazily initialize the data source and other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Palmer committed Oct 4, 2008
1 parent cb99872 commit 1463286
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 114 deletions.
223 changes: 120 additions & 103 deletions English.lproj/MainMenu.xib

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions GNFileSystemItem.h
Expand Up @@ -25,4 +25,5 @@
- (BOOL)isLeafNode;
- (NSDictionary*)attributes;
- (BOOL)isHeading;
- (BOOL)ignoredByGit:(NSString *)fileItem;
@end
20 changes: 13 additions & 7 deletions GNFileSystemItem.m
Expand Up @@ -34,13 +34,19 @@ + (NSString *)repoRoot {
return [[[NSApplication sharedApplication] delegate] repository_location];
}

// - (NSString *)ignoredByGit:(NSString *)fileItem
// {
// NSString *ret = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/env" arguments:
// [NSArray arrayWithObjects:@"git", @"status", fileItem, nil]];
// NSLog(@"%s RET: %@", _cmd, ret);
// return ret;
// }
- (BOOL)ignoredByGit:(NSString *)fileItem
{
NSString *format;
if([[self fullPath] hasSuffix:@"/"])
format = @"%@%@";
else
format = @"%@/%@";

NSString *file = [NSString stringWithFormat:format, [self fullPath], fileItem];

BOOL ignored = [[[NSApplication sharedApplication] delegate] is_file_ignored:file];
return !ignored;
}

// Creates, caches, and returns the array of children
// Loads children incrementally
Expand Down
11 changes: 11 additions & 0 deletions GNTreeDataSource.m
Expand Up @@ -53,5 +53,16 @@ - (NSCell *)outlineView:(NSOutlineView *)sender dataCellForTableColumn:(id)cell
return nil;
}

- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item
{
BOOL isDir;
[[NSFileManager defaultManager] fileExistsAtPath:[item fullPath] isDirectory:&isDir];

if([item isHeading] || isDir)
return NO;

return YES;
}

@end

36 changes: 34 additions & 2 deletions controllers/ApplicationController.rb
Expand Up @@ -20,6 +20,8 @@
OSX.ns_import 'CommitSummaryCell'
include OSX

#Grit.debug = true

# we use ENV['PWD'] instead of Dir.getwd if it exists so
# `open GitNub` will work, since that launches us at / but leaves ENV['PWD'] intact
pwd = Pathname.new(ENV['PWD'].nil? ? Dir.getwd : ENV['PWD'])
Expand Down Expand Up @@ -61,7 +63,7 @@ def awakeFromNib

@branch_field.cell.setBackgroundStyle(NSBackgroundStyleRaised)
@tab_panel.setDelegate(self)

setup_search_field
setup_refs_view_menu

Expand All @@ -86,6 +88,11 @@ def repo
end
end

def is_file_ignored(file)
#return ignore_list.include?(file)
return false
end

def repository_location
REPOSITORY_LOCATION.to_s.gsub('.git', '')
end
Expand Down Expand Up @@ -118,7 +125,32 @@ def tabView_didSelectTabViewItem(tab_view, tab_item)
Notify.send "tab_view_changed", { :tab_item => tab_item.identifier }
end

def swap_branch(item)
@commits_controller.swap_branch(item)
Notify.send('branch_was_changed', {:title => item.title})
end

def active_branch
@commits_controller.branch
end

private
def ignore_list
@ignore_list ||= lambda do
# Grit takes over ls-files so we have to run it this way
#repo.git.sh("cd #{repository_location}")
files = repo.git.run(nil, "ls-files", nil, {:others => true, :exclude_from => "#{repo.path}/info/exclude"}, [])
#puts files

#files = files.split("\n").collect {|f| %(#{repository_location}#{f.strip.chomp}) }
# files.each do |f|
# puts f
# end
#puts files
files
end.call
end

def setup_refs_view_menu
[@local_branches_menu, @remote_branches_menu, @tags_menu].each { |m| m.submenu.setAutoenablesItems(false) }

Expand All @@ -133,7 +165,7 @@ def setup_refs_view_menu
item = NSMenuItem.alloc.initWithTitle_action_keyEquivalent(head.name, :swap_branch, index.to_s)
item.setEnabled(true)
item.setTag(index)
item.setTarget(@commits_controller)
item.setTarget(self)
menu.submenu.addItem(item)
end
end
Expand Down
2 changes: 2 additions & 0 deletions controllers/CommitsController.rb
Expand Up @@ -25,6 +25,8 @@ class CommitsController < OSX::NSObject
ib_outlet :commit_details
ib_outlet :application_controller

attr_reader :branch

def awakeFromNib
@searching = false
@current_commit_offset = 0
Expand Down
27 changes: 26 additions & 1 deletion controllers/TreeController.rb
Expand Up @@ -15,9 +15,34 @@ class TreeController < OSX::NSObject
ib_outlet :tree_outline
ib_outlet :file_canvas
ib_outlet :tree_data_source
ib_outlet :main_canvas
ib_outlet :main_webview

def awakeFromNib
@tree_outline.setDelegate(@tree_data_source)
dsource = GNTreeDataSource.alloc.init
@tree_outline.setDataSource(dsource)
@tree_outline.setDelegate(dsource)
@tree_outline.expandItem(@tree_outline.itemAtRow(0))
NSNotificationCenter.defaultCenter.objc_send(:addObserver, self,
:selector, :item_was_selected,
:name, "NSOutlineViewSelectionDidChangeNotification",
:object, @tree_outline)

Notify.on 'branch_was_changed' do |opts|
puts "BRANCH WAS CHANGED"
end
end

def branch_was_changed(branch)
puts "BRANCH WAS CHANGED"
end

def item_was_selected(notification)
outline_view = notification.object
item = outline_view.itemAtRow(outline_view.selectedRow)
unless item.nil?
puts NSApplication.sharedApplication.delegate.active_branch
puts item.fullPath
end
end
end
2 changes: 1 addition & 1 deletion lib/osx_notify.rb
Expand Up @@ -13,7 +13,7 @@ def self.on(name, &block)
notify.block = block

c = OSX::NSDistributedNotificationCenter.defaultCenter
c.addObserver_selector_name_object_ notify, "call:", name, nil
c.addObserver_selector_name_object notify, "call:", name, nil
return notify
end

Expand Down

0 comments on commit 1463286

Please sign in to comment.