diff --git a/Common.h b/Common.h index 587d637c..08bd1d17 100644 --- a/Common.h +++ b/Common.h @@ -134,6 +134,21 @@ typedef enum PlatypusOutputType { @"Droplet", \ ] +#define IsTextStyledOutputType(X) ( X == PLATYPUS_OUTPUT_PROGRESSBAR || \ + X == PLATYPUS_OUTPUT_TEXTWINDOW || \ + X == PLATYPUS_OUTPUT_STATUSMENU ) + +#define IsTextStyledOutputTypeString(X) ( [X isEqualToString:@"Progress Bar"] || \ + [X isEqualToString:@"Text Window"] || \ + [X isEqualToString:@"Status Menu"] ) + +#define IsTextSizableOutputType(X) (X == PLATYPUS_OUTPUT_PROGRESSBAR || \ + X == PLATYPUS_OUTPUT_TEXTWINDOW || \ + X == PLATYPUS_OUTPUT_WEBVIEW ) + +#define IsTextViewScrollableOutputType(X) ( X == PLATYPUS_OUTPUT_PROGRESSBAR || \ + X == PLATYPUS_OUTPUT_TEXTWINDOW ) + #pragma mark - // abbreviations, Obj-C is sometimes tediously verbose diff --git a/ScriptExec/ScriptExecController.m b/ScriptExec/ScriptExecController.m index 8bd6f9e0..d9efbe63 100644 --- a/ScriptExec/ScriptExecController.m +++ b/ScriptExec/ScriptExecController.m @@ -596,6 +596,8 @@ - (void)initialiseInterface { // style the text field outputTextView = progressBarTextView; + [outputTextView setBackgroundColor:textBackgroundColor]; + [outputTextView setTextColor:textForegroundColor]; // add drag instructions message if droplet NSString *progBarMsg = isDroppable ? @"Drag files to process" : @"Running..."; @@ -621,6 +623,8 @@ - (void)initialiseInterface { } [textOutputProgressIndicator setUsesThreadedAnimation:YES]; + [outputTextView setBackgroundColor:textBackgroundColor]; + [outputTextView setTextColor:textForegroundColor]; // prepare window [textOutputWindow setTitle:appName]; @@ -1188,7 +1192,7 @@ - (void)appendOutput:(NSData *)data { } } - if (outputType == PLATYPUS_OUTPUT_TEXTWINDOW || outputType == PLATYPUS_OUTPUT_PROGRESSBAR) { + if (IsTextViewScrollableOutputType(outputType)) { [outputTextView scrollRangeToVisible:NSMakeRange([[outputTextView textStorage] length], 0)]; } } @@ -1284,9 +1288,7 @@ - (IBAction)hideDetails { // save output in text field to file when Save to File menu item is invoked - (IBAction)saveToFile:(id)sender { - if (outputType != PLATYPUS_OUTPUT_TEXTWINDOW && - outputType != PLATYPUS_OUTPUT_WEBVIEW && - outputType != PLATYPUS_OUTPUT_PROGRESSBAR) { + if (!IsTextStyledOutputType(outputType)) { return; } NSString *outSuffix = (outputType == PLATYPUS_OUTPUT_WEBVIEW) ? @"html" : @"txt"; @@ -1308,25 +1310,22 @@ - (IBAction)saveToFile:(id)sender { // save only works for text window, web view output types // and open only works for droppable apps that accept files as script args - (BOOL)validateMenuItem:(NSMenuItem *)anItem { + + // status item menus are always enabled if (outputType == PLATYPUS_OUTPUT_STATUSMENU) { return YES; } - // save to file item - if ([[anItem title] isEqualToString:@"Save to File…"] && - (outputType != PLATYPUS_OUTPUT_TEXTWINDOW && outputType != PLATYPUS_OUTPUT_WEBVIEW && outputType != PLATYPUS_OUTPUT_PROGRESSBAR)) { + if (!IsTextStyledOutputType(outputType) && [[anItem title] isEqualToString:@"Save to File…"]) { return NO; } - // open should only work if it's a droppable app - if ([[anItem title] isEqualToString:@"Open…"] && (!isDroppable || !acceptsFiles)) { + // open should only work if it's a droppable app that accepts files + if ((!isDroppable || !acceptsFiles) && [[anItem title] isEqualToString:@"Open…"]) { return NO; } - // Make text bigger stuff - if (outputType != PLATYPUS_OUTPUT_TEXTWINDOW && outputType != PLATYPUS_OUTPUT_PROGRESSBAR - && outputType != PLATYPUS_OUTPUT_WEBVIEW) { - if ([[anItem title] isEqualToString:@"Make Text Bigger"] || [[anItem title] isEqualToString:@"Make Text Smaller"]) { - return NO; - } + // change text size + if (IsTextSizableOutputType(outputType) && [[anItem title] hasPrefix:@"Make Text"]) { + return NO; } return YES; diff --git a/Shared/PlatypusAppSpec.m b/Shared/PlatypusAppSpec.m index 1c471653..86fde1b9 100644 --- a/Shared/PlatypusAppSpec.m +++ b/Shared/PlatypusAppSpec.m @@ -521,9 +521,7 @@ - (NSMutableDictionary *)appSettingsPlist { appSettingsPlist[@"PromptForFileOnLaunch"] = self[@"PromptForFileOnLaunch"]; // we need only set text settings for the output types that use this information - if ([self[@"Output"] isEqualToString:@"Progress Bar"] || - [self[@"Output"] isEqualToString:@"Text Window"] || - [self[@"Output"] isEqualToString:@"Status Menu"]) { + if (IsTextStyledOutputTypeString(self[@"Output"])) { appSettingsPlist[@"TextFont"] = self[@"TextFont"]; appSettingsPlist[@"TextSize"] = self[@"TextSize"]; appSettingsPlist[@"TextForeground"] = self[@"TextForeground"]; @@ -816,10 +814,8 @@ - (NSString *)commandString:(BOOL)shortOpts { parametersString = [parametersString stringByAppendingString:[NSString stringWithFormat:@"%@ '%@' ", str, arg]]; } - // create args for text settings if progress bar/text window or status menu - if (([self[@"Output"] isEqualToString:@"Text Window"] || - [self[@"Output"] isEqualToString:@"Progress Bar"] || - [self[@"Output"] isEqualToString:@"Status Menu"])) { + // create args for text settings + if (IsTextStyledOutputTypeString(self[@"Output"])) { NSString *textFgString = @"", *textBgString = @"", *textFontString = @""; if (![self[@"TextForeground"] isEqualToString:DEFAULT_OUTPUT_FG_COLOR]) {