From 1d5ac4c0f11e84ba5612c04c7984768f797a729c Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 15 Oct 2010 10:40:15 +0000 Subject: =?UTF-8?q?=E2=80=A2=20implemented=20for=20TableStructure's=20sour?= =?UTF-8?q?ce=20table=20the=20possibility=20to=20hide/unhide=20the=20colum?= =?UTF-8?q?ns:=20Key,=20encoding,=20collation,=20comment=20by=20adding=20a?= =?UTF-8?q?=20gear=20menu=20'View=20Columns';=20the=20hide=20status=20will?= =?UTF-8?q?=20be=20saved=20inside=20the=20Pref=20key:=20'NSTableView=20Hid?= =?UTF-8?q?den=20Columns=20SPTableStructureSource'=20-=20this=20implements?= =?UTF-8?q?=20the=20feature=20request=20issue=20868?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPTableStructure.h | 3 +++ Source/SPTableStructure.m | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) (limited to 'Source') diff --git a/Source/SPTableStructure.h b/Source/SPTableStructure.h index d5229153..b6c29f45 100644 --- a/Source/SPTableStructure.h +++ b/Source/SPTableStructure.h @@ -54,6 +54,8 @@ IBOutlet NSSplitView *tablesIndexesSplitView; IBOutlet NSButton *indexesShowButton; + IBOutlet id viewColumnsMenu; + IBOutlet id encodingPopupCell; id databaseDataInstance; @@ -85,6 +87,7 @@ - (IBAction)removeField:(id)sender; - (IBAction)resetAutoIncrement:(id)sender; - (IBAction)showOptimizedFieldType:(id)sender; +- (IBAction)toggleColumnView:(id)sender; - (BOOL)cancelRowEditing; // Index sheet methods diff --git a/Source/SPTableStructure.m b/Source/SPTableStructure.m index a51fa12e..55309cb1 100644 --- a/Source/SPTableStructure.m +++ b/Source/SPTableStructure.m @@ -151,6 +151,24 @@ object:tableDocumentInstance]; [prefs addObserver:indexesController forKeyPath:SPUseMonospacedFonts options:NSKeyValueObservingOptionNew context:NULL]; + + // Init the view column submenu according to saved hidden status; + // menu items are identified by their tag number which represents the initial column index + for(NSMenuItem *item in [viewColumnsMenu itemArray]) [item setState:NSOnState]; // Set all items to NSOnState + for(NSTableColumn *col in [tableSourceView tableColumns]) { + if([col isHidden]) { + if([[col identifier] isEqualToString:@"Key"]) + [[viewColumnsMenu itemWithTag:7] setState:NSOffState]; + else if([[col identifier] isEqualToString:@"encoding"]) + [[viewColumnsMenu itemWithTag:10] setState:NSOffState]; + else if([[col identifier] isEqualToString:@"collation"]) + [[viewColumnsMenu itemWithTag:11] setState:NSOffState]; + else if([[col identifier] isEqualToString:@"comment"]) + [[viewColumnsMenu itemWithTag:12] setState:NSOffState]; + } + } + [tableSourceView reloadData]; + } #pragma mark - @@ -470,6 +488,45 @@ } +/** + * Control the visibility of the columns + */ +- (IBAction)toggleColumnView:(id)sender +{ + + NSString *columnIdentifierName = nil; + + switch([sender tag]) { + case 7: + columnIdentifierName = @"Key"; + break; + case 10: + columnIdentifierName = @"encoding"; + break; + case 11: + columnIdentifierName = @"collation"; + break; + case 12: + columnIdentifierName = @"comment"; + break; + default: + return; + } + + for(NSTableColumn *col in [tableSourceView tableColumns]) { + + if([[col identifier] isEqualToString:columnIdentifierName]) { + [col setHidden:([sender state] == NSOffState) ? NO : YES]; + [sender setState:![sender state]]; + break; + } + + } + + [tableSourceView reloadData]; + +} + /** * Copies a field and goes in edit mode for the new field */ -- cgit v1.2.3