blob: bf821f9bab10756db6bdaab07b41f1923a807133 [file] [log] [blame]
Alexandre Lision8521baa2015-03-13 11:08:00 -04001/*
2 * Copyright (C) 2004-2015 Savoir-Faire Linux Inc.
3 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Additional permission under GNU GPL version 3 section 7:
20 *
21 * If you modify this program, or any covered work, by linking or
22 * combining it with the OpenSSL project's OpenSSL library (or a
23 * modified version of that library), containing parts covered by the
24 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
25 * grants you additional permission to convey the resulting work.
26 * Corresponding Source for a non-source form of such a combination
27 * shall include the source code for the parts of OpenSSL used as well
28 * as that of the covered work.
29 */
Alexandre Lision5855b6a2015-02-03 11:31:05 -050030#import "HistoryViewController.h"
Alexandre Lision5855b6a2015-02-03 11:31:05 -050031
32#import <historymodel.h>
33
34#define COLUMNID_HISTORY @"HistoryColumn" // the single column name in our outline view
35
36
37
38@implementation HistoryViewController
39
40@synthesize treeController;
41
42
43
44- (id)initWithCoder:(NSCoder *)aDecoder
45{
46
47
48 if (self = [super initWithCoder:aDecoder]) {
49 NSLog(@"INIT HVC");
50
51 }
52 return self;
53}
54
55
56
57- (void)awakeFromNib
58{
59 NSLog(@"awakeFromNib");
60
61 treeController = [[QNSTreeController alloc] initWithQModel:HistoryModel::instance()];
62
63 [treeController setAvoidsEmptySelection:NO];
64 [treeController setChildrenKeyPath:@"children"];
65
66 [self.historyView bind:@"content" toObject:treeController withKeyPath:@"arrangedObjects" options:nil];
67 [self.historyView bind:@"sortDescriptors" toObject:treeController withKeyPath:@"sortDescriptors" options:nil];
68 [self.historyView bind:@"selectionIndexPaths" toObject:treeController withKeyPath:@"selectionIndexPaths" options:nil];
69
70 NSInteger idx = [historyView columnWithIdentifier:COLUMNID_HISTORY];
71 [[[[self.historyView tableColumns] objectAtIndex:idx] headerCell] setStringValue:@"Name"];
72
Alexandre Lision4a7b95e2015-02-20 10:06:43 -050073 //HistoryModel::instance()->addBackend(new MinimalHistoryBackend(nil),
74 // LoadOptions::FORCE_ENABLED);
Alexandre Lision5855b6a2015-02-03 11:31:05 -050075
76}
77
78#pragma mark - NSOutlineViewDelegate methods
79
80// -------------------------------------------------------------------------------
81// shouldSelectItem:item
82// -------------------------------------------------------------------------------
83- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item;
84{
85 return YES;
86}
87
88// -------------------------------------------------------------------------------
89// dataCellForTableColumn:tableColumn:item
90// -------------------------------------------------------------------------------
91- (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item
92{
93 NSCell *returnCell = [tableColumn dataCell];
94
95
96 if(item == nil)
97 return returnCell;
98 if ([[tableColumn identifier] isEqualToString:COLUMNID_HISTORY])
99 {
100
101 NSIndexPath* idx = ((NSTreeNode*)item).indexPath;
102 NSUInteger myArray[[idx length]];
103 [idx getIndexes:myArray];
104
105 //NSLog(@"dataCellForTableColumn, indexPath: %d", myArray[0]);
106
107 QModelIndex qIdx = HistoryModel::instance()->index(myArray[0], 0);
108
109 QVariant test = HistoryModel::instance()->data(qIdx, Qt::DisplayRole);
110 }
111
112 return returnCell;
113}
114
115// -------------------------------------------------------------------------------
116// textShouldEndEditing:fieldEditor
117// -------------------------------------------------------------------------------
118- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
119{
120 if ([[fieldEditor string] length] == 0)
121 {
122 // don't allow empty node names
123 return NO;
124 }
125 else
126 {
127 return YES;
128 }
129}
130
131// -------------------------------------------------------------------------------
132// shouldEditTableColumn:tableColumn:item
133//
134// Decide to allow the edit of the given outline view "item".
135// -------------------------------------------------------------------------------
136- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item
137{
138 return NO;
139}
140
141// -------------------------------------------------------------------------------
142// outlineView:willDisplayCell:forTableColumn:item
143// -------------------------------------------------------------------------------
144- (void)outlineView:(NSOutlineView *)olv willDisplayCell:(NSCell*)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
145{
146 if ([[tableColumn identifier] isEqualToString:COLUMNID_HISTORY])
147 {
148 NSIndexPath* idx = ((NSTreeNode*)item).indexPath;
149 NSUInteger myArray[[idx length]];
150 [idx getIndexes:myArray];
151 //NSLog(@"array:%@", idx);
152
153 QModelIndex qIdx;
154 if(idx.length == 2)
155 qIdx = HistoryModel::instance()->index(myArray[1], 0, HistoryModel::instance()->index(myArray[0], 0));
156 else
157 qIdx = HistoryModel::instance()->index(myArray[0], 0);
158
159
160 if(qIdx.isValid())
161 cell.title = HistoryModel::instance()->data(qIdx, Qt::DisplayRole).toString().toNSString();
162 }
163}
164
165// -------------------------------------------------------------------------------
166// outlineViewSelectionDidChange:notification
167// -------------------------------------------------------------------------------
168- (void)outlineViewSelectionDidChange:(NSNotification *)notification
169{
170 // ask the tree controller for the current selection
171 //NSLog(@"outlineViewSelectionDidChange!!");
172}
173
174@end