Skip to content

Commit

Permalink
Blame view working, still have a lot of polish left
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Palmer committed Oct 6, 2008
1 parent 2b70bce commit ea24051
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 10 deletions.
4 changes: 4 additions & 0 deletions GitNub.xcodeproj/project.pbxproj
Expand Up @@ -38,6 +38,7 @@
283E2F7E0E9574A000E33E25 /* GNOutlineView.m in Sources */ = {isa = PBXBuildFile; fileRef = 283E2F7C0E9574A000E33E25 /* GNOutlineView.m */; };
288853050D7CE2E500862D67 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 288853040D7CE2E500862D67 /* LICENSE */; };
288CB41A0D8789DD0092B5CC /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 288CB4180D8789DD0092B5CC /* MainMenu.xib */; };
28EF91600E98243A009B70DF /* blame.html in Resources */ = {isa = PBXBuildFile; fileRef = 28EF915F0E98243A009B70DF /* blame.html */; };
4DDCA7070ACC9A6100E082CE /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
4DDCA7080ACC9A6100E082CE /* rb_main.rb in Resources */ = {isa = PBXBuildFile; fileRef = E8F5E25803AEB7C803A81C6F /* rb_main.rb */; };
4DDCA70A0ACC9A6100E082CE /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
Expand Down Expand Up @@ -94,6 +95,7 @@
283E2F7C0E9574A000E33E25 /* GNOutlineView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GNOutlineView.m; sourceTree = "<group>"; };
288853040D7CE2E500862D67 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
288CB4190D8789DD0092B5CC /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = "<group>"; };
28EF915F0E98243A009B70DF /* blame.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = blame.html; sourceTree = "<group>"; };
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
Expand Down Expand Up @@ -195,6 +197,7 @@
281AEAC00E65412C00B48530 /* delete.png */,
281AEAC10E65412C00B48530 /* gitnub-icon.icns */,
281AEAC20E65412C00B48530 /* style.css */,
28EF915F0E98243A009B70DF /* blame.html */,
);
path = assets;
sourceTree = "<group>";
Expand Down Expand Up @@ -329,6 +332,7 @@
281AEACE0E6541AB00B48530 /* Info.xib in Resources */,
281AED6C0E6677B500B48530 /* GitNubWebView.rb in Resources */,
283E2EC20E932E9E00E33E25 /* TreeController.rb in Resources */,
28EF91600E98243A009B70DF /* blame.html in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
28 changes: 28 additions & 0 deletions assets/blame.html
@@ -0,0 +1,28 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Commit</title>
<link rel="stylesheet" href="style.css" type="text/css" charset="utf-8" />
</head>

<body>
<div id="content">
<div id="metadata">
<h1 id="title">Blame</h1>
<p id="hash"></p>
<div id="message"></div>
<h2 id="date"></h2>
</div>

<div id="main">
<div id="blame">

</div>
</div>
</div>

</body>
</html>
49 changes: 48 additions & 1 deletion assets/style.css
Expand Up @@ -177,4 +177,51 @@ pre code {
}


/* @end */
/* @end */

/*------------------------------------------------------------------------------------
@group blame
------------------------------------------------------------------------------------*/

#blame-list li {
line-height: 100%;
border-bottom: 1px solid #f7f7f7;
padding: 0;
margin: 0;
position: relative;
display: block;
min-height: 24px;
font-size: 92%;
}

#blame pre {
line-height: 100%;
overflow: visible;
border: 0 !important;
margin: 0 0 0 21px !important;
padding: 0 !important;
white-space: pre-wrap;
}

#blame code {
line-height: 100%;
}
/*
#blame .linenum {
position: absolute;
top: 5px;
left: 0;
width: 16px;
text-align: right;
font-family: Courier, monospace;
}*/

#blame .gravatar {
position: absolute;
top: 5px;
left: 0;
padding: 1px;
border: 1px solid #eee;
}

