-
Notifications
You must be signed in to change notification settings - Fork 9
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
Zoom menu items; Menu Items validation #105
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,8 +36,7 @@ final class MainViewController: NSViewController { | |
let tabCollectionViewModel: TabCollectionViewModel | ||
|
||
private var selectedTabViewModelCancellable: AnyCancellable? | ||
private var canGoForwardCancellable: AnyCancellable? | ||
private var canGoBackCancellable: AnyCancellable? | ||
private var navigationalCancellables = Set<AnyCancellable>() | ||
private var canBookmarkCancellable: AnyCancellable? | ||
private var canInsertLastRemovedTabCancellable: AnyCancellable? | ||
private var findInPageCancellable: AnyCancellable? | ||
|
@@ -58,7 +57,6 @@ final class MainViewController: NSViewController { | |
|
||
listenToKeyDownEvents() | ||
subscribeToSelectedTabViewModel() | ||
subscribeToCanInsertLastRemovedTab() | ||
findInPageContainerView.applyDropShadow() | ||
} | ||
|
||
|
@@ -70,18 +68,6 @@ final class MainViewController: NSViewController { | |
fatalError("Default AppKit State Restoration should not be used") | ||
} | ||
|
||
func windowDidBecomeMain() { | ||
NSApplication.shared.mainMenuTyped.setWindowRelatedMenuItems(enabled: true) | ||
|
||
updateBackMenuItem() | ||
updateForwardMenuItem() | ||
updateReopenLastClosedTabMenuItem() | ||
} | ||
|
||
func windowDidResignMain() { | ||
NSApplication.shared.mainMenuTyped.setWindowRelatedMenuItems(enabled: false) | ||
} | ||
|
||
func windowWillClose() { | ||
if let monitor = keyDownMonitor { | ||
NSEvent.removeMonitor(monitor) | ||
|
@@ -132,43 +118,32 @@ final class MainViewController: NSViewController { | |
|
||
private func subscribeToSelectedTabViewModel() { | ||
selectedTabViewModelCancellable = tabCollectionViewModel.$selectedTabViewModel.receive(on: DispatchQueue.main).sink { [weak self] _ in | ||
self?.navigationalCancellables = [] | ||
self?.subscribeToCanGoBackForward() | ||
self?.subscribeToFindInPage() | ||
self?.subscribeToCanBookmark() | ||
} | ||
} | ||
|
||
private func subscribeToFindInPage() { | ||
findInPageCancellable?.cancel() | ||
let model = tabCollectionViewModel.selectedTabViewModel?.findInPage | ||
findInPageCancellable = model?.$visible.receive(on: DispatchQueue.main).sink { [weak self] _ in | ||
model?.$visible.receive(on: DispatchQueue.main).sink { [weak self] _ in | ||
self?.updateFindInPage() | ||
} | ||
}.store(in: &self.navigationalCancellables) | ||
} | ||
|
||
private func subscribeToCanGoBackForward() { | ||
canGoBackCancellable?.cancel() | ||
canGoBackCancellable = tabCollectionViewModel.selectedTabViewModel?.$canGoBack.receive(on: DispatchQueue.main).sink { [weak self] _ in | ||
tabCollectionViewModel.selectedTabViewModel?.$canGoBack.receive(on: DispatchQueue.main).sink { [weak self] _ in | ||
self?.updateBackMenuItem() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only left validation for states that can change while Main Menu is open; Other validation moved to MainMenuActions |
||
} | ||
canGoForwardCancellable?.cancel() | ||
canGoForwardCancellable = tabCollectionViewModel.selectedTabViewModel?.$canGoForward.receive(on: DispatchQueue.main).sink { [weak self] _ in | ||
}.store(in: &self.navigationalCancellables) | ||
tabCollectionViewModel.selectedTabViewModel?.$canGoForward.receive(on: DispatchQueue.main).sink { [weak self] _ in | ||
self?.updateForwardMenuItem() | ||
} | ||
} | ||
|
||
private func subscribeToCanBookmark() { | ||
canBookmarkCancellable?.cancel() | ||
canBookmarkCancellable = tabCollectionViewModel.selectedTabViewModel?.$canBeBookmarked.receive(on: DispatchQueue.main).sink { [weak self] _ in | ||
self?.updateBookmarksMenu() | ||
} | ||
} | ||
|
||
private func subscribeToCanInsertLastRemovedTab() { | ||
canInsertLastRemovedTabCancellable?.cancel() | ||
canInsertLastRemovedTabCancellable = tabCollectionViewModel.$canInsertLastRemovedTab.receive(on: DispatchQueue.main).sink { [weak self] _ in | ||
self?.updateReopenLastClosedTabMenuItem() | ||
} | ||
}.store(in: &self.navigationalCancellables) | ||
tabCollectionViewModel.selectedTabViewModel?.$canReload.receive(on: DispatchQueue.main).sink { [weak self] _ in | ||
self?.updateReloadMenuItem() | ||
}.store(in: &self.navigationalCancellables) | ||
tabCollectionViewModel.selectedTabViewModel?.$isLoading.receive(on: DispatchQueue.main).sink { [weak self] _ in | ||
self?.updateStopMenuItem() | ||
}.store(in: &self.navigationalCancellables) | ||
} | ||
|
||
private func updateFindInPage() { | ||
|
@@ -191,53 +166,63 @@ final class MainViewController: NSViewController { | |
} | ||
|
||
private func updateBackMenuItem() { | ||
guard let selectedTabViewModel = tabCollectionViewModel.selectedTabViewModel else { | ||
guard self.view.window?.isMainWindow == true, | ||
let selectedTabViewModel = tabCollectionViewModel.selectedTabViewModel | ||
else { | ||
os_log("MainViewController: No tab view model selected", type: .error) | ||
return | ||
} | ||
guard let backMenuItem = NSApplication.shared.mainMenuTyped.backMenuItem else { | ||
os_log("MainViewController: Failed to get reference to back menu item", type: .error) | ||
assertionFailure("MainViewController: Failed to get reference to back menu item") | ||
return | ||
} | ||
|
||
backMenuItem.isEnabled = selectedTabViewModel.canGoBack | ||
} | ||
|
||
func updateForwardMenuItem() { | ||
guard let selectedTabViewModel = tabCollectionViewModel.selectedTabViewModel else { | ||
private func updateForwardMenuItem() { | ||
guard self.view.window?.isMainWindow == true, | ||
let selectedTabViewModel = tabCollectionViewModel.selectedTabViewModel | ||
else { | ||
os_log("MainViewController: No tab view model selected", type: .error) | ||
return | ||
} | ||
guard let forwardMenuItem = NSApplication.shared.mainMenuTyped.forwardMenuItem else { | ||
os_log("MainViewController: Failed to get reference to back menu item", type: .error) | ||
assertionFailure("MainViewController: Failed to get reference to Forward menu item") | ||
return | ||
} | ||
|
||
forwardMenuItem.isEnabled = selectedTabViewModel.canGoForward | ||
} | ||
|
||
private func updateBookmarksMenu() { | ||
guard let selectedTabViewModel = tabCollectionViewModel.selectedTabViewModel else { | ||
private func updateReloadMenuItem() { | ||
guard self.view.window?.isMainWindow == true, | ||
let selectedTabViewModel = tabCollectionViewModel.selectedTabViewModel | ||
else { | ||
os_log("MainViewController: No tab view model selected", type: .error) | ||
return | ||
} | ||
guard let bookmarkThisPageMenuItem = NSApplication.shared.mainMenuTyped.bookmarkThisPageMenuItem, | ||
let favoriteThisPageMenuItem = NSApplication.shared.mainMenuTyped.favoriteThisPageMenuItem else { | ||
os_log("MainViewController: Failed to get reference to bookmarks menu items", type: .error) | ||
guard let reloadMenuItem = NSApplication.shared.mainMenuTyped.reloadMenuItem else { | ||
assertionFailure("MainViewController: Failed to get reference to Reload menu item") | ||
return | ||
} | ||
|
||
bookmarkThisPageMenuItem.isEnabled = selectedTabViewModel.canBeBookmarked | ||
favoriteThisPageMenuItem.isEnabled = selectedTabViewModel.canBeBookmarked | ||
reloadMenuItem.isEnabled = selectedTabViewModel.canReload | ||
} | ||
|
||
func updateReopenLastClosedTabMenuItem() { | ||
guard let reopenLastClosedTabMenuItem = NSApplication.shared.mainMenuTyped.reopenLastClosedTabMenuItem else { | ||
os_log("MainViewController: Failed to get reference to back menu item", type: .error) | ||
private func updateStopMenuItem() { | ||
guard self.view.window?.isMainWindow == true, | ||
let selectedTabViewModel = tabCollectionViewModel.selectedTabViewModel | ||
else { | ||
os_log("MainViewController: No tab view model selected", type: .error) | ||
return | ||
} | ||
guard let stopMenuItem = NSApplication.shared.mainMenuTyped.stopMenuItem else { | ||
assertionFailure("MainViewController: Failed to get reference to Stop menu item") | ||
return | ||
} | ||
|
||
reopenLastClosedTabMenuItem.isEnabled = tabCollectionViewModel.canInsertLastRemovedTab | ||
stopMenuItem.isEnabled = selectedTabViewModel.isLoading | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All validation moved to MainMenuActions.swift