/PKDeletableTableView.m

http://peacock-gcms.googlecode.com/
Objective C | 172 lines | 93 code | 11 blank | 68 comment | 31 complexity | f64b6d91186558b2d5b513a7d1ef530a MD5 | raw file
  1. //
  2. // This file is part of the application with the working name:
  3. // Peacock
  4. //
  5. // Created by Johan Kool.
  6. // Copyright 2003-2008 Johan Kool.
  7. //
  8. // This program is free software: you can redistribute it and/or modify
  9. // it under the terms of the GNU General Public License as published by
  10. // the Free Software Foundation, either version 3 of the License, or
  11. // (at your option) any later version.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU General Public License
  19. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. //
  21. #import "PKDeletableTableView.h"
  22. @implementation PKDeletableTableView
  23. - (void)bind:(NSString *)binding toObject:(id)observable
  24. withKeyPath:(NSString *)keyPath options:(NSDictionary *)options
  25. {
  26. if ( [binding isEqualToString:@"content"] )
  27. {
  28. tableContentController = observable;
  29. [tableContentKey release];
  30. tableContentKey = [keyPath copy];
  31. }
  32. [super bind:binding toObject:observable withKeyPath:keyPath options:options];
  33. }
  34. - (void)keyDown:(NSEvent *)event{
  35. unichar key = [[event charactersIgnoringModifiers] characterAtIndex:0];
  36. // get flags and strip the lower 16 (device dependant) bits
  37. unsigned int flags = ( [event modifierFlags] & 0x00FF );
  38. if ((key == NSDeleteCharacter) && (flags == 0))
  39. {
  40. if ([self selectedRow] == -1)
  41. {
  42. NSBeep();
  43. }
  44. else
  45. {
  46. NSEnumerator *enumerator = [[tableContentController selectedObjects] objectEnumerator];
  47. id object;
  48. while ((object = [enumerator nextObject]) != nil) {
  49. if ([object respondsToSelector:@selector(selfDeconstruct)]) {
  50. [object performSelector:@selector(selfDeconstruct)];
  51. }
  52. }
  53. [tableContentController removeObjectsAtArrangedObjectIndexes:
  54. [self selectedRowIndexes]];
  55. }
  56. }
  57. else if ((key == NSLeftArrowFunctionKey) && (flags == 0))
  58. {
  59. if (leftSideTableView)
  60. {
  61. if ([leftSideTableView isHiddenOrHasHiddenAncestor]) {
  62. [super keyDown:event];
  63. return;
  64. }
  65. [[leftSideTableView window] makeFirstResponder:leftSideTableView];
  66. if (([leftSideTableView selectedRow] == -1) && ([leftSideTableView numberOfRows] > 0)) {
  67. [leftSideTableView selectRow:0 byExtendingSelection:NO];
  68. }
  69. }
  70. else
  71. {
  72. [super keyDown:event];
  73. }
  74. }
  75. else if ((key == NSRightArrowFunctionKey) && (flags == 0))
  76. {
  77. if (rightSideTableView)
  78. {
  79. if ([rightSideTableView isHiddenOrHasHiddenAncestor]) {
  80. [super keyDown:event];
  81. return;
  82. }
  83. [[rightSideTableView window] makeFirstResponder:rightSideTableView];
  84. if (([rightSideTableView selectedRow] == -1) && ([rightSideTableView numberOfRows] > 0)) {
  85. [rightSideTableView selectRow:0 byExtendingSelection:NO];
  86. }
  87. }
  88. else
  89. {
  90. [super keyDown:event];
  91. }
  92. }
  93. else
  94. {
  95. [super keyDown:event]; // let somebody else handle the event
  96. }
  97. }
  98. - (void)unbind:(NSString *)binding{
  99. [super unbind:binding];
  100. if ( [binding isEqualToString:@"content"] )
  101. {
  102. tableContentController = nil;
  103. [tableContentKey release];
  104. tableContentKey = nil;
  105. }
  106. }
  107. /*
  108. #pragma mark Column Hiding
  109. //column identifier visible index
  110. //column1 identifier1 YES 1
  111. //column2 identifier2 YES 2
  112. //column3 identifier3 NO 3
  113. //column4 identifier4 YES 4
  114. //column5 identifier5 NO 5
  115. //column6 identifier6 YES 6
  116. - (BOOL)allowsColumnHiding;
  117. {
  118. return allowsColumnHiding
  119. }
  120. - (void)setAllowsColumnHiding:(BOOL)boolValue
  121. {
  122. allowsColumnHiding = boolValue;
  123. }
  124. - (void)hideColumnWithIdentifier:(id)identifier
  125. {
  126. NSTableColumn *tableColumn = [self tableColumnWithIdentifier:identifier];
  127. NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:tableColumn, @"tableColumn", index, @"index", nil];
  128. [hiddenColumns addObject:dict];
  129. [self removeTableColumn:tableColumn];
  130. }
  131. - (void)showColumnWithIdentifier:(id)identifier;
  132. - (void)toggleColumnWithIdentifier:(id)identifier
  133. {
  134. if ([self visibleColumnWithIdentifier:identifier]) {
  135. [self hideColumnWithIdentifier:identifier];
  136. } else {
  137. [self showColumnWithIdentifier:identifier];
  138. }
  139. }
  140. - (BOOL)visibleColumnWithIdentifier:(id)identifier
  141. {
  142. int index = [[self tableColumns] indexOfObject:[self tableColumnWithIdentifier:identifier]];
  143. if (index != NSNotFound)
  144. return [[columnVisibility valueForKey:[NSString stringWithFormat:@"%d",index]] boolValue];
  145. return nil;
  146. }
  147. */
  148. @synthesize leftSideTableView;
  149. @synthesize allowsColumnHiding;
  150. @synthesize allowsRowDeletion;
  151. @synthesize tableContentController;
  152. @synthesize tableContentKey;
  153. @synthesize columnVisibility;
  154. @synthesize rightSideTableView;
  155. @end