Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user style-sheet from Application Support/GitX/Custom.css #250

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Classes/Util/NSFileManager+DirectoryLocations.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// NSFileManager+DirectoryLocations.h
//
// Created by Matt Gallagher on 06 May 2010
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software. Permission is granted to anyone to
// use this software for any purpose, including commercial applications, and to
// alter it and redistribute it freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source
// distribution.
//

#import <Foundation/Foundation.h>

//
// DirectoryLocations is a set of global methods for finding the fixed location
// directoriess.
//
@interface NSFileManager (DirectoryLocations)

- (NSString *)findOrCreateDirectory:(NSSearchPathDirectory)searchPathDirectory
inDomain:(NSSearchPathDomainMask)domainMask
appendPathComponent:(NSString *)appendComponent
error:(NSError **)errorOut;
- (NSString *)applicationSupportDirectory;

@end
155 changes: 155 additions & 0 deletions Classes/Util/NSFileManager+DirectoryLocations.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
//
// NSFileManager+DirectoryLocations.m
//
// Created by Matt Gallagher on 06 May 2010
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software. Permission is granted to anyone to
// use this software for any purpose, including commercial applications, and to
// alter it and redistribute it freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source
// distribution.
//

#import "NSFileManager+DirectoryLocations.h"

enum
{
DirectoryLocationErrorNoPathFound,
DirectoryLocationErrorFileExistsAtLocation
};

NSString * const DirectoryLocationDomain = @"DirectoryLocationDomain";

@implementation NSFileManager (DirectoryLocations)

//
// findOrCreateDirectory:inDomain:appendPathComponent:error:
//
// Method to tie together the steps of:
// 1) Locate a standard directory by search path and domain mask
// 2) Select the first path in the results
// 3) Append a subdirectory to that path
// 4) Create the directory and intermediate directories if needed
// 5) Handle errors by emitting a proper NSError object
//
// Parameters:
// searchPathDirectory - the search path passed to NSSearchPathForDirectoriesInDomains
// domainMask - the domain mask passed to NSSearchPathForDirectoriesInDomains
// appendComponent - the subdirectory appended
// errorOut - any error from file operations
//
// returns the path to the directory (if path found and exists), nil otherwise
//
- (NSString *)findOrCreateDirectory:(NSSearchPathDirectory)searchPathDirectory
inDomain:(NSSearchPathDomainMask)domainMask
appendPathComponent:(NSString *)appendComponent
error:(NSError **)errorOut
{
//
// Search for the path
//
NSArray* paths = NSSearchPathForDirectoriesInDomains(
searchPathDirectory,
domainMask,
YES);
if ([paths count] == 0)
{
if (errorOut)
{
NSDictionary *userInfo =
[NSDictionary dictionaryWithObjectsAndKeys:
NSLocalizedStringFromTable(
@"No path found for directory in domain.",
@"Errors",
nil),
NSLocalizedDescriptionKey,
[NSNumber numberWithInteger:searchPathDirectory],
@"NSSearchPathDirectory",
[NSNumber numberWithInteger:domainMask],
@"NSSearchPathDomainMask",
nil];
*errorOut =
[NSError
errorWithDomain:DirectoryLocationDomain
code:DirectoryLocationErrorNoPathFound
userInfo:userInfo];
}
return nil;
}

//
// Normally only need the first path returned
//
NSString *resolvedPath = [paths objectAtIndex:0];

//
// Append the extra path component
//
if (appendComponent)
{
resolvedPath = [resolvedPath
stringByAppendingPathComponent:appendComponent];
}

//
// Create the path if it doesn't exist
//
NSError *error = nil;
BOOL success = [self
createDirectoryAtPath:resolvedPath
withIntermediateDirectories:YES
attributes:nil
error:&error];
if (!success)
{
if (errorOut)
{
*errorOut = error;
}
return nil;
}

//
// If we've made it this far, we have a success
//
if (errorOut)
{
*errorOut = nil;
}
return resolvedPath;
}

//
// applicationSupportDirectory
//
// Returns the path to the applicationSupportDirectory (creating it if it doesn't
// exist).
//
- (NSString *)applicationSupportDirectory
{
NSString *executableName =
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleExecutable"];
NSError *error;
NSString *result =
[self
findOrCreateDirectory:NSApplicationSupportDirectory
inDomain:NSUserDomainMask
appendPathComponent:executableName
error:&error];
if (!result)
{
NSLog(@"Unable to find or create application support directory:\n%@", error);
}
return result;
}

