Skip to content

Instantly share code, notes, and snippets.

View dystonie's full-sized avatar

Guido Ronchetti dystonie

View GitHub Profile

Keybase proof

I hereby claim:

  • I am dystonie on github.
  • I am dystonie (https://keybase.io/dystonie) on keybase.
  • I have a public key whose fingerprint is B62A E3CD C216 FEE9 DB89 B769 1952 3FE7 7953 F600

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am dystonie on github.
  • I am dystonie (https://keybase.io/dystonie) on keybase.
  • I have a public key ASA4l4P3MkGrjvq1YGZP4Zsz3LId2rui-LldTWLat0ChgQo

To claim this, I am signing this object:

@dystonie
dystonie / NSOpenPanel.m
Created August 20, 2012 12:49
Open Panel
NSOpenPanel *openPanel = [[[NSOpenPanel alloc] init] autorelease];
[openPanel setAllowsMultipleSelection:NO];
[openPanel setAllowedFileTypes:filetypes];
if ([openPanel runModal] == NSFileHandlingPanelOKButton) {
//Some code to do
}
else {
//If cancel was clicked
}
@dystonie
dystonie / Asset.m
Created August 20, 2012 12:47
NSLog Debugging
#ifdef DEBUGX
NSLog(@"%s %@", __FUNCTION__, objectToDisplay));
#endif
@dystonie
dystonie / recursiveTroughtSubviews.m
Created August 20, 2012 12:47
Recursive NSView navigator
static inline NSSet *recursiveTroughtSubviews(NSView *aView, NSSet *previousResults) {
NSMutableSet *tmpSet = [NSMutableSet set];
//There are objects
if (aView && [aView subviews] > 0) {
//Enumerate array
NSArray *viewsToNavigate = [aView subviews];
@dystonie
dystonie / Asset.m
Created August 20, 2012 12:45
Basic Plist to Dictionary
//Getting plist path
NSString *path = [[NSBundle mainBundle] pathForResource:plistName ofType:@"plist"];
//Alloc Dictionary
NSDictionary *dictTMP = [NSDictionary dictionaryWithContentsOfFile:path];
#ifdef DEBUGX
NSLog(@"%s - 3 - %@", __FUNCTION__, dictTMP);
#endif
@dystonie
dystonie / Asset.m
Created August 20, 2012 12:44
Macro Localized String
// --------------------------------------------------------------
//Macros
#pragma mark Localization Macro
#define lString(x) NSLocalizedStringFromTable(x, @"DYDocStrings", @"")
@dystonie
dystonie / NSAlert.m
Created August 20, 2012 12:43
Alert Dialog
NSAlert *alert = [NSAlert alertWithMessageText:@"Text" defaultButton:@"OK" alternateButton:@"Cancel" otherButton:nil
informativeTextWithFormat:@"%@",someLocalizedVariable];
[alert beginSheetModalForWindow:mainWindow modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil];
//didEnd:
-(void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
if (returnCode == NSAlertDefaultReturn) {
//Dialogo Risposta
}
}
@dystonie
dystonie / NSSavePanel.m
Created August 20, 2012 12:42
Save Panel
NSSavePanel *savePanel = [[[NSSavePanel alloc] init] autorelease];
[savePanel setAllowedFileTypes:[NSArray arrayWithObjects:@"fileType", nil]];
[savePanel setCanCreateDirectories:YES];
[savePanel setCanSelectHiddenExtension:TRUE];
[savePanel setExtensionHidden:TRUE];
[savePanel setMessage:@"Message to display"];
[savePanel setNameFieldStringValue:@"Default file name"];
[savePanel setDirectoryURL:[NSURL URLWithString:NSHomeDirectory()]]; //Change us you prefer
//display the NSSavePanel
NSInteger runResult = [savePanel runModal];
@dystonie
dystonie / Asset.c
Created August 20, 2012 12:40
DEBUG_LOG()
#import <stdio.h>
#import <stdarg.h>
int globalLevel = 50;
#define DEBUG_LOG(logLevel, format, ...) \
do { \
if ((logLevel) > globalLevel) printf((format), ##__VA_ARGS__); \
} while (0)