Added window associations to the auto type fix dialog

Moved handling from app delegate to window controller
fixed isse with wrongfully setting document on fixAutotypeWindow
This commit is contained in:
michael starke
2014-03-28 00:11:53 +01:00
parent 34b8169895
commit e8a0e0f0a3
7 changed files with 122 additions and 63 deletions

View File

@@ -16,27 +16,27 @@
<window title="Fix Autotype" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="F0z-JX-Cv5"> <window title="Fix Autotype" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="F0z-JX-Cv5">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/> <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/> <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="419" height="490"/> <rect key="contentRect" x="196" y="240" width="655" height="630"/>
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1028"/> <rect key="screenRect" x="0.0" y="0.0" width="2560" height="1418"/>
<view key="contentView" id="se5-gp-TjO"> <view key="contentView" id="se5-gp-TjO">
<rect key="frame" x="0.0" y="0.0" width="419" height="490"/> <rect key="frame" x="0.0" y="0.0" width="655" height="630"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<subviews> <subviews>
<scrollView autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="y73-eV-Aoo"> <scrollView autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="y73-eV-Aoo">
<rect key="frame" x="20" y="61" width="379" height="409"/> <rect key="frame" x="20" y="61" width="615" height="456"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<clipView key="contentView" id="Phq-Ux-7lP"> <clipView key="contentView" id="Phq-Ux-7lP">
<rect key="frame" x="1" y="17" width="377" height="391"/> <rect key="frame" x="1" y="17" width="613" height="438"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" alternatingRowBackgroundColors="YES" columnReordering="NO" autosaveColumns="NO" typeSelect="NO" headerView="wul-lK-g0n" id="nVa-6i-9j2"> <tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" alternatingRowBackgroundColors="YES" columnReordering="NO" autosaveColumns="NO" typeSelect="NO" headerView="wul-lK-g0n" id="nVa-6i-9j2">
<rect key="frame" x="0.0" y="0.0" width="377" height="391"/> <rect key="frame" x="0.0" y="0.0" width="613" height="438"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/> <size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/> <color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
<tableColumns> <tableColumns>
<tableColumn identifier="TitleCell" width="116" minWidth="40" maxWidth="1000" id="Khy-1d-ouB"> <tableColumn identifier="TitleCell" width="213.56640625" minWidth="40" maxWidth="1000" id="Khy-1d-ouB">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Title"> <tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Title">
<font key="font" metaFont="smallSystem"/> <font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
@@ -49,7 +49,7 @@
</textFieldCell> </textFieldCell>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/> <tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
</tableColumn> </tableColumn>
<tableColumn identifier="AutotypeCell" width="144.35546875" minWidth="40" maxWidth="1000" id="zVR-Xo-8oY"> <tableColumn identifier="AutotypeCell" width="246.828125" minWidth="40" maxWidth="1000" id="zVR-Xo-8oY">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Keystroke Sequence"> <tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Keystroke Sequence">
<font key="font" metaFont="smallSystem"/> <font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
@@ -62,7 +62,7 @@
</textFieldCell> </textFieldCell>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/> <tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
</tableColumn> </tableColumn>
<tableColumn identifier="IsDefaultCell" width="107.5" minWidth="10" maxWidth="3.4028234663852886e+38" id="0uz-Re-mk3"> <tableColumn identifier="IsDefaultCell" width="143" minWidth="10" maxWidth="3.4028234663852886e+38" id="0uz-Re-mk3">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Is default"> <tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Is default">
<font key="font" metaFont="smallSystem"/> <font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
@@ -85,31 +85,34 @@
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/> <color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</clipView> </clipView>
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="UGM-Rv-JzB"> <scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="UGM-Rv-JzB">
<rect key="frame" x="1" y="391" width="515" height="16"/> <rect key="frame" x="1" y="346" width="467" height="16"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
</scroller> </scroller>
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="W8o-DQ-iiR"> <scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="NO" id="W8o-DQ-iiR">
<rect key="frame" x="-15" y="17" width="16" height="0.0"/> <rect key="frame" x="581" y="17" width="16" height="0.0"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
</scroller> </scroller>
<tableHeaderView key="headerView" id="wul-lK-g0n"> <tableHeaderView key="headerView" id="wul-lK-g0n">
<rect key="frame" x="0.0" y="0.0" width="377" height="17"/> <rect key="frame" x="0.0" y="0.0" width="613" height="17"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
</tableHeaderView> </tableHeaderView>
</scrollView> </scrollView>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="2Ui-5h-uFs"> <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="2Ui-5h-uFs">
<rect key="frame" x="271" y="13" width="134" height="32"/> <rect key="frame" x="507" y="13" width="134" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Clear Autotype" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="sGh-Ec-oIL"> <buttonCell key="cell" type="push" title="Clear Autotype" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="sGh-Ec-oIL">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
<string key="keyEquivalent" base64-UTF8="YES">
DQ
</string>
</buttonCell> </buttonCell>
<connections> <connections>
<action selector="clearAutotype:" target="-2" id="ePc-iQ-f9g"/> <action selector="clearAutotype:" target="-2" id="ePc-iQ-f9g"/>
</connections> </connections>
</button> </button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="iZd-HT-6CT"> <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="iZd-HT-6CT">
<rect key="frame" x="189" y="13" width="82" height="32"/> <rect key="frame" x="425" y="13" width="82" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="KhL-Mg-BJ7"> <buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="KhL-Mg-BJ7">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -122,15 +125,29 @@ Gw
<action selector="orderOut:" target="-1" id="BWI-LN-m2J"/> <action selector="orderOut:" target="-1" id="BWI-LN-m2J"/>
</connections> </connections>
</button> </button>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="8tc-oM-VP4">
<rect key="frame" x="18" y="540" width="619" height="70"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" allowsEditingTextAttributes="YES" id="quD-MA-fPt">
<font key="font" metaFont="smallSystem"/>
<string key="title">Below is a list of all entries, groups and window associations for the database. Normally you should see most of the entries marked as default (YES) and with a keystroke sequence {USERNAME}{TAB}{ENTER}. If the sequence however is {TAB}{USERNAME}{TAB}{ENTER} and default is NO it's highly likely that MacPass (0.4 or 0.4.1) did fuck this up.
To fix this, you can select entries and clear their sequence. You may also customize any sequence to your liking. Inputs are NOT validated.</string>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews> </subviews>
<constraints> <constraints>
<constraint firstAttribute="trailing" secondItem="2Ui-5h-uFs" secondAttribute="trailing" constant="20" id="Enl-NU-6sz"/> <constraint firstAttribute="trailing" secondItem="2Ui-5h-uFs" secondAttribute="trailing" constant="20" id="Enl-NU-6sz"/>
<constraint firstAttribute="trailing" secondItem="8tc-oM-VP4" secondAttribute="trailing" constant="20" id="FWG-XF-hF9"/>
<constraint firstItem="2Ui-5h-uFs" firstAttribute="leading" secondItem="iZd-HT-6CT" secondAttribute="trailing" constant="12" id="K5O-HW-msJ"/> <constraint firstItem="2Ui-5h-uFs" firstAttribute="leading" secondItem="iZd-HT-6CT" secondAttribute="trailing" constant="12" id="K5O-HW-msJ"/>
<constraint firstAttribute="bottom" secondItem="2Ui-5h-uFs" secondAttribute="bottom" constant="20" id="Lfc-Fq-4IC"/> <constraint firstAttribute="bottom" secondItem="2Ui-5h-uFs" secondAttribute="bottom" constant="20" id="Lfc-Fq-4IC"/>
<constraint firstItem="8tc-oM-VP4" firstAttribute="top" secondItem="se5-gp-TjO" secondAttribute="top" constant="20" id="WNW-Xe-7ol"/>
<constraint firstItem="iZd-HT-6CT" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="se5-gp-TjO" secondAttribute="leading" constant="20" symbolic="YES" id="cQL-6C-Wam"/> <constraint firstItem="iZd-HT-6CT" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="se5-gp-TjO" secondAttribute="leading" constant="20" symbolic="YES" id="cQL-6C-Wam"/>
<constraint firstAttribute="trailing" secondItem="y73-eV-Aoo" secondAttribute="trailing" constant="20" id="eEP-Dv-Nxs"/> <constraint firstAttribute="trailing" secondItem="y73-eV-Aoo" secondAttribute="trailing" constant="20" id="eEP-Dv-Nxs"/>
<constraint firstItem="y73-eV-Aoo" firstAttribute="top" secondItem="se5-gp-TjO" secondAttribute="top" constant="20" id="eTt-c8-ztu"/>
<constraint firstItem="iZd-HT-6CT" firstAttribute="centerY" secondItem="2Ui-5h-uFs" secondAttribute="centerY" id="fi6-45-S3y"/> <constraint firstItem="iZd-HT-6CT" firstAttribute="centerY" secondItem="2Ui-5h-uFs" secondAttribute="centerY" id="fi6-45-S3y"/>
<constraint firstItem="8tc-oM-VP4" firstAttribute="leading" secondItem="se5-gp-TjO" secondAttribute="leading" constant="20" id="g7S-IX-9b9"/>
<constraint firstItem="y73-eV-Aoo" firstAttribute="top" secondItem="8tc-oM-VP4" secondAttribute="bottom" constant="23" id="gbK-21-VBE"/>
<constraint firstItem="y73-eV-Aoo" firstAttribute="leading" secondItem="se5-gp-TjO" secondAttribute="leading" constant="20" id="mkc-Fr-gJM"/> <constraint firstItem="y73-eV-Aoo" firstAttribute="leading" secondItem="se5-gp-TjO" secondAttribute="leading" constant="20" id="mkc-Fr-gJM"/>
<constraint firstItem="2Ui-5h-uFs" firstAttribute="top" secondItem="y73-eV-Aoo" secondAttribute="bottom" constant="20" id="xpf-JP-jIQ"/> <constraint firstItem="2Ui-5h-uFs" firstAttribute="top" secondItem="y73-eV-Aoo" secondAttribute="bottom" constant="20" id="xpf-JP-jIQ"/>
</constraints> </constraints>

