From cca4f8dc17e904c516dc7e3ba8193aff5b8f9e70 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Sun, 24 Jan 2010 21:39:43 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20possibility=20to=20add=20a=20query?= =?UTF-8?q?=20favorite=20by=20user-definable=20alphanumeric=20tab=20trigge?= =?UTF-8?q?r;=20eg=20if=20tab=20trigger=20is=20set=20to=20"sel"=20sel?= =?UTF-8?q?=E2=87=A5=20will=20insert=20the=20first=20query=20which=20has?= =?UTF-8?q?=20the=20defined=20the=20tab=20trigger=20=E2=80=A2=20preparatio?= =?UTF-8?q?ns=20to=20insert=20programmable=20query=20favorites=20-=20eg=20?= =?UTF-8?q?"SELECT=20${*}=20FROM=20${Table}"=20--=20after=20insertion=20"S?= =?UTF-8?q?ELECT=20*=20FROM=20Table"=20the=20'*'=20is=20highlighted=20to?= =?UTF-8?q?=20change,=20press=20=E2=87=A5=20to=20select=20the=20next=20sni?= =?UTF-8?q?ppet=20'Table';=20=E2=87=A7=E2=87=A5=20selects=20the=20previous?= =?UTF-8?q?=20snippet;=20the=20snippet=20selection=20follows=20the=20user?= =?UTF-8?q?=20input=20-=20Note:=20not=20yet=20active?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CustomQuery.m | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'Source/CustomQuery.m') diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index b536491b..2e3b16c4 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -215,7 +215,7 @@ [textView setSelectedRange:NSMakeRange(0,[[textView string] length])]; // The actual query strings have been already stored as tooltip - [textView insertText:[[queryFavoritesButton selectedItem] toolTip]]; + [textView insertFavoriteAsSnippet:[[queryFavoritesButton selectedItem] toolTip] atRange:[textView selectedRange]]; } } @@ -2020,6 +2020,7 @@ // Ensure that the notification is from the custom query text view if ( [aNotification object] != textView ) return; + [textView checkForCaretInsideSnippet]; // Remove all background color attributes used by highlighting the current query if([prefs boolForKey:SPCustomQueryHighlightCurrentQuery]) { // Remove only the background attribute for the current range if still valid @@ -2701,8 +2702,17 @@ [menu addItem:headerMenuItem]; [headerMenuItem release]; for (NSDictionary *favorite in [[SPQueryController sharedQueryController] favoritesForFileURL:[tableDocumentInstance fileURL]]) { - NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithString:[favorite objectForKey:@"name"]] action:NULL keyEquivalent:@""]; + if (![favorite isKindOfClass:[NSDictionary class]] || ![favorite objectForKey:@"name"]) continue; + NSMutableParagraphStyle *paraStyle = [[[NSMutableParagraphStyle alloc] init] autorelease]; + [paraStyle setTabStops:[NSArray array]]; + [paraStyle addTabStop:[[[NSTextTab alloc] initWithType:NSRightTabStopType location:190.0] autorelease]]; + NSDictionary *attributes = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:paraStyle, [NSFont systemFontOfSize:11], nil] forKeys:[NSArray arrayWithObjects:NSParagraphStyleAttributeName, NSFontAttributeName, nil]]; + NSAttributedString *titleString = [[[NSAttributedString alloc] + initWithString:([favorite objectForKey:@"tabtrigger"] && [(NSString*)[favorite objectForKey:@"tabtrigger"] length]) ? [NSString stringWithFormat:@"%@\t%@⇥", [favorite objectForKey:@"name"], [favorite objectForKey:@"tabtrigger"]] : [favorite objectForKey:@"name"] + attributes:attributes] autorelease]; + NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""]; [item setToolTip:[NSString stringWithString:[favorite objectForKey:@"query"]]]; + [item setAttributedTitle:titleString]; [item setIndentationLevel:1]; [menu addItem:item]; [item release]; @@ -2717,8 +2727,16 @@ [headerMenuItem release]; for (NSDictionary *favorite in [prefs objectForKey:SPQueryFavorites]) { if (![favorite isKindOfClass:[NSDictionary class]] || ![favorite objectForKey:@"name"]) continue; - NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithString:[favorite objectForKey:@"name"]] action:NULL keyEquivalent:@""]; + NSMutableParagraphStyle *paraStyle = [[[NSMutableParagraphStyle alloc] init] autorelease]; + [paraStyle setTabStops:[NSArray array]]; + [paraStyle addTabStop:[[[NSTextTab alloc] initWithType:NSRightTabStopType location:190.0] autorelease]]; + NSDictionary *attributes = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:paraStyle, [NSFont systemFontOfSize:11], nil] forKeys:[NSArray arrayWithObjects:NSParagraphStyleAttributeName, NSFontAttributeName, nil]]; + NSAttributedString *titleString = [[[NSAttributedString alloc] + initWithString:([favorite objectForKey:@"tabtrigger"] && [(NSString*)[favorite objectForKey:@"tabtrigger"] length]) ? [NSString stringWithFormat:@"%@\t%@⇥", [favorite objectForKey:@"name"], [favorite objectForKey:@"tabtrigger"]] : [favorite objectForKey:@"name"] + attributes:attributes] autorelease]; + NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""]; [item setToolTip:[NSString stringWithString:[favorite objectForKey:@"query"]]]; + [item setAttributedTitle:titleString]; [item setIndentationLevel:1]; [menu addItem:item]; [item release]; -- cgit v1.2.3