Skip to content

Commit

Permalink
Moved output type checking into macros + fixed issue with background/…
Browse files Browse the repository at this point in the history
…foreground color of text views
  • Loading branch information
sveinbjornt committed Nov 28, 2015
1 parent 737b716 commit a162374
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
15 changes: 15 additions & 0 deletions Common.h
Expand Up @@ -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
Expand Down
29 changes: 14 additions & 15 deletions ScriptExec/ScriptExecController.m
Expand Up @@ -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...";
Expand All @@ -621,6 +623,8 @@ - (void)initialiseInterface {
}

[textOutputProgressIndicator setUsesThreadedAnimation:YES];
[outputTextView setBackgroundColor:textBackgroundColor];
[outputTextView setTextColor:textForegroundColor];

// prepare window
[textOutputWindow setTitle:appName];
Expand Down Expand Up @@ -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)];
}
}
Expand Down Expand Up @@ -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";
Expand All @@ -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;
Expand Down
10 changes: 3 additions & 7 deletions Shared/PlatypusAppSpec.m
Expand Up @@ -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"];
Expand Down Expand Up @@ -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]) {
Expand Down

0 comments on commit a162374

Please sign in to comment.