mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-24 09:59:43 +00:00
More drafting for editing (broken!)
Signed-off-by: michael starke <michael.starke@hicknhack-software.com>
This commit is contained in:
@@ -7,8 +7,8 @@
|
||||
//
|
||||
|
||||
#import "MPDocument.h"
|
||||
#import "KPKEditingSession.h"
|
||||
|
||||
#import "KPKTree.h"
|
||||
#import "KPKNode.h"
|
||||
|
||||
NSString *const MPDocumentDidBeginEditingSelectedItem = @"com.hicknhack.macpass.MPDocumentDidBeginEditingSelectedItem";
|
||||
@@ -17,14 +17,12 @@ NSString *const MPDocumentDidCommitChangesToSelectedItem = @"com.hicknhack.mac
|
||||
|
||||
@implementation MPDocument (EditingSession)
|
||||
|
||||
- (BOOL)isEditing {
|
||||
return (self.editingSession != nil);
|
||||
- (BOOL)hasActiveEditingSession {
|
||||
// return (self.tree.activeEditingSession != nil);
|
||||
// return (self.editingSession != nil);
|
||||
}
|
||||
|
||||
- (void)commitChangesToSelectedItem:(id)sender {
|
||||
if(nil == self.editingSession) {
|
||||
return; // No session to commit
|
||||
}
|
||||
/* Force any lingering updates to be written */
|
||||
/* FIXME explore potential usage of:
|
||||
* NSObject(NSEditorRegistration)
|
||||
@@ -33,20 +31,17 @@ NSString *const MPDocumentDidCommitChangesToSelectedItem = @"com.hicknhack.mac
|
||||
[((NSWindowController *)self.windowControllers.firstObject).window makeFirstResponder:nil];
|
||||
|
||||
/* update the data */
|
||||
[self.editingSession.source commitEditing];
|
||||
if(self.editingSession.source.asEntry) {
|
||||
[self.selectedItem commitEditing];
|
||||
if(self.selectedItem.asEntry) {
|
||||
[self.undoManager setActionName:NSLocalizedString(@"UPDATE_ENTRY", "")];
|
||||
}
|
||||
else if(self.editingSession.source.asGroup) {
|
||||
else if(self.selectedItem.asGroup) {
|
||||
[self.undoManager setActionName:NSLocalizedString(@"UPDATE_GROUP", "")];
|
||||
}
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidCommitChangesToSelectedItem object:self];
|
||||
}
|
||||
|
||||
- (void)cancelChangesToSelectedItem:(id)sender {
|
||||
if(nil == self.editingSession) {
|
||||
return; // No session to cancel
|
||||
}
|
||||
[self.selectedItem cancelEditing];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidCancelChangesToSelectedItem object:self];
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
|
||||
*/
|
||||
@property (nonatomic, readonly) BOOL hasSearch;
|
||||
@property (nonatomic, copy) MPEntrySearchContext *searchContext;
|
||||
@property (nonatomic, strong) NSArray *searchResult;
|
||||
@property (nonatomic, strong, readonly) NSArray *searchResult;
|
||||
|
||||
+ (KPKVersion)versionForFileType:(NSString *)fileType;
|
||||
+ (NSString *)fileTypeForVersion:(KPKVersion)version;
|
||||
@@ -222,8 +222,6 @@ APPKIT_EXTERN NSString *const MPDocumentDidCommitChangesToSelectedItem;
|
||||
|
||||
@interface MPDocument (EditingSession)
|
||||
|
||||
- (BOOL)isEditing;
|
||||
|
||||
#pragma mark Edit Actions
|
||||
- (IBAction)beginEditingSelectedItem:(id)sender;
|
||||
- (IBAction)cancelChangesToSelectedItem:(id)sender;
|
||||
|
||||
@@ -487,11 +487,4 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
|
||||
[[[self view] window] makeFirstResponder:nil];
|
||||
}
|
||||
|
||||
- (void)_didBeginEditingSelectedItem:(NSNotification *)notification {
|
||||
[self _toggleEditing:YES];
|
||||
}
|
||||
|
||||
- (void)_didCancelOrCommitChangesToSelectedItem:(NSNotification *)notification {
|
||||
[self _toggleEditing:NO];
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#import "MPInspectorViewController.h"
|
||||
#import "MPDatePickingViewController.h"
|
||||
#import "MPDocument.h"
|
||||
#import "KPKEditingSession.h"
|
||||
#import "MPEntryInspectorViewController.h"
|
||||
#import "MPGroupInspectorViewController.h"
|
||||
#import "MPIconHelper.h"
|
||||
@@ -108,8 +107,8 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
|
||||
[[self view] layout];
|
||||
|
||||
/* Init edit and cancel buttons */
|
||||
self.editButton.action = @selector(beginEditingSelectedItem:);
|
||||
self.cancelEditButton.action = @selector(cancelChangesToSelectedItem:);
|
||||
self.editButton.action = @selector(beginEditing:);
|
||||
self.cancelEditButton.action = @selector(cancelEditing:);
|
||||
self.cancelEditButton.hidden = YES;
|
||||
|
||||
[self _updateBindings:nil];
|
||||
@@ -121,22 +120,6 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
|
||||
selector:@selector(_didChangeCurrentItem:)
|
||||
name:MPDocumentCurrentItemChangedNotification
|
||||
object:document];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(_didBeginEditingSelectedItem:)
|
||||
name:MPDocumentDidBeginEditingSelectedItem
|
||||
object:document];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(_didCancelOrCommitChangesToSelectedItem:)
|
||||
name:MPDocumentDidCommitChangesToSelectedItem
|
||||
object:document];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(_didCancelOrCommitChangesToSelectedItem:)
|
||||
name:MPDocumentDidCancelChangesToSelectedItem
|
||||
object:document];
|
||||
|
||||
[self.entryViewController regsiterNotificationsForDocument:document];
|
||||
|
||||
[self.entryViewController setupBindings:document];
|
||||
@@ -315,21 +298,21 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
|
||||
[self _updateBindings:document.selectedItem];
|
||||
}
|
||||
|
||||
- (void)_didBeginEditingSelectedItem:(NSNotification *)notification {
|
||||
MPDocument *document = notification.object;
|
||||
self.editButton.action = @selector(commitChangesToSelectedItem:);
|
||||
- (IBAction)beginEditing:(id)sender {
|
||||
self.editButton.action = @selector(commitEditing:);
|
||||
self.editButton.title = NSLocalizedString(@"SAVE", "");
|
||||
self.cancelEditButton.hidden = NO;
|
||||
[self _updateBindings:document.editingSession.node];
|
||||
[self _toggleEditors:YES];
|
||||
}
|
||||
|
||||
- (void)_didCancelOrCommitChangesToSelectedItem:(NSNotification *)notification {
|
||||
MPDocument *document = notification.object;
|
||||
- (IBAction)cancelEditing:(id)sender {
|
||||
self.editButton.title = NSLocalizedString(@"EDIT", "");
|
||||
self.cancelEditButton.hidden = YES;
|
||||
self.editButton.action = @selector(beginEditingSelectedItem:);
|
||||
[self _updateBindings:document.selectedItem];
|
||||
self.editButton.action = @selector(beginEditing:);
|
||||
[self _toggleEditors:NO];
|
||||
}
|
||||
|
||||
- (IBAction)commitEditing:(id)sender {
|
||||
[self cancelEditing:sender];
|
||||
}
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user