diff --git a/Edit.xcodeproj/project.pbxproj b/Edit.xcodeproj/project.pbxproj index 83c5610..66a6bc7 100644 --- a/Edit.xcodeproj/project.pbxproj +++ b/Edit.xcodeproj/project.pbxproj @@ -7,7 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - C900A7C52A9E9468000556A6 /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C900A7C42A9E9468000556A6 /* PreferencesWindowController.swift */; }; C900A7C82A9E94AE000556A6 /* libPreferencesWindow.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C900A7BA2A9E93FC000556A6 /* libPreferencesWindow.a */; }; C900A7CA2A9E94B4000556A6 /* ExtendableHost in Frameworks */ = {isa = PBXBuildFile; productRef = C900A7C92A9E94B4000556A6 /* ExtendableHost */; }; C900A7D12A9F472E000556A6 /* Chime.appextensionpoint in Copy Extensions */ = {isa = PBXBuildFile; fileRef = C900A7CF2A9F46EF000556A6 /* Chime.appextensionpoint */; }; @@ -71,7 +70,7 @@ C96B61F12BDA707200561DE8 /* DocumentCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = C96B61EC2BDA6F5900561DE8 /* DocumentCoordinator.swift */; }; C96B61F22BDA708A00561DE8 /* libDocument.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C9FE52D42A7532C700CACA1A /* libDocument.a */; }; C96B61F32BDA70DA00561DE8 /* libEditor.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C9FE537A2A7662DC00CACA1A /* libEditor.a */; }; - C96B61FD2BDA714700561DE8 /* ScrollViewPlus in Frameworks */ = {isa = PBXBuildFile; productRef = C96B61FC2BDA714700561DE8 /* ScrollViewPlus */; }; + C96B61FD2BDA714700561DE8 /* ScrollViewPlus in Frameworks */ = {isa = PBXBuildFile; platformFilters = (macos, ); productRef = C96B61FC2BDA714700561DE8 /* ScrollViewPlus */; }; C96B61FE2BDA719100561DE8 /* libGutter.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C9891B352AFFF1F700C8F393 /* libGutter.a */; }; C96B61FF2BDA71B200561DE8 /* libUIUtility.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C9FE53232A75A17700CACA1A /* libUIUtility.a */; }; C96B62002BDA71E400561DE8 /* libStatus.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C9FE539B2A76709D00CACA1A /* libStatus.a */; }; @@ -105,8 +104,6 @@ C97918DA2A9E080C0046EAF1 /* ViewPlus in Frameworks */ = {isa = PBXBuildFile; productRef = C97918D92A9E080C0046EAF1 /* ViewPlus */; }; C97918DE2A9E39030046EAF1 /* OpenQuicklyWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C97918DD2A9E39030046EAF1 /* OpenQuicklyWindowController.swift */; }; C97918E02A9E39D80046EAF1 /* NSRect+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = C97918DF2A9E39D80046EAF1 /* NSRect+Helpers.swift */; }; - C97918EC2A9E49130046EAF1 /* ShapeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C97918EB2A9E49130046EAF1 /* ShapeView.swift */; }; - C97918EE2A9E49330046EAF1 /* ShapeLayerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C97918ED2A9E49330046EAF1 /* ShapeLayerController.swift */; }; C97918F22A9E49EE0046EAF1 /* BinaryFloatingPoint+AngleUnits.swift in Sources */ = {isa = PBXBuildFile; fileRef = C97918F12A9E49EE0046EAF1 /* BinaryFloatingPoint+AngleUnits.swift */; }; C97918F52A9E4A3B0046EAF1 /* HexagonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C97918F32A9E4A1C0046EAF1 /* HexagonView.swift */; }; C97918F62A9E4A4D0046EAF1 /* NSBezierPath+Paths.swift in Sources */ = {isa = PBXBuildFile; fileRef = C97918EF2A9E49AD0046EAF1 /* NSBezierPath+Paths.swift */; }; @@ -215,7 +212,6 @@ C9FE53AD2A7677A700CACA1A /* EditorScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9FE53AC2A7677A700CACA1A /* EditorScrollView.swift */; }; C9FE53B92A77334E00CACA1A /* SourceViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9FE53B82A77334E00CACA1A /* SourceViewController.swift */; }; C9FE53BF2A77C02400CACA1A /* BoundingBorders.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9FE53BE2A77C02400CACA1A /* BoundingBorders.swift */; }; - C9FE53C12A77C06800CACA1A /* ColorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9FE53C02A77C06700CACA1A /* ColorView.swift */; }; C9FE53D82A77D98A00CACA1A /* EditorContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9FE53D72A77D98A00CACA1A /* EditorContent.swift */; }; C9FE53E82A7A5B2000CACA1A /* LazyRemoteExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9FE53E72A7A5B2000CACA1A /* LazyRemoteExtension.swift */; }; C9FE53FF2A7A5F1600CACA1A /* Logger+init.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9FE53FE2A7A5F1600CACA1A /* Logger+init.swift */; }; @@ -867,7 +863,6 @@ /* Begin PBXFileReference section */ C900A7BA2A9E93FC000556A6 /* libPreferencesWindow.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPreferencesWindow.a; sourceTree = BUILT_PRODUCTS_DIR; }; - C900A7C42A9E9468000556A6 /* PreferencesWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindowController.swift; sourceTree = ""; }; C900A7CF2A9F46EF000556A6 /* Chime.appextensionpoint */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Chime.appextensionpoint; sourceTree = ""; }; C92672F72B0399D800B3CE2F /* SwiftExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftExtension.swift; path = "submodules/chime-swift/Sources/ChimeSwift/SwiftExtension.swift"; sourceTree = SOURCE_ROOT; }; C92673282B04046700B3CE2F /* Edit-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Edit-Debug.xcconfig"; sourceTree = ""; }; @@ -935,8 +930,6 @@ C97918D22A9E04470046EAF1 /* NSTableView+Reuse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSTableView+Reuse.swift"; sourceTree = ""; }; C97918DD2A9E39030046EAF1 /* OpenQuicklyWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenQuicklyWindowController.swift; sourceTree = ""; }; C97918DF2A9E39D80046EAF1 /* NSRect+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSRect+Helpers.swift"; sourceTree = ""; }; - C97918EB2A9E49130046EAF1 /* ShapeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShapeView.swift; sourceTree = ""; }; - C97918ED2A9E49330046EAF1 /* ShapeLayerController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShapeLayerController.swift; sourceTree = ""; }; C97918EF2A9E49AD0046EAF1 /* NSBezierPath+Paths.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSBezierPath+Paths.swift"; sourceTree = ""; }; C97918F12A9E49EE0046EAF1 /* BinaryFloatingPoint+AngleUnits.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BinaryFloatingPoint+AngleUnits.swift"; sourceTree = ""; }; C97918F32A9E4A1C0046EAF1 /* HexagonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HexagonView.swift; sourceTree = ""; }; @@ -1064,7 +1057,6 @@ C9FE53AC2A7677A700CACA1A /* EditorScrollView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditorScrollView.swift; sourceTree = ""; }; C9FE53B82A77334E00CACA1A /* SourceViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SourceViewController.swift; sourceTree = ""; }; C9FE53BE2A77C02400CACA1A /* BoundingBorders.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BoundingBorders.swift; sourceTree = ""; }; - C9FE53C02A77C06700CACA1A /* ColorView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorView.swift; sourceTree = ""; }; C9FE53C82A77CC1E00CACA1A /* libTheme.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libTheme.a; sourceTree = BUILT_PRODUCTS_DIR; }; C9FE53D72A77D98A00CACA1A /* EditorContent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditorContent.swift; sourceTree = ""; }; C9FE53DD2A7A5A2A00CACA1A /* libExtensionHost.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libExtensionHost.a; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -1335,7 +1327,6 @@ C900A7C32A9E9417000556A6 /* PreferencesWindow */ = { isa = PBXGroup; children = ( - C900A7C42A9E9468000556A6 /* PreferencesWindowController.swift */, C9E0BA2F2BD2C1EF007AF034 /* SettingsView.swift */, C9E0BA362BD2C96D007AF034 /* ThemeTile.swift */, C9E0BA342BD2C7F2007AF034 /* ThemeView.swift */, @@ -1767,7 +1758,6 @@ C97918B72A9D49190046EAF1 /* AttributedText.swift */, C97918F12A9E49EE0046EAF1 /* BinaryFloatingPoint+AngleUnits.swift */, C9FE53BE2A77C02400CACA1A /* BoundingBorders.swift */, - C9FE53C02A77C06700CACA1A /* ColorView.swift */, C97918F32A9E4A1C0046EAF1 /* HexagonView.swift */, C97918942A9CCC980046EAF1 /* Modifiers */, C97918DF2A9E39D80046EAF1 /* NSRect+Helpers.swift */, @@ -1775,8 +1765,6 @@ C9FE532D2A75A1C100CACA1A /* RepresentableView.swift */, C9FE532E2A75A1C100CACA1A /* RepresentableViewController.swift */, C97918792A9CBF8C0046EAF1 /* RoundedCorners.swift */, - C97918ED2A9E49330046EAF1 /* ShapeLayerController.swift */, - C97918EB2A9E49130046EAF1 /* ShapeView.swift */, ); path = UIUtility; sourceTree = ""; @@ -2066,7 +2054,6 @@ dependencies = ( C9E0BA392BD2C98A007AF034 /* PBXTargetDependency */, C9E0BA332BD2C2BE007AF034 /* PBXTargetDependency */, - C900A7CC2A9E956B000556A6 /* PBXTargetDependency */, ); name = PreferencesWindow; productName = PreferencesWindow; @@ -2552,6 +2539,7 @@ buildRules = ( ); dependencies = ( + C9CDC24D2BDABFE000183752 /* PBXTargetDependency */, ); name = UIUtility; productName = UIUtility; @@ -2569,6 +2557,7 @@ buildRules = ( ); dependencies = ( + C9CDC24A2BDAB56400183752 /* PBXTargetDependency */, C999C7862ABDA97500D49939 /* PBXTargetDependency */, C9E8781E2A9FD0B70018340C /* PBXTargetDependency */, C9FE53962A766D2F00CACA1A /* PBXTargetDependency */, @@ -2850,7 +2839,9 @@ projectRoot = ""; targets = ( C9FE52982A7525D000CACA1A /* Edit */, + C9B8AA172B362DDD00C79606 /* Preview */, C9FE52F32A7539B100CACA1A /* ChimeKit */, + C92931412B80CC6700C64DDE /* EditKit */, C9FE52AD2A7525D300CACA1A /* EditTests */, C9FE52B72A7525D300CACA1A /* EditUITests */, C9FE52D32A7532C700CACA1A /* Document */, @@ -2871,11 +2862,9 @@ C9891B342AFFF1F700C8F393 /* Gutter */, C9BDB5472B00FD89009225FB /* SwiftExtension */, C9B8A9DC2B31E43800C79606 /* TextSystem */, - C9B8AA172B362DDD00C79606 /* Preview */, C9B8AA492B37055800C79606 /* SyntaxService */, C973DFFF2B62BDB3000998F7 /* Highlighting */, C942E6752B67B78E00792DD4 /* UserScript */, - C92931412B80CC6700C64DDE /* EditKit */, C9E0B9FB2BD27F0F007AF034 /* Diagnostics */, ); }; @@ -2979,7 +2968,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - C900A7C52A9E9468000556A6 /* PreferencesWindowController.swift in Sources */, C9E0BA352BD2C7F2007AF034 /* ThemeView.swift in Sources */, C9E0BA312BD2C1FA007AF034 /* SettingsView.swift in Sources */, C9E0BA372BD2C96D007AF034 /* ThemeTile.swift in Sources */, @@ -3205,12 +3193,9 @@ C97918972A9CCCF60046EAF1 /* BottomSlideEffect.swift in Sources */, C97918D32A9E04470046EAF1 /* NSTableView+Reuse.swift in Sources */, C979187C2A9CC1190046EAF1 /* RoundedCorners.swift in Sources */, - C9FE53C12A77C06800CACA1A /* ColorView.swift in Sources */, C9FE532F2A75A1C100CACA1A /* RepresentableView.swift in Sources */, - C97918EE2A9E49330046EAF1 /* ShapeLayerController.swift in Sources */, C97918982A9CCCFD0046EAF1 /* TrailingSlideEffect.swift in Sources */, C97918F22A9E49EE0046EAF1 /* BinaryFloatingPoint+AngleUnits.swift in Sources */, - C97918EC2A9E49130046EAF1 /* ShapeView.swift in Sources */, C9FE53302A75A1C100CACA1A /* RepresentableViewController.swift in Sources */, C97918D12A9E03C00046EAF1 /* NSImageView+Symbol.swift in Sources */, C97918F62A9E4A4D0046EAF1 /* NSBezierPath+Paths.swift in Sources */, @@ -3327,10 +3312,6 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ - C900A7CC2A9E956B000556A6 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - productRef = C900A7CB2A9E956B000556A6 /* ViewPlus */; - }; C900A7CE2A9E9600000556A6 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = C900A7B92A9E93FC000556A6 /* PreferencesWindow */; @@ -3480,6 +3461,9 @@ }; C96B61FB2BDA714000561DE8 /* PBXTargetDependency */ = { isa = PBXTargetDependency; + platformFilters = ( + macos, + ); productRef = C96B61FA2BDA714000561DE8 /* ScrollViewPlus */; }; C96B62022BDA71FE00561DE8 /* PBXTargetDependency */ = { @@ -3735,6 +3719,14 @@ isa = PBXTargetDependency; productRef = C9BFA1A82BC072E300E86487 /* Glyph */; }; + C9CDC24A2BDAB56400183752 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + productRef = C9CDC2492BDAB56400183752 /* ViewPlus */; + }; + C9CDC24D2BDABFE000183752 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + productRef = C9CDC24C2BDABFE000183752 /* NSUI */; + }; C9CDEB5C2B51621C009E252A /* PBXTargetDependency */ = { isa = PBXTargetDependency; productRef = C9CDEB5B2B51621C009E252A /* ColorToolbox */; @@ -4728,7 +4720,7 @@ repositoryURL = "https://github.com/mattmassicotte/nsui.git"; requirement = { kind = revision; - revision = ad4cb093c70c731b4a036d30a2a39f8db6afe2c6; + revision = b6c32973b2a9dc16c465f3e3bc44e9abb27d1683; }; }; C9BFA1AE2BC0927A00E86487 /* XCRemoteSwiftPackageReference "Glyph" */ = { @@ -4827,11 +4819,6 @@ package = C9FE53EB2A7A5D9700CACA1A /* XCRemoteSwiftPackageReference "Extendable" */; productName = ExtendableHost; }; - C900A7CB2A9E956B000556A6 /* ViewPlus */ = { - isa = XCSwiftPackageProductDependency; - package = C97918D42A9E07F00046EAF1 /* XCRemoteSwiftPackageReference "ViewPlus" */; - productName = ViewPlus; - }; C926734F2B06719C00B3CE2F /* Neon */ = { isa = XCSwiftPackageProductDependency; productName = Neon; @@ -5073,6 +5060,16 @@ package = C9BFA1A12BBF4FA200E86487 /* XCRemoteSwiftPackageReference "nsui" */; productName = NSUI; }; + C9CDC2492BDAB56400183752 /* ViewPlus */ = { + isa = XCSwiftPackageProductDependency; + package = C97918D42A9E07F00046EAF1 /* XCRemoteSwiftPackageReference "ViewPlus" */; + productName = ViewPlus; + }; + C9CDC24C2BDABFE000183752 /* NSUI */ = { + isa = XCSwiftPackageProductDependency; + package = C9BFA1A12BBF4FA200E86487 /* XCRemoteSwiftPackageReference "nsui" */; + productName = NSUI; + }; C9CDEB5B2B51621C009E252A /* ColorToolbox */ = { isa = XCSwiftPackageProductDependency; package = C9CDEB582B51620E009E252A /* XCRemoteSwiftPackageReference "ColorToolbox" */; diff --git a/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index f01b0c8..a47add1 100644 --- a/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -135,7 +135,7 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/mattmassicotte/nsui.git", "state" : { - "revision" : "ad4cb093c70c731b4a036d30a2a39f8db6afe2c6" + "revision" : "b6c32973b2a9dc16c465f3e3bc44e9abb27d1683" } }, { diff --git a/Edit/Modules/OpenQuickly/OpenQuicklyViewController.swift b/Edit/Modules/OpenQuickly/OpenQuicklyViewController.swift index 5ed797c..7ae4e19 100644 --- a/Edit/Modules/OpenQuickly/OpenQuicklyViewController.swift +++ b/Edit/Modules/OpenQuickly/OpenQuicklyViewController.swift @@ -61,7 +61,7 @@ final class OpenQuicklyViewController: XiblessViewController { } override func loadView() { - self.view = ColorView.roundedRect(color: NSColor.windowBackgroundColor, radii: (15.0, 15.0, 15.0, 15.0)) + self.view = NSView() // NSHostingView(rootView: RoundedRectangle(cornerRadius: 15.0)) inputView.placeholderString = "Open Quickly" inputView.font = NSFont.systemFont(ofSize: 18.0) diff --git a/Edit/Modules/PreferencesWindow/PreferencesWindowController.swift b/Edit/Modules/PreferencesWindow/PreferencesWindowController.swift deleted file mode 100644 index b306ca1..0000000 --- a/Edit/Modules/PreferencesWindow/PreferencesWindowController.swift +++ /dev/null @@ -1,191 +0,0 @@ -import AppKit -import SwiftUI - -import ExtensionKit -import ViewPlus - -public final class PreferencesWindowController: NSWindowController { - private let toolbar = NSToolbar(identifier: NSToolbar.Identifier.preferences) - -// lazy var generalPrefsViewController = GeneralPreferencesViewController() -// lazy var appearancePrefsViewController = AppearancePrefsViewController() -// lazy var editingBehaviorPrefsViewController = EditingBehaviorPrefsViewController() - lazy var extensionPrefsViewController = EXAppExtensionBrowserViewController() -// lazy var commandLinePrefsViewController = NSHostingController(rootView: CommandLinePrefsView()) - - public init() { - let height: CGFloat = 406 - - let rect = NSRect(x: 0, y: 0, width: height * 16.0/9.0, height: height) - let w = NSWindow(contentRect: .zero, styleMask: [.closable, .titled, .unifiedTitleAndToolbar], backing: .buffered, defer: true) - w.center() - - super.init(window: w) - - self.setupContent() - } - - @available(*, unavailable) - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - func setupContent() { - toolbar.delegate = self - toolbar.allowsExtensionItems = false - toolbar.allowsUserCustomization = false - toolbar.displayMode = .iconAndLabel - - window?.toolbar = toolbar - window?.showsToolbarButton = false - -// toolbar.selectedItemIdentifier = NSToolbarItem.Identifier.general -// setActiveController(generalPrefsViewController) - toolbar.selectedItemIdentifier = .extensions - setActiveController(extensionPrefsViewController) - - guard let contentView = window?.contentView else { - return - } - - NSLayoutConstraint.activate([ - contentView.heightAnchor.constraint(equalToConstant: 406), - contentView.widthAnchor.constraint(equalTo: contentView.heightAnchor, multiplier: 16.0/9.0), - ]) - } - - func setActiveController(_ controller: NSViewController) { - guard let contentView = window?.contentView else { - return - } - - for subview in contentView.subviews { - subview.isHidden = true - } - - if controller.view.superview != window?.contentView { - controller.view.removeFromSuperview() - contentView.addSubview(controller.view) - controller.view.useAutoLayout = true - - NSLayoutConstraint.activate([ - controller.view.topAnchor.constraint(equalTo: contentView.topAnchor), - controller.view.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), - controller.view.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), - controller.view.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), - ]) - } - - controller.view.isHidden = false - } -} - -extension PreferencesWindowController { - @IBAction func showGeneral(_ sender: Any?) { -// setActiveController(generalPrefsViewController) - } - - @IBAction func showAppearance(_ sender: Any?) { -// setActiveController(appearancePrefsViewController) - } - - @IBAction func showEditingBehavior(_ sender: Any?) { -// setActiveController(editingBehaviorPrefsViewController) - } - - @IBAction func showExtensions(_ sender: Any?) { - setActiveController(extensionPrefsViewController) - } - - @IBAction func showCommandLine(_ sender: Any?) { -// setActiveController(commandLinePrefsViewController) - } -} - -fileprivate extension NSToolbar.Identifier { - static let preferences = NSToolbar.Identifier("com.chimehq.Edit.Preferences-Toolbar") -} - -fileprivate extension NSToolbarItem.Identifier { - static let general = NSToolbarItem.Identifier("com.chimehq.Edit.Preferences-Toolbar.General") - static let appearance = NSToolbarItem.Identifier("com.chimehq.Edit.Preferences-Toolbar.Appearance") - static let editingBehavior = NSToolbarItem.Identifier("com.chimehq.Edit.Preferences-Toolbar.Editing-Behavior") - static let extensions = NSToolbarItem.Identifier("com.chimehq.Edit.Preferences-Toolbar.Extensions") - static let commandLine = NSToolbarItem.Identifier("com.chimehq.Edit.Preferences-Toolbar.CommandLine") -} - -extension PreferencesWindowController: NSToolbarDelegate { - - public func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? { - var toolbarItem: NSToolbarItem? - - switch itemIdentifier { - case .general: - let item = NSToolbarItem(itemIdentifier: itemIdentifier) - item.label = NSLocalizedString("preferences.toolbar.general", comment: "Preferences Toolbar General Button Label") - item.paletteLabel = item.label - item.toolTip = item.label - item.target = self - item.action = #selector(showGeneral(_:)) - item.image = NSImage(named: "preferences.toolbar.general") - - toolbarItem = item - case .appearance: - let item = NSToolbarItem(itemIdentifier: itemIdentifier) - item.label = NSLocalizedString("preferences.toolbar.appearance", comment: "Preferences Toolbar Appearance Button Label") - item.paletteLabel = item.label - item.toolTip = item.label - item.target = self - item.action = #selector(showAppearance(_:)) - item.image = NSImage(named: "preferences.toolbar.appearance") - - toolbarItem = item - case .editingBehavior: - let item = NSToolbarItem(itemIdentifier: itemIdentifier) - item.label = NSLocalizedString("editing-behavior", comment: "Preferences Toolbar Appearance Button Label") - item.paletteLabel = item.label - item.toolTip = item.label - item.target = self - item.action = #selector(showEditingBehavior(_:)) - item.image = NSImage(named: "preferences.toolbar.editor") - - toolbarItem = item - case .extensions: - let item = NSToolbarItem(itemIdentifier: itemIdentifier) - item.label = "Extensions" - item.paletteLabel = item.label - item.toolTip = item.label - item.target = self - item.action = #selector(showExtensions(_:)) - item.image = NSImage(systemSymbolName: "puzzlepiece.extension", accessibilityDescription: "Extensions") - - toolbarItem = item - case .commandLine: - let item = NSToolbarItem(itemIdentifier: itemIdentifier) - item.label = "Command Line" - item.paletteLabel = item.label - item.toolTip = item.label - item.target = self - item.action = #selector(showCommandLine(_:)) - item.image = NSImage(named: "terminal") - - toolbarItem = item - default: - break - } - - return toolbarItem - } - - public func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] { - [.extensions] - } - - public func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] { - return toolbarDefaultItemIdentifiers(toolbar) - } - - public func toolbarSelectableItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] { - return toolbarDefaultItemIdentifiers(toolbar) - } -} diff --git a/Edit/Modules/Theme/Extensions/Query+Extras.swift b/Edit/Modules/Theme/Extensions/Query+Extras.swift index be8a37f..630f0f5 100644 --- a/Edit/Modules/Theme/Extensions/Query+Extras.swift +++ b/Edit/Modules/Theme/Extensions/Query+Extras.swift @@ -1,11 +1,12 @@ -import AppKit import ThemePark public typealias Query = ThemePark.Query +#if canImport(AppKit) && !targetEnvironment(macCatalyst) +import AppKit + extension Query.Context { -#if os(macOS) @MainActor public init(window: NSWindow?) { self.init(appearance: window?.appearance) @@ -17,5 +18,5 @@ extension Query.Context { self.init(controlState: .inactive, colorScheme: dark ? .dark : .light) } -#endif } +#endif diff --git a/Edit/Modules/UIUtility/AppKit/NSBezierPath+Paths.swift b/Edit/Modules/UIUtility/AppKit/NSBezierPath+Paths.swift index f26e675..745b7db 100644 --- a/Edit/Modules/UIUtility/AppKit/NSBezierPath+Paths.swift +++ b/Edit/Modules/UIUtility/AppKit/NSBezierPath+Paths.swift @@ -1,4 +1,4 @@ -import AppKit +import NSUI public struct RoundedRectRadii: Sendable, Hashable { public let topLeading: CGFloat @@ -13,7 +13,7 @@ public struct RoundedRectRadii: Sendable, Hashable { self.bottomTrailing = bottomTrailing } - public init(_ radii: NSBezierPath.Radii) { + public init(_ radii: NSUIBezierPath.Radii) { self.topLeading = radii.0 self.topTrailing = radii.1 self.bottomTrailing = radii.2 @@ -32,7 +32,7 @@ public struct RoundedRectRadii: Sendable, Hashable { return max(topLeading, bottomLeading, topTrailing, bottomTrailing) } - public var radiiTuple: NSBezierPath.Radii { + public var radiiTuple: NSUIBezierPath.Radii { (topLeading, topTrailing, bottomTrailing, bottomLeading) } @@ -59,11 +59,11 @@ public struct RoundedRectRadii: Sendable, Hashable { public static let zero = RoundedRectRadii(topLeading: 0.0, bottomLeading: 0.0, topTrailing: 0.0, bottomTrailing: 0.0) } -public extension NSBezierPath { +public extension NSUIBezierPath { typealias Radii = (CGFloat, CGFloat, CGFloat, CGFloat) - static func roundedPath(rect: NSRect, radii: Radii) -> NSBezierPath { - let path = NSBezierPath() + static func roundedPath(rect: CGRect, radii: Radii) -> NSUIBezierPath { + let path = NSUIBezierPath() // A -> B // | | @@ -74,21 +74,21 @@ public extension NSBezierPath { let bottomRight = rect.maxXMinYPoint let bottomLeft = rect.minXMinYPoint - path.move(to: NSPoint(x: topLeft.x, y: topLeft.y - radii.0)) - path.curve(to: NSPoint(x: topLeft.x + radii.0, y: topLeft.y), controlPoint1: topLeft, controlPoint2: topLeft) - path.line(to: NSPoint(x: topRight.x - radii.1, y: topRight.y)) - path.curve(to: NSPoint(x: topRight.x, y: topRight.y - radii.1), controlPoint1: topRight, controlPoint2: topRight) - path.line(to: NSPoint(x: bottomRight.x, y: bottomRight.y + radii.2)) - path.curve(to: NSPoint(x: bottomRight.x - radii.2, y: bottomRight.y), controlPoint1: bottomRight, controlPoint2: bottomRight) - path.line(to: NSPoint(x: bottomLeft.x + radii.3, y: bottomLeft.y)) - path.curve(to: NSPoint(x: bottomLeft.x, y: bottomLeft.y + radii.3), controlPoint1: bottomLeft, controlPoint2: bottomLeft) + path.move(to: CGPoint(x: topLeft.x, y: topLeft.y - radii.0)) + path.addCurve(to: CGPoint(x: topLeft.x + radii.0, y: topLeft.y), controlPoint1: topLeft, controlPoint2: topLeft) + path.addLine(to: CGPoint(x: topRight.x - radii.1, y: topRight.y)) + path.addCurve(to: CGPoint(x: topRight.x, y: topRight.y - radii.1), controlPoint1: topRight, controlPoint2: topRight) + path.addLine(to: CGPoint(x: bottomRight.x, y: bottomRight.y + radii.2)) + path.addCurve(to: CGPoint(x: bottomRight.x - radii.2, y: bottomRight.y), controlPoint1: bottomRight, controlPoint2: bottomRight) + path.addLine(to: CGPoint(x: bottomLeft.x + radii.3, y: bottomLeft.y)) + path.addCurve(to: CGPoint(x: bottomLeft.x, y: bottomLeft.y + radii.3), controlPoint1: bottomLeft, controlPoint2: bottomLeft) path.close() return path } - static func roundedPath(rect: NSRect, radii: RoundedRectRadii) -> NSBezierPath { + static func roundedPath(rect: CGRect, radii: RoundedRectRadii) -> NSUIBezierPath { return roundedPath(rect: rect, radii: (radii.topLeading, radii.topTrailing, radii.bottomTrailing, radii.bottomLeading)) } } diff --git a/Edit/Modules/UIUtility/AppKit/NSImageView+Symbol.swift b/Edit/Modules/UIUtility/AppKit/NSImageView+Symbol.swift index 54e7f77..a5cc35f 100644 --- a/Edit/Modules/UIUtility/AppKit/NSImageView+Symbol.swift +++ b/Edit/Modules/UIUtility/AppKit/NSImageView+Symbol.swift @@ -1,11 +1,13 @@ -import AppKit +import NSUI -public extension NSImageView { +#if os(macOS) +public extension NSUIImageView { convenience init(systemSymbolName symbolName: String, accessibilityDescription description: String? = nil) { - if let image = NSImage(systemSymbolName: symbolName, accessibilityDescription: description) { + if let image = NSUIImage(systemSymbolName: symbolName, accessibilityDescription: description) { self.init(image: image) } else { self.init() } } } +#endif diff --git a/Edit/Modules/UIUtility/AppKit/NSTableView+Reuse.swift b/Edit/Modules/UIUtility/AppKit/NSTableView+Reuse.swift index 0f88f48..475eb02 100644 --- a/Edit/Modules/UIUtility/AppKit/NSTableView+Reuse.swift +++ b/Edit/Modules/UIUtility/AppKit/NSTableView+Reuse.swift @@ -1,3 +1,4 @@ +#if os(macOS) import AppKit extension NSTableView { @@ -14,3 +15,4 @@ extension NSTableView { return generator() } } +#endif diff --git a/Edit/Modules/UIUtility/AttributedText.swift b/Edit/Modules/UIUtility/AttributedText.swift index 31be96a..646ce35 100644 --- a/Edit/Modules/UIUtility/AttributedText.swift +++ b/Edit/Modules/UIUtility/AttributedText.swift @@ -1,7 +1,9 @@ import SwiftUI +import NSUI -public struct AttributedText: NSViewRepresentable { - public typealias NSViewType = NSTextField +@MainActor +public struct AttributedText: NSUIViewRepresentable { + public typealias NSUIViewType = NSUILabel private let text: NSAttributedString @@ -9,9 +11,16 @@ public struct AttributedText: NSViewRepresentable { text = attributedString } - public func makeNSView(context: Self.Context) -> NSTextField { - let textField = NSTextField(labelWithAttributedString: text) + public func makeNSUIView(context: Self.Context) -> NSUIViewType { +#if os(macOS) + let textField = NSUIViewType(labelWithAttributedString: text) + textField.isSelectable = true +#else + let textField = NSUIViewType() + + textField.attributedText = text +#endif // textField.allowsEditingTextAttributes = true // Fix of clear of styles on click textField.preferredMaxLayoutWidth = textField.frame.width @@ -19,8 +28,8 @@ public struct AttributedText: NSViewRepresentable { return textField } - public func updateNSView(_ nsView: NSTextField, context: Self.Context) { - nsView.attributedStringValue = text + public func updateNSUIView(_ view: NSUIViewType, context: Self.Context) { + view.attributedText = text } } diff --git a/Edit/Modules/UIUtility/ColorView.swift b/Edit/Modules/UIUtility/ColorView.swift deleted file mode 100644 index d952190..0000000 --- a/Edit/Modules/UIUtility/ColorView.swift +++ /dev/null @@ -1,65 +0,0 @@ -import AppKit - -open class ColorView: ShapeView { - open var radii: NSBezierPath.Radii { - didSet { - let value = self.radii - - self.pathProvider = { (rect) in - NSBezierPath.roundedPath(rect: rect, radii: value) - } - } - } - - public var color: NSColor { - get { - return fillColor! - } - set { - fillColor = newValue - } - } - - public init(frame frameRect: NSRect = .zero, color: NSColor, radii: NSBezierPath.Radii) { - self.radii = radii - - super.init { (rect) in - return NSBezierPath.roundedPath(rect: rect, radii: radii) - } - - self.fillColor = color - } - - public convenience init(frame frameRect: NSRect = .zero, color: NSColor, radii: RoundedRectRadii = .zero) { - let adaptedRadii = (radii.topLeading, radii.topTrailing, radii.bottomTrailing, radii.bottomLeading) - - self.init(frame: frameRect, color: color, radii: adaptedRadii) - } - - @available(*, unavailable) - public required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } -} - -extension ShapeView { - public static func rect(color: NSColor) -> ShapeView { - let view = ShapeView { (rect) -> NSBezierPath in - NSBezierPath(rect: rect) - } - - view.fillColor = color - - return view - } - - public static func roundedRect(color: NSColor? = nil, radii: NSBezierPath.Radii) -> ShapeView { - let view = ShapeView { (rect) -> NSBezierPath in - NSBezierPath.roundedPath(rect: rect, radii: radii) - } - - view.fillColor = color - - return view - } -} diff --git a/Edit/Modules/UIUtility/HexagonView.swift b/Edit/Modules/UIUtility/HexagonView.swift index a71661d..ecede36 100644 --- a/Edit/Modules/UIUtility/HexagonView.swift +++ b/Edit/Modules/UIUtility/HexagonView.swift @@ -1,16 +1,16 @@ -import AppKit +import NSUI -public class HexagonView: NSView { +public class HexagonView: NSUIView { - public var strokeColor: NSColor = NSColor.black - public var fillColor: NSColor = NSColor.white + public var strokeColor: NSUIColor = .black + public var fillColor: NSUIColor = .white public static let sinComponent = sin(CGFloat.pi / 3.0) public static let cosComponent = cos(CGFloat.pi / 3.0) - public override func draw(_ dirtyRect: NSRect) { + public override func draw(_ dirtyRect: CGRect) { let length = self.bounds.width / 2.0 - let center = NSPoint(x: length, y: self.bounds.height / 2.0) + let center = CGPoint(x: length, y: self.bounds.height / 2.0) let path = HexagonView.hexagonPath(at: center, sideLength: length) @@ -21,24 +21,24 @@ public class HexagonView: NSView { path.stroke() } - public static func hexagonPath(at center: NSPoint, sideLength length: CGFloat) -> NSBezierPath { + public static func hexagonPath(at center: CGPoint, sideLength length: CGFloat) -> NSUIBezierPath { let cosValue = HexagonView.cosComponent * length let sinValue = HexagonView.sinComponent * length - let path = NSBezierPath() + let path = NSUIBezierPath() - path.move(to: NSPoint(x: center.x - cosValue, y: center.y + sinValue)) - path.line(to: NSPoint(x: center.x + cosValue, y: center.y + sinValue)) - path.line(to: NSPoint(x: center.x + length, y: center.y)) - path.line(to: NSPoint(x: center.x + cosValue, y: center.y - sinValue)) - path.line(to: NSPoint(x: center.x - cosValue, y: center.y - sinValue)) - path.line(to: NSPoint(x: center.x - length, y: center.y)) + path.move(to: CGPoint(x: center.x - cosValue, y: center.y + sinValue)) + path.addLine(to: CGPoint(x: center.x + cosValue, y: center.y + sinValue)) + path.addLine(to: CGPoint(x: center.x + length, y: center.y)) + path.addLine(to: CGPoint(x: center.x + cosValue, y: center.y - sinValue)) + path.addLine(to: CGPoint(x: center.x - cosValue, y: center.y - sinValue)) + path.addLine(to: CGPoint(x: center.x - length, y: center.y)) path.close() return path } - public static func hexagonPath(within rect: NSRect) -> NSBezierPath { + public static func hexagonPath(within rect: CGRect) -> NSUIBezierPath { // defend against nonsense rectangles precondition(!rect.isEmpty && !rect.isInfinite) @@ -54,17 +54,16 @@ public class HexagonView: NSView { return hexagonPath(at: center, sideLength: length) } - public static func hexagonImage(length: CGFloat, fillColor: NSColor, strokeColor: NSColor) -> NSImage { - return NSImage(size: NSSize(width: length * 2.0, height: length * 2.0), flipped: false, drawingHandler: { (rect) -> Bool in - let path = HexagonView.hexagonPath(at: NSPoint(x: length, y: length), sideLength: length) - fillColor.setFill() - path.fill() - - strokeColor.setStroke() - path.stroke() - - return true - }) - } - +// public static func hexagonImage(length: CGFloat, fillColor: NSUIColor, strokeColor: NSUIColor) -> NSUIImage { +// return NSUIImage(size: CGSize(width: length * 2.0, height: length * 2.0), flipped: false, drawingHandler: { (rect) -> Bool in +// let path = HexagonView.hexagonPath(at: CGPoint(x: length, y: length), sideLength: length) +// fillColor.setFill() +// path.fill() +// +// strokeColor.setStroke() +// path.stroke() +// +// return true +// }) +// } } diff --git a/Edit/Modules/UIUtility/NSRect+Helpers.swift b/Edit/Modules/UIUtility/NSRect+Helpers.swift index bd078ac..c945746 100644 --- a/Edit/Modules/UIUtility/NSRect+Helpers.swift +++ b/Edit/Modules/UIUtility/NSRect+Helpers.swift @@ -1,61 +1,61 @@ import Foundation -public enum NSRectCentering { +public enum RectCentering { case vertical case horizontal case both } -public extension NSRect { - func outsetBy(dx: CGFloat, dy: CGFloat) -> NSRect { +public extension CGRect { + func outsetBy(dx: CGFloat, dy: CGFloat) -> CGRect { return insetBy(dx: -dx, dy: -dy) } - func insetBy(_ size: NSSize) -> NSRect { + func insetBy(_ size: CGSize) -> CGRect { return insetBy(dx: size.width, dy: size.height) } - func outsetBy(_ size: NSSize) -> NSRect { + func outsetBy(_ size: CGSize) -> CGRect { return outsetBy(dx: size.width, dy: size.height) } - func centerWithin(_ rect: NSRect, centering: NSRectCentering = .both) -> NSRect { + func centerWithin(_ rect: CGRect, centering: RectCentering = .both) -> CGRect { let dx = (rect.width - width) / 2.0 let dy = (rect.height - height) / 2.0 switch centering { case .horizontal: - return NSMakeRect(dx + rect.origin.x, rect.origin.y, width, height) + return CGRect(x: dx + rect.origin.x, y: rect.origin.y, width: width, height: height) case .vertical: - return NSMakeRect(rect.origin.x, dy + rect.origin.y, width, height) + return CGRect(x: rect.origin.x, y: dy + rect.origin.y, width: width, height: height) case .both: - return NSMakeRect(dx + rect.origin.x, dy + rect.origin.y, width, height) + return CGRect(x: dx + rect.origin.x, y: dy + rect.origin.y, width: width, height: height) } } - var outwardIntegral: NSRect { - return NSIntegralRectWithOptions(self, .alignAllEdgesOutward) - } +// var outwardIntegral: CGRect { +// return NSIntegralRectWithOptions(self, .alignAllEdgesOutward) +// } } -public extension NSRect { - var minXMaxYPoint: NSPoint { - return NSPoint(x: minX, y: maxY) +public extension CGRect { + var minXMaxYPoint: CGPoint { + return CGPoint(x: minX, y: maxY) } - var maxXMaxYPoint: NSPoint { - return NSPoint(x: maxX, y: maxY) + var maxXMaxYPoint: CGPoint { + return CGPoint(x: maxX, y: maxY) } - var minXMinYPoint: NSPoint { - return NSPoint(x: minX, y: minY) + var minXMinYPoint: CGPoint { + return CGPoint(x: minX, y: minY) } - var maxXMinYPoint: NSPoint { - return NSPoint(x: maxX, y: minY) + var maxXMinYPoint: CGPoint { + return CGPoint(x: maxX, y: minY) } - var center: NSPoint { - return NSPoint(x: midX, y: midY) + var center: CGPoint { + return CGPoint(x: midX, y: midY) } } diff --git a/Edit/Modules/UIUtility/RepresentableView.swift b/Edit/Modules/UIUtility/RepresentableView.swift index 6b71662..e555778 100644 --- a/Edit/Modules/UIUtility/RepresentableView.swift +++ b/Edit/Modules/UIUtility/RepresentableView.swift @@ -1,18 +1,20 @@ import SwiftUI +import NSUI -public struct RepresentableView: NSViewRepresentable { +public struct RepresentableView: NSUIViewRepresentable { + public typealias NSUIViewType = View public let view: View public init(view: View) { self.view = view } - public func makeNSView(context: Context) -> View { + public func makeNSUIView(context: Context) -> View { view.translatesAutoresizingMaskIntoConstraints = false return view } - public func updateNSView(_ nsView: View, context: Context) { + public func updateNSUIView(_ view: View, context: Context) { } } diff --git a/Edit/Modules/UIUtility/RepresentableViewController.swift b/Edit/Modules/UIUtility/RepresentableViewController.swift index 88d5d4d..54ae02c 100644 --- a/Edit/Modules/UIUtility/RepresentableViewController.swift +++ b/Edit/Modules/UIUtility/RepresentableViewController.swift @@ -1,28 +1,31 @@ import SwiftUI +import NSUI + +public struct RepresentableViewController: NSUIViewControllerRepresentable { + public typealias NSUIViewControllerType = Controller -public struct RepresentableViewController: NSViewControllerRepresentable { let controller: () -> Controller public init(_ controller: @escaping () -> Controller) { self.controller = controller } - public func makeNSViewController(context: Context) -> some NSViewController { + public func makeNSUIViewController(context: Context) -> Controller { controller() } - public func updateNSViewController(_ nsViewController: NSViewControllerType, context: Context) { + public func updateNSUIViewController(_ viewController: Controller, context: Context) { } } extension RepresentableViewController { /// Provide a intermediary SwiftUI view for APIs that use `NSViewController`. @MainActor - public static func wrap(controller: Controller, block: (Self) -> Content) -> NSHostingController { + public static func wrap(controller: Controller, block: (Self) -> Content) -> NSUIHostingController { let represented = RepresentableViewController({ controller }) let content = block(represented) - return NSHostingController(rootView: content) + return NSUIHostingController(rootView: content) } } diff --git a/Edit/Modules/UIUtility/ShapeLayerController.swift b/Edit/Modules/UIUtility/ShapeLayerController.swift deleted file mode 100644 index 9ac7d44..0000000 --- a/Edit/Modules/UIUtility/ShapeLayerController.swift +++ /dev/null @@ -1,33 +0,0 @@ -import AppKit - -public class ShapeLayerController: NSObject, CALayerDelegate { - public typealias PathProviderBlock = (NSRect) -> NSBezierPath - - public var pathProvider: PathProviderBlock - - public init(pathProvider: @escaping PathProviderBlock) { - self.pathProvider = pathProvider - - super.init() - } - - public func display(_ layer: CALayer) { - let rect = layer.bounds - - if rect.isEmpty || rect.isInfinite { - return - } - - let path = pathProvider(rect) - - guard let layer = layer as? CAShapeLayer else { - fatalError("delegate of a non CAShapeLayer") - } - - layer.path = path.cgPath - } - - public func action(for layer: CALayer, forKey event: String) -> CAAction? { - return NSNull() - } -} diff --git a/Edit/Modules/UIUtility/ShapeView.swift b/Edit/Modules/UIUtility/ShapeView.swift deleted file mode 100644 index c8f1c10..0000000 --- a/Edit/Modules/UIUtility/ShapeView.swift +++ /dev/null @@ -1,130 +0,0 @@ -import AppKit - -open class ShapeView: NSView { - private let shapeLayerController: ShapeLayerController - private let shapeLayer: CAShapeLayer - - var pathProvider: (NSRect) -> NSBezierPath { - get { - return shapeLayerController.pathProvider - } - set { - shapeLayerController.pathProvider = newValue - shapeLayer.setNeedsDisplay() - } - } - - public var rotationInDegrees: CGFloat = 0.0 { - didSet { - let radians = self.rotationInDegrees.degreesToRadians() - - shapeLayer.transform = CATransform3DMakeRotation(radians, 0.0, 0.0, 1.0) - } - } - - public var strokeColor: NSColor? { - didSet { - shapeLayer.strokeColor = strokeColor?.cgColor - } - } - - public var fillColor: NSColor? { - didSet { - shapeLayer.fillColor = fillColor?.cgColor - } - } - - public var lineWidth: CGFloat = 1.0 { - didSet { - shapeLayer.lineWidth = lineWidth - } - } - - public init(pathProvider: @escaping (NSRect) -> NSBezierPath) { - self.shapeLayerController = ShapeLayerController(pathProvider: pathProvider) - self.shapeLayer = CAShapeLayer() - - super.init(frame: NSRect.zero) - } - - required public init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - public override func makeBackingLayer() -> CALayer { - let mainLayer = CALayer() - - mainLayer.addSublayer(shapeLayer) - - shapeLayer.delegate = shapeLayerController - shapeLayer.needsDisplayOnBoundsChange = true - - return mainLayer - } - - public override func layout() { - super.layout() - - guard let bounds = layer?.bounds else { - return - } - - // prevent animations while adjusting our layer properties - CATransaction.begin() - CATransaction.setDisableActions(true) - - let halfWidth = bounds.width / 2.0 - let halfHeight = bounds.height / 2.0 - - shapeLayer.position = CGPoint(x: halfWidth, y: halfHeight) - shapeLayer.bounds = CGRect(x: 0.0, y: 0.0, width: bounds.width, height: bounds.height) - - CATransaction.commit() - } - - public override func viewDidChangeEffectiveAppearance() { - // I'm not entirely sure this is still neccessary... - effectiveAppearance.performAsCurrentDrawingAppearance { - shapeLayer.fillColor = fillColor?.cgColor - shapeLayer.strokeColor = strokeColor?.cgColor - } - } -} - -extension ShapeView { - public func startRotationAnimation(duration: Double, clockwise: Bool) { - let animation = CABasicAnimation(keyPath: "transform.rotation.z") - - animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear) - animation.duration = duration - animation.repeatCount = Float.infinity - - let factor = clockwise ? 1.0 : -1.0 - - animation.byValue = factor * 2.0 * Double.pi - - shapeLayer.add(animation, forKey: "transform.rotation.z") - } - - public func stopAllAnimations() { - shapeLayer.removeAllAnimations() - } - - public static func hexagon(lineWidth: CGFloat) -> ShapeView { - let view = ShapeView { (rect) -> NSBezierPath in - - // must inset by lineThickness - let insetRect = rect.insetBy(dx: lineWidth, dy: lineWidth) - if insetRect.isEmpty || insetRect.isInfinite { - return NSBezierPath(rect: rect) - } - - return HexagonView.hexagonPath(within: insetRect) - } - - view.lineWidth = lineWidth - view.fillColor = nil - - return view - } -} diff --git a/Edit/Sources/AppDelegate.swift b/Edit/Sources/AppDelegate.swift index 2e8d62f..70ada67 100644 --- a/Edit/Sources/AppDelegate.swift +++ b/Edit/Sources/AppDelegate.swift @@ -51,93 +51,5 @@ extension AppDelegate { @IBAction func showPreferences(_ sender: Any?) { preferencesController.window?.center() preferencesController.showWindow(self) - -// let controller = PreviewViewController(nibName: nil, bundle: nil) -// -// let window = NSWindow(contentViewController: controller) -// -// window.setContentSize(.init(width: 600, height: 600)) -// window.makeKeyAndOrderFront(nil) -// -// Task { -// let url = URL(fileURLWithPath: "/Users/matt/Desktop/RunloopActor.swift") -// try! await controller.preparePreviewOfFile(at: url) -// } -// -// self.tempWindow = window } } - -//import ChimeKit -//import Editor -//import Theme -//import UIUtility -//import UniformTypeIdentifiers -// -//extension URL { -// var contentType: UTType? { -// get throws { -// try resourceValues(forKeys: [.contentTypeKey]).contentType -// } -// } -// -// var resolvedContentType: UTType? { -// get throws { -// guard let utType = try contentType else { return nil } -// -// return UTType.resolveType(with: utType.identifier, url: self) -// } -// } -//} -// -//final class PreviewViewController: NSViewController { -// private let coordinator: DocumentCoordinator -// -// private let theme: Theme -// -// override init(nibName nibNameOrNil: NSNib.Name?, bundle nibBundleOrNil: Bundle?) { -// self.coordinator = DocumentCoordinator() -// -// let themeId = UserDefaults.standard.string(forKey: "theme-identifier") ?? "Midnight.xcode" -// self.theme = ThemeStore().theme(with: themeId) -// -// super.init(nibName: nil, bundle: nil) -// } -// -// required init?(coder: NSCoder) { -// fatalError("init(coder:) has not been implemented") -// } -// -// override func loadView() { -// let hostingView = RepresentableViewController({ self.coordinator.editorContentController }) -// .environment(\.theme, theme) -// -// self.view = NSHostingView(rootView: hostingView) -// -// coordinator.highlighter.updateTheme(theme, context: .init(window: nil)) -// } -// -// func preparePreviewOfFile(at url: URL) async throws { -// let config = DocumentConfiguration() -// let context = Query.Context(window: self.view.window) -// let attrs = theme.typingAttributes(tabWidth: config.tabWidth, context: context) -// -// try coordinator.textSystem.reload(from: url, attributes: attrs) -// -// let newContentId = coordinator.textSystem.contentIdentity -// -// let utType = (try? url.resolvedContentType) ?? UTType.plainText -// -// let initial = DocumentContext() -// let new = DocumentContext( -// id: initial.id, -// contentId: newContentId, -// url: url, -// uti: utType, -// configuration: initial.configuration, -// projectContext: nil -// ) -// -// coordinator.documentContextChanged(from: initial, to: new) -// } -//}