aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPWindowController.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2010-06-30 23:44:55 +0000
committerrowanbeentje <rowan@beent.je>2010-06-30 23:44:55 +0000
commit219afc56c02b508fbb6d706dfed4e1a1ccc949d4 (patch)
treede4e473de2a5fd1063c671733a5f7552e6080ba0 /Source/SPWindowController.m
parentba332e64c29622e0b69412cb2fea639182ac1d1c (diff)
downloadsequelpro-219afc56c02b508fbb6d706dfed4e1a1ccc949d4.tar.gz
sequelpro-219afc56c02b508fbb6d706dfed4e1a1ccc949d4.tar.bz2
sequelpro-219afc56c02b508fbb6d706dfed4e1a1ccc949d4.zip
Improve tab functionality, behaviour and interaction.
PSMTabBar general improvements: - Fix a phantom tab appearing in windows a tab was just dragged out of - Add support for a new control usersSafariStyleDragging property; this causes tabs being dragged inside a tab bar to snap to the tab bar, be drawn at full transparency (also no longer darkening the placeholder position), and alters tab ordering within the tab bar to be based on the tab position rather than the mouse position, for a more Mac-like reordering feel. - Add support for dragging items onto the menubar to cancel the drag - Alter the image of the dragged tab to use a tab drawn onto a transparent background instead of snapshotting a rectangle around the tab, improving drag appearance - Allow tabs to be dragged partially off screen and keep their position instead of snapping back fully onto the screen - Improve behaviour when dragging tabs out of and back into tab bars, or into new windows, resizing the tabs in the target tab bar to improve display and no longer intermittently showing close buttons while dragging - Pull windows to the front as tabs are dragged onto their tab bars - Abstract Custom Query Editor text snippet code, adding a delegate method so code could be moved to the SP window manager. Sequel Pro tab styling improvements: - Improve and clean up tab drawing code - Draw background tabs with shadows as appropriate - Improve logic for how background tab edges are drawn, handling edges cases better (active tab in overflow menu etc) and vastly improving drawing when a tab is being dragged (respect placeholder position when stacking tabs, draw edges on either side) Sequel Pro tab behaviour improvements: - Improve show/hide tab bar interaction - Improve window positioning after creating new windows via a drag - Alter tab dragging out of the tab bar to use an image based on the full window appearance - looks better, and fixes issues like the tab bar background not being drawn while dragging
Diffstat (limited to 'Source/SPWindowController.m')
-rw-r--r--Source/SPWindowController.m55
1 files changed, 41 insertions, 14 deletions
diff --git a/Source/SPWindowController.m b/Source/SPWindowController.m
index 5cd98870..ed443ac4 100644
--- a/Source/SPWindowController.m
+++ b/Source/SPWindowController.m
@@ -27,6 +27,7 @@
#import "SPDatabaseDocument.h"
#import <PSMTabBar/PSMTabBarControl.h>
#import <PSMTabBar/PSMTabStyle.h>
+#import "PSMTabDragAssistant.h"
@interface SPWindowController (PrivateAPI)
@@ -61,6 +62,7 @@
[tabBar setCellOptimumWidth:250];
[tabBar setSelectsTabsOnMouseDown:YES];
[tabBar setTearOffStyle:PSMTabBarTearOffAlphaWindow];
+ [tabBar setUsesSafariStyleDragging:YES];
// hook up add tab button
[[tabBar addTabButton] setTarget:self];
@@ -265,7 +267,7 @@
- (IBAction)toggleTabBarShown:(id)sender
{
- [tabBar setHideForSingleTab:![tabBar isTabBarHidden]];
+ [tabBar setHideForSingleTab:![tabBar hideForSingleTab]];
[[NSUserDefaults standardUserDefaults] setBool:![tabBar hideForSingleTab] forKey:SPAlwaysShowWindowTabBar];
}
@@ -341,6 +343,7 @@
*/
- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem
{
+ if ([[PSMTabDragAssistant sharedDragAssistant] isDragging]) return;
selectedTableDocument = [tabViewItem identifier];
[selectedTableDocument didBecomeActiveTabInWindow];
if ([[self window] isKeyWindow]) [selectedTableDocument tabDidBecomeKey];
@@ -410,6 +413,22 @@
}
/**
+ * Respond to dragging events entering the tab in the tab bar.
+ * Allows custom behaviours - for example, if dragging text, switch to the custom
+ * query view.
+ */
+- (void)draggingEvent:(id <NSDraggingInfo>)dragEvent enteredTabBar:(PSMTabBarControl *)tabBarControl tabView:(NSTabViewItem *)tabViewItem
+{
+ SPDatabaseDocument *theDocument = [tabViewItem identifier];
+
+ if (![theDocument isCustomQuerySelected]
+ && [[[dragEvent draggingPasteboard] types] indexOfObject:NSStringPboardType] != NSNotFound)
+ {
+ [theDocument viewQuery:self];
+ }
+}
+
+/**
* Show tooltip for a tab view item.
*/
- (NSString *)tabView:(NSTabView *)aTabView toolTipForTabViewItem:(NSTabViewItem *)tabViewItem
@@ -456,6 +475,14 @@
}
/**
+ * When dragging a tab off a tab bar, add a shadow to the drag window.
+ */
+- (void)tabViewDragWindowCreated:(NSWindow *)dragWindow
+{
+ [dragWindow setHasShadow:YES];
+}
+
+/**
* Allow dragging and dropping of tabs to any position, including out of a tab bar
* to create a new window.
*/
@@ -481,9 +508,9 @@
toolbarHeight = innerFrame.size.height - [[[self window] contentView] frame].size.height;
}
- // Tweak window positioning according to the style and toolbar
- point.x -= [[tabBar style] leftMarginForTabBarControl];
- point.y += 21 + toolbarHeight - kPSMTabBarControlHeight;
+ // Adjust the positioning as appropriate
+ point.y += toolbarHeight;
+ if ([[NSUserDefaults standardUserDefaults] boolForKey:SPAlwaysShowWindowTabBar]) point.y += kPSMTabBarControlHeight;
// Set the new window position and size
NSRect targetWindowFrame = [[self window] frame];
@@ -510,10 +537,13 @@
NSImage *viewImage = [[NSImage alloc] init];
// Capture an image of the entire window
- [[[self window] contentView] lockFocus];
- NSBitmapImageRep *viewRep = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:[[[self window] contentView] frame]] autorelease];
+ CGImageRef windowImage = CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, [[self window] windowNumber], kCGWindowImageBoundsIgnoreFraming);
+ NSBitmapImageRep *viewRep = [[NSBitmapImageRep alloc] initWithCGImage:windowImage];
[viewImage addRepresentation:viewRep];
- [[[self window] contentView] unlockFocus];
+
+ // Calculate the titlebar+toolbar height
+ CGFloat contentViewOffsetY = [[self window] frame].size.height - [[[self window] contentView] frame].size.height;
+ offset->height = contentViewOffsetY + [tabBar frame].size.height;
// Draw over the tab bar area
[viewImage lockFocus];
@@ -529,17 +559,12 @@
// Draw the background flipped, which is actually the right way up
NSAffineTransform *transform = [NSAffineTransform transform];
+ [transform translateXBy:0.0 yBy:[[[self window] contentView] frame].size.height];
[transform scaleXBy:1.0 yBy:-1.0];
[transform concat];
- tabFrame.origin.y = -tabFrame.origin.y - tabFrame.size.height;
[(id <PSMTabStyle>)[[aTabView delegate] style] drawBackgroundInRect:tabFrame];
- [transform invert];
- [transform concat];
[viewImage unlockFocus];
- offset->height = 21;
- *styleMask = NSTitledWindowMask | NSUnifiedTitleAndToolbarWindowMask;
-
return [viewImage autorelease];
}
@@ -557,7 +582,9 @@
*/
- (void)tabDragStopped:(id)sender
{
- [tabBar setHideForSingleTab:YES];
+ if (![[NSUserDefaults standardUserDefaults] boolForKey:SPAlwaysShowWindowTabBar]) {
+ [tabBar setHideForSingleTab:YES];
+ }
}
#pragma mark -