public this repo is viewable by everyone
Description: A Gitk-like application written in RubyCocoa that looks like it belongs on a Mac. See the wiki for downloads and screenshots.
Homepage: http://alternateidea.com
Clone URL: git://github.com/Caged/gitnub.git
Click here to lend your support to: gitnub and make a donation at www.pledgie.com !
commit  31d87daed47be3336a133aea4a52b0fd3ed2bfc4
tree    e26c7badd893553ae60b6f91243a251e0804a8cf
parent  87c0a61921d76f4e5076798b398bc69bf9e0d990 parent  8371aa6417af86ce08b556b585aa2ef4630d2af8
gitnub / ApplicationController.rb
100644 77 lines (66 sloc) 2.031 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#
# ApplicationController.rb
# GitNub
#
# Created by Justin Palmer on 3/1/08.
# Copyright (c) 2008 Active Reload, LLC. All rights reserved.
#
$VERBOSE = nil
require 'rubygems'
require 'pathname'
require 'osx/cocoa'
require 'mime-types/lib/mime/types'
require 'grit/lib/grit'
require 'lib/time_extensions'
require 'InfoWindowController'
 
OSX.ns_import 'CommitSummaryCell'
include OSX
 
# 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'])
REPOSITORY_LOCATION = pwd + `cd #{pwd} && git rev-parse --git-dir 2>/dev/null`.chomp
 
class ApplicationController < OSX::NSObject
  ib_outlet :commits_table
  ib_outlet :commits_controller
  ib_outlet :window
  ib_outlet :main_canvas
  ib_outlet :main_view
  ib_outlet :branch_field
  ib_outlet :tab_panel
  ib_outlet :extras_segment
  
  def applicationDidFinishLaunching(sender)
    @window.makeKeyAndOrderFront(self)
  end
  
  def applicationShouldTerminateAfterLastWindowClosed(notification)
    return true
  end
  
  def awakeFromNib
    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)
    
    @branch_field.cell.setBackgroundStyle(NSBackgroundStyleRaised)
  end
  
  def repo
    begin
      @repo ||= Grit::Repo.new(REPOSITORY_LOCATION)
    rescue Grit::InvalidGitRepositoryError
      return false
    end
  end
  
  ib_action :show_info_panel
  def show_info_panel(sender)
    if @info_controller.nil?
      @info_controller = InfoWindowController.alloc.init_with_repository(@repo)
    end
    @info_controller.showWindow(self)
  end
  
  ib_action :swap_tab
  def swap_tab(segment)
    tag = %w(commits network)[segment.cell.tagForSegment(segment.selectedSegment)]
    @tab_panel.selectTabViewItemWithIdentifier(tag)
  end
end