generated from kodecocodes/bkk-materials
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '03-adding-menus-and-toolbars' into editions/1.0
- Loading branch information
Showing
70 changed files
with
4,864 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
453 changes: 453 additions & 0 deletions
453
03-adding-menus-and-toolbars/projects/challenge/OnThisDay.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
...lbars/projects/challenge/OnThisDay.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...s/challenge/OnThisDay.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
38 changes: 38 additions & 0 deletions
38
...-and-toolbars/projects/challenge/OnThisDay.xcodeproj/xcshareddata/IDETemplateMacros.plist
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>FILEHEADER</key> | ||
<string>/ Copyright (c) ___YEAR___ Razeware LLC | ||
/// | ||
/// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
/// of this software and associated documentation files (the "Software"), to deal | ||
/// in the Software without restriction, including without limitation the rights | ||
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
/// copies of the Software, and to permit persons to whom the Software is | ||
/// furnished to do so, subject to the following conditions: | ||
/// | ||
/// The above copyright notice and this permission notice shall be included in | ||
/// all copies or substantial portions of the Software. | ||
/// | ||
/// Notwithstanding the foregoing, you may not use, copy, modify, merge, publish, | ||
/// distribute, sublicense, create a derivative work, and/or sell copies of the | ||
/// Software in any work that is designed, intended, or marketed for pedagogical or | ||
/// instructional purposes related to programming, coding, application development, | ||
/// or information technology. Permission for such use, copying, modification, | ||
/// merger, publication, distribution, sublicensing, creation of derivative works, | ||
/// or sale is expressly withheld. | ||
/// | ||
/// This project and source code may use libraries or frameworks that are | ||
/// released under various Open-Source licenses. Use of those libraries and | ||
/// frameworks are governed by their own individual licenses. | ||
/// | ||
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
/// THE SOFTWARE.</string> | ||
</dict> | ||
</plist> |
11 changes: 11 additions & 0 deletions
11
...-toolbars/projects/challenge/OnThisDay/Assets.xcassets/AccentColor.colorset/Contents.json
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...nd-toolbars/projects/challenge/OnThisDay/Assets.xcassets/AppIcon.appiconset/Contents.json
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "16x16" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "16x16" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "32x32" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "32x32" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "128x128" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "128x128" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "256x256" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "256x256" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "512x512" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "512x512" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
03-adding-menus-and-toolbars/projects/challenge/OnThisDay/Assets.xcassets/Contents.json
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
03-adding-menus-and-toolbars/projects/challenge/OnThisDay/Controls/Menus.swift
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/// Copyright (c) 2022 Razeware LLC | ||
/// | ||
/// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
/// of this software and associated documentation files (the "Software"), to deal | ||
/// in the Software without restriction, including without limitation the rights | ||
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
/// copies of the Software, and to permit persons to whom the Software is | ||
/// furnished to do so, subject to the following conditions: | ||
/// | ||
/// The above copyright notice and this permission notice shall be included in | ||
/// all copies or substantial portions of the Software. | ||
/// | ||
/// Notwithstanding the foregoing, you may not use, copy, modify, merge, publish, | ||
/// distribute, sublicense, create a derivative work, and/or sell copies of the | ||
/// Software in any work that is designed, intended, or marketed for pedagogical or | ||
/// instructional purposes related to programming, coding, application development, | ||
/// or information technology. Permission for such use, copying, modification, | ||
/// merger, publication, distribution, sublicensing, creation of derivative works, | ||
/// or sale is expressly withheld. | ||
/// | ||
/// This project and source code may use libraries or frameworks that are | ||
/// released under various Open-Source licenses. Use of those libraries and | ||
/// frameworks are governed by their own individual licenses. | ||
/// | ||
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
/// THE SOFTWARE. | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
struct Menus: Commands { | ||
@AppStorage("showTotals") var showTotals = true | ||
@AppStorage("displayMode") var displayMode = DisplayMode.auto | ||
|
||
var body: some Commands { | ||
SidebarCommands() | ||
ToolbarCommands() | ||
|
||
CommandGroup(before: .help) { | ||
Button("APIzen.Date web site") { | ||
showAPIWebSite() | ||
} | ||
.keyboardShortcut("/", modifiers: .command) | ||
} | ||
|
||
CommandMenu("Display") { | ||
Toggle(isOn: $showTotals) { | ||
Text("Show Totals") | ||
} | ||
.keyboardShortcut("t", modifiers: .command) | ||
|
||
Divider() | ||
|
||
Picker("Appearance", selection: $displayMode) { | ||
ForEach(DisplayMode.allCases, id: \.self) { | ||
Text($0.rawValue) | ||
.tag($0) | ||
} | ||
} | ||
|
||
// Optional menu items | ||
// | ||
// Divider() | ||
// | ||
// Menu("Display Submenu") { | ||
// Button("Light") { | ||
// displayMode = .light | ||
// } | ||
// .keyboardShortcut("L", modifiers: .command) | ||
// | ||
// Button("Dark") { | ||
// displayMode = .dark | ||
// } | ||
// .keyboardShortcut("D", modifiers: .command) | ||
// | ||
// Button("Auto") { | ||
// displayMode = .auto | ||
// } | ||
// .keyboardShortcut("U", modifiers: .command) | ||
// } | ||
} | ||
} | ||
|
||
func showAPIWebSite() { | ||
let address = "https://apizen.date" | ||
guard let url = URL(string: address) else { | ||
fatalError("Invalid address") | ||
} | ||
NSWorkspace.shared.open(url) | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
03-adding-menus-and-toolbars/projects/challenge/OnThisDay/Controls/Toolbar.swift
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/// Copyright (c) 2022 Razeware LLC | ||
/// | ||
/// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
/// of this software and associated documentation files (the "Software"), to deal | ||
/// in the Software without restriction, including without limitation the rights | ||
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
/// copies of the Software, and to permit persons to whom the Software is | ||
/// furnished to do so, subject to the following conditions: | ||
/// | ||
/// The above copyright notice and this permission notice shall be included in | ||
/// all copies or substantial portions of the Software. | ||
/// | ||
/// Notwithstanding the foregoing, you may not use, copy, modify, merge, publish, | ||
/// distribute, sublicense, create a derivative work, and/or sell copies of the | ||
/// Software in any work that is designed, intended, or marketed for pedagogical or | ||
/// instructional purposes related to programming, coding, application development, | ||
/// or information technology. Permission for such use, copying, modification, | ||
/// merger, publication, distribution, sublicensing, creation of derivative works, | ||
/// or sale is expressly withheld. | ||
/// | ||
/// This project and source code may use libraries or frameworks that are | ||
/// released under various Open-Source licenses. Use of those libraries and | ||
/// frameworks are governed by their own individual licenses. | ||
/// | ||
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
/// THE SOFTWARE. | ||
|
||
import SwiftUI | ||
|
||
struct Toolbar: CustomizableToolbarContent { | ||
var body: some CustomizableToolbarContent { | ||
ToolbarItem( | ||
id: "toggleSidebar", | ||
placement: .navigation, | ||
showsByDefault: true | ||
) { | ||
Button { | ||
toggleSidebar() | ||
} label: { | ||
Label("Toggle Sidebar", systemImage: "sidebar.left") | ||
} | ||
.help("Toggle Sidebar") | ||
} | ||
} | ||
|
||
func toggleSidebar() { | ||
NSApp.keyWindow? | ||
.contentViewController? | ||
.tryToPerform(#selector(NSSplitViewController.toggleSidebar(_:)), with: nil) | ||
} | ||
} |
Oops, something went wrong.