Skip to content

Commit

Permalink
do not restrict uncrustification to Objective-C files
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitsan committed Jul 18, 2013
1 parent ceeddb5 commit 785cde9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Classes/BBUncrustify.m
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ + (void)uncrustifyFilesAtURLs:(NSArray *)fileURLs configurationFileURL:(NSURL *)
[fileURLs enumerateObjectsWithOptions:0 usingBlock:^(NSURL *fileURL, NSUInteger idx, BOOL *stop) {
if ([[NSFileManager defaultManager] fileExistsAtPath:fileURL.path]) {
NSMutableArray *args = NSMutableArray.array;

NSString *uti = [[NSWorkspace sharedWorkspace] typeOfFile:fileURL.path error:nil];
BOOL isObjectiveCFile = ([[NSWorkspace sharedWorkspace] type:uti conformsToType:(NSString *)kUTTypeObjectiveCSource] || [[NSWorkspace sharedWorkspace] type:uti conformsToType:(NSString *)kUTTypeCHeader]);

This comment has been minimized.

Copy link
@mengelbrecht

mengelbrecht Aug 21, 2013

This causes C/C++ header files to be formatted with the -l OC flag (for me this enables namespace indenting which is otherwise disabled).

if (isObjectiveCFile) {
[args addObjectsFromArray:@[@"-l", @"OC"]];
}

[args addObjectsFromArray:@[@"--frag", @"--no-backup"]];
[args addObjectsFromArray:@[@"-c", configurationFileURL.path, fileURL.path]];

Expand Down
2 changes: 1 addition & 1 deletion Classes/BBXcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ typedef NS_ENUM (NSUInteger, BBCodeFormattingScheme) {
+ (IDEWorkspaceDocument *)currentWorkspaceDocument;
+ (IDESourceCodeDocument *)currentSourceCodeDocument;
+ (NSTextView *)currentSourceCodeTextView;
+ (NSArray *)selectedObjCFileNavigableItems;
+ (NSArray *)selectedSourceCodeFileNavigableItems;
+ (BOOL)uncrustifyCodeOfDocument:(IDESourceCodeDocument *)document inWorkspace:(IDEWorkspace *)workspace;
+ (BOOL)uncrustifyCodeAtRanges:(NSArray *)ranges document:(IDESourceCodeDocument *)document inWorkspace:(IDEWorkspace *)workspace;
@end
5 changes: 2 additions & 3 deletions Classes/BBXcode.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ + (NSTextView *)currentSourceCodeTextView {
return nil;
}

+ (NSArray *)selectedObjCFileNavigableItems {
+ (NSArray *)selectedSourceCodeFileNavigableItems {
NSMutableArray *mutableArray = [NSMutableArray array];

id currentWindowController = [[NSApp keyWindow] windowController];
if ([currentWindowController isKindOfClass:NSClassFromString(@"IDEWorkspaceWindowController")]) {
IDEWorkspaceWindowController *workspaceController = currentWindowController;
Expand All @@ -104,7 +103,7 @@ + (NSArray *)selectedObjCFileNavigableItems {
if ([selectedObject isKindOfClass:NSClassFromString(@"IDEFileNavigableItem")]) {
IDEFileNavigableItem *fileNavigableItem = selectedObject;
NSString *uti = fileNavigableItem.documentType.identifier;
if ([uti isEqualToString:(NSString *)kUTTypeObjectiveCSource] || [uti isEqualToString:(NSString *)kUTTypeCHeader]) {
if ([[NSWorkspace sharedWorkspace] type:uti conformsToType:(NSString *)kUTTypeSourceCode]) {
[mutableArray addObject:fileNavigableItem];
}
}
Expand Down

0 comments on commit 785cde9

Please sign in to comment.