NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *source = [defaults objectForKey: @"SourceLanguage" ];
...
[defaults setObject:language forKey: @"SourceLanguage" ];
* This source code was highlighted with Source Code Highlighter .
[sourceLanguagesButton removeAllItems];
[sourceLanguagesButton addItemWithTitle:NSLocalizedString( @"auto" , @"" )];
[[sourceLanguagesButton menu] addItem:[NSMenuItem separatorItem]];
for ( int i = 0; i < 10; i++)
{
[sourceLanguagesButton addItemWithTitle:[NSString stringWithFormat: @"%i" , i]];
}
* This source code was highlighted with Source Code Highlighter .
[contactButton setTitle:NSLocalizedString( @"Contact" , @"" )];
NSMutableAttributedString *colorTitle = [[NSMutableAttributedString alloc] initWithAttributedString:[contactButton attributedTitle]];
[colorTitle addAttribute:NSForegroundColorAttributeName value :[NSColor whiteColor] range:NSMakeRange(0, [colorTitle length])];
[contactButton setAttributedTitle:colorTitle];
[colorTitle addAttribute:NSForegroundColorAttributeName value :[NSColor blackColor] range:NSMakeRange(0, [colorTitle length])];
[contactButton setAttributedAlternateTitle:colorTitle];
[colorTitle release];
* This source code was highlighted with Source Code Highlighter .
typedef void *CGSWindowFilterRef;
typedef int CGSConnectionID;
typedef int CGSWindowID;
extern CGSConnectionID _CGSDefaultConnection( void );
extern CGError CGSNewCIFilterByName(CGSConnectionID cid, CFStringRef filterName, CGSWindowFilterRef *outFilter);
extern CGError CGSAddWindowFilter(CGSConnectionID cid, CGSWindowID wid, CGSWindowFilterRef filter, int flags);
extern CGError CGSRemoveWindowFilter(CGSConnectionID cid, CGSWindowID wid, CGSWindowFilterRef filter);
extern CGError CGSReleaseCIFilter(CGSConnectionID cid, CGSWindowFilterRef filter);
extern CGError CGSSetCIFilterValuesFromDictionary(CGSConnectionID cid, CGSWindowFilterRef filter, CFDictionaryRef filterValues);
* This source code was highlighted with Source Code Highlighter .
CGSWindowID wid;
CGSWindowFilterRef fid;
* This source code was highlighted with Source Code Highlighter .
int compositingType = 1;
wid = [[self window] windowNumber];
CGSNewCIFilterByName(_CGSDefaultConnection(), (CFStringRef) @"CIGaussianBlur" , &fid);
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:3.0] forKey: @"inputRadius" ];
CGSSetCIFilterValuesFromDictionary(_CGSDefaultConnection(), fid, (CFDictionaryRef)options);
CGSAddWindowFilter(_CGSDefaultConnection(), wid, fid, compositingType);
* This source code was highlighted with Source Code Highlighter .
if (fid)
{
CGSRemoveWindowFilter(_CGSDefaultConnection(), wid, fid);
CGSReleaseCIFilter(_CGSDefaultConnection(), fid);
}
* This source code was highlighted with Source Code Highlighter .
NSView *titlebar = [[self.window standardWindowButton:NSWindowCloseButton] superview];
* This source code was highlighted with Source Code Highlighter .
NSPoint point = [NSEvent mouseLocation];
* This source code was highlighted with Source Code Highlighter .
[textView setFont:[NSFont systemFontOfSize:20]];
* This source code was highlighted with Source Code Highlighter .
NSPoint top;
if ([textView isFlipped])
{
top = NSMakePoint(0.0, 0.0);
}
else
{
top = NSMakePoint(0.0, NSMaxY([textView frame]) - NSHeight([textView bounds]));
}
[textView scrollPoint:top];
* This source code was highlighted with Source Code Highlighter .
[ object setHidden:YES];
* This source code was highlighted with Source Code Highlighter .
- (NSMenu *)textView:(NSTextView *)view menu:(NSMenu *)menu forEvent:(NSEvent *) event atIndex:(NSUInteger)charIndex
{
NSMenuItem *spotlight = nil;
NSMenuItem *google = nil;
NSMenuItem *dictionary = nil;
NSMenuItem *copy = nil;
NSMenuItem *speech = nil;
int count = [menu numberOfItems];
for ( int i = 0; i < count; i++)
{
SEL action = [[menu itemAtIndex:i] action];
if (action == @selector(spotlight:))
{
spotlight = [[menu itemAtIndex:i] retain];
}
else if (action == @selector(_searchWithGoogleFromMenu:))
{
google = [[menu itemAtIndex:i] retain];
}
else if (action == @selector(_lookUpDefiniteRangeInDictionaryFromMenu:))
{
dictionary = [[menu itemAtIndex:i] retain];
}
else if (action == @selector(copy:))
{
copy = [[menu itemAtIndex:i] retain];
}
else if (action == @selector(submenuAction:))
{
NSMenu *submenu = [[menu itemAtIndex:i] submenu];
if (submenu)
{
if ([submenu numberOfItems] == 2)
{
if ([[submenu itemAtIndex:0] action] == @selector(startSpeaking:))
{
speech = [[menu itemAtIndex:i] retain];
}
}
}
}
}
if (!copy)
{
if (spotlight) [spotlight release];
if (google) [google release];
if (dictionary) [dictionary release];
if (speech) [speech release];
return menu;
}
[menu removeAllItems];
if (spotlight) [menu addItem:spotlight], [spotlight release];
if (google) [menu addItem:google], [google release];
if (dictionary) [menu addItem:dictionary], [dictionary release];
if ([menu numberOfItems] > 0) [menu addItem:[NSMenuItem separatorItem]];
[menu addItem:copy], [copy release];
if (speech)
{
[menu addItem:[NSMenuItem separatorItem]];
[menu addItem:speech], [speech release];
}
return menu;
}
* This source code was highlighted with Source Code Highlighter .
NSString *sourceText = [originalText stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *langs = [[NSString stringWithFormat: @"%@|%@" , sourceLanguage, targetLanguage] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *requestURL = [NSString stringWithFormat: @"%@&q=%@&langpair=%@" , GoogleURL, sourceText, langs];
NSURL *url = [NSURL URLWithString:requestURL];
NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:20.0];
fetcherG = [[GDataHTTPFetcher httpFetcherWithRequest:request] retain];
[fetcherG beginFetchWithDelegate:self
didFinishSelector:@selector(httpFetcher:finishedWithData:)
didFailSelector:@selector(httpFetcher:didFail:)];
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/86299/
All Articles