aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2009-04-24 01:07:20 +0000
committerrowanbeentje <rowan@beent.je>2009-04-24 01:07:20 +0000
commit180579d026ffae575a25e698c279c465dbd1bd6b (patch)
tree8453037d233ffa6416215f920b05489dc3ebabbc /Source
parent99cd06e66527beef638493b007c036929d5da283 (diff)
downloadsequelpro-180579d026ffae575a25e698c279c465dbd1bd6b.tar.gz
sequelpro-180579d026ffae575a25e698c279c465dbd1bd6b.tar.bz2
sequelpro-180579d026ffae575a25e698c279c465dbd1bd6b.zip
- Add support for click and click-and-drag selection when the line number view receives mouse events. Enables easy selection of lines.
Diffstat (limited to 'Source')
-rw-r--r--Source/NoodleLineNumberView.h3
-rw-r--r--Source/NoodleLineNumberView.m65
2 files changed, 67 insertions, 1 deletions
diff --git a/Source/NoodleLineNumberView.h b/Source/NoodleLineNumberView.h
index 7d12d47d..85316dd0 100644
--- a/Source/NoodleLineNumberView.h
+++ b/Source/NoodleLineNumberView.h
@@ -39,6 +39,9 @@
NSColor *textColor;
NSColor *alternateTextColor;
NSColor *backgroundColor;
+
+ // Add support for selection by clicking/dragging
+ unsigned dragSelectionStartLine;
}
- (id)initWithScrollView:(NSScrollView *)aScrollView;
diff --git a/Source/NoodleLineNumberView.m b/Source/NoodleLineNumberView.m
index d1ecbd96..a4383102 100644
--- a/Source/NoodleLineNumberView.m
+++ b/Source/NoodleLineNumberView.m
@@ -28,7 +28,7 @@
//
// This version of the NoodleLineNumberView for Sequel Pro removes marker
-// functionality.
+// functionality and adds selection by clicking on the ruler.
#import "NoodleLineNumberView.h"
@@ -439,6 +439,69 @@
}
}
+- (void)mouseDown:(NSEvent *)theEvent
+{
+ NSPoint location;
+ unsigned line;
+ NSTextView *view;
+
+ if (![[self clientView] isKindOfClass:[NSTextView class]]) return;
+ view = (NSTextView *)[self clientView];
+
+ location = [self convertPoint:[theEvent locationInWindow] fromView:nil];
+ line = [self lineNumberForLocation:location.y];
+ dragSelectionStartLine = line;
+
+ if (line != NSNotFound)
+ {
+ unsigned int selectionStart, selectionEnd;
+ NSMutableArray *lines = [self lineIndices];
+
+ selectionStart = [[lines objectAtIndex:(line - 1)] unsignedIntValue];
+ if (line < [lines count]) {
+ selectionEnd = [[lines objectAtIndex:line] unsignedIntValue];
+ } else {
+ selectionEnd = [[view string] length];
+ }
+ [view setSelectedRange:NSMakeRange(selectionStart, selectionEnd - selectionStart)];
+ }
+}
+
+- (void)mouseDragged:(NSEvent *)theEvent
+{
+ NSPoint location;
+ unsigned line, startLine, endLine;
+ NSTextView *view;
+
+ if (![[self clientView] isKindOfClass:[NSTextView class]] || dragSelectionStartLine == NSNotFound) return;
+ view = (NSTextView *)[self clientView];
+
+ location = [self convertPoint:[theEvent locationInWindow] fromView:nil];
+ line = [self lineNumberForLocation:location.y];
+
+ if (line != NSNotFound)
+ {
+ unsigned int selectionStart, selectionEnd;
+ NSMutableArray *lines = [self lineIndices];
+ if (line >= dragSelectionStartLine) {
+ startLine = dragSelectionStartLine;
+ endLine = line;
+ } else {
+ startLine = line;
+ endLine = dragSelectionStartLine;
+ }
+
+ selectionStart = [[lines objectAtIndex:(startLine - 1)] unsignedIntValue];
+ if (endLine < [lines count]) {
+ selectionEnd = [[lines objectAtIndex:endLine] unsignedIntValue];
+ } else {
+ selectionEnd = [[view string] length];
+ }
+ [view setSelectedRange:NSMakeRange(selectionStart, selectionEnd - selectionStart)];
+ }
+
+ [view autoscroll:theEvent];
+}
#pragma mark NSCoding methods