Added dynamic visibility for edit button. Button should only be used if history is enabled and thus will be saved. Otherwise direct editing should be possible

This commit is contained in:
michael starke
2013-10-23 03:01:12 +02:00
parent 620be11f0d
commit 55b4ce648f
8 changed files with 98 additions and 54 deletions

View File

@@ -107,7 +107,7 @@
<object class="NSImageCell" key="NSCell" id="152819686">
<int key="NSCellFlags">134217728</int>
<int key="NSCellFlags2">33554432</int>
<object class="NSCustomResource" key="NSContents" id="202092680">
<object class="NSCustomResource" key="NSContents">
<string key="NSClassName">NSImage</string>
<string key="NSResourceName">NSActionTemplate</string>
</object>
@@ -127,22 +127,24 @@
<object class="NSButton" id="830540359">
<reference key="NSNextResponder" ref="381395509"/>
<int key="NSvFlags">-2147483380</int>
<string key="NSFrame">{{20, 2}, {35, 25}}</string>
<string key="NSFrame">{{197, 2}, {60, 25}}</string>
<reference key="NSSuperview" ref="381395509"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:22</string>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="348505851">
<int key="NSCellFlags">-2080374784</int>
<int key="NSCellFlags2">134217728</int>
<string key="NSContents"/>
<string key="NSContents">Edit</string>
<reference key="NSSupport" ref="240853158"/>
<string key="NSCellIdentifier">_NS:22</string>
<reference key="NSControlView" ref="830540359"/>
<int key="NSButtonFlags">-2034483200</int>
<int key="NSButtonFlags2">163</int>
<reference key="NSNormalImage" ref="202092680"/>
<object class="NSCustomResource" key="NSNormalImage">
<string key="NSClassName">NSImage</string>
<string key="NSResourceName">07_NotepadTemplate</string>
</object>
<string key="NSAlternateContents"/>
<string key="NSKeyEquivalent"/>
<int key="NSPeriodicDelay">400</int>
@@ -164,7 +166,6 @@
<string key="NSFrame">{{0, 30}, {278, 369}}</string>
<reference key="NSSuperview" ref="233312071"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="906788312"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<array class="NSMutableArray" key="NSTabViewItems">
<object class="NSTabViewItem" id="367063082">
@@ -175,7 +176,7 @@
<string key="NSFrameSize">{278, 369}</string>
<reference key="NSSuperview" ref="45251842"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<reference key="NSNextKeyView" ref="381395509"/>
<string key="NSReuseIdentifierKey">_NS:28</string>
</object>
<string key="NSLabel">Entry</string>
@@ -317,6 +318,14 @@
</object>
<int key="connectionID">3095</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">editButton</string>
<reference key="source" ref="1001"/>
<reference key="destination" ref="830540359"/>
</object>
<int key="connectionID">3122</int>
</object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
@@ -610,6 +619,23 @@
<int key="objectID">2930</int>
<reference key="object" ref="381395509"/>
<array class="NSMutableArray" key="children">
<object class="IBNSLayoutConstraint" id="359501674">
<reference key="firstItem" ref="381395509"/>
<int key="firstAttribute">6</int>
<int key="relation">0</int>
<reference key="secondItem" ref="830540359"/>
<int key="secondAttribute">6</int>
<float key="multiplier">1</float>
<object class="IBLayoutConstant" key="constant">
<double key="value">21</double>
</object>
<float key="priority">1000</float>
<reference key="containingView" ref="381395509"/>
<int key="scoringType">3</int>
<float key="scoringTypeFloat">9</float>
<int key="contentType">3</int>
<bool key="placeholder">NO</bool>
</object>
<object class="IBNSLayoutConstraint" id="696932551">
<reference key="firstItem" ref="830540359"/>
<int key="firstAttribute">10</int>
@@ -627,23 +653,6 @@
<int key="contentType">2</int>
<bool key="placeholder">NO</bool>
</object>
<object class="IBNSLayoutConstraint" id="618180937">
<reference key="firstItem" ref="830540359"/>
<int key="firstAttribute">5</int>
<int key="relation">0</int>
<reference key="secondItem" ref="381395509"/>
<int key="secondAttribute">5</int>
<float key="multiplier">1</float>
<object class="IBNSLayoutSymbolicConstant" key="constant">
<double key="value">20</double>
</object>
<float key="priority">1000</float>
<reference key="containingView" ref="381395509"/>
<int key="scoringType">0</int>
<float key="scoringTypeFloat">29</float>
<int key="contentType">3</int>
<bool key="placeholder">NO</bool>
</object>
<object class="IBNSLayoutConstraint" id="574545128">
<reference key="firstItem" ref="381395509"/>
<int key="firstAttribute">8</int>
@@ -877,13 +886,13 @@
<reference key="parent" ref="830540359"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">3111</int>
<reference key="object" ref="618180937"/>
<int key="objectID">3112</int>
<reference key="object" ref="696932551"/>
<reference key="parent" ref="381395509"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">3112</int>
<reference key="object" ref="696932551"/>
<int key="objectID">3123</int>
<reference key="object" ref="359501674"/>
<reference key="parent" ref="381395509"/>
</object>
</array>
@@ -925,8 +934,8 @@
<string key="2929.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<array class="NSMutableArray" key="2930.IBNSViewMetadataConstraints">
<reference ref="574545128"/>
<reference ref="618180937"/>
<reference ref="696932551"/>
<reference ref="359501674"/>
</array>
<boolean value="NO" key="2930.IBNSViewMetadataTranslatesAutoresizingMaskIntoConstraints"/>
<string key="2930.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -968,14 +977,14 @@
<boolean value="NO" key="3109.IBNSViewMetadataTranslatesAutoresizingMaskIntoConstraints"/>
<string key="3109.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="3110.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="3111.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="3112.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="3123.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">3117</int>
<int key="maxID">3123</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -1004,6 +1013,7 @@
<dictionary class="NSMutableDictionary" key="outlets">
<string key="bottomBar">HNHGradientView</string>
<string key="createdTextField">NSTextField</string>
<string key="editButton">NSButton</string>
<string key="itemImageView">MPPopupImageView</string>
<string key="itemNameTextField">NSTextField</string>
<string key="modifiedTextField">NSTextField</string>
@@ -1019,6 +1029,10 @@
<string key="name">createdTextField</string>
<string key="candidateClassName">NSTextField</string>
</object>
<object class="IBToOneOutletInfo" key="editButton">
<string key="name">editButton</string>
<string key="candidateClassName">NSButton</string>
</object>
<object class="IBToOneOutletInfo" key="itemImageView">
<string key="name">itemImageView</string>
<string key="candidateClassName">MPPopupImageView</string>
@@ -1084,10 +1098,10 @@
</object>
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
<object class="NSMutableDictionary" key="IBDocument.LastKnownImageSizes">
<string key="NS.key.0">NSActionTemplate</string>
<string key="NS.object.0">{15, 15}</string>
</object>
<dictionary class="NSMutableDictionary" key="IBDocument.LastKnownImageSizes">
<string key="07_NotepadTemplate">{16, 16}</string>
<string key="NSActionTemplate">{15, 15}</string>
</dictionary>
<bool key="IBDocument.UseAutolayout">YES</bool>
</data>
</archive>

