Skip to content

Commit

Permalink
Do not show alternative selection state
Browse files Browse the repository at this point in the history
  • Loading branch information
levinli303 committed Nov 30, 2023
1 parent 50488c1 commit 7523b40
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
4 changes: 2 additions & 2 deletions MobileCelestia.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,7 @@
"-Wl,-ld_classic",
);
SDKROOT = iphoneos;
SHARED_BUILD_NUMBER = 394;
SHARED_BUILD_NUMBER = 395;
SHARED_BUILD_VERSION = 1.6.3;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand Down Expand Up @@ -1682,7 +1682,7 @@
"-Wl,-ld_classic",
);
SDKROOT = iphoneos;
SHARED_BUILD_NUMBER = 394;
SHARED_BUILD_NUMBER = 395;
SHARED_BUILD_VERSION = 1.6.3;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
Expand Down
24 changes: 7 additions & 17 deletions MobileCelestia/Celestia/CelestiaInteractionController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -562,24 +562,20 @@ extension CelestiaInteractionController: UIContextMenuInteractionDelegate {
return UIMenu(options: .displayInline, children: [contextMenuForLocation(location: location)])
}
} else {
guard let (selection, displaySurface) = executor.getSynchronously({ core in
guard let selection = executor.getSynchronously({ core in
let handler = ContextMenuHandler()
core.contextMenuHandler = handler
core.mouseButtonDown(at: location, modifiers: 0, with: .right)
core.mouseButtonUp(at: location, modifiers: 0, with: .right)
core.contextMenuHandler = nil
if let selection = handler.pendingSelection {
return (selection, core.simulation.activeObserver.displayedSurface)
} else {
return nil
}
return handler.pendingSelection
}) else {
return nil
}

return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { [weak self] _ in
guard let self else { return nil }
return UIMenu(children: self.contextMenuForSelection(selection: selection, displaySurface: displaySurface))
return UIMenu(children: self.contextMenuForSelection(selection: selection))
}
}
}
Expand All @@ -592,28 +588,24 @@ extension CelestiaInteractionController: UIContextMenuInteractionDelegate {
return
}
Task {
guard let (selection, displaySurface) = await self.executor.get({ core in
guard let selection = await self.executor.get({ core in
let handler = ContextMenuHandler()
core.contextMenuHandler = handler
core.mouseButtonDown(at: location, modifiers: 0, with: .right)
core.mouseButtonUp(at: location, modifiers: 0, with: .right)
core.contextMenuHandler = nil
if let selection = handler.pendingSelection {
return (selection, core.simulation.activeObserver.displayedSurface)
} else {
return nil
}
return handler.pendingSelection
}) else {
completion([])
return
}

completion(self.contextMenuForSelection(selection: selection, displaySurface: displaySurface))
completion(self.contextMenuForSelection(selection: selection))
}
}
}

private func contextMenuForSelection(selection: Selection, displaySurface: String) -> [UIMenuElement] {
private func contextMenuForSelection(selection: Selection) -> [UIMenuElement] {
let titleAction = UIAction(title: core.simulation.universe.name(for: selection)) { _ in }
titleAction.attributes = [.disabled]
var actions: [UIMenuElement] = [titleAction]
Expand Down Expand Up @@ -649,13 +641,11 @@ extension CelestiaInteractionController: UIContextMenuInteractionDelegate {
guard let self else { return }
self.executor.runAsynchronously { $0.simulation.activeObserver.displayedSurface = "" }
}
defaultSurfaceItem.state = displaySurface == "" ? .on : .off
let otherSurfaces = alternativeSurfaces.map { name -> UIAction in
let action = UIAction(title: name) { [weak self] _ in
guard let self else { return }
self.executor.runAsynchronously { $0.simulation.activeObserver.displayedSurface = name }
}
action.state = displaySurface == name ? .on : .off
return action
}
let menu = UIMenu(title: CelestiaString("Alternate Surfaces", comment: ""), children: [defaultSurfaceItem] + otherSurfaces)
Expand Down

0 comments on commit 7523b40

Please sign in to comment.