bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTableView autosave patches - noattach


From: Marko Mikulicic
Subject: NSTableView autosave patches - noattach
Date: Tue, 21 Aug 2001 15:29:47 -0400
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.3) Gecko/20010801

Hello,

I think the mailinglist system refuses all my messages with attachments.
I'll post the patch inline:

Added column autosave functionality to NSTableView.

Marko

######################### cut here #####################

diff -r -C 2 gui.orig/Headers/gnustep/gui/NSTableView.h gui/Headers/gnustep/gui/NSTableView.h
*** gui.orig/Headers/gnustep/gui/NSTableView.h  Mon Aug 13 11:08:49 2001
--- gui/Headers/gnustep/gui/NSTableView.h       Mon Aug 20 21:22:38 2001
***************
*** 94,97 ****
--- 94,100 ----
       tile at the end */
    BOOL   _tilingDisabled;
+
+   NSString *_autosaveName;
+   BOOL _autosaveTableColumns;
  }

diff -r -C 2 gui.orig/Source/NSTableView.m gui/Source/NSTableView.m
*** gui.orig/Source/NSTableView.m       Mon Aug 13 11:06:53 2001
--- gui/Source/NSTableView.m    Tue Aug 21 13:55:33 2001
***************
*** 43,46 ****
--- 43,48 ----
  static NSNotificationCenter *nc = nil;

+ static NSString *NSTableViewColumnsKey = @"NSTableViewColumns";
+
  /* The selection arrays are stored so that the selected columns/rows
     are always in ascending order.  The following function is used
***************
*** 232,235 ****
--- 234,238 ----
  - (BOOL) _editPreviousEditableCellBeforeRow: (int)row
column: (int)column;
+ - (void) _autosaveTableColumns;
  @end

***************
*** 274,277 ****
--- 277,287 ----
    _cornerView = [GSTableCornerView new];
    [self tile];
+
+   // autosave
+   [nc addObserver: self
+          selector: @selector(_autosaveTableColumns)
+              name: NSTableViewColumnDidResizeNotification
+            object: self];
+
    return self;
  }
***************
*** 287,290 ****
--- 297,301 ----
    TEST_RELEASE (_headerView);
    TEST_RELEASE (_cornerView);
+   TEST_RELEASE (_autosaveName);
    if (_numberOfColumns > 0)
      {
***************
*** 481,484 ****
--- 492,497 ----
      object: self
      userInfo: dict];
+
+   [self _autosaveTableColumns];
  }

***************
*** 2708,2729 ****
  - (NSString *) autosaveName
  {
!   // TODO
!   return nil;
  }

  - (BOOL) autosaveTableColumns
  {
!   // TODO
!   return NO;
  }

  - (void) setAutosaveName: (NSString *)name
  {
!   // TODO
  }

  - (void) setAutosaveTableColumns: (BOOL)flag
  {
!   // TODO
  }

--- 2721,2800 ----
  - (NSString *) autosaveName
  {
!   return _autosaveName;
  }

  - (BOOL) autosaveTableColumns
  {
!   return _autosaveTableColumns;
  }

  - (void) setAutosaveName: (NSString *)name
  {
!   _autosaveName = RETAIN(name);
  }

  - (void) setAutosaveTableColumns: (BOOL)flag
  {
! if(flag == YES && flag != _autosaveTableColumns && _autosaveName != nil) { // read
!     NSUserDefaults    *defaults;
!     NSDictionary      *columnsConfig;
!     NSDictionary        *config;
!
!     defaults  = [NSUserDefaults standardUserDefaults];
!     columnsConfig = [defaults objectForKey: NSTableViewColumnsKey];
!     if(columnsConfig != nil)
!       {
!       config = [columnsConfig objectForKey: _autosaveName];
!       if(config != nil)
!         {
!           NSEnumerator *en = [[config allKeys] objectEnumerator];
!           NSString *colKey;
!           NSArray *colDesc;
!           NSTableColumn *col;
!       
!           while((colKey = [en nextObject]))
!             if((col = [self tableColumnWithIdentifier: colKey]))
!               {
!                 colDesc = [config objectForKey: colKey];
!                 [col setWidth: [[colDesc objectAtIndex: 0] intValue]];
!                 [self moveColumn: [self columnWithIdentifier: colKey]
! toColumn: [[colDesc objectAtIndex: 1] intValue]];
!               }
!         }
!       }
!   }
!   _autosaveTableColumns = flag;
! }
!
! - (void) _autosaveTableColumns
! {
!   if(_autosaveTableColumns && _autosaveName != nil)
!     {
!       NSUserDefaults      *defaults;
!       NSMutableDictionary *columnsConfig;
!       NSMutableDictionary *config;
!       NSTableColumn       *column;
!       id                  en;
!
!       defaults  = [NSUserDefaults standardUserDefaults];
!
! columnsConfig = [[defaults objectForKey: NSTableViewColumnsKey] mutableCopy];
!       if(columnsConfig == nil)
!       columnsConfig = [NSMutableDictionary new];
!
!       config = [[columnsConfig objectForKey: _autosaveName] mutableCopy];
!       if(config == nil)
!       config = [NSMutableDictionary new];
!
!       en = [[self tableColumns] objectEnumerator];
!       while((column = [en nextObject]))
! [config setObject: [NSArray arrayWithObjects: [NSNumber numberWithInt: [column width]], ! [NSNumber numberWithInt: [self columnWithIdentifier: [column identifier]]],nil]
!               forKey: [column identifier]];
!
!       [columnsConfig setObject: config forKey: _autosaveName];
!       [defaults setObject: columnsConfig forKey: NSTableViewColumnsKey];
!       [defaults synchronize];
!     }
  }


######################### cut here #####################




reply via email to

[Prev in Thread] Current Thread [Next in Thread]