// Portions of code from
// https://github.com/MellongLau/AMMethod2Implement
// MIT license
#import "P4XcodeHelper.h"
#import <AppKit/AppKit.h>
@implementation P4XcodeHelper
+ (NSURL*)currentProjectURL
{
for (NSDocument* currentDoc in [NSApp orderedDocuments])
{
@try
{
NSURL* url = [[[currentDoc valueForKeyPath:@"_workspace.representingFilePath.fileURL"]
URLByDeletingLastPathComponent]
filePathURL];
if (url)
{
return url;
}
}
@catch (NSException* exception)
{
NSLog(@"Exception raised while searching for workspace URL: %@", exception);
}
}
return nil;
}
/*
https://github.com/MellongLau/AMMethod2Implement/blob/master/AMMethod2Implement/AMXcodeHelper.m
*/
+ (id)currentEditor
{
NSWindow* window = [NSApp keyWindow];
NSWindowController *windowController = [window windowController];
if (windowController == nil)
{
return nil;
}
if ([windowController isKindOfClass:NSClassFromString(@"IDEWorkspaceWindowController")])
{
IDEWorkspaceWindowController *workspaceController = (IDEWorkspaceWindowController *)windowController;
IDEEditorArea *editorArea = [workspaceController editorArea];
IDEEditorContext *editorContext = [editorArea lastActiveEditorContext];
return [editorContext editor];
}
return nil;
}
+ (NSObject *)currentWorkspaceDocument
{
NSWindowController *currentWindowController = [[NSApp keyWindow] windowController];
id document = [currentWindowController document];
if (currentWindowController && [document isKindOfClass:NSClassFromString(@"IDEWorkspaceDocument")])
{
return (NSObject *)document;
}
return nil;
}
+ (IDESourceCodeDocument *)currentSourceCodeDocument
{
id currentEditor = [P4XcodeHelper currentEditor];
if (currentEditor == nil)
{
return nil;
}
if ([currentEditor isKindOfClass:NSClassFromString(@"IDESourceCodeEditor")])
{
IDESourceCodeEditor *editor = [P4XcodeHelper currentEditor];
return editor.sourceCodeDocument;
}
if ([currentEditor isKindOfClass:NSClassFromString(@"IDESourceCodeComparisonEditor")])
{
IDESourceCodeComparisonEditor *editor = currentEditor;
if ([[editor primaryDocument]
isKindOfClass:NSClassFromString(@"IDESourceCodeDocument")])
{
IDESourceCodeDocument *document =
(IDESourceCodeDocument *)editor.primaryDocument;
return document;
}
}
#if (0) // not yet implemented
if ([currentEditor isKindOfClass:NSClassFromString(@"IDEQuickLookEditor")])
{
IDESourceCodeEditor *editor = [P4XcodeHelper currentEditor];
return editor.sourceCodeDocument;
}
#endif
#if defined(_DEBUG)
if([currentEditor respondsToSelector:@selector(className)])
{
NSLog(@"Class type %@\n", [currentEditor className]);
}
#endif
return nil;
}
@end
@implementation IDESourceCodeDocument
- (DVTSourceTextStorage *)textStorage
{
return nil;
}
- (NSUndoManager *)undoManager
{
return nil;
}
@end
#
Change
User
Description
Committed
#7
20141
Jaime Rios
Merging using M_robc_apple-to_jaime_rios_XcodePerforcePlugin
#6
13723
Jaime Rios
Fixed problem with menu items not being created because mainMenu is not available at startup for Xcode 6.3.2.
#5
13687
Jaime Rios
Added Xcode 6.3.2 support; minor editing changes; fixes for Swift compiler errors.
#4
11740
Jaime Rios
Updated readme text with additional known issues; refactored p4 revert function; added perforce icon to alert message.
#3
11733
Jaime Rios
Refactored code to have more functionality within Swift code; fixed perforce connection bugs.
#2
11714
Jaime Rios
Added unit tests; fixed bugs found during testing; added Jon Reid's XcodeCoverage files http://qualitycoding.org/xcode-code-coverage/ modified project to produce code coverage reports.
#1
11694
Jaime Rios
Initial add of XcodePerforcePlugin project to guest depot.