Skip to content
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
49 changes: 49 additions & 0 deletions MacDown/Code/Application/MPMainController.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ NS_INLINE void treat()
}];
}

NS_INLINE MPDocument *MPDocumentForFindActions()
{
NSWindow *window = NSApp.keyWindow ?: NSApp.mainWindow;
id document = window.windowController.document;
if ([document isKindOfClass:MPDocument.class])
return document;

return nil;
}

@interface MPMainController ()
@property (readonly) NSWindowController *preferencesWindowController;
Expand Down Expand Up @@ -216,9 +225,49 @@ - (IBAction)openGitHub:(id)sender
[[NSWorkspace sharedWorkspace] openURL:url];
}

- (IBAction)performFindPanelAction:(id)sender
{
MPDocument *document = MPDocumentForFindActions();
if (![document respondsToSelector:_cmd])
{
NSBeep();
return;
}

[document performFindPanelAction:sender];
}

- (IBAction)centerSelectionInVisibleArea:(id)sender
{
MPDocument *document = MPDocumentForFindActions();
if (![document respondsToSelector:_cmd])
{
NSBeep();
return;
}

[document centerSelectionInVisibleArea:sender];
}


#pragma mark - Override

- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item
{
if (item.action == @selector(performFindPanelAction:) ||
item.action == @selector(centerSelectionInVisibleArea:))
{
MPDocument *document = MPDocumentForFindActions();
if (![document respondsToSelector:item.action])
return NO;
if ([document respondsToSelector:@selector(validateUserInterfaceItem:)])
return [document validateUserInterfaceItem:item];
return YES;
}

return YES;
}

- (instancetype)init
{
self = [super init];
Expand Down
3 changes: 3 additions & 0 deletions MacDown/Code/Document/MPDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
@property (nonatomic, readwrite) NSString *markdown;
@property (nonatomic, readonly) NSString *html;

- (IBAction)performFindPanelAction:(id)sender;
- (IBAction)centerSelectionInVisibleArea:(id)sender;

/**
* Toggle the checkbox at the specified index in the markdown source.
* Unchecked checkboxes ([ ]) become checked ([x]), and vice versa.
Expand Down
Loading