Skip to content

Commit

Permalink
Add autosave when you press CTRL+X (don't need to save with CMD+S bef…
Browse files Browse the repository at this point in the history
…ore)
  • Loading branch information
Eric Degrange committed Oct 25, 2014
1 parent b994c1b commit d785225
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Support/Xcode/Source/Classes/SFDYCIHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,33 @@
#import <AppKit/AppKit.h>


@interface IDEEditorContext : NSObject
- (id)editor;
@end

@interface IDEEditorDocument : NSDocument
- (void)ide_saveDocument:(id)arg1;
@end

@interface IDEEditorArea : NSObject
- (IDEEditorContext *)lastActiveEditorContext;
@property(readonly) IDEEditorDocument *primaryEditorDocument;
@end

@interface IDENavigatorArea : NSObject
- (id)currentNavigator;
@end

@interface IDEWorkspaceTabController : NSObject
@property (readonly) IDENavigatorArea *navigatorArea;
@end

@interface IDEWorkspaceWindowController : NSObject
@property (readonly) IDEWorkspaceTabController *activeWorkspaceTabController;
- (IDEEditorArea *)editorArea;
@end


@interface SFDYCIHelper : NSObject {

}
Expand Down
22 changes: 22 additions & 0 deletions Support/Xcode/Source/Classes/SFDYCIHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,29 @@ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
}


- (IDEEditorDocument *)currentDocument
{
NSWindowController *currentWindowController = [[NSApp keyWindow] windowController];
if ([currentWindowController isKindOfClass:NSClassFromString(@"IDEWorkspaceWindowController")]) {
IDEWorkspaceWindowController *workspaceController = (IDEWorkspaceWindowController *)currentWindowController;
IDEEditorArea *editorArea = [workspaceController editorArea];
return editorArea.primaryEditorDocument;
}
return nil;
}

- (void)recompileAndInject:(id)sender {

if ([self currentDocument]) {
[[self currentDocument] saveDocument:nil];
}

dispatch_async(dispatch_get_main_queue(), ^{ // This add a little delay for saving, maybe a perform:withDelay will be better ?
[self recompileAndInjectAfterSave: nil];
});
}

- (void)recompileAndInjectAfterSave:(id)sender {
NSLog(@"Yupee :)");
NSResponder * firstResponder = [[NSApp keyWindow] firstResponder];
NSLog(@"firstResponder = %@", firstResponder);
Expand Down

0 comments on commit d785225

Please sign in to comment.