View File

@@ -18,12 +18,6 @@ APPKIT_EXTERN NSString *const MPDocumentDidUnlockDatabaseNotification;
APPKIT_EXTERN NSString *const MPDocumentEntryKey;
APPKIT_EXTERN NSString *const MPDocumentGroupKey;
/*
APPKIT_EXTERN NSString *const MPDocumentDidChangeCurrentItemNotification;
APPKIT_EXTERN NSString *const MPDocumentDidChangeCurrentGroupNotication;
APPKIT_EXTERN NSString *const MPDocumnetDidChangeCurrentEntryNotification;
*/
@class KPKGroup;
@class KPKEntry;
@class KPKTree;
@@ -32,7 +26,6 @@ APPKIT_EXTERN NSString *const MPDocumnetDidChangeCurrentEntryNotification;
@interface MPDocument : NSDocument
/* true, if password and/or keyfile are set */
@property (assign, readonly) BOOL hasPasswordOrKey;
@property (nonatomic, readonly, assign) BOOL encrypted;
@@ -63,21 +56,32 @@ APPKIT_EXTERN NSString *const MPDocumnetDidChangeCurrentEntryNotification;
- (BOOL)unlockWithPassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL error:(NSError *__autoreleasing*)error;
#pragma mark Data Lookup
/*
Returns the entry for the given UUID, nil if none was found
/**
* Finds an entry with the given UUID. If none is found, nil is returned
* @param uuid The UUID for the searched Entry
* @return enty, matching the UUID, nil if none was found
*/
- (KPKEntry *)findEntry:(NSUUID *)uuid;
/**
* Finds the group with the given UUID in this document. If none if found, nil is returned
* @param uuid The UUID of the searched group
* @return matching group, nil if none was found
*/
- (KPKGroup *)findGroup:(NSUUID *)uuid;
- (void)useGroupAsTrash:(KPKGroup *)group;
- (void)useGroupAsTemplate:(KPKGroup *)group;
/**
* Determines, whether the given item is inside the trash.
* The trash group itself is not considered as trashed.
* Hence when sending this message with the trash group as item, NO is returned
* @param item Item to test if trashed or not
* @return YES, if the item is inside the trash, NO otherwise (and if item is trash group)
*/
- (BOOL)isItemTrashed:(id)item;
#pragma mark Export
- (void)writeXMLToURL:(NSURL *)url;
#pragma mark Undo Data Manipulation
/* Undoable Intiialization of elements */
- (KPKGroup *)createGroup:(KPKGroup *)parent;
- (KPKEntry *)createEntry:(KPKGroup *)parent;

