Skip to content

Commit

Permalink
Add the ability to clear recently picked colors
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jun 30, 2022
1 parent b099fb4 commit b4bc4f5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Color Picker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@
repositoryURL = "https://github.com/getsentry/sentry-cocoa";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 7.16.0;
minimumVersion = 7.17.0;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
28 changes: 17 additions & 11 deletions Color Picker/ColorPickerScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@ private struct RecentlyPickedColorsButton: View {

var body: some View {
Menu {
ForEach(recentlyPickedColors.reversed()) { color in
Button {
appState.colorPanel.color = color
} label: {
Label {
Text(color.stringRepresentation)
} icon: {
// We don't use SwiftUI here as it only supports showing an actual image. (macOS 12.0)
// https://github.com/feedback-assistant/reports/issues/247
Image(nsImage: color.swatchImage)
Group {
ForEach(recentlyPickedColors.reversed()) { color in
Button {
appState.colorPanel.color = color
} label: {
Label {
Text(color.stringRepresentation)
} icon: {
// We don't use SwiftUI here as it only supports showing an actual image. (macOS 12.0)
// https://github.com/feedback-assistant/reports/issues/247
Image(nsImage: color.swatchImage)
}
.labelStyle(.titleAndIcon)
}
.labelStyle(.titleAndIcon)
}
Divider()
Button("Clear") {
recentlyPickedColors = []
}
}
// Without, it becomes disabled. (macOS 12.4)
Expand Down
1 change: 1 addition & 0 deletions Color Picker/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ extension SSApp {
/**
The SwiftUI settings window.
*/
@MainActor
static var settingsWindow: NSWindow? {
NSApp.windows.first { $0.frameAutosaveName == "com_apple_SwiftUI_Settings_window" }
}
Expand Down

0 comments on commit b4bc4f5

Please sign in to comment.