mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-29 09:52:03 +00:00
People: Lay out the main window as a triple split view controller
`MainSplitViewController` now serves as the main window's content view controller with three split view items: a sidebar for the source list, a content list for the people table, and a default item for the detail pane. The sidebar enforces minimum and maximum widths and hosts the button bar resize control on the first divider, while the detail pane is collapsible and retains the width required by its fields. Holding priorities direct window width changes to the people table, the split view autosaves its layout, and sidebar and detail toggles animate. The detail pane tracks the people table's selection via `representedObject` so panes remain decoupled, binding its controls in a single column that expands with the pane's width. `PeopleViewController` no longer embeds a nested split view or detail pane, and `MainWindowController` no longer manages split view layout. Updated the class tree in `AppController.j`, the `README` structure table, and checklist item 12 to reflect the new layout.
This commit is contained in:
1 parent
144161cb7e
commit
7650ff6b12
6 files changed
+224
-236
No files matched your search
@@ -10,10 +10,11 @@
|
||||
* AppController (ApplicationLifecycle/)
|
||||
* ├─ SettingsWindowController (ApplicationLifecycle/Settings/)
|
||||
* └─ MainWindowController (PrimaryInterface/MainWindow/, bridge window, toolbar)
|
||||
* ├─ SourceListViewController (Library/Navigation/, view-based CPOutlineView, DnD target)
|
||||
* │ └─ SourceListCellView (Library/Navigation/SourceItemCell/, icon and badge views)
|
||||
* ├─ PeopleViewController (Library/ContentViewer/, bound CPTableView, DnD source)
|
||||
* │ └─ PersonDetailViewController (Library/PersonInspector/, selection bindings)
|
||||
* ├─ MainSplitViewController (PrimaryInterface/MainWindowSplitView/, content view controller)
|
||||
* │ ├─ SourceListViewController (Library/Navigation/, sidebar item, view-based CPOutlineView)
|
||||
* │ │ └─ SourceListCellView (Library/Navigation/SourceItemCell/, icon and badge views)
|
||||
* │ ├─ PeopleViewController (Library/ContentViewer/, content list item, bound CPTableView)
|
||||
* │ └─ PersonDetailViewController (Library/PersonInspector/, default item, representedObject)
|
||||
* ├─ SmartFolderEditorController (Library/Navigation/SmartFolderEditor/, sheet, CPPredicateEditor)
|
||||
* └─ NameSheetController (Library/Navigation/GroupNameSheet/, sheet)
|
||||
*
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* PeopleViewController.j
|
||||
* People
|
||||
*
|
||||
* Right hand side of the main split view. Exercises:
|
||||
* Middle pane of the main window: the people table. Exercises:
|
||||
* - CPArrayController with content, filterPredicate, sortDescriptors and
|
||||
* selection (incl. setSelectedObjects: across content changes)
|
||||
* - cell-based CPTableView fully driven by bindings (value, selection,
|
||||
@@ -11,24 +11,21 @@
|
||||
* autosaved column state, alternating rows, grid lines
|
||||
* - the table as drag source (rows -> source list groups)
|
||||
* - CPPasteboard (copy / paste as tab separated text)
|
||||
* - nested CPSplitView hosting a child view controller (detail pane)
|
||||
*
|
||||
* The array controller's selection is what the detail pane shows; the main split view
|
||||
* controller connects the two.
|
||||
*/
|
||||
|
||||
@import <AppKit/AppKit.j>
|
||||
@import "../Library.j"
|
||||
@import "../PersonInspector/PersonDetailViewController.j"
|
||||
|
||||
@implementation PeopleViewController : CPViewController
|
||||
{
|
||||
Library _library;
|
||||
CPArrayController _arrayController;
|
||||
CPTableView _tableView;
|
||||
CPSplitView _splitView;
|
||||
CPView _tablePane;
|
||||
CPTextField _statusField;
|
||||
PersonDetailViewController _detailController;
|
||||
CPString _contentTitle;
|
||||
float _lastDetailHeight;
|
||||
}
|
||||
|
||||
- (id)initWithLibrary:(Library)aLibrary
|
||||
@@ -37,7 +34,6 @@
|
||||
{
|
||||
_library = aLibrary;
|
||||
_contentTitle = @"";
|
||||
_lastDetailHeight = PersonDetailPreferredHeight;
|
||||
|
||||
_arrayController = [[CPArrayController alloc] init];
|
||||
[_arrayController setEditable:YES];
|
||||
@@ -69,29 +65,7 @@
|
||||
|
||||
- (void)loadView
|
||||
{
|
||||
var frame = CGRectMake(0, 0, 800, 600),
|
||||
view = [[CPView alloc] initWithFrame:frame];
|
||||
|
||||
[view setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
|
||||
|
||||
_splitView = [[CPSplitView alloc] initWithFrame:frame];
|
||||
[_splitView setVertical:NO];
|
||||
[_splitView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
|
||||
[_splitView setDelegate:self];
|
||||
|
||||
_tablePane = [self _buildTablePane:CGRectMake(0, 0, CGRectGetWidth(frame), CGRectGetHeight(frame) - _lastDetailHeight)];
|
||||
[_splitView addSubview:_tablePane];
|
||||
|
||||
_detailController = [[PersonDetailViewController alloc] initWithArrayController:_arrayController];
|
||||
var detailView = [_detailController view];
|
||||
[detailView setFrame:CGRectMake(0, 0, CGRectGetWidth(frame), _lastDetailHeight)];
|
||||
[_splitView addSubview:detailView];
|
||||
|
||||
[view addSubview:_splitView];
|
||||
[self setView:view];
|
||||
|
||||
[_splitView setAutosaveName:@"People.PeopleSplit"];
|
||||
|
||||
[self setView:[self _buildTablePane:CGRectMake(0, 0, 800, 600)]];
|
||||
[self _updateStatus];
|
||||
}
|
||||
|
||||
@@ -283,64 +257,6 @@
|
||||
[[_tableView window] makeFirstResponder:_tableView];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Detail pane
|
||||
|
||||
- (BOOL)isDetailVisible
|
||||
{
|
||||
var detailView = [[_splitView subviews] objectAtIndex:1];
|
||||
return ![_splitView isSubviewCollapsed:detailView] && CGRectGetHeight([detailView frame]) > 0;
|
||||
}
|
||||
|
||||
- (void)toggleDetail
|
||||
{
|
||||
var total = CGRectGetHeight([_splitView bounds]),
|
||||
divider = [_splitView dividerThickness];
|
||||
|
||||
if ([self isDetailVisible])
|
||||
{
|
||||
_lastDetailHeight = CGRectGetHeight([[[_splitView subviews] objectAtIndex:1] frame]);
|
||||
[_splitView setPosition:total ofDividerAtIndex:0];
|
||||
}
|
||||
else
|
||||
[_splitView setPosition:total - divider - MAX(_lastDetailHeight, 150) ofDividerAtIndex:0];
|
||||
}
|
||||
|
||||
// Split view delegate (detail pane)
|
||||
- (BOOL)splitView:(CPSplitView)aSplitView canCollapseSubview:(CPView)aSubview
|
||||
{
|
||||
return aSubview === [[aSplitView subviews] objectAtIndex:1];
|
||||
}
|
||||
|
||||
- (float)splitView:(CPSplitView)aSplitView constrainMinCoordinate:(float)proposedMin ofSubviewAt:(int)anIndex
|
||||
{
|
||||
return 120.0;
|
||||
}
|
||||
|
||||
- (float)splitView:(CPSplitView)aSplitView constrainMaxCoordinate:(float)proposedMax ofSubviewAt:(int)anIndex
|
||||
{
|
||||
return CGRectGetHeight([aSplitView bounds]) - 150.0;
|
||||
}
|
||||
|
||||
- (void)splitView:(CPSplitView)aSplitView resizeSubviewsWithOldSize:(CGSize)oldSize
|
||||
{
|
||||
// Keep the detail pane at a fixed height while the window resizes.
|
||||
var subviews = [aSplitView subviews],
|
||||
top = subviews[0],
|
||||
bottom = subviews[1],
|
||||
size = [aSplitView bounds].size,
|
||||
divider = [aSplitView dividerThickness],
|
||||
bottomHeight = [aSplitView isSubviewCollapsed:bottom] ? 0 : CGRectGetHeight([bottom frame]);
|
||||
|
||||
bottomHeight = MIN(bottomHeight, MAX(0, size.height - divider - 120));
|
||||
|
||||
[top setFrame:CGRectMake(0, 0, size.width, MAX(0, size.height - bottomHeight - divider))];
|
||||
[bottom setFrame:CGRectMake(0, size.height - bottomHeight, size.width, bottomHeight)];
|
||||
|
||||
// A custom resizeSubviewsWithOldSize: bypasses CPSplitView's own layout pass,
|
||||
// so the divider must be told to redraw at the new width.
|
||||
[aSplitView setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Pasteboard helpers
|
||||
|
||||
- (CPString)tabSeparatedStringForPeople:(CPArray)thePeople
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
* PersonDetailViewController.j
|
||||
* People
|
||||
*
|
||||
* Detail pane below the people table. Every control is bound to
|
||||
* arrayController.selection.<key>, which exercises CPControllerSelectionProxy,
|
||||
* placeholder binding options (no selection / multiple values / null) and a
|
||||
* read-only binding to a KVO-dependent derived key ("age").
|
||||
* Detail pane, the third column of the main window. It shows the person in its
|
||||
* representedObject, which the main split view controller binds to the selection of the people
|
||||
* table. Every control is bound to representedObject.<key>, which exercises
|
||||
* CPControllerSelectionProxy through a view controller, placeholder binding options (no
|
||||
* selection / multiple values / null) and a read-only binding to a KVO-dependent derived key
|
||||
* ("age").
|
||||
*
|
||||
* Controls covered: CPTextField (+formatter), CPComboBox, CPPopUpButton
|
||||
* (selectedValue binding), CPDatePicker, CPCheckBox, CPBox.
|
||||
@@ -18,27 +20,31 @@
|
||||
// the row's midline regardless of each control's intrinsic height.
|
||||
var RowHeight = 30.0,
|
||||
RowPitch = 36.0,
|
||||
RowCount = 10,
|
||||
Margin = 12.0,
|
||||
LabelWidth = 90.0,
|
||||
LabelGap = 8.0,
|
||||
FieldWidth = 230.0,
|
||||
ColumnGap = 40.0,
|
||||
ShortFieldWidth = 140.0,
|
||||
TextFieldHeight = 29.0,
|
||||
PopUpHeight = 25.0,
|
||||
DatePickerHeight= 25.0;
|
||||
DatePickerHeight= 25.0,
|
||||
BoxHeight = RowCount * RowPitch + 40.0;
|
||||
|
||||
PersonDetailPreferredHeight = 5 * RowPitch + 52.0;
|
||||
/*
|
||||
The width the pane takes at first and after a reset, and the narrowest it can become. The
|
||||
fields take the width between the two.
|
||||
*/
|
||||
PersonDetailPreferredWidth = 2 * Margin + LabelWidth + LabelGap + FieldWidth + 2 * Margin + 8.0;
|
||||
PersonDetailMinimumWidth = PersonDetailPreferredWidth - FieldWidth + ShortFieldWidth;
|
||||
|
||||
@implementation PersonDetailViewController : CPViewController
|
||||
{
|
||||
CPArrayController _arrayController;
|
||||
}
|
||||
|
||||
- (id)initWithArrayController:(CPArrayController)anArrayController
|
||||
- (id)init
|
||||
{
|
||||
if (self = [super initWithCibName:nil bundle:nil])
|
||||
_arrayController = anArrayController;
|
||||
|
||||
return self;
|
||||
return [super initWithCibName:nil bundle:nil];
|
||||
}
|
||||
|
||||
- (CPDictionary)_placeholderOptions
|
||||
@@ -49,77 +55,78 @@ PersonDetailPreferredHeight = 5 * RowPitch + 52.0;
|
||||
@"", CPNullPlaceholderBindingOption];
|
||||
}
|
||||
|
||||
- (void)_bind:(CPView)aControl binding:(CPString)aBinding key:(CPString)aKey options:(CPDictionary)options
|
||||
{
|
||||
[aControl bind:aBinding toObject:self withKeyPath:@"representedObject." + aKey options:options];
|
||||
}
|
||||
|
||||
- (void)loadView
|
||||
{
|
||||
var frame = CGRectMake(0, 0, 800, PersonDetailPreferredHeight),
|
||||
var frame = CGRectMake(0, 0, PersonDetailPreferredWidth, BoxHeight + 2 * 8.0),
|
||||
view = [[CPView alloc] initWithFrame:frame];
|
||||
|
||||
[view setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
|
||||
|
||||
var box = [[CPBox alloc] initWithFrame:CGRectInset(frame, 12, 8)];
|
||||
var box = [[CPBox alloc] initWithFrame:CGRectMake(Margin, 8.0, CGRectGetWidth(frame) - 2 * Margin, BoxHeight)];
|
||||
[box setTitle:@"Selected Person"];
|
||||
[box setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
|
||||
[box setAutoresizingMask:CPViewWidthSizable | CPViewMaxYMargin];
|
||||
[view addSubview:box];
|
||||
|
||||
var content = [box contentView],
|
||||
options = [self _placeholderOptions],
|
||||
left = 12.0,
|
||||
right = left + LabelWidth + LabelGap + FieldWidth + ColumnGap;
|
||||
x = Margin,
|
||||
fieldX = x + LabelWidth + LabelGap,
|
||||
row = 0;
|
||||
|
||||
// ---- Left column
|
||||
[[self _textFieldInRow:0 column:left label:@"First Name:" in:content]
|
||||
bind:CPValueBinding toObject:_arrayController withKeyPath:@"selection.firstName" options:options];
|
||||
[self _bind:[self _textFieldInRow:row++ label:@"First Name:" in:content] binding:CPValueBinding key:@"firstName" options:options];
|
||||
[self _bind:[self _textFieldInRow:row++ label:@"Last Name:" in:content] binding:CPValueBinding key:@"lastName" options:options];
|
||||
[self _bind:[self _textFieldInRow:row++ label:@"Email:" in:content] binding:CPValueBinding key:@"email" options:options];
|
||||
|
||||
[[self _textFieldInRow:1 column:left label:@"Last Name:" in:content]
|
||||
bind:CPValueBinding toObject:_arrayController withKeyPath:@"selection.lastName" options:options];
|
||||
|
||||
[[self _textFieldInRow:2 column:left label:@"Email:" in:content]
|
||||
bind:CPValueBinding toObject:_arrayController withKeyPath:@"selection.email" options:options];
|
||||
|
||||
[self _labelInRow:3 column:left title:@"Department:" in:content];
|
||||
[self _labelInRow:row title:@"Department:" in:content];
|
||||
var department = [[CPPopUpButton alloc] initWithFrame:CGRectMakeZero() pullsDown:NO];
|
||||
[department addItemsWithTitles:LibraryDepartments];
|
||||
[self _place:department row:3 x:left + LabelWidth + LabelGap width:FieldWidth height:PopUpHeight in:content];
|
||||
[department bind:CPSelectedValueBinding toObject:_arrayController withKeyPath:@"selection.department" options:nil];
|
||||
[self _place:department row:row++ x:fieldX width:FieldWidth height:PopUpHeight in:content];
|
||||
[department setAutoresizingMask:CPViewWidthSizable];
|
||||
[self _bind:department binding:CPSelectedValueBinding key:@"department" options:nil];
|
||||
|
||||
var manager = [CPCheckBox checkBoxWithTitle:@"Manager"];
|
||||
[manager setAllowsMixedState:YES];
|
||||
[manager sizeToFit];
|
||||
[self _place:manager row:4 x:left + LabelWidth + LabelGap width:CGRectGetWidth([manager frame]) height:CGRectGetHeight([manager frame]) in:content];
|
||||
[manager bind:CPValueBinding toObject:_arrayController withKeyPath:@"selection.isManager" options:nil];
|
||||
[self _place:manager row:row++ x:fieldX width:CGRectGetWidth([manager frame]) height:CGRectGetHeight([manager frame]) in:content];
|
||||
[self _bind:manager binding:CPValueBinding key:@"isManager" options:nil];
|
||||
|
||||
// ---- Right column
|
||||
[self _labelInRow:0 column:right title:@"City:" in:content];
|
||||
[self _labelInRow:row title:@"City:" in:content];
|
||||
var city = [[CPComboBox alloc] initWithFrame:CGRectMakeZero()];
|
||||
[city addItemsWithObjectValues:LibraryCities];
|
||||
[city setEditable:YES];
|
||||
[self _place:city row:0 x:right + LabelWidth + LabelGap width:FieldWidth height:TextFieldHeight in:content];
|
||||
[city bind:CPValueBinding toObject:_arrayController withKeyPath:@"selection.city" options:options];
|
||||
[self _place:city row:row++ x:fieldX width:FieldWidth height:TextFieldHeight in:content];
|
||||
[city setAutoresizingMask:CPViewWidthSizable];
|
||||
[self _bind:city binding:CPValueBinding key:@"city" options:options];
|
||||
|
||||
[self _labelInRow:1 column:right title:@"Birth Date:" in:content];
|
||||
var birthDate = [[CPDatePicker alloc] initWithFrame:CGRectMake(0, 0, 140, DatePickerHeight)];
|
||||
[self _labelInRow:row title:@"Birth Date:" in:content];
|
||||
var birthDate = [[CPDatePicker alloc] initWithFrame:CGRectMake(0, 0, ShortFieldWidth, DatePickerHeight)];
|
||||
[birthDate setDatePickerStyle:CPTextFieldAndStepperDatePickerStyle];
|
||||
[birthDate setDatePickerElements:CPYearMonthDayDatePickerElementFlag];
|
||||
[self _place:birthDate row:1 x:right + LabelWidth + LabelGap width:140 height:CGRectGetHeight([birthDate frame]) in:content];
|
||||
[birthDate bind:CPValueBinding toObject:_arrayController withKeyPath:@"selection.birthDate" options:nil];
|
||||
[self _place:birthDate row:row++ x:fieldX width:ShortFieldWidth height:CGRectGetHeight([birthDate frame]) in:content];
|
||||
[self _bind:birthDate binding:CPValueBinding key:@"birthDate" options:nil];
|
||||
|
||||
[self _labelInRow:2 column:right title:@"Age:" in:content];
|
||||
var age = [self _valueLabelInRow:2 x:right + LabelWidth + LabelGap in:content];
|
||||
[age bind:CPValueBinding toObject:_arrayController withKeyPath:@"selection.age" options:options];
|
||||
[self _labelInRow:row title:@"Age:" in:content];
|
||||
[self _bind:[self _valueLabelInRow:row++ in:content] binding:CPValueBinding key:@"age" options:options];
|
||||
|
||||
var salary = [self _textFieldInRow:3 column:right label:@"Salary:" in:content],
|
||||
var salary = [self _textFieldInRow:row++ label:@"Salary:" in:content],
|
||||
numberFormatter = [[CPNumberFormatter alloc] init];
|
||||
[numberFormatter setNumberStyle:CPNumberFormatterDecimalStyle];
|
||||
[salary setFormatter:numberFormatter];
|
||||
[salary setAlignment:CPRightTextAlignment];
|
||||
[salary setFrameSize:CGSizeMake(140, CGRectGetHeight([salary frame]))];
|
||||
[salary bind:CPValueBinding toObject:_arrayController withKeyPath:@"selection.salary" options:options];
|
||||
[salary setFrameSize:CGSizeMake(ShortFieldWidth, CGRectGetHeight([salary frame]))];
|
||||
[salary setAutoresizingMask:CPViewNotSizable];
|
||||
[self _bind:salary binding:CPValueBinding key:@"salary" options:options];
|
||||
|
||||
[self _labelInRow:4 column:right title:@"Record ID:" in:content];
|
||||
var uid = [self _valueLabelInRow:4 x:right + LabelWidth + LabelGap in:content];
|
||||
[self _labelInRow:row title:@"Record ID:" in:content];
|
||||
var uid = [self _valueLabelInRow:row++ in:content];
|
||||
[uid setSelectable:YES];
|
||||
[uid setTextColor:[CPColor secondaryLabelColor]];
|
||||
[uid bind:CPValueBinding toObject:_arrayController withKeyPath:@"selection.uid" options:options];
|
||||
[self _bind:uid binding:CPValueBinding key:@"uid" options:options];
|
||||
|
||||
[self setView:view];
|
||||
}
|
||||
@@ -140,37 +147,39 @@ PersonDetailPreferredHeight = 5 * RowPitch + 52.0;
|
||||
[aSuperview addSubview:aView];
|
||||
}
|
||||
|
||||
- (CPTextField)_labelInRow:(int)aRow column:(float)anX title:(CPString)aTitle in:(CPView)aSuperview
|
||||
- (CPTextField)_labelInRow:(int)aRow title:(CPString)aTitle in:(CPView)aSuperview
|
||||
{
|
||||
var label = [CPTextField labelWithTitle:aTitle];
|
||||
|
||||
[label setAlignment:CPRightTextAlignment];
|
||||
[label setVerticalAlignment:CPCenterVerticalTextAlignment];
|
||||
[self _place:label row:aRow x:anX width:LabelWidth height:RowHeight in:aSuperview];
|
||||
[self _place:label row:aRow x:Margin width:LabelWidth height:RowHeight in:aSuperview];
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
- (CPTextField)_valueLabelInRow:(int)aRow x:(float)anX in:(CPView)aSuperview
|
||||
- (CPTextField)_valueLabelInRow:(int)aRow in:(CPView)aSuperview
|
||||
{
|
||||
var label = [CPTextField labelWithTitle:@""];
|
||||
|
||||
[label setVerticalAlignment:CPCenterVerticalTextAlignment];
|
||||
[self _place:label row:aRow x:anX + 4 width:FieldWidth - 4 height:RowHeight in:aSuperview];
|
||||
[self _place:label row:aRow x:Margin + LabelWidth + LabelGap + 4 width:FieldWidth - 4 height:RowHeight in:aSuperview];
|
||||
[label setAutoresizingMask:CPViewWidthSizable];
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
- (CPTextField)_textFieldInRow:(int)aRow column:(float)anX label:(CPString)aTitle in:(CPView)aSuperview
|
||||
- (CPTextField)_textFieldInRow:(int)aRow label:(CPString)aTitle in:(CPView)aSuperview
|
||||
{
|
||||
[self _labelInRow:aRow column:anX title:aTitle in:aSuperview];
|
||||
[self _labelInRow:aRow title:aTitle in:aSuperview];
|
||||
|
||||
var field = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
|
||||
|
||||
[field setEditable:YES];
|
||||
[field setBezeled:YES];
|
||||
[field setVerticalAlignment:CPCenterVerticalTextAlignment];
|
||||
[self _place:field row:aRow x:anX + LabelWidth + LabelGap width:FieldWidth height:TextFieldHeight in:aSuperview];
|
||||
[self _place:field row:aRow x:Margin + LabelWidth + LabelGap width:FieldWidth height:TextFieldHeight in:aSuperview];
|
||||
[field setAutoresizingMask:CPViewWidthSizable];
|
||||
|
||||
return field;
|
||||
}
|
||||
|
||||
@@ -3,14 +3,13 @@
|
||||
* People
|
||||
*
|
||||
* Owns the full-platform (bridge) main window. Instantiates the sidebar and
|
||||
* people view controllers and loads their views into a vertical CPSplitView.
|
||||
* Exercises:
|
||||
* people view controllers and hands them to MainSplitViewController, the window's
|
||||
* content view controller, which lays out the three panes. Exercises:
|
||||
* - CPWindowController created in code, window delegate + responder chain
|
||||
* target for menu / toolbar / button bar actions (sent to nil)
|
||||
* - CPToolbar with standard image items, whose glyphs come from the asset
|
||||
* catalog with a dark variant, and a view item (CPSearchField)
|
||||
* - CPSplitView delegate API: min/max constraints, collapsing, custom
|
||||
* resizeSubviewsWithOldSize:, autosave, button bar resize control
|
||||
* - CPWindow content view controller
|
||||
* - one -validateUserInterfaceItem: for the menus and the toolbar items
|
||||
* - CPAlert as a sheet
|
||||
* - CPPasteboard copy / paste
|
||||
@@ -20,6 +19,7 @@
|
||||
@import "../../Library/Library.j"
|
||||
@import "../../Library/Navigation/SourceListViewController.j"
|
||||
@import "../../Library/ContentViewer/PeopleViewController.j"
|
||||
@import "../MainWindowSplitView/MainSplitViewController.j"
|
||||
@import "../../Library/Navigation/SmartFolderEditor/SmartFolderEditorController.j"
|
||||
@import "../../Library/Navigation/GroupNameSheet/NameSheetController.j"
|
||||
@import "../../ApplicationLifecycle/Settings/SettingsWindowController.j"
|
||||
@@ -33,9 +33,6 @@ var ToolbarSidebarIdentifier = @"SidebarItem",
|
||||
ToolbarNewPersonIdentifier = @"NewPersonItem",
|
||||
ToolbarAllPeopleIdentifier = @"ShowAllPeopleItem",
|
||||
ToolbarItemImageSize = CGSizeMake(32.0, 32.0),
|
||||
SidebarDefaultWidth = 230.0,
|
||||
SidebarMinWidth = 160.0,
|
||||
SidebarMaxWidth = 420.0,
|
||||
ResetAlertResetTag = 1001,
|
||||
ResetAlertCancelTag = 1002;
|
||||
|
||||
@@ -43,7 +40,7 @@ var ToolbarSidebarIdentifier = @"SidebarItem",
|
||||
{
|
||||
Library _library;
|
||||
|
||||
CPSplitView _splitView;
|
||||
MainSplitViewController _splitViewController;
|
||||
SourceListViewController _sourceListController;
|
||||
PeopleViewController _peopleController;
|
||||
SmartFolderEditorController _folderEditor;
|
||||
@@ -52,7 +49,6 @@ var ToolbarSidebarIdentifier = @"SidebarItem",
|
||||
CPSearchField _searchField;
|
||||
CPPredicate _searchPredicate;
|
||||
id _selectedItem;
|
||||
float _lastSidebarWidth;
|
||||
}
|
||||
|
||||
- (id)initWithLibrary:(Library)aLibrary
|
||||
@@ -62,7 +58,6 @@ var ToolbarSidebarIdentifier = @"SidebarItem",
|
||||
if (self = [super initWithWindow:window])
|
||||
{
|
||||
_library = aLibrary;
|
||||
_lastSidebarWidth = SidebarDefaultWidth;
|
||||
|
||||
[window setDelegate:self];
|
||||
[window setTitle:@"Smart Folders Demo"];
|
||||
@@ -72,8 +67,10 @@ var ToolbarSidebarIdentifier = @"SidebarItem",
|
||||
|
||||
_peopleController = [[PeopleViewController alloc] initWithLibrary:_library];
|
||||
|
||||
_splitViewController = [[MainSplitViewController alloc] initWithSourceListController:_sourceListController peopleController:_peopleController];
|
||||
|
||||
[self _buildToolbar];
|
||||
[self _buildSplitView];
|
||||
[window setContentViewController:_splitViewController];
|
||||
|
||||
[[CPNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(libraryDidChange:)
|
||||
@@ -88,30 +85,6 @@ var ToolbarSidebarIdentifier = @"SidebarItem",
|
||||
|
||||
// ---------------------------------------------------------------- Interface
|
||||
|
||||
- (void)_buildSplitView
|
||||
{
|
||||
var contentView = [[self window] contentView],
|
||||
bounds = [contentView bounds];
|
||||
|
||||
_splitView = [[CPSplitView alloc] initWithFrame:bounds];
|
||||
[_splitView setVertical:YES];
|
||||
[_splitView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
|
||||
[_splitView setDelegate:self];
|
||||
|
||||
var sidebar = [_sourceListController view],
|
||||
people = [_peopleController view];
|
||||
|
||||
[sidebar setFrame:CGRectMake(0, 0, SidebarDefaultWidth, CGRectGetHeight(bounds))];
|
||||
[people setFrame:CGRectMake(SidebarDefaultWidth + 1, 0, MAX(0, CGRectGetWidth(bounds) - SidebarDefaultWidth - 1), CGRectGetHeight(bounds))];
|
||||
|
||||
[_splitView addSubview:sidebar];
|
||||
[_splitView addSubview:people];
|
||||
[contentView addSubview:_splitView];
|
||||
|
||||
[_splitView setButtonBar:[_sourceListController buttonBar] forDividerAtIndex:0];
|
||||
[_splitView setAutosaveName:@"People.MainSplit"];
|
||||
}
|
||||
|
||||
- (void)_buildToolbar
|
||||
{
|
||||
_searchField = [[CPSearchField alloc] initWithFrame:CGRectMake(0, 0, 220, 30)];
|
||||
@@ -211,44 +184,11 @@ var ToolbarSidebarIdentifier = @"SidebarItem",
|
||||
[anItem setAction:anAction];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Split view delegate (sidebar)
|
||||
|
||||
- (BOOL)splitView:(CPSplitView)aSplitView canCollapseSubview:(CPView)aSubview
|
||||
{
|
||||
return aSubview === [_sourceListController view];
|
||||
}
|
||||
|
||||
- (float)splitView:(CPSplitView)aSplitView constrainMinCoordinate:(float)proposedMin ofSubviewAt:(int)anIndex
|
||||
{
|
||||
return SidebarMinWidth;
|
||||
}
|
||||
|
||||
- (float)splitView:(CPSplitView)aSplitView constrainMaxCoordinate:(float)proposedMax ofSubviewAt:(int)anIndex
|
||||
{
|
||||
return MIN(SidebarMaxWidth, CGRectGetWidth([aSplitView bounds]) - 300.0);
|
||||
}
|
||||
|
||||
- (void)splitView:(CPSplitView)aSplitView resizeSubviewsWithOldSize:(CGSize)oldSize
|
||||
{
|
||||
// Sidebar keeps its width, the people pane takes up the rest.
|
||||
var subviews = [aSplitView subviews],
|
||||
sidebar = subviews[0],
|
||||
main = subviews[1],
|
||||
size = [aSplitView bounds].size,
|
||||
divider = [aSplitView dividerThickness],
|
||||
sidebarWidth = [aSplitView isSubviewCollapsed:sidebar] ? 0 : CGRectGetWidth([sidebar frame]);
|
||||
|
||||
[sidebar setFrame:CGRectMake(0, 0, sidebarWidth, size.height)];
|
||||
[main setFrame:CGRectMake(sidebarWidth + divider, 0, MAX(0, size.width - sidebarWidth - divider), size.height)];
|
||||
|
||||
// Custom layout bypasses CPSplitView's own pass: redraw the divider.
|
||||
[aSplitView setNeedsDisplay:YES];
|
||||
}
|
||||
// ---------------------------------------------------------------- Panes
|
||||
|
||||
- (BOOL)isSidebarVisible
|
||||
{
|
||||
var sidebar = [_sourceListController view];
|
||||
return ![_splitView isSubviewCollapsed:sidebar] && CGRectGetWidth([sidebar frame]) > 0;
|
||||
return [_splitViewController isSidebarVisible];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Source list delegate
|
||||
@@ -488,18 +428,12 @@ var ToolbarSidebarIdentifier = @"SidebarItem",
|
||||
|
||||
- (void)toggleSidebar:(id)sender
|
||||
{
|
||||
if ([self isSidebarVisible])
|
||||
{
|
||||
_lastSidebarWidth = CGRectGetWidth([[_sourceListController view] frame]);
|
||||
[_splitView setPosition:0 ofDividerAtIndex:0];
|
||||
}
|
||||
else
|
||||
[_splitView setPosition:MAX(_lastSidebarWidth, SidebarMinWidth) ofDividerAtIndex:0];
|
||||
[_splitViewController toggleSidebar:sender];
|
||||
}
|
||||
|
||||
- (void)toggleDetail:(id)sender
|
||||
{
|
||||
[_peopleController toggleDetail];
|
||||
[_splitViewController toggleDetail:sender];
|
||||
}
|
||||
|
||||
- (void)showAllPeople:(id)sender
|
||||
@@ -558,10 +492,7 @@ var ToolbarSidebarIdentifier = @"SidebarItem",
|
||||
}];
|
||||
[toolbar setVisible:YES];
|
||||
|
||||
[_splitView setPosition:SidebarDefaultWidth ofDividerAtIndex:0];
|
||||
|
||||
if (![_peopleController isDetailVisible])
|
||||
[_peopleController toggleDetail];
|
||||
[_splitViewController restoreDefaultLayout];
|
||||
|
||||
[SettingsWindowController resetAppearance];
|
||||
}
|
||||
@@ -619,7 +550,7 @@ var ToolbarSidebarIdentifier = @"SidebarItem",
|
||||
break;
|
||||
|
||||
case @selector(toggleDetail:):
|
||||
[anItem setTitle:[_peopleController isDetailVisible] ? @"Hide Details" : @"Show Details"];
|
||||
[anItem setTitle:[_splitViewController isDetailVisible] ? @"Hide Details" : @"Show Details"];
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* MainSplitViewController.j
|
||||
* People
|
||||
*
|
||||
* Content view controller of the main window: the three panes of the library side by side,
|
||||
* Navigation | Content | Detail. Exercises:
|
||||
* - CPSplitViewController as a window's content view controller
|
||||
* - CPSplitViewItem: a sidebar item, a content list item and a default item, with minimum
|
||||
* and maximum thicknesses and holding priorities
|
||||
* - animated collapse and expansion of the sidebar and the detail pane
|
||||
* - autosave of the split view, and a button bar resize control on the first divider
|
||||
* - the detail pane shows the content's selection through its representedObject, so the
|
||||
* panes do not know about each other; only this controller knows the layout
|
||||
*/
|
||||
|
||||
@import <AppKit/AppKit.j>
|
||||
|
||||
@import "../../Library/Navigation/SourceListViewController.j"
|
||||
@import "../../Library/ContentViewer/PeopleViewController.j"
|
||||
@import "../../Library/PersonInspector/PersonDetailViewController.j"
|
||||
|
||||
var SidebarDefaultWidth = 230.0,
|
||||
SidebarMinimumWidth = 160.0,
|
||||
SidebarMaximumWidth = 420.0,
|
||||
ContentMinimumWidth = 300.0,
|
||||
ToggleDuration = 0.25,
|
||||
SplitViewAutosaveName = @"People.MainSplitView";
|
||||
|
||||
@implementation MainSplitViewController : CPSplitViewController
|
||||
{
|
||||
SourceListViewController _sourceListController;
|
||||
PeopleViewController _peopleController;
|
||||
PersonDetailViewController _detailController;
|
||||
|
||||
CPSplitViewItem _sidebarItem;
|
||||
CPSplitViewItem _contentItem;
|
||||
CPSplitViewItem _detailItem;
|
||||
}
|
||||
|
||||
- (id)initWithSourceListController:(SourceListViewController)aSourceListController peopleController:(PeopleViewController)aPeopleController
|
||||
{
|
||||
if (self = [super initWithCibName:nil bundle:nil])
|
||||
{
|
||||
_sourceListController = aSourceListController;
|
||||
_peopleController = aPeopleController;
|
||||
_detailController = [[PersonDetailViewController alloc] init];
|
||||
|
||||
[_detailController bind:@"representedObject" toObject:[_peopleController arrayController] withKeyPath:@"selection" options:nil];
|
||||
|
||||
_sidebarItem = [CPSplitViewItem sidebarWithViewController:_sourceListController];
|
||||
[_sidebarItem setMinimumThickness:SidebarMinimumWidth];
|
||||
[_sidebarItem setMaximumThickness:SidebarMaximumWidth];
|
||||
|
||||
_contentItem = [CPSplitViewItem contentListWithViewController:_peopleController];
|
||||
[_contentItem setMinimumThickness:ContentMinimumWidth];
|
||||
|
||||
_detailItem = [CPSplitViewItem splitViewItemWithViewController:_detailController];
|
||||
[_detailItem setCanCollapse:YES];
|
||||
[_detailItem setMinimumThickness:PersonDetailMinimumWidth];
|
||||
|
||||
/*
|
||||
The table takes the space the window gains or loses; the sidebar and the detail
|
||||
pane keep their widths.
|
||||
*/
|
||||
[_sidebarItem setHoldingPriority:270];
|
||||
[_detailItem setHoldingPriority:260];
|
||||
[_contentItem setHoldingPriority:250];
|
||||
|
||||
[self setSplitViewItems:[_sidebarItem, _contentItem, _detailItem]];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
var splitView = [self splitView];
|
||||
|
||||
[splitView setButtonBar:[_sourceListController buttonBar] forDividerAtIndex:0];
|
||||
[splitView setAutosaveName:SplitViewAutosaveName];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Panes
|
||||
|
||||
- (BOOL)isSidebarVisible
|
||||
{
|
||||
return ![_sidebarItem isCollapsed];
|
||||
}
|
||||
|
||||
- (BOOL)isDetailVisible
|
||||
{
|
||||
return ![_detailItem isCollapsed];
|
||||
}
|
||||
|
||||
/*
|
||||
The detail pane is a default item, not an inspector item, so -toggleInspector: does not
|
||||
reach it.
|
||||
*/
|
||||
- (void)toggleDetail:(id)sender
|
||||
{
|
||||
[CPAnimationContext runAnimationGroup:function(aContext)
|
||||
{
|
||||
[aContext setDuration:ToggleDuration];
|
||||
[[_detailItem animator] setCollapsed:![_detailItem isCollapsed]];
|
||||
}
|
||||
completionHandler:nil];
|
||||
}
|
||||
|
||||
/*
|
||||
Shows the sidebar and the detail pane, and gives both their default widths.
|
||||
*/
|
||||
- (void)restoreDefaultLayout
|
||||
{
|
||||
var splitView = [self splitView];
|
||||
|
||||
[_sidebarItem setCollapsed:NO];
|
||||
[_detailItem setCollapsed:NO];
|
||||
|
||||
[splitView setPosition:CGRectGetWidth([splitView bounds]) - [splitView dividerThickness] - PersonDetailPreferredWidth ofDividerAtIndex:1];
|
||||
[splitView setPosition:SidebarDefaultWidth ofDividerAtIndex:0];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -19,14 +19,15 @@ spaces, because the legacy toolchain does not accept them.
|
||||
| `main.j`, `Info.plist` | entry point, `CPApplicationDelegateClass` = `AppController` |
|
||||
| `ApplicationLifecycle/AppController.j` | creates model, main menu, main window controller |
|
||||
| `ApplicationLifecycle/Settings/SettingsWindowController.j` | settings window |
|
||||
| `PrimaryInterface/MainWindow/MainWindowController.j` | bridge window, toolbar, sidebar split view, routed actions, menu and toolbar validation |
|
||||
| `PrimaryInterface/MainWindow/MainWindowController.j` | bridge window, toolbar, routed actions, menu and toolbar validation |
|
||||
| `PrimaryInterface/MainWindowSplitView/MainSplitViewController.j` | the window's content view controller: Navigation, Content and Detail side by side as split view items |
|
||||
| `Library/Library.j`, `Library/Person.j` | model, KVO observation, `CPUserDefaults` persistence, sample data |
|
||||
| `Library/Navigation/SourceListViewController.j` | view-based `CPOutlineView` source list, drop target, button bar |
|
||||
| `Library/Navigation/SourceItemCell/` | outline cell view with its icon and count badge, drawn with `CPBezierPath` |
|
||||
| `Library/Navigation/SmartFolderEditor/SmartFolderEditorController.j` | sheet with `CPPredicateEditor` built from row templates |
|
||||
| `Library/Navigation/GroupNameSheet/NameSheetController.j` | name sheet for new and renamed groups |
|
||||
| `Library/ContentViewer/PeopleViewController.j` | `CPArrayController` + bound `CPTableView`, drag source, pasteboard, detail split |
|
||||
| `Library/PersonInspector/PersonDetailViewController.j` | controls bound to `selection.*` |
|
||||
| `Library/ContentViewer/PeopleViewController.j` | `CPArrayController` + bound `CPTableView`, drag source, pasteboard |
|
||||
| `Library/PersonInspector/PersonDetailViewController.j` | detail column; controls bound to `representedObject.*`, which is the table's selection |
|
||||
|
||||
## Manual test checklist
|
||||
|
||||
@@ -44,7 +45,12 @@ spaces, because the legacy toolchain does not accept them.
|
||||
multi-select shows "Multiple Values"; changing Birth Date updates Age (dependent key).
|
||||
11. Copy (⌘C) then Paste (⌘V): duplicated people appear selected. Delete key removes people
|
||||
(from the group only, when a group is selected).
|
||||
12. View menu / toolbar: hide and show sidebar and detail pane; drag the sidebar resize control in the button bar.
|
||||
12. The window shows three columns: sidebar, people table, detail pane. Resize the window: the table takes the
|
||||
change, the sidebar and the detail pane keep their widths. Drag both dividers; the sidebar stays between
|
||||
160 and 420 points, the detail pane does not become narrower than its fields allow. Reload: both widths and
|
||||
any hidden pane are restored (autosave).
|
||||
View menu / toolbar: hide and show sidebar and detail pane, animated; a hidden pane comes back at its
|
||||
width. Drag the sidebar resize control in the button bar.
|
||||
Toolbar items are enabled exactly when their menu items are: Edit only for a smart folder,
|
||||
New Smart Folder and New Group not while a sheet is open. In dark mode the glyphs are light.
|
||||
View ▸ Hide Toolbar hides it and the item then reads Show Toolbar.
|
||||
|
||||
Reference in new issue
Block a user