@end
43 changes: 37 additions & 6 deletions Classes/git/PBGitXProtocol.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "PBGitXProtocol.h"

#import "NSFileManager+DirectoryLocations.h"

@implementation PBGitXProtocol

Expand All @@ -24,15 +25,45 @@ + (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request
-(void)startLoading
{
NSURL *url = [[self request] URL];

if ([[url host] isEqualToString:@"custom.css"]) {
[self startLoadingCustomCSS];
return;
}

PBGitRepository *repo = [[self request] repository];

if(!repo) {
[[self client] URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:nil]];
return;
NSString * commit = [url host];
NSString * filepath = [url path];
if (repo) {
[self startLoadingGitFile:filepath atCommit:commit withRepository:repo];
return;
}

[[self client] URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:nil]];
}

- (void)startLoadingCustomCSS
{
NSString * filepath = [[[NSFileManager defaultManager] applicationSupportDirectory] stringByAppendingPathComponent:@"Custom.css"];
NSFileHandle * filehandle = [NSFileHandle fileHandleForReadingAtPath:[filepath stringByExpandingTildeInPath]];
[self startLoadingToEndOfFileHandle:filehandle];
}

NSString *specifier = [NSString stringWithFormat:@"%@:%@", [url host], [[url path] substringFromIndex:1]];
handle = [repo handleInWorkDirForArguments:[NSArray arrayWithObjects:@"cat-file", @"blob", specifier, nil]];
- (void)startLoadingGitFile:(NSString *)filepath atCommit:(NSString *)commit withRepository:(PBGitRepository *)repo
{
NSString *specifier = [NSString stringWithFormat:@"%@:%@", commit, [filepath substringFromIndex:1]];
NSFileHandle * filehandle = [repo handleInWorkDirForArguments:[NSArray arrayWithObjects:@"cat-file", @"blob", specifier, nil]];
[self startLoadingToEndOfFileHandle:filehandle];
}

- (void)startLoadingToEndOfFileHandle:(NSFileHandle *)handle_
{
if (handle_ == nil) {
[[self client] URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:nil]];
return;
}

handle = handle_;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishFileLoad:) name:NSFileHandleReadToEndOfFileCompletionNotification object:handle];
[handle readToEndOfFileInBackgroundAndNotify];

