mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-12-03 19:44:22 +00:00
People: Add a contextual menu to the table and show notes first
Promote the Notes column to the first column, and restore default column ordering and widths on Reset Application. Add a contextual menu with Edit, Deselect All, Invert Selection, and Delete Selected, leaving menu item targets nil so actions resolve dynamically along the responder chain. Document the test items in the README.
This commit is contained in:
1 parent
bb65f7ca80
commit
d50be786ff
3 files changed
+176
-15
No files matched your search
@@ -13,6 +13,8 @@
|
||||
* - CPPasteboard (copy / paste as tab separated text)
|
||||
* - a notes column: a CPImageView data view bound to hasNotes through a named
|
||||
* CPValueTransformer, with an image in its header instead of a title
|
||||
* - a contextual menu from the delegate, whose items go through the responder chain:
|
||||
* Edit, Deselect All (the table's own action), Invert Selection and Delete Selected
|
||||
*
|
||||
* The editable columns take edits only while the library is editable; the controller observes
|
||||
* the library's "editable" key and sets each column's editable state.
|
||||
@@ -74,6 +76,9 @@ var NotesMask = "url('data:image/svg+xml;charset=utf-8;base64,PHN2ZyB4
|
||||
CPTextField _statusField;
|
||||
CPString _contentTitle;
|
||||
CPArray _editableColumns;
|
||||
CPArray _defaultColumnLayout;
|
||||
CPMenu _tableMenu;
|
||||
CPInteger _menuRow;
|
||||
}
|
||||
|
||||
- (id)initWithLibrary:(Library)aLibrary
|
||||
@@ -83,6 +88,8 @@ var NotesMask = "url('data:image/svg+xml;charset=utf-8;base64,PHN2ZyB4
|
||||
_library = aLibrary;
|
||||
_contentTitle = @"";
|
||||
_editableColumns = [];
|
||||
_defaultColumnLayout = [];
|
||||
_menuRow = CPNotFound;
|
||||
|
||||
_arrayController = [[CPArrayController alloc] init];
|
||||
[_arrayController setEditable:YES];
|
||||
@@ -158,6 +165,19 @@ var NotesMask = "url('data:image/svg+xml;charset=utf-8;base64,PHN2ZyB4
|
||||
var numberFormatter = [[CPNumberFormatter alloc] init];
|
||||
[numberFormatter setNumberStyle:CPNumberFormatterDecimalStyle];
|
||||
|
||||
// Notes, the first column: an icon when the person has notes, nothing when not.
|
||||
var notesView = [[CPImageView alloc] initWithFrame:CGRectMakeZero()];
|
||||
[notesView setImageScaling:CPImageScaleNone];
|
||||
[notesView setImageAlignment:CPImageAlignCenter];
|
||||
|
||||
var notesColumn = [self _addColumn:@"hasNotes" title:@"" width:28 editable:NO dataView:notesView
|
||||
options:@{ CPValueTransformerNameBindingOption: NotesIconTransformerName }];
|
||||
[notesColumn setResizingMask:CPTableColumnNoResizing];
|
||||
[notesColumn setHeaderToolTip:@"Notes"];
|
||||
[[[notesColumn headerView] textField] setImage:MaskImage(NotesMask, NotesIconSize, [CPColor secondaryLabelColor])];
|
||||
[[[notesColumn headerView] textField] setImagePosition:CPImageOnly];
|
||||
[[notesColumn headerView] setAlignment:CPCenterTextAlignment];
|
||||
|
||||
[self _addColumn:@"lastName" title:@"Last Name" width:120 editable:YES dataView:nil];
|
||||
[self _addColumn:@"firstName" title:@"First Name" width:110 editable:YES dataView:nil];
|
||||
[self _addColumn:@"department" title:@"Department" width:110 editable:YES dataView:nil];
|
||||
@@ -175,19 +195,6 @@ var NotesMask = "url('data:image/svg+xml;charset=utf-8;base64,PHN2ZyB4
|
||||
[[managerColumn headerView] setAlignment:CPCenterTextAlignment];
|
||||
[managerColumn setResizingMask:CPTableColumnNoResizing];
|
||||
|
||||
// Notes: an icon when the person has notes, nothing when not.
|
||||
var notesView = [[CPImageView alloc] initWithFrame:CGRectMakeZero()];
|
||||
[notesView setImageScaling:CPImageScaleNone];
|
||||
[notesView setImageAlignment:CPImageAlignCenter];
|
||||
|
||||
var notesColumn = [self _addColumn:@"hasNotes" title:@"" width:28 editable:NO dataView:notesView
|
||||
options:@{ CPValueTransformerNameBindingOption: NotesIconTransformerName }];
|
||||
[notesColumn setResizingMask:CPTableColumnNoResizing];
|
||||
[notesColumn setHeaderToolTip:@"Notes"];
|
||||
[[[notesColumn headerView] textField] setImage:MaskImage(NotesMask, NotesIconSize, [CPColor secondaryLabelColor])];
|
||||
[[[notesColumn headerView] textField] setImagePosition:CPImageOnly];
|
||||
[[notesColumn headerView] setAlignment:CPCenterTextAlignment];
|
||||
|
||||
[self _addColumn:@"email" title:@"Email" width:220 editable:YES dataView:nil];
|
||||
|
||||
// Selection and sorting through bindings.
|
||||
@@ -201,6 +208,8 @@ var NotesMask = "url('data:image/svg+xml;charset=utf-8;base64,PHN2ZyB4
|
||||
[_tableView setDraggingSourceOperationMask:CPDragOperationCopy | CPDragOperationMove forLocal:YES];
|
||||
[_tableView setDraggingSourceOperationMask:CPDragOperationCopy forLocal:NO];
|
||||
|
||||
_tableMenu = [self _buildTableMenu];
|
||||
|
||||
[_tableView setAutosaveName:@"People.PeopleTable"];
|
||||
[_tableView setAutosaveTableColumns:YES];
|
||||
|
||||
@@ -286,11 +295,109 @@ var NotesMask = "url('data:image/svg+xml;charset=utf-8;base64,PHN2ZyB4
|
||||
|
||||
[column setDataView:aDataView];
|
||||
[_tableView addTableColumn:column];
|
||||
[_defaultColumnLayout addObject:{ identifier: aKey, width: aWidth }];
|
||||
[column bind:CPValueBinding toObject:_arrayController withKeyPath:@"arrangedObjects." + aKey options:someOptions];
|
||||
|
||||
return column;
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the columns to the order and widths they are built with. The table's autosave then
|
||||
stores that layout. Reset Application uses it.
|
||||
*/
|
||||
- (void)restoreDefaultColumns
|
||||
{
|
||||
[self view];
|
||||
|
||||
for (var i = 0, count = [_defaultColumnLayout count]; i < count; i++)
|
||||
{
|
||||
var layout = _defaultColumnLayout[i],
|
||||
index = [_tableView columnWithIdentifier:layout.identifier];
|
||||
|
||||
if (index === CPNotFound)
|
||||
continue;
|
||||
|
||||
if (index !== i)
|
||||
[_tableView moveColumn:index toColumn:i];
|
||||
|
||||
[[_tableView tableColumnWithIdentifier:layout.identifier] setWidth:layout.width];
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Contextual menu
|
||||
|
||||
/*
|
||||
The items have no target, so each action goes through the responder chain from the table:
|
||||
Deselect All reaches the table itself, Edit and Invert Selection this controller, and
|
||||
Delete Selected the window controller, which also deletes with the minus button and the
|
||||
Delete key.
|
||||
*/
|
||||
- (CPMenu)_buildTableMenu
|
||||
{
|
||||
var menu = [[CPMenu alloc] initWithTitle:@"People"];
|
||||
|
||||
[menu addItemWithTitle:@"Edit" action:@selector(editClickedPerson:) keyEquivalent:@""];
|
||||
[menu addItem:[CPMenuItem separatorItem]];
|
||||
[menu addItemWithTitle:@"Deselect All" action:@selector(deselectAll:) keyEquivalent:@""];
|
||||
[menu addItemWithTitle:@"Invert Selection" action:@selector(invertSelection:) keyEquivalent:@""];
|
||||
[menu addItem:[CPMenuItem separatorItem]];
|
||||
[menu addItemWithTitle:@"Delete Selected" action:@selector(removeSelectedPeople:) keyEquivalent:@""];
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
/*
|
||||
Shows the contextual menu for a right-click. The table becomes the first responder, so the
|
||||
menu's actions start their way through the responder chain at the table.
|
||||
*/
|
||||
- (CPMenu)tableView:(CPTableView)aTableView menuForTableColumn:(CPTableColumn)aColumn row:(CPInteger)aRow
|
||||
{
|
||||
_menuRow = aRow;
|
||||
[[_tableView window] makeFirstResponder:_tableView];
|
||||
|
||||
return _tableMenu;
|
||||
}
|
||||
|
||||
/*
|
||||
Selects the person whose row was right-clicked, turns on edit mode and edits the row.
|
||||
*/
|
||||
- (@action)editClickedPerson:(id)aSender
|
||||
{
|
||||
var people = [_arrayController arrangedObjects];
|
||||
|
||||
if (_menuRow < 0 || _menuRow >= [people count])
|
||||
return;
|
||||
|
||||
[_library setEditable:YES];
|
||||
[self selectPerson:[people objectAtIndex:_menuRow] edit:YES];
|
||||
}
|
||||
|
||||
/*
|
||||
Selects the rows that are not selected, and deselects the rows that are.
|
||||
*/
|
||||
- (@action)invertSelection:(id)aSender
|
||||
{
|
||||
var count = [[_arrayController arrangedObjects] count],
|
||||
inverted = [CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, count)];
|
||||
|
||||
[inverted removeIndexes:[_arrayController selectionIndexes]];
|
||||
[_arrayController setSelectionIndexes:inverted];
|
||||
}
|
||||
|
||||
- (BOOL)validateMenuItem:(CPMenuItem)anItem
|
||||
{
|
||||
switch ([anItem action])
|
||||
{
|
||||
case @selector(editClickedPerson:):
|
||||
return _menuRow >= 0 && _menuRow < [[_arrayController arrangedObjects] count];
|
||||
|
||||
case @selector(invertSelection:):
|
||||
return [[_arrayController arrangedObjects] count] > 0;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Content
|
||||
|
||||
- (void)setPeople:(CPArray)thePeople filterPredicate:(CPPredicate)aPredicate title:(CPString)aTitle
|
||||
|
||||
@@ -452,7 +452,7 @@ var ToolbarSidebarIdentifier = @"SidebarItem",
|
||||
|
||||
[alert setAlertStyle:CPWarningAlertStyle];
|
||||
[alert setMessageText:@"Reset the application?"];
|
||||
[alert setInformativeText:@"All people, groups and smart folders will be replaced by the sample data. The toolbar, the sidebar, the detail pane, the recent searches and the appearance return to their defaults. This cannot be undone."];
|
||||
[alert setInformativeText:@"All people, groups and smart folders will be replaced by the sample data. The toolbar, the table columns, the sidebar, the detail pane, the recent searches and the appearance return to their defaults. This cannot be undone."];
|
||||
[alert addButtonWithTitle:@"Reset"];
|
||||
[alert addButtonWithTitle:@"Cancel"];
|
||||
|
||||
@@ -495,6 +495,7 @@ var ToolbarSidebarIdentifier = @"SidebarItem",
|
||||
[toolbar setVisible:YES];
|
||||
|
||||
[_splitViewController restoreDefaultLayout];
|
||||
[_peopleController restoreDefaultColumns];
|
||||
|
||||
[SettingsWindowController resetAppearance];
|
||||
}
|
||||
|
||||
@@ -61,4 +61,57 @@ spaces, because the legacy toolchain does not accept them.
|
||||
toolbar stays (autosave). While the sheet is open, the toolbar items do not act.
|
||||
The standard Colors item opens the colour panel. In both appearances its labels, the boxes
|
||||
around the preview and the swatches, and the opacity slider's track and knob show.
|
||||
13. File ▸ Reset Application…: alert sheet, then sample data, default toolbar (items, Icon and Text, regular size), sidebar width, detail pane, empty recent searches and Auto appearance restored at once, without a reload. Cancel changes nothing.
|
||||
13. File ▸ Reset Application…: alert sheet, then sample data, default toolbar (items, Icon and Text, regular size), default table columns (order and widths, Notes first), sidebar width, detail pane, empty recent searches and Auto appearance restored at once, without a reload. Cancel changes nothing.
|
||||
|
||||
## Items to exercise
|
||||
|
||||
These items extend People for testers and developers. Most of them add a new way to reach an
|
||||
existing action. If the application routes its actions through the responder chain, each one
|
||||
should be nearly trivial to add. Together they exercise the kind of interface that is difficult
|
||||
to build with a web component framework.
|
||||
|
||||
### Detail pane
|
||||
|
||||
1. Edit history. This needs a change to the data model.
|
||||
- The detail pane has an Edit History section. A table shows one row for each saved edit,
|
||||
with its time and an optional description.
|
||||
- When an edit is saved, a modal alert asks for an optional description. Accept is the
|
||||
default button. All controls in the alert take part in tab selection.
|
||||
- The detail button bar has a Reject button that discards the edit. A modal alert asks the
|
||||
user to confirm first. Confirm is the default button.
|
||||
- The time is stored in UTC and shown in local time, in conversational form.
|
||||
2. When no single row is selected, a covering view over the detail pane says
|
||||
"Please select a single row to edit or display."
|
||||
3. The contextual menu of the Notes field adds the selection commands and basic style commands.
|
||||
|
||||
### People table
|
||||
|
||||
4. The Notes column is the first column by default.
|
||||
5. A Revisions column next to it shows the number of saved edits, from the edit history.
|
||||
6. Quick look: a popover shows the whole record of a row.
|
||||
- Hovering over a row for about 0.8 seconds opens a popover anchored to that row. While it is
|
||||
open, moving to another row moves it at once. A click outside it, a scroll or the pointer
|
||||
leaving the table closes it.
|
||||
- The space bar opens and closes the popover for the selected row.
|
||||
- The popover holds a second detail view controller, the same class as the detail pane, so it
|
||||
shows every section, notes included. It also works when the detail pane is hidden. In edit
|
||||
mode the person can be edited in the popover.
|
||||
- No popover opens while a cell is edited or a drag is in progress.
|
||||
- This exercises CPPopover, CPTrackingArea, a view controller used twice, and bindings and
|
||||
the first responder in a popover window.
|
||||
7. A contextual menu on the table offers:
|
||||
- Edit: edits the row that was clicked.
|
||||
- Deselect All.
|
||||
- Invert Selection.
|
||||
- Delete Selected: deletes the selection, whether it has one row or many, contiguous or not.
|
||||
It is disabled when nothing is selected.
|
||||
|
||||
### Window and menus
|
||||
|
||||
8. In edit mode, Hide Details is disabled everywhere: menu, toolbar and button bar.
|
||||
9. The navigation button bar has a pop-up menu on its right side. When the menu bar is hidden,
|
||||
it holds every main menu item that no other control offers.
|
||||
10. An About dialog.
|
||||
11. An action hides and shows the main menu. This shows both styles of application menu use.
|
||||
12. A search field shows at the top of the navigation sidebar only while the toolbar is hidden.
|
||||
An animated move between the two places is optional.
|
||||
Reference in new issue
Block a user