Skip to content
This repository has been archived by the owner on Nov 3, 2020. It is now read-only.

Add support for tracking if the Podfile has been edited in another app (Issue 114) #220

Merged
merged 5 commits into from
Jan 19, 2016
Merged
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
13 changes: 13 additions & 0 deletions app/CocoaPods/CPPodfileEditorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class CPPodfileEditorViewController: NSViewController, NSTextViewDelegate, SMLAu
guard let podfileVC = podfileViewController, project = podfileVC.userProject else {
return print("CPPodfileEditorViewController is not set up with a PodfileVC in the VC heirarchy.")
}

project.delegate = self

editor.syntaxColoured = true
editor.syntaxDefinitionName = "Podfile"
Expand Down Expand Up @@ -255,3 +257,14 @@ extension EditorLineSelection {
}

}

// MARK: - CPUserProjectDelegate
extension CPPodfileEditorViewController: CPUserProjectDelegate {

func contentDidChangeinUserProject(userProject: CPUserProject) {
editor.string = userProject.contents

// Passing the message on to the syntax checker
syntaxChecker.textDidChange(NSNotification(name: "", object: nil))
}
}
10 changes: 10 additions & 0 deletions app/CocoaPods/CPUserProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@ NS_ASSUME_NONNULL_BEGIN
/// the job of actually representing the Podfile and it's
/// metadata is handled by `CPPodfile` from CocoaPods-ObjC

@class CPUserProject;

@protocol CPUserProjectDelegate <NSObject>

- (void)contentDidChangeinUserProject:(CPUserProject *)userProject;

@end

@interface CPUserProject : NSDocument

@property (nonatomic, weak) id<CPUserProjectDelegate> delegate;

/// The raw string content of the Podfile
@property (strong) NSString * contents;

Expand Down
17 changes: 17 additions & 0 deletions app/CocoaPods/CPUserProject.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,21 @@ - (void)setPodfilePlugins:(NSArray<NSString *> *)podfilePlugins
[self.completionPromise checkForFulfillment];
}

#pragma mark - NSFilePresenter

- (void)presentedItemDidChange
{
NSError *error;
[self readFromURL:self.fileURL ofType:self.fileType error:&error];

if (!error) {
if ( [self.delegate respondsToSelector: @selector(contentDidChangeinUserProject:)] ) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.delegate contentDidChangeinUserProject:self];
});
}
}

}

@end