View File

@@ -239,7 +239,6 @@ typedef NS_ENUM(NSUInteger, MPAlertType) {
}
#pragma mark Properties
- (KPKVersion)versionForFileType {
return [[self class] versionForFileType:[self fileType]];
}

View File

@@ -406,6 +406,8 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
[_entryViewController updateResponderChain];
[_inspectorViewController updateResponderChain];
[_outlineViewController updateResponderChain];
/* Custom setup after being added to window */
[_inspectorViewController prepareView];
[_outlineViewController showOutline];
}

View File

@@ -245,7 +245,6 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
NSTextField *textField = [view textField];
if(!isModifedColumn && !isNotesColumn) {
/* clean up old formatter that might be left */
NSLog(@"Cleaing formatter. %@", [textField formatter]);
[textField setFormatter:nil];
}
if(isModifedColumn) {

View File

@@ -19,10 +19,12 @@
@property (weak) IBOutlet NSTextField *noSelectionInfo;
@property (weak) IBOutlet MPPopupImageView *itemImageView;
@property (weak) IBOutlet NSTextField *itemNameTextField;
@property (weak) IBOutlet NSButton *editButton;
- (IBAction)showImagePopup:(id)sender;
/* Seperate call to ensure alle registered objects are in place */
- (void)setupNotifications:(NSWindowController *)windowController;
- (void)prepareView;
@end

View File

@@ -16,6 +16,8 @@
#import "NSDate+Humanized.h"
#import "KPKTree.h"
#import "KPKMetaData.h"
#import "HNHGradientView.h"
#import "MPPopupImageView.h"
@@ -35,6 +37,8 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
@property (nonatomic, strong) NSDate *modificationDate;
@property (nonatomic, strong) NSDate *creationDate;
@property (nonatomic, assign) BOOL showEditButton;
@property (nonatomic, assign) NSUInteger activeTab;
@property (weak) IBOutlet NSTabView *tabView;
@@ -52,6 +56,7 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
_activeTab = MPEmptyTab;
_entryViewController = [[MPEntryInspectorViewController alloc] init];
_groupViewController = [[MPGroupInspectorViewController alloc] init];
_showEditButton = NO;
}
return self;
}
@@ -60,6 +65,21 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark Properties
- (void)setActiveTab:(NSUInteger)activeTab {
if(_activeTab != activeTab) {
_activeTab = activeTab;
self.showEditButton = [[[self windowController] document] tree].metaData.isHistoryEnabled;
}
}
- (void)setShowEditButton:(BOOL)showEditButton {
showEditButton &= (self.activeTab == MPEntryTab);
if(_showEditButton != showEditButton) {
_showEditButton = showEditButton;
}
}
- (void)didLoadView {
[_bottomBar setBorderType:HNHBorderTop];
[[self.noSelectionInfo cell] setBackgroundStyle:NSBackgroundStyleRaised];
@@ -94,7 +114,6 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
selector:@selector(_didChangeCurrentItem:)
name:MPCurrentItemChangedNotification
object:document];
[_entryViewController setupBindings:document];
[_groupViewController setupBindings:document];
@@ -145,9 +164,14 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
_popover = nil;
}
#pragma mark -
#pragma mark Item Binding
#pragma mark Bindings
- (void)prepareView {
MPDocument *document = [[self windowController] document];
[self bind:@"showEditButton" toObject:document.tree.metaData withKeyPath:@"isHistoryEnabled" options:nil];
NSDictionary *bindingOptions = @{ NSValueTransformerNameBindingOption : NSNegateBooleanTransformerName };
[self.editButton bind:NSHiddenBinding toObject:self withKeyPath:@"showEditButton" options:bindingOptions];
}
- (void)_updateItemBindings:(id)item {
if(!item) {
@@ -177,6 +201,7 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
- (void)_didChangeCurrentItem:(NSNotification *)notification {
MPDocument *document = [notification object];
if(!document.selectedItem) {
/* show emty tab and hide edit button */
self.activeTab = MPEmptyTab;
}
else {
@@ -191,5 +216,4 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
}
[self _updateItemBindings:document.selectedItem];
}
@end