Table in fix auto type window now gets updates if something changes in the document while the window is open

This commit is contained in:
michael starke
2014-06-25 20:10:51 +02:00
parent 24e45b74e9
commit b80eb3a9b1

View File

@@ -44,22 +44,15 @@ NSString *const kMPIconCell = @"IconCell";
@interface MPFixAutotypeWindowController () { @interface MPFixAutotypeWindowController () {
NSMutableArray *_elements; NSMutableArray *_elements;
BOOL _didRegisterForUndoRedo;
} }
@end @end
@implementation MPFixAutotypeWindowController @implementation MPFixAutotypeWindowController
- (instancetype)init { - (NSString *)windowNibName {
self = [super initWithWindowNibName:@"FixAutotypeWindow"]; return @"FixAutotypeWindow";
return self;
}
- (instancetype)initWithWindow:(NSWindow *)window {
self = [super initWithWindow:window];
if (self) {
}
return self;
} }
- (void)windowDidLoad { - (void)windowDidLoad {
@@ -67,6 +60,7 @@ NSString *const kMPIconCell = @"IconCell";
} }
- (void)dealloc { - (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self.window orderOut:self]; [self.window orderOut:self];
} }
@@ -78,6 +72,12 @@ NSString *const kMPIconCell = @"IconCell";
if(_workingDocument != workingDocument) { if(_workingDocument != workingDocument) {
_workingDocument = workingDocument; _workingDocument = workingDocument;
} }
if(!_didRegisterForUndoRedo) {
NSUndoManager *manager = [_workingDocument undoManager];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didChangeDocument:) name:NSUndoManagerDidRedoChangeNotification object:manager];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didChangeDocument:) name:NSUndoManagerDidUndoChangeNotification object:manager];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didChangeDocument:) name:NSUndoManagerDidCloseUndoGroupNotification object:manager];
}
_elements = nil; _elements = nil;
[self.tableView reloadData]; [self.tableView reloadData];
} }
@@ -232,5 +232,9 @@ NSString *const kMPIconCell = @"IconCell";
} }
} }
#pragma mark NSUndoManagerNotifications
- (void)_didChangeDocument:(NSNotification *)notification {
[self.tableView reloadData];
}
@end @end