Skip to content

Commit

Permalink
allow dragging the divider beyond the search field to collapse the to…
Browse files Browse the repository at this point in the history
…olbar; dragging the divider down expands the toolbar
  • Loading branch information
Zachary Schneirov committed Aug 16, 2010
1 parent e73eadc commit f1ae7fb
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
3 changes: 3 additions & 0 deletions AppController.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ void outletObjectAwoke(id sender);
- (BOOL)displayContentsForNoteAtIndex:(int)noteIndex;
- (void)processChangedSelectionForTable:(NSTableView*)table;
- (void)setEmptyViewState:(BOOL)state;
- (void)cancelOperation:(id)sender;
- (void)_setCurrentNote:(NoteObject*)aNote;
- (void)_expandToolbar;
- (void)_collapseToolbar;
- (NoteObject*)selectedNoteObject;

- (void)restoreListStateUsingPreferences;
Expand Down
56 changes: 55 additions & 1 deletion AppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ - (void)awakeFromNib {
[toolbar setDisplayMode:NSToolbarDisplayModeIconOnly];
// [toolbar setSizeMode:NSToolbarSizeModeRegular];
[toolbar setShowsBaselineSeparator:YES];
[toolbar setVisible:![[NSUserDefaults standardUserDefaults] boolForKey:@"ToolbarHidden"]];
[toolbar setDelegate:self];
[window setToolbar:toolbar];

Expand Down Expand Up @@ -714,6 +715,11 @@ - (NSMenu *)applicationDockMenu:(NSApplication *)sender {
return dockMenu;
}

- (void)cancel:(id)sender {
//fallback for when other views are hidden/removed during toolbar collapse
[self cancelOperation:sender];
}

- (void)cancelOperation:(id)sender {
//simulate a search for nothing

Expand Down Expand Up @@ -1305,7 +1311,55 @@ - (BOOL)splitView:(RBSplitView*)sender shouldHandleEvent:(NSEvent*)theEvent inDi

//mail.app-like resizing behavior wrt item selections
- (void)willAdjustSubviews:(RBSplitView*)sender {
[notesTableView makeFirstPreviouslyVisibleRowVisibleIfNecessary];
[notesTableView makeFirstPreviouslyVisibleRowVisibleIfNecessary];
}

- (void)_expandToolbar {
if (![toolbar isVisible]) {
[window setTitle:@"Notation"];
if (currentNote)
[field setStringValue:titleOfNote(currentNote)];
[window toggleToolbarShown:nil];
if (![splitView isDragging])
[[splitView subviewAtPosition:0] setDimension:100.0];
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"ToolbarHidden"];
}
}

- (void)_collapseToolbar {
if ([toolbar isVisible]) {
if (currentNote)
[window setTitle:titleOfNote(currentNote)];
[window toggleToolbarShown:nil];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"ToolbarHidden"];
}
}

- (BOOL)splitView:(RBSplitView*)sender shouldResizeWindowForDivider:(NSUInteger)divider
betweenView:(RBSplitSubview*)leading andView:(RBSplitSubview*)trailing willGrow:(BOOL)grow {

if ([sender isDragging]) {
BOOL toolbarVisible = [toolbar isVisible];
NSPoint mouse = [sender convertPoint:[[window currentEvent] locationInWindow] fromView:nil];

if ((toolbarVisible && !grow && mouse.y < -28.0 && ![leading canShrink]) ||
(!toolbarVisible && grow)) {
BOOL wasVisible = toolbarVisible;
if (toolbarVisible) {
[self _collapseToolbar];
} else {
[self _expandToolbar];
}

if (!wasVisible && [window firstResponder] == window) {
//if dualfield had first responder previously, it might need to be restored
//if it had been removed from the view hierarchy due to hiding the toolbar
[field selectText:sender];
}
}
}

return NO;
}

- (void)tableViewColumnDidResize:(NSNotification *)aNotification {
Expand Down

0 comments on commit f1ae7fb

Please sign in to comment.