/* @end */
2 changes: 1 addition & 1 deletion controllers/CommitsController.rb
Expand Up @@ -189,7 +189,7 @@ def update_main_document
li.setInnerHTML(%(<a href="#diff-#{i}" class="">#{diff.b_path}</a>))
file_list.appendChild(li)

unless diff.deleted_file or diff.diff.nil?
unless diff.deleted_file || diff.diff.nil?
diff_div = doc.createElement('div')
diff_div.setAttribute__('class', 'diff')
diff_div.setAttribute__('id', "diff-#{i}")
Expand Down
95 changes: 87 additions & 8 deletions controllers/TreeController.rb
Expand Up @@ -9,20 +9,23 @@
require 'osx/cocoa'
OSX.ns_import 'GNFileSystemItem'
OSX.ns_import 'GNTreeDataSource'

require 'fileutils'

class TreeController < OSX::NSObject
IMAGE_MIMES = ["image/png", "img/jpeg", "image/jpg", "image/gif", "img/bmp"]
ELEMENTS = {
:blame => 'blame',
:list => 'blame-list'
}

ib_outlet :tree_outline
ib_outlet :file_canvas
ib_outlet :tree_data_source
ib_outlet :main_canvas


def awakeFromNib
main_view = WebView.alloc.init
main_view.setAutoresizingMask(NSViewWidthSizable|NSViewHeightSizable)
main_view.setFrameSize(@main_canvas.frame.size)
@main_canvas.addSubview(main_view)

setup_web_view
dsource = GNTreeDataSource.alloc.init
@tree_outline.setDataSource(dsource)
@tree_outline.setDelegate(dsource)
Expand All @@ -45,8 +48,84 @@ 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
Thread.start do
doc = @main_view.mainFrame.DOMDocument
app = NSApplication.sharedApplication.delegate
branch = app.active_branch
file = item.fullPath.sub(app.repository_location, '')
commit = app.repo.commit(branch.to_s)
blob = commit.tree/file.to_s

set_html('title', File.basename(file))
element = doc.getElementById(ELEMENTS[:blame])
element.setInnerHTML("")

unless blob.nil?
set_html('hash', blob.id)

render_last_commit_html(app, branch, file)

if IMAGE_MIMES.include?(blob.mime_type)
return display_as_image(blob, item)
end

blame = Grit::Blob.blame(app.repo, commit.id, file.to_s)

blame_list = doc.createElement('ul')
blame_list.setAttribute__('id', ELEMENTS[:list])
blame_list.setInnerHTML('')
blame.each do |commit, lines|
lines.each do |line|
line = line.empty? ? "&nbsp;" : line.escapeHTML
li = doc.createElement('li')
img = doc.createElement('img')
url = gravatar_url(commit.author.email, 16).to_s
img.setAttribute__('src', url)
img.setAttribute__('class', 'gravatar')
li.setInnerHTML(%(<pre><code>#{line}</code></pre>))
li.appendChild(img)
blame_list.appendChild(li)
end
end
element.appendChild(blame_list)
else
set_html('hash', 'Untracked or ignored file')
end
end
end
end

private

def render_last_commit_html(branch, file)
last_commit = app.repo.log(branch, file)
puts last_commit
#active_commit.authored_date.to_system_time
end

def display_as_image(blob, outline_item)
doc = @main_view.mainFrame.DOMDocument
img = doc.createElement('img')
url = NSURL.fileURLWithPath(outline_item.fullPath)
img.setAttribute__('src', url.to_s)
doc.getElementById(ELEMENT[:blame]).appendChild(img)
end

def render_last_commit_html(blob, branch)

end

def setup_web_view
@main_view = WebView.alloc.init
@main_view.setAutoresizingMask(NSViewWidthSizable|NSViewHeightSizable)
@main_view.setFrameSize(@main_canvas.frame.size)
@main_canvas.addSubview(@main_view)

web_view = File.join(NSBundle.mainBundle.bundlePath, "Contents", "Resources", "blame.html")
@main_view.mainFrame.loadRequest(NSURLRequest.requestWithURL(NSURL.fileURLWithPath(web_view)))
end

def set_html(element, html)
@main_view.mainFrame.DOMDocument.getElementById(element).setInnerHTML(html)
end
end

0 comments on commit ea24051

Please sign in to comment.