Skip to content
This repository was archived by the owner on Nov 4, 2019. It is now read-only.
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
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
- Reed Stoner <kaltekar@gmail.com>
- Aleksandr Kostyutchenko <kossnocorp@gmail.com>
- Edward Patel <edward.patel@gmail.com>
- Jurriaan Pruis <jurriaan@colouredpeople.com>
51 changes: 34 additions & 17 deletions resources/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="296"/>
<integer value="587"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand Down Expand Up @@ -903,6 +903,14 @@
<reference key="NSOnImage" ref="35465992"/>
<reference key="NSMixedImage" ref="502551668"/>
</object>
<object class="NSMenuItem" id="546896684">
<reference key="NSMenu" ref="492985390"/>
<string key="NSTitle">Autosave after losing focus</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="35465992"/>
<reference key="NSMixedImage" ref="502551668"/>
</object>
</object>
</object>
</object>
Expand Down Expand Up @@ -1597,6 +1605,14 @@
</object>
<int key="connectionID">619</int>
</object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">toggleAutoSaveOnLosingFocus:</string>
<reference key="source" ref="1014"/>
<reference key="destination" ref="546896684"/>
</object>
<int key="connectionID">621</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
Expand Down Expand Up @@ -2315,6 +2331,7 @@
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="747518793"/>
<reference ref="546896684"/>
</object>
<reference key="parent" ref="211435410"/>
</object>
Expand Down Expand Up @@ -2404,6 +2421,11 @@
<reference key="object" ref="904850443"/>
<reference key="parent" ref="466310130"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">620</int>
<reference key="object" ref="546896684"/>
<reference key="parent" ref="492985390"/>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
Expand Down Expand Up @@ -2607,6 +2629,7 @@
<string>611.IBPluginDependency</string>
<string>613.IBPluginDependency</string>
<string>616.IBPluginDependency</string>
<string>620.IBPluginDependency</string>
<string>72.IBPluginDependency</string>
<string>72.ImportedFromIB2</string>
<string>73.IBPluginDependency</string>
Expand Down Expand Up @@ -2815,7 +2838,7 @@
<integer value="1"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{{355, 813}, {265, 23}}</string>
<string>{{537, 793}, {274, 43}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
Expand All @@ -2834,6 +2857,7 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<integer value="1"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<integer value="1"/>
Expand Down Expand Up @@ -2877,7 +2901,7 @@
</object>
</object>
<nil key="sourceID"/>
<int key="maxID">619</int>
<int key="maxID">621</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
Expand Down Expand Up @@ -3055,6 +3079,7 @@
<string>focusLocationBar:</string>
<string>goToLine:</string>
<string>reloadStyle:</string>
<string>toggleAutoSaveOnLosingFocus:</string>
<string>toggleSplitView:</string>
<string>toggleStatusBarVisibility:</string>
</object>
Expand All @@ -3065,6 +3090,7 @@
<string>id</string>
<string>id</string>
<string>id</string>
<string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
Expand All @@ -3074,6 +3100,7 @@
<string>focusLocationBar:</string>
<string>goToLine:</string>
<string>reloadStyle:</string>
<string>toggleAutoSaveOnLosingFocus:</string>
<string>toggleSplitView:</string>
<string>toggleStatusBarVisibility:</string>
</object>
Expand All @@ -3091,6 +3118,10 @@
<string key="name">reloadStyle:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">toggleAutoSaveOnLosingFocus:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">toggleSplitView:</string>
<string key="candidateClassName">id</string>
Expand Down Expand Up @@ -3343,20 +3374,6 @@
</object>
<object class="NSMutableArray" key="referencedPartialClassDescriptionsV3.2+">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBPartialClassDescription">
<string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
<string key="minorKey">FScript.framework/Headers/FSNSNumber.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
<string key="minorKey">FScript.framework/Headers/FSNSObject.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
Expand Down
14 changes: 14 additions & 0 deletions src/KAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,20 @@ - (void)applicationWillTerminate:(NSNotification *)aNotification {
// TODO: terminate node thread
}

- (void)applicationWillResignActive:(NSNotification *)notification {
DLOG("Not Active Anymore");
if(kconf_bool(@"editor/save/onlosefocus", NO)) {
DLOG("Saving Documents");
KDocumentController* controller = [KDocumentController kodController];
NSArray* documents = controller.documents;
for(KDocument* document in documents) {
if ([document isDirty] && [document canQuietlySaveDocument]) {
[document saveDocument:nil];
}
}
}
}


- (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames {
//DLOG("application:openFiles:%@", filenames);
Expand Down
1 change: 1 addition & 0 deletions src/KBrowserWindowController.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- (IBAction)toggleSplitView:(id)sender;
- (IBAction)reloadStyle:(id)sender;
- (IBAction)goToLine:(id)sender;
- (IBAction)toggleAutoSaveOnLosingFocus:(id)sender;

- (BOOL)openFileDirectoryAtURL:(NSURL *)absoluteURL error:(NSError **)outError;

Expand Down
12 changes: 12 additions & 0 deletions src/KBrowserWindowController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ - (IBAction)toggleSplitView:(id)sender {
[splitView_ toggleCollapse:sender];
}

- (IBAction)toggleAutoSaveOnLosingFocus:(id)sender {
NSMenuItem *menuItem = (NSMenuItem*) sender;
if([menuItem state] == NSOffState) {
[menuItem setState:NSOnState];
} else {
[menuItem setState:NSOffState];
}
kconf_set_bool(@"editor/save/onlosefocus", [menuItem state] == NSOnState);
}

- (IBAction)reloadStyle:(id)sender {
[[KStyle sharedStyle] reload];
Expand Down Expand Up @@ -251,6 +260,9 @@ - (BOOL)validateMenuItem:(NSMenuItem *)item {
[item setState:!statusBarController_.isHidden];
return YES;
}
} else if (item.action == @selector(toggleAutoSaveOnLosingFocus:)) {
[item setState: kconf_bool(@"editor/save/onlosefocus", NO)];
return YES;
} else {
y = [super validateMenuItem:item];
#if 0
Expand Down
1 change: 1 addition & 0 deletions src/KDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ extern NSString *const KDocumentWillCloseNotification;

@property(assign, nonatomic) BOOL isDirty;
@property BOOL hasMetaRuler;
@property(readonly) BOOL canQuietlySaveDocument;
@property(readonly) BOOL canSaveDocument;
@property(readonly) BOOL hasRemoteSource;
@property(assign) NSStringEncoding textEncoding;
Expand Down
13 changes: 10 additions & 3 deletions src/KDocument.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1627,11 +1627,18 @@ - (BOOL)readFromData:(NSData *)data

// Returns true to indicate a saveDocument: message is allowed, saving the
// document to it's current URL
- (BOOL)canSaveDocument {
- (BOOL)canQuietlySaveDocument {
NSURL *url = self.fileURL;
KURLHandler *urlHandler =
[[KDocumentController kodController] urlHandlerForURL:url];
return ( (urlHandler && [urlHandler canWriteURL:url]) || !url );
[[KDocumentController kodController] urlHandlerForURL:url];
return ( (urlHandler && [urlHandler canWriteURL:url]) );
}

// Returns true to indicate a saveDocument: message is allowed, saving the
// document to it's current URL or that it's OK save to a new file
- (BOOL)canSaveDocument {
NSURL *url = self.fileURL;
return ( [self canQuietlySaveDocument] || !url );
}


Expand Down