Permalink
Browse files

Remove custom reopen-files handling. Remove custom is-document-edited…

… status.
  • Loading branch information...
1 parent 0df8e60 commit 51116aad6aa4bf6689a4aab74b7ffa78b05e3bf4 @p2 committed Feb 22, 2013
Showing with 45 additions and 135 deletions.
  1. +10 −67 AppController.m
  2. +20 −28 CSVWindowController.m
  3. +0 −2 MyDocument.h
  4. +12 −33 MyDocument.m
  5. +3 −5 MyDocumentController.m
View
@@ -15,12 +15,10 @@
#import "PPStringFormatManager.h"
#import "PPStringFormat.h"
-#define kDocsOpenAtQuitKey @"DocsOpenAtQuit"
-
@interface AppController ()
-- (void) updateExportFormatSelector;
+- (void)updateExportFormatSelector;
@end
@@ -32,88 +30,35 @@ @implementation AppController
@synthesize exportFormatSelector;
-- (void) dealloc
+- (void)dealloc
{
self.exportAccessoryView = nil;
self.exportHeadersCheckbox = nil;
self.exportFormatSelector = nil;
[super dealloc];
}
-#pragma mark -
-#pragma mark Application Delegate
-- (BOOL) applicationShouldOpenUntitledFile:(NSApplication *)sender
+#pragma mark - Application Delegate
+- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
{
return NO;
}
-- (void) applicationDidFinishLaunching:(NSNotification *)aNotification
+- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
- //NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
-
- // load the open documents, if desired
- if (YES) {
- NSError *error = nil;
-
- /*
- NSArray *lastOpenDocs = [defaults objectForKey:kDocsOpenAtQuitKey];
-
- // open all
- for (NSString *URLString in lastOpenDocs) {
- NSURL *latestPath = [NSURL URLWithString:URLString];
- DLog(@"%@", latestPath);
- if (![[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:latestPath display:YES error:&error]) {
- ALog(@"Failed to open recent document: %@", [error userInfo]);
- }
- } // */
-
- // does not work, so for now we open the most recently opened document
- NSArray *recentURLs = [[NSDocumentController sharedDocumentController] recentDocumentURLs];
- if ([recentURLs count] > 0) {
- NSURL *mostRecentURL = [recentURLs objectAtIndex:0];
- if (![[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:mostRecentURL display:YES error:&error]) {
- ALog(@"Error opening most recent document at %@: %@", mostRecentURL, [error userInfo]);
- }
- }
- }
-
// create empty file if desired
if (NO) {
[[NSDocumentController sharedDocumentController] newDocument:self];
}
}
-/*
-- (NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication *)sender
-{
- // save open document URLs - PROBLEM & TODO: When we arrive here, the document controller already closed all documents
- NSArray *openDocs = [[NSDocumentController sharedDocumentController] documents];
- NSMutableArray *openURLs = [NSMutableArray arrayWithCapacity:[openDocs count]];
-
- if ([openDocs count] > 0) {
- for (NSDocument *document in openDocs) {
- NSURL *url = [document fileURL];
- if (nil != url) {
- [openURLs addObject:[url absoluteString]];
- }
- }
- }
-
- // save to prefs
- DLog(@"%@", openDocs);
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- [defaults setObject:openDocs forKey:kDocsOpenAtQuitKey];
-
- return NSTerminateNow;
-} // */
-#pragma mark -
-# pragma mark Clipboard
-- (IBAction) newDocumentFromClipboard:(id)sender
+# pragma mark - Clipboard
+- (IBAction)newDocumentFromClipboard:(id)sender
{
NSString *pboardData = [[NSPasteboard generalPasteboard] stringForType:NSStringPboardType];
if (pboardData) {
@@ -133,18 +78,16 @@ - (IBAction) newDocumentFromClipboard:(id)sender
// parse string
[myDocument.csvDocument parseCSVString:pboardData error:nil];
- myDocument.documentEdited = YES;
}
else {
NSLog(@"No data is available from the clipboard");
}
}
-#pragma mark -
-#pragma mark Saving
-- (IBAction) exportDocument:(id)sender
+#pragma mark - Saving
+- (IBAction)exportDocument:(id)sender
{
// get active document
NSDocumentController *docController = [NSDocumentController sharedDocumentController];
@@ -194,7 +137,7 @@ - (IBAction) exportDocument:(id)sender
}
-- (void) updateExportFormatSelector
+- (void)updateExportFormatSelector
{
[exportFormatSelector removeAllItems];
for (PPStringFormat *format in [PPStringFormatManager sharedManager].formats) {
View
@@ -170,7 +170,7 @@ - (void) moveColumn:(NSInteger)oldPosition ofTable:(NSTableView *)aTableView to:
}
}
-- (void) didMoveColumn:(NSInteger)oldPosition ofTable:(NSTableView *)aTableView to:(NSInteger)newPosition
+- (void)didMoveColumn:(NSInteger)oldPosition ofTable:(NSTableView *)aTableView to:(NSInteger)newPosition
{
if (oldPosition != newPosition) {
NSUndoManager *undoManager = [document undoManager];
@@ -188,24 +188,21 @@ - (void) didMoveColumn:(NSInteger)oldPosition ofTable:(NSTableView *)aTableView
// propagate changes to CSVDocument
[document.csvDocument setColumnOrderByKeys:arr];
- document.documentEdited = YES;
}
}
-- (IBAction) addCSVRow:(id)sender
+- (IBAction)addCSVRow:(id)sender
{
[document.csvDocument.rowController add:sender];
- document.documentEdited = YES;
}
-- (IBAction) removeCSVRow:(id)sender
+- (IBAction)removeCSVRow:(id)sender
{
[document.csvDocument.rowController remove:sender];
- document.documentEdited = YES;
}
-- (void) removeSelectedRows:(id)sender
+- (void)removeSelectedRows:(id)sender
{
NSIndexSet *indexes = [mainTable selectedRowIndexes];
if ([indexes count] > 0) {
@@ -217,23 +214,22 @@ - (void) removeSelectedRows:(id)sender
}
}
-- (IBAction) restoreOriginalOrder:(id)sender;
+- (IBAction)restoreOriginalOrder:(id)sender;
{
[document restoreOriginalOrder];
}
-- (void) didRestoreOriginalOrder
+- (void)didRestoreOriginalOrder
{
[mainTable setSortDescriptors:nil];
[mainTable setSortDescriptorsWithColumn:nil]; // necessary since we have overridden setSortDescriptors:
[[mainTable headerView] setNeedsDisplay:YES];
}
-#pragma mark -
-#pragma mark TableView Delegate
-- (void) redefineTable
+#pragma mark - TableView Delegate
+- (void)redefineTable
{
// remove OLD columns
NSArray *columnsToRemove = [[mainTable tableColumns] copy];
@@ -284,7 +280,7 @@ - (void) redefineTable
}
}
-- (void) addColumn:(CSVColumn *)newColumn toTable:(NSTableView *)aTableView atPosition:(NSUInteger)position withWidth:(CGFloat)width
+- (void)addColumn:(CSVColumn *)newColumn toTable:(NSTableView *)aTableView atPosition:(NSUInteger)position withWidth:(CGFloat)width
{
if (aTableView == mainTable) {
@@ -326,7 +322,7 @@ - (void) addColumn:(CSVColumn *)newColumn toTable:(NSTableView *)aTableView atPo
}
-- (void) tableViewSelectionDidChange:(NSNotification *)notification
+- (void)tableViewSelectionDidChange:(NSNotification *)notification
{
NSInteger selected_row = [mainTable selectedRow];
if (selected_row >= 0) {
@@ -339,7 +335,7 @@ - (void) tableViewSelectionDidChange:(NSNotification *)notification
}
-- (void) tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *)tableColumn
+- (void)tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *)tableColumn
{
// set sort descriptors
if (mainTable == tableView) {
@@ -349,14 +345,13 @@ - (void) tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *
}
-- (void) tableView:(DataTableView *)tableView didChangeTableColumnState:(DataTableColumn *)tableColumn
+- (void)tableView:(DataTableView *)tableView didChangeTableColumnState:(DataTableColumn *)tableColumn
{
[document.csvDocument setColumnActive:tableColumn.active forColumnKey:[tableColumn identifier]];
- document.documentEdited = YES;
}
-- (void) tableView:(NSTableView*)aTableView mouseDownInHeaderOfTableColumn:(NSTableColumn*)tableColumn
+- (void)tableView:(NSTableView*)aTableView mouseDownInHeaderOfTableColumn:(NSTableColumn*)tableColumn
{
if (0 == [[aTableView tableColumns] indexOfObject:tableColumn]) {
[aTableView setAllowsColumnReordering:NO];
@@ -366,7 +361,7 @@ - (void) tableView:(NSTableView*)aTableView mouseDownInHeaderOfTableColumn:(NSTa
}
}
-- (void) tableView:(NSTableView *)tableView didDragTableColumn:(NSTableColumn *)tableColumn
+- (void)tableView:(NSTableView *)tableView didDragTableColumn:(NSTableColumn *)tableColumn
{
if (mainTable == tableView) {
if (![kHeaderColumnIdentifier isEqualToString:[tableColumn identifier]]) {
@@ -391,7 +386,7 @@ - (void) tableView:(NSTableView *)tableView didDragTableColumn:(NSTableColumn *)
}
}
-- (void) tableViewColumnDidMove:(NSNotification*)aNotification
+- (void)tableViewColumnDidMove:(NSNotification*)aNotification
{
NSDictionary* userInfo = [aNotification userInfo];
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
@@ -433,16 +428,15 @@ - (void) tableView:(NSTableView *)aTableView sortDescriptorsDidChange:(NSArray *
document.dataIsAtOriginalOrder = (nil == currentDescriptors || 0 == [currentDescriptors count]);
}
-- (void) refreshData
+- (void)refreshData
{
[mainTable reloadData];
}
-#pragma mark -
-#pragma mark Toolbar
-- (BOOL) validateToolbarItem:(NSToolbarItem *)theItem
+#pragma mark - Toolbar
+- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
{
if (addRowItem == theItem) {
return [document.csvDocument.rowController canInsert];
@@ -460,20 +454,18 @@ - (BOOL) validateToolbarItem:(NSToolbarItem *)theItem
return YES;
}
if (restoreOrderItem == theItem) {
- return document.documentEdited;
+ return !document.dataIsAtOriginalOrder;
}
return YES;
}
-#pragma mark -
-#pragma mark Inspector
+#pragma mark - Inspector
- (IBAction) showInspector:(id)sender
{
[CSVInspector show:sender];
}
-#pragma mark -
View
@@ -34,7 +34,6 @@
CSVDocument *csvDocument;
BOOL documentLoaded;
- BOOL documentEdited;
BOOL dataIsAtOriginalOrder;
NSUInteger numRowsToExpect;
PPStringFormat *importFormat;
@@ -52,7 +51,6 @@
@property (nonatomic, retain) CSVDocument *csvDocument;
@property (nonatomic, assign) BOOL documentLoaded;
-@property (assign, getter=isDocumentEdited) BOOL documentEdited;
@property (nonatomic, assign) BOOL dataIsAtOriginalOrder;
@property (nonatomic, retain) PPStringFormat *importFormat;
@property (nonatomic, retain) PPStringFormat *exportFormat;
Oops, something went wrong.

0 comments on commit 51116aa

Please sign in to comment.