View File

@@ -35,7 +35,6 @@ FOUNDATION_EXTERN NSString *const MPDidChangeStoredKeyFilesSettings;
- (IBAction)showPasswordCreator:(id)sender; - (IBAction)showPasswordCreator:(id)sender;
- (IBAction)createNewDatabase:(id)sender; - (IBAction)createNewDatabase:(id)sender;
- (IBAction)openDatabase:(id)sender; - (IBAction)openDatabase:(id)sender;
- (IBAction)fixAutotype:(id)sender;
/** /**
* Clears the stored key files for any documents. * Clears the stored key files for any documents.
* @param sender sender of this action * @param sender sender of this action

View File

@@ -31,7 +31,6 @@
#import "MPLockDaemon.h" #import "MPLockDaemon.h"
#import "MPAutotypeDaemon.h" #import "MPAutotypeDaemon.h"
#import "MPDocumentWindowController.h" #import "MPDocumentWindowController.h"
#import "MPFixAutotypeWindowController.h"
#import "MPDockTileHelper.h" #import "MPDockTileHelper.h"
#import "MPTemporaryFileStorageCenter.h" #import "MPTemporaryFileStorageCenter.h"
@@ -52,7 +51,6 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
@property (strong, nonatomic) MPSettingsWindowController *settingsController; @property (strong, nonatomic) MPSettingsWindowController *settingsController;
@property (strong, nonatomic) MPPasswordCreatorViewController *passwordCreatorController; @property (strong, nonatomic) MPPasswordCreatorViewController *passwordCreatorController;
@property (strong) MPFixAutotypeWindowController *fixAutotypeWindowController;
@end @end
@@ -213,14 +211,6 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kMPSettingsKeyRememeberdKeysForDatabases]; [[NSUserDefaults standardUserDefaults] removeObjectForKey:kMPSettingsKeyRememeberdKeysForDatabases];
} }
- (void)fixAutotype:(id)sender {
if(!self.fixAutotypeWindowController) {
self.fixAutotypeWindowController = [[MPFixAutotypeWindowController alloc] init];
}
[self.fixAutotypeWindowController reset];
[self.fixAutotypeWindowController setDocument:[[NSDocumentController sharedDocumentController] currentDocument]];
[[self.fixAutotypeWindowController window] makeKeyAndOrderFront:sender];
}
#pragma mark - #pragma mark -
#pragma mark Private Helper #pragma mark Private Helper

View File

@@ -49,12 +49,16 @@
- (IBAction)pickIcon:(id)sender; - (IBAction)pickIcon:(id)sender;
- (IBAction)pickExpiryDate:(id)sender; - (IBAction)pickExpiryDate:(id)sender;
#pragma mark Helper
- (void)fixAutotype:(id)sender;
#pragma mark View Actions #pragma mark View Actions
- (IBAction)toggleInspector:(id)sender; - (IBAction)toggleInspector:(id)sender;
- (IBAction)focusGroups:(id)sender; - (IBAction)focusGroups:(id)sender;
- (IBAction)focusEntries:(id)sender; - (IBAction)focusEntries:(id)sender;
- (IBAction)focusInspector:(id)sender; - (IBAction)focusInspector:(id)sender;
#pragma mark MPPasswordEditWindowDelegater #pragma mark MPPasswordEditWindowDelegater
- (void)didFinishPasswordEditing:(BOOL)changedPasswordOrKey; - (void)didFinishPasswordEditing:(BOOL)changedPasswordOrKey;

View File

@@ -20,6 +20,7 @@
#import "MPConstants.h" #import "MPConstants.h"
#import "MPSettingsHelper.h" #import "MPSettingsHelper.h"
#import "MPDocumentWindowDelegate.h" #import "MPDocumentWindowDelegate.h"
#import "MPFixAutotypeWindowController.h"
#import "MPContextToolbarButton.h" #import "MPContextToolbarButton.h"
#import "KPKTree.h" #import "KPKTree.h"
@@ -48,6 +49,7 @@ typedef void (^MPPasswordChangedBlock)(void);
@property (strong) MPDocumentWindowDelegate *documentWindowDelegate; @property (strong) MPDocumentWindowDelegate *documentWindowDelegate;
@property (strong) MPPasswordEditWindowController *passwordEditWindowController; @property (strong) MPPasswordEditWindowController *passwordEditWindowController;
@property (strong) MPToolbarDelegate *toolbarDelegate; @property (strong) MPToolbarDelegate *toolbarDelegate;
@property (strong) MPFixAutotypeWindowController *fixAutotypeWindowController;
@property (nonatomic, copy) MPPasswordChangedBlock passwordChangedBlock; @property (nonatomic, copy) MPPasswordChangedBlock passwordChangedBlock;
@@ -238,6 +240,14 @@ typedef void (^MPPasswordChangedBlock)(void);
}]; }];
} }
- (void)fixAutotype:(id)sender {
if(!self.fixAutotypeWindowController) {
self.fixAutotypeWindowController = [[MPFixAutotypeWindowController alloc] init];
}
self.fixAutotypeWindowController.workingDocument = [self document];
[[self.fixAutotypeWindowController window] makeKeyAndOrderFront:sender];
}
- (void)showPasswordInput { - (void)showPasswordInput {
if(!self.passwordInputController) { if(!self.passwordInputController) {
self.passwordInputController = [[MPPasswordInputController alloc] init]; self.passwordInputController = [[MPPasswordInputController alloc] init];

View File

@@ -13,6 +13,7 @@
@interface MPFixAutotypeWindowController : NSWindowController <NSTableViewDataSource, NSTableViewDelegate> @interface MPFixAutotypeWindowController : NSWindowController <NSTableViewDataSource, NSTableViewDelegate>
@property (weak) IBOutlet NSTableView *tableView; @property (weak) IBOutlet NSTableView *tableView;
@property (nonatomic, weak) MPDocument *workingDocument;
/** /**
* Clears the autotype sequences for the selected entries * Clears the autotype sequences for the selected entries
@@ -21,6 +22,4 @@
*/ */
- (IBAction)clearAutotype:(id)sender; - (IBAction)clearAutotype:(id)sender;
- (void)reset;
@end @end

