Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add done-file CLI argument #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions TodoTxtMac/TTMAppController.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ extern NSString *const TodoFileArgument;
*/
- (NSString*)commandLineArgumentTodoFile;

/*!
* @method openDoneFileFromCommandLineArgument:
* @abstract This method opens a done.txt file based on the command line argument.
* The name of the argument is defined in the DoneFileArgument constant.
* If there is no command line argument, this method does nothing.
*/
- (void)openDoneFileFromCommandLineArgument;

/*!
* @method commandLineArgumentDoneFile:
* @abstract This method returns the value of the done-file command line argument.
* If there is no command-line argument, it returns null.
*/
- (NSString*)commandLineArgumentDoneFile;

/*!
* @method openDocumentFromFilePath:
* @abstract This method opens a todo.txt file (TTMDocument) based on a file path.
Expand Down
14 changes: 14 additions & 0 deletions TodoTxtMac/TTMAppController.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ @implementation TTMAppController

// Constants for command-line argument names
NSString *const TodoFileArgument = @"todo-file";
NSString *const DoneFileArgument = @"done-file";

- (id)init {
self = [super init];
Expand Down Expand Up @@ -195,11 +196,24 @@ - (void)openTodoFileFromCommandLineArgument {
[self openDocumentFromFilePath:fileToOpenOnLaunch];
}

- (void)openDoneFileFromCommandLineArgument {
NSString *fileToOpenOnLaunch = [self commandLineArgumentDoneFile];
if (!fileToOpenOnLaunch) {
return;
}
[self openDocumentFromFilePath:fileToOpenOnLaunch];
}

- (NSString*)commandLineArgumentTodoFile {
NSUserDefaults *args = [NSUserDefaults standardUserDefaults];
return [args stringForKey:TodoFileArgument];
}

- (NSString*)commandLineArgumentDoneFile {
NSUserDefaults *args = [NSUserDefaults standardUserDefaults];
return [args stringForKey:DoneFileArgument];
}

- (void)openDocumentFromFilePath:(NSString*)filePath {
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
[self openDocumentFromFileURL:fileURL];
Expand Down
6 changes: 5 additions & 1 deletion TodoTxtMac/TTMAppDelegate.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ @implementation TTMAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
[self.appController initializeUserDefaults:self];

// Open file from command line argument. Does nothing if there is no command line argument.
// Open todo file from command line argument. Does nothing if there is no command line argument.
[self.appController openTodoFileFromCommandLineArgument];

// Open done file from command line argument. Does nothing if there is no command line argument.
[self.appController openDoneFileFromCommandLineArgument];

// Open default todo file, if one is selected and the option is enabled.
[self.appController openDefaultTodoFile];
}
Expand All @@ -67,6 +70,7 @@ - (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender {
// Without this method override, opening a todo file using the command line argument
// or the default todo file user preference also opens an Untitled document every time.
return ([self.appController commandLineArgumentTodoFile] == NULL &&
[self.appController commandLineArgumentDoneFile] == NULL &&
![[NSUserDefaults standardUserDefaults] boolForKey:@"openDefaultTodoFileOnStartup"]);
}

Expand Down