Skip to content

Commit

Permalink
Add menu items allowing you to view remote branches and tags. Hat tip…
Browse files Browse the repository at this point in the history
… to dysinger for the initial work on this.
  • Loading branch information
Justin Palmer committed Jun 5, 2008
1 parent 72ace73 commit 571feaa
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 37 deletions.
44 changes: 36 additions & 8 deletions ApplicationController.rb
Expand Up @@ -33,6 +33,9 @@ class ApplicationController < OSX::NSObject
ib_outlet :branch_field
ib_outlet :tab_panel
ib_outlet :extras_segment
ib_outlet :local_branches_menu
ib_outlet :remote_branches_menu
ib_outlet :tags_menu

def applicationDidFinishLaunching(sender)
@window.makeKeyAndOrderFront(self)
Expand All @@ -43,16 +46,19 @@ def applicationShouldTerminateAfterLastWindowClosed(notification)
end

def awakeFromNib
repo
@window.delegate = self
column = @commits_table.tableColumns[0]
cell = CommitSummaryCell.alloc.init
column.dataCell = cell
if repo
@window.delegate = self
column = @commits_table.tableColumns[0]
cell = CommitSummaryCell.alloc.init
column.dataCell = cell

@main_view.setFrameSize(@main_canvas.frame.size)
@main_canvas.addSubview(@main_view)
@main_view.setFrameSize(@main_canvas.frame.size)
@main_canvas.addSubview(@main_view)

@branch_field.cell.setBackgroundStyle(NSBackgroundStyleRaised)
@branch_field.cell.setBackgroundStyle(NSBackgroundStyleRaised)

setup_refs_view_menu
end
end

def repo
Expand All @@ -74,4 +80,26 @@ def swap_tab(segment)
tag = %w(commits network)[segment.cell.tagForSegment(segment.selectedSegment)]
@tab_panel.selectTabViewItemWithIdentifier(tag)
end

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

heads = repo.heads.sort_by do |head|
head.name == 'master' ? "***" : head.name
end

add_menu_item = lambda do |refs, menu|
refs.each_with_index do |head, index|
item = NSMenuItem.alloc.initWithTitle_action_keyEquivalent(head.name, :swap_branch, index.to_s)
item.setEnabled(true)
item.setTarget(@commits_controller)
menu.submenu.addItem(item)
end
end

add_menu_item.call(heads, @local_branches_menu)
add_menu_item.call(repo.remotes, @remote_branches_menu)
add_menu_item.call(repo.tags, @tags_menu)
end
end
11 changes: 9 additions & 2 deletions CommitsController.rb
Expand Up @@ -40,7 +40,7 @@ def awakeFromNib
if fetch_git_repository
fetch_git_branch
setup_commit_detail_view
fetch_commits_for @branch, @offset
fetch_commits_for(@branch, @offset)
setup_branches_menu
setup_paging_control
@commits_table.reloadData
Expand Down Expand Up @@ -211,12 +211,19 @@ def update_main_document
def refresh
current_commit = active_commit && active_commit.id
@branch = @branch_select.titleOfSelectedItem
fetch_commits_for @branch, @offset
fetch_commits_for(@branch, @offset)

@commits_table.reloadData
select_latest_commit
end

def swap_branch(foo)
@branch = foo.title
fetch_commits_for(@branch, @offset)
@commits_table.reloadData
select_latest_commit
end


private

Expand Down

0 comments on commit 571feaa

Please sign in to comment.