View File

@@ -12,18 +12,15 @@
#import "KPKEntry.h" #import "KPKEntry.h"
#import "KPKGroup.h" #import "KPKGroup.h"
#import "KPKAutotype.h" #import "KPKAutotype.h"
#import "KPKWindowAssociation.h"
NSString *const kMPAutotypeCell = @"AutotypeCell"; NSString *const kMPAutotypeCell = @"AutotypeCell";
NSString *const kMPTitleCell = @"TitleCell"; NSString *const kMPTitleCell = @"TitleCell";
NSString *const kMPIsDefaultCell = @"IsDefaultCell"; NSString *const kMPIsDefaultCell = @"IsDefaultCell";
@interface KPKGroup (Breadcrumb) /* Helper Categries */
- (NSString *)breadcrumb; @implementation KPKGroup (MPFixAutotypeWindowControllerBreadCrumb)
@end
@implementation KPKGroup (Breadcrumb)
- (NSString *)breadcrumb { - (NSString *)breadcrumb {
if(self.parent) { if(self.parent) {
@@ -34,12 +31,20 @@ NSString *const kMPIsDefaultCell = @"IsDefaultCell";
@end @end
@interface MPFixAutotypeWindowController () { @implementation KPKWindowAssociation (MPFixAutotypeWindowControllerQualifedName)
NSMutableArray *_elements;
- (NSString *)qualifedName {
return [[NSString alloc] initWithFormat:@"%@ (%@)", self.windowTitle, self.autotype.entry.title ];
} }
@end @end
@interface MPFixAutotypeWindowController () {
NSMutableArray *_elements;
}
@end
@implementation MPFixAutotypeWindowController @implementation MPFixAutotypeWindowController
- (instancetype)init { - (instancetype)init {
@@ -58,32 +63,39 @@ NSString *const kMPIsDefaultCell = @"IsDefaultCell";
[super windowDidLoad]; [super windowDidLoad];
} }
- (void)reset {
#pragma mark -
#pragma mark Properties
- (void)setWorkingDocument:(MPDocument *)workingDocument {
if(_workingDocument != workingDocument) {
_workingDocument = workingDocument;
}
_elements = nil; _elements = nil;
[self.tableView reloadData]; [self.tableView reloadData];
} }
#pragma mark - #pragma mark -
#pragma mark Actions #pragma mark Actions
- (void)clearAutotype:(id)sender { - (void)clearAutotype:(id)sender {
[[self.workingDocument undoManager] beginUndoGrouping];
MPDocument *document = [self document];
[[document undoManager] beginUndoGrouping];
NSIndexSet *indexes = [self.tableView selectedRowIndexes]; NSIndexSet *indexes = [self.tableView selectedRowIndexes];
MPFixAutotypeWindowController __weak *weakSelf = self; MPFixAutotypeWindowController __weak *weakSelf = self;
[indexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) { [indexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
id item = [weakSelf entriesAndGroups][idx]; id item = [weakSelf entriesAndGroups][idx];
if([item respondsToSelector:@selector(defaultAutoTypeSequence)]) { if([item isKindOfClass:[KPKEntry class]]){
[item autotype].defaultKeystrokeSequence = nil;
}
else if([item isKindOfClass:[KPKGroup class]]) {
[item setDefaultAutoTypeSequence:nil]; [item setDefaultAutoTypeSequence:nil];
} }
else { else {
[item autotype].defaultKeystrokeSequence = nil; [item setKeystrokeSequence:nil];
} }
}]; }];
[[document undoManager] endUndoGrouping]; [[self.workingDocument undoManager] endUndoGrouping];
[[document undoManager] setActionName:@"Clear Autotype"]; [[self.workingDocument undoManager] setActionName:@"Clear Autotype"];
[self.tableView reloadDataForRowIndexes:indexes columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,2)]]; [self.tableView reloadDataForRowIndexes:indexes columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,2)]];
} }
@@ -95,26 +107,48 @@ NSString *const kMPIsDefaultCell = @"IsDefaultCell";
} }
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
id node = [self entriesAndGroups][row]; id item = [self entriesAndGroups][row];
KPKGroup *group;
KPKEntry *entry;
KPKWindowAssociation *association;
if([item isKindOfClass:[KPKEntry class]]) {
entry = item;
}
else if([item isKindOfClass:[KPKGroup class]]) {
group = item;
}
else if([item isKindOfClass:[KPKWindowAssociation class]]) {
association = item;
}
if([[tableColumn identifier] isEqualToString:kMPTitleCell]) { if([[tableColumn identifier] isEqualToString:kMPTitleCell]) {
if( [node respondsToSelector:@selector(title)]) { if(entry) {
return [node title]; return entry.title;
} }
return [node breadcrumb]; if(group) {
return [group breadcrumb];
}
return [association qualifedName];
} }
else if ([[tableColumn identifier] isEqualToString:kMPAutotypeCell]) { else if ([[tableColumn identifier] isEqualToString:kMPAutotypeCell]) {
if([node respondsToSelector:@selector(defaultAutoTypeSequence)]) { if(entry) {
return [node defaultAutoTypeSequence]; return entry.autotype.defaultKeystrokeSequence;
} }
return [[node autotype] defaultKeystrokeSequence]; if(group) {
return group.defaultAutoTypeSequence;
}
return association.keystrokeSequence;
} }
else if([[tableColumn identifier] isEqualToString:kMPIsDefaultCell]) { else if([[tableColumn identifier] isEqualToString:kMPIsDefaultCell]) {
BOOL isDefault = NO; BOOL isDefault = NO;
if([node respondsToSelector:@selector(hasDefaultAutotypeSequence)]) { if(entry) {
isDefault = [node hasDefaultAutotypeSequence]; isDefault = entry.autotype.hasDefaultKeystrokeSequence;
}
else if( group ) {
isDefault = group.hasDefaultAutotypeSequence;
} }
else { else {
isDefault = [[node autotype] hasDefaultKeystrokeSequence]; isDefault = association.hasDefaultKeystrokeSequence;
} }
return isDefault ? @"Yes" : @"No"; return isDefault ? @"Yes" : @"No";
} }
@@ -124,12 +158,16 @@ NSString *const kMPIsDefaultCell = @"IsDefaultCell";
- (void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { - (void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
id item = [self entriesAndGroups][row]; id item = [self entriesAndGroups][row];
if([item respondsToSelector:@selector(defaultAutoTypeSequence)]) {
[item setDefaultAutoTypeSequence:object]; if([item isKindOfClass:[KPKEntry class]]) {
}
else {
[[item autotype] setDefaultKeystrokeSequence:object]; [[item autotype] setDefaultKeystrokeSequence:object];
} }
else if([item isKindOfClass:[KPKGroup class]]) {
[item setDefaultKeystrokeSequence:object];
}
else if([item isKindOfClass:[KPKWindowAssociation class]]) {
[item setKeystrokeSequence:object];
}
} }
#pragma mark - #pragma mark -
@@ -150,8 +188,7 @@ NSString *const kMPIsDefaultCell = @"IsDefaultCell";
- (NSArray *)entriesAndGroups { - (NSArray *)entriesAndGroups {
if(nil == _elements) { if(nil == _elements) {
_elements = [[NSMutableArray alloc] init]; _elements = [[NSMutableArray alloc] init];
MPDocument *document = [self document]; [self flattenGroup:self.workingDocument.root toArray:_elements];
[self flattenGroup:document.root toArray:_elements];
} }
return _elements; return _elements;
} }
@@ -159,7 +196,10 @@ NSString *const kMPIsDefaultCell = @"IsDefaultCell";
- (void)flattenGroup:(KPKGroup *)group toArray:(NSMutableArray *)array { - (void)flattenGroup:(KPKGroup *)group toArray:(NSMutableArray *)array {
[array addObject:group]; [array addObject:group];
[array addObjectsFromArray:group.entries]; for(KPKEntry *entry in group.entries) {
[array addObject:entry];
[array addObjectsFromArray:entry.autotype.associations];
}
for(KPKGroup *childGroup in group.groups) { for(KPKGroup *childGroup in group.groups) {
[self flattenGroup:childGroup toArray:array]; [self flattenGroup:childGroup toArray:array];
} }