Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 1 | // |
| 2 | // HistoryViewController.m |
| 3 | // Ring |
| 4 | // |
| 5 | // Created by Alexandre Lision on 2015-01-28. |
| 6 | // |
| 7 | // |
| 8 | |
| 9 | #import "HistoryViewController.h" |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 10 | |
| 11 | #import <historymodel.h> |
| 12 | |
| 13 | #define COLUMNID_HISTORY @"HistoryColumn" // the single column name in our outline view |
| 14 | |
| 15 | |
| 16 | |
| 17 | @implementation HistoryViewController |
| 18 | |
| 19 | @synthesize treeController; |
| 20 | |
| 21 | |
| 22 | |
| 23 | - (id)initWithCoder:(NSCoder *)aDecoder |
| 24 | { |
| 25 | |
| 26 | |
| 27 | if (self = [super initWithCoder:aDecoder]) { |
| 28 | NSLog(@"INIT HVC"); |
| 29 | |
| 30 | } |
| 31 | return self; |
| 32 | } |
| 33 | |
| 34 | |
| 35 | |
| 36 | - (void)awakeFromNib |
| 37 | { |
| 38 | NSLog(@"awakeFromNib"); |
| 39 | |
| 40 | treeController = [[QNSTreeController alloc] initWithQModel:HistoryModel::instance()]; |
| 41 | |
| 42 | [treeController setAvoidsEmptySelection:NO]; |
| 43 | [treeController setChildrenKeyPath:@"children"]; |
| 44 | |
| 45 | [self.historyView bind:@"content" toObject:treeController withKeyPath:@"arrangedObjects" options:nil]; |
| 46 | [self.historyView bind:@"sortDescriptors" toObject:treeController withKeyPath:@"sortDescriptors" options:nil]; |
| 47 | [self.historyView bind:@"selectionIndexPaths" toObject:treeController withKeyPath:@"selectionIndexPaths" options:nil]; |
| 48 | |
| 49 | NSInteger idx = [historyView columnWithIdentifier:COLUMNID_HISTORY]; |
| 50 | [[[[self.historyView tableColumns] objectAtIndex:idx] headerCell] setStringValue:@"Name"]; |
| 51 | |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame^] | 52 | //HistoryModel::instance()->addBackend(new MinimalHistoryBackend(nil), |
| 53 | // LoadOptions::FORCE_ENABLED); |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 54 | |
| 55 | } |
| 56 | |
| 57 | #pragma mark - NSOutlineViewDelegate methods |
| 58 | |
| 59 | // ------------------------------------------------------------------------------- |
| 60 | // shouldSelectItem:item |
| 61 | // ------------------------------------------------------------------------------- |
| 62 | - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item; |
| 63 | { |
| 64 | return YES; |
| 65 | } |
| 66 | |
| 67 | // ------------------------------------------------------------------------------- |
| 68 | // dataCellForTableColumn:tableColumn:item |
| 69 | // ------------------------------------------------------------------------------- |
| 70 | - (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 71 | { |
| 72 | NSCell *returnCell = [tableColumn dataCell]; |
| 73 | |
| 74 | |
| 75 | if(item == nil) |
| 76 | return returnCell; |
| 77 | if ([[tableColumn identifier] isEqualToString:COLUMNID_HISTORY]) |
| 78 | { |
| 79 | |
| 80 | NSIndexPath* idx = ((NSTreeNode*)item).indexPath; |
| 81 | NSUInteger myArray[[idx length]]; |
| 82 | [idx getIndexes:myArray]; |
| 83 | |
| 84 | //NSLog(@"dataCellForTableColumn, indexPath: %d", myArray[0]); |
| 85 | |
| 86 | QModelIndex qIdx = HistoryModel::instance()->index(myArray[0], 0); |
| 87 | |
| 88 | QVariant test = HistoryModel::instance()->data(qIdx, Qt::DisplayRole); |
| 89 | } |
| 90 | |
| 91 | return returnCell; |
| 92 | } |
| 93 | |
| 94 | // ------------------------------------------------------------------------------- |
| 95 | // textShouldEndEditing:fieldEditor |
| 96 | // ------------------------------------------------------------------------------- |
| 97 | - (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor |
| 98 | { |
| 99 | if ([[fieldEditor string] length] == 0) |
| 100 | { |
| 101 | // don't allow empty node names |
| 102 | return NO; |
| 103 | } |
| 104 | else |
| 105 | { |
| 106 | return YES; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | // ------------------------------------------------------------------------------- |
| 111 | // shouldEditTableColumn:tableColumn:item |
| 112 | // |
| 113 | // Decide to allow the edit of the given outline view "item". |
| 114 | // ------------------------------------------------------------------------------- |
| 115 | - (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 116 | { |
| 117 | return NO; |
| 118 | } |
| 119 | |
| 120 | // ------------------------------------------------------------------------------- |
| 121 | // outlineView:willDisplayCell:forTableColumn:item |
| 122 | // ------------------------------------------------------------------------------- |
| 123 | - (void)outlineView:(NSOutlineView *)olv willDisplayCell:(NSCell*)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 124 | { |
| 125 | if ([[tableColumn identifier] isEqualToString:COLUMNID_HISTORY]) |
| 126 | { |
| 127 | NSIndexPath* idx = ((NSTreeNode*)item).indexPath; |
| 128 | NSUInteger myArray[[idx length]]; |
| 129 | [idx getIndexes:myArray]; |
| 130 | //NSLog(@"array:%@", idx); |
| 131 | |
| 132 | QModelIndex qIdx; |
| 133 | if(idx.length == 2) |
| 134 | qIdx = HistoryModel::instance()->index(myArray[1], 0, HistoryModel::instance()->index(myArray[0], 0)); |
| 135 | else |
| 136 | qIdx = HistoryModel::instance()->index(myArray[0], 0); |
| 137 | |
| 138 | |
| 139 | if(qIdx.isValid()) |
| 140 | cell.title = HistoryModel::instance()->data(qIdx, Qt::DisplayRole).toString().toNSString(); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | // ------------------------------------------------------------------------------- |
| 145 | // outlineViewSelectionDidChange:notification |
| 146 | // ------------------------------------------------------------------------------- |
| 147 | - (void)outlineViewSelectionDidChange:(NSNotification *)notification |
| 148 | { |
| 149 | // ask the tree controller for the current selection |
| 150 | //NSLog(@"outlineViewSelectionDidChange!!"); |
| 151 | } |
| 152 | |
| 153 | @end |