Permalink
Browse files

Basic open panel to select repositories and validate the url

  • Loading branch information...
1 parent 977e38d commit 71836dfa6d075b42106cefba8515c1bf29a8b6ec @Abizern committed Sep 14, 2011
Showing with 187 additions and 213 deletions.
  1. +2 −8 CommitViewer.xcodeproj/project.pbxproj
  2. +5 −1 CommitViewer/AppDelegate.h
  3. +70 −2 CommitViewer/AppDelegate.m
  4. +110 −202 CommitViewer/en.lproj/MainMenu.xib
@@ -13,7 +13,6 @@
EE22C34E14201226002E215F /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = EE22C34C14201226002E215F /* Credits.rtf */; };
EE22C35114201226002E215F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = EE22C35014201226002E215F /* AppDelegate.m */; };
EE22C35414201227002E215F /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = EE22C35214201227002E215F /* MainMenu.xib */; };
- EE22C37814201835002E215F /* JCSSheetController.m in Sources */ = {isa = PBXBuildFile; fileRef = EE22C37714201835002E215F /* JCSSheetController.m */; };
EE22C37B14201862002E215F /* ObjectiveGit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EE22C36B14201769002E215F /* ObjectiveGit.framework */; };
EE22C37E1420188E002E215F /* ObjectiveGit.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = EE22C36B14201769002E215F /* ObjectiveGit.framework */; };
/* End PBXBuildFile section */
@@ -98,8 +97,6 @@
EE22C35314201227002E215F /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainMenu.xib; sourceTree = "<group>"; };
EE22C35A14201343002E215F /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
EE22C35B14201769002E215F /* ObjectiveGitFramework.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ObjectiveGitFramework.xcodeproj; path = "objective-git/ObjectiveGitFramework.xcodeproj"; sourceTree = "<group>"; };
- EE22C37614201835002E215F /* JCSSheetController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JCSSheetController.h; path = JCSSheetController/JCSSheetController.h; sourceTree = SOURCE_ROOT; };
- EE22C37714201835002E215F /* JCSSheetController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = JCSSheetController.m; path = JCSSheetController/JCSSheetController.m; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -158,8 +155,6 @@
EE22C35A14201343002E215F /* AppDelegate.h */,
EE22C35014201226002E215F /* AppDelegate.m */,
EE22C35214201227002E215F /* MainMenu.xib */,
- EE22C37614201835002E215F /* JCSSheetController.h */,
- EE22C37714201835002E215F /* JCSSheetController.m */,
EE22C34414201226002E215F /* Supporting Files */,
);
path = CommitViewer;
@@ -308,7 +303,6 @@
files = (
EE22C34A14201226002E215F /* main.m in Sources */,
EE22C35114201226002E215F /* AppDelegate.m in Sources */,
- EE22C37814201835002E215F /* JCSSheetController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -359,7 +353,7 @@
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
- GCC_ENABLE_OBJC_GC = required;
+ GCC_ENABLE_OBJC_GC = unsupported;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
@@ -387,7 +381,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
- GCC_ENABLE_OBJC_GC = required;
+ GCC_ENABLE_OBJC_GC = unsupported;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
@@ -7,11 +7,15 @@
//
#import <Cocoa/Cocoa.h>
+@class GTCommit;
-@interface AppDelegate : NSObject <NSApplicationDelegate> {
+@interface AppDelegate : NSObject <NSApplicationDelegate, NSOpenSavePanelDelegate> {
NSWindow *window;
}
@property (assign) IBOutlet NSWindow *window;
+@property (nonatomic, retain) GTCommit *commit;
+
+- (IBAction)openNewRepository:(id)sender;
@end
View
@@ -7,14 +7,82 @@
//
#import "AppDelegate.h"
+#import <ObjectiveGit/ObjectiveGit.h>
+
+@interface AppDelegate ()
+
+- (NSURL *)repositoryURLForURL:(NSURL *)url;
+
+@end
@implementation AppDelegate
@synthesize window;
+@synthesize commit;
-- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
-{
+- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
}
+
+
+- (IBAction)openNewRepository:(id)sender {
+ NSOpenPanel *panel = [NSOpenPanel openPanel];
+ panel.delegate = self;
+ panel.canChooseDirectories = YES;
+ panel.showsHiddenFiles = YES;
+
+ [panel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) {
+ if (result == NSFileHandlingPanelOKButton) {
+ NSLog(@"selected: %@", [self repositoryURLForURL:panel.URL]);
+ }
+ }];
+
+}
+
+#pragma mark - OpenSavePanel Delegate methods
+
+- (BOOL)panel:(id)sender shouldEnableURL:(NSURL *)url {
+ // Should do more here to enable and disable items - but I'm lazy.
+ return YES;
+}
+
+- (BOOL)panel:(NSOpenPanel *)sender validateURL:(NSURL *)url error:(NSError **)outError {
+ if (!([self repositoryURLForURL:url])) {
+ return NO;
+ }
+
+ return YES;
+}
+
+#pragma mark - class extension
+
+- (NSURL *)repositoryURLForURL:(NSURL *)url {
+ // returns the repository URL or nil if it can't be made.
+ // If the URL is a file, it should have the extension '.git' - bare repository
+ // If the URL is a folder it should have the name '.git'
+ // If the URL is a folder, then it should contain a subfolder called '.git
+ NSString *kGit = @".git";
+ NSString *endPoint = [url lastPathComponent];
+ NSLog(@"Endpoint: %@", endPoint);
+
+ if ([[endPoint lowercaseString] hasSuffix:kGit]) {
+ return url;
+ }
+
+ if ([endPoint isEqualToString:kGit]) {
+ return url;
+ }
+
+ NSURL *possibleGitDir = [url URLByAppendingPathComponent:kGit isDirectory:YES];
+ if ([possibleGitDir checkResourceIsReachableAndReturnError:NULL]) {
+ return possibleGitDir;
+ }
+
+ NSLog(@"Not a valid path");
+ return nil;
+
+
+}
+
@end
Oops, something went wrong.

0 comments on commit 71836df

Please sign in to comment.