Expand Down
8 changes: 8 additions & 0 deletions GitX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
911112370E5A097800BF76B4 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 911112360E5A097800BF76B4 /* Security.framework */; };
913D5E500E55645900CECEA2 /* gitx in Resources */ = {isa = PBXBuildFile; fileRef = 913D5E490E55644600CECEA2 /* gitx */; };
A27BDC65182267E600251A23 /* NSFileManager+DirectoryLocations.m in Sources */ = {isa = PBXBuildFile; fileRef = A27BDC64182267E600251A23 /* NSFileManager+DirectoryLocations.m */; };
A27BDC66182267E600251A23 /* NSFileManager+DirectoryLocations.m in Sources */ = {isa = PBXBuildFile; fileRef = A27BDC64182267E600251A23 /* NSFileManager+DirectoryLocations.m */; };
BC0444AD17648CC900353E6D /* AddRemoteTemplate.png in Resources */ = {isa = PBXBuildFile; fileRef = BC0444AC17648CC900353E6D /* AddRemoteTemplate.png */; };
BC0444B817648D0200353E6D /* BranchHighlighted.png in Resources */ = {isa = PBXBuildFile; fileRef = BC0444B717648D0200353E6D /* BranchHighlighted.png */; };
BC0444BA17648DA800353E6D /* FolderHighlighted.png in Resources */ = {isa = PBXBuildFile; fileRef = BC0444B917648DA700353E6D /* FolderHighlighted.png */; };
Expand Down Expand Up @@ -644,6 +646,8 @@
8D1107320486CEB800E47090 /* GitX.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GitX.app; sourceTree = BUILT_PRODUCTS_DIR; };
911112360E5A097800BF76B4 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = /System/Library/Frameworks/Security.framework; sourceTree = "<absolute>"; };
913D5E490E55644600CECEA2 /* gitx */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = gitx; sourceTree = BUILT_PRODUCTS_DIR; };
A27BDC63182267E600251A23 /* NSFileManager+DirectoryLocations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSFileManager+DirectoryLocations.h"; sourceTree = "<group>"; };
A27BDC64182267E600251A23 /* NSFileManager+DirectoryLocations.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSFileManager+DirectoryLocations.m"; sourceTree = "<group>"; };
BC0444AC17648CC900353E6D /* AddRemoteTemplate.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = AddRemoteTemplate.png; sourceTree = "<group>"; };
BC0444B717648D0200353E6D /* BranchHighlighted.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = BranchHighlighted.png; sourceTree = "<group>"; };
BC0444B917648DA700353E6D /* FolderHighlighted.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = FolderHighlighted.png; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1104,6 +1108,8 @@
4A5D76A414A9A9CC00DF6C68 /* Util */ = {
isa = PBXGroup;
children = (
A27BDC63182267E600251A23 /* NSFileManager+DirectoryLocations.h */,
A27BDC64182267E600251A23 /* NSFileManager+DirectoryLocations.m */,
4A5D76A514A9A9CC00DF6C68 /* NSApplication+GitXScripting.h */,
4A5D76A614A9A9CC00DF6C68 /* NSApplication+GitXScripting.m */,
4A5D76A714A9A9CC00DF6C68 /* NSFileHandleExt.h */,
Expand Down Expand Up @@ -1564,6 +1570,7 @@
4A5D76E914A9A9CC00DF6C68 /* PBGitWindowController.m in Sources */,
4A5D76EA14A9A9CC00DF6C68 /* PBHistorySearchController.m in Sources */,
4A5D76EB14A9A9CC00DF6C68 /* PBPrefsWindowController.m in Sources */,
A27BDC65182267E600251A23 /* NSFileManager+DirectoryLocations.m in Sources */,
4A5D76EC14A9A9CC00DF6C68 /* PBRefController.m in Sources */,
4A5D76ED14A9A9CC00DF6C68 /* PBRepositoryDocumentController.m in Sources */,
4A5D76EE14A9A9CC00DF6C68 /* PBServicesController.m in Sources */,
Expand Down Expand Up @@ -1650,6 +1657,7 @@
buildActionMask = 2147483647;
files = (
4A5D773A14A9A9F600DF6C68 /* gitx.m in Sources */,
A27BDC66182267E600251A23 /* NSFileManager+DirectoryLocations.m in Sources */,
4A5D773C14A9AA2F00DF6C68 /* PBGitBinary.m in Sources */,
4A5D773D14A9AA3700DF6C68 /* PBEasyPipe.m in Sources */,
4AB057E41652652000DE751D /* GitRepoFinder.m in Sources */,
Expand Down
1 change: 1 addition & 0 deletions html/views/commit/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<script src="../../lib/keyboardNavigation.js" type="text/javascript" charset="utf-8"></script>

<link rel="stylesheet" href="commit.css" type="text/css" media="screen" title="no title" charset="utf-8">
<link rel="stylesheet" href="GitX://custom.css" type="text/css" media="screen" title="no title" charset="utf-8">
<script src="commit.js" type="text/javascript" charset="utf-8"></script>
<script src="multipleSelection.js" type="text/javascript" charset="utf-8"></script>
</head>
Expand Down
1 change: 1 addition & 0 deletions html/views/diff/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<script src="../../lib/keyboardNavigation.js" type="text/javascript" charset="utf-8"></script>

<link rel="stylesheet" href="diffWindow.css" type="text/css" media="screen" title="no title" charset="utf-8">
<link rel="stylesheet" href="GitX://custom.css" type="text/css" media="screen" title="no title" charset="utf-8">
<script src="diffWindow.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript" charset="utf-8">
Expand Down
1 change: 1 addition & 0 deletions html/views/history/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<script src="../../lib/keyboardNavigation.js" type="text/javascript" charset="utf-8"></script>

<link rel="stylesheet" href="history.css" type="text/css" media="screen" title="no title" charset="utf-8">
<link rel="stylesheet" href="GitX://custom.css" type="text/css" media="screen" title="no title" charset="utf-8">
<script src="history.js" type="text/javascript" charset="utf-8"></script>
</head>

Expand Down