diff --git a/CodeEdit.xcodeproj/project.pbxproj b/CodeEdit.xcodeproj/project.pbxproj index c405bfb973..9267bff297 100644 --- a/CodeEdit.xcodeproj/project.pbxproj +++ b/CodeEdit.xcodeproj/project.pbxproj @@ -35,6 +35,7 @@ 34EE19BE27E0469C00F152CE /* BlurView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34EE19BD27E0469C00F152CE /* BlurView.swift */; }; 5C403B8F27E20F8000788241 /* WorkspaceClient in Frameworks */ = {isa = PBXBuildFile; productRef = 5C403B8E27E20F8000788241 /* WorkspaceClient */; }; 5CF38A5E27E48E6C0096A0F7 /* CodeFile in Frameworks */ = {isa = PBXBuildFile; productRef = 5CF38A5D27E48E6C0096A0F7 /* CodeFile */; }; + 90571F6027E89210006E606C /* CodeEdit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90571F5F27E89210006E606C /* CodeEdit.swift */; }; B658FB3427DA9E1000EA4DBD /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B658FB3327DA9E1000EA4DBD /* Assets.xcassets */; }; B658FB3727DA9E1000EA4DBD /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B658FB3627DA9E1000EA4DBD /* Preview Assets.xcassets */; }; B65E614627E6765D00255275 /* Introspect in Frameworks */ = {isa = PBXBuildFile; productRef = B65E614527E6765D00255275 /* Introspect */; }; @@ -96,6 +97,7 @@ 34EE19BD27E0469C00F152CE /* BlurView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurView.swift; sourceTree = ""; }; 5E3C6A3427E72AE000A7CA0D /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = ""; }; 70F2E28327E848720002BA81 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = ""; }; + 90571F5F27E89210006E606C /* CodeEdit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeEdit.swift; sourceTree = ""; }; B658FB2C27DA9E0F00EA4DBD /* CodeEdit.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CodeEdit.app; sourceTree = BUILT_PRODUCTS_DIR; }; B658FB3127DA9E0F00EA4DBD /* WorkspaceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkspaceView.swift; sourceTree = ""; }; B658FB3327DA9E1000EA4DBD /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -267,6 +269,7 @@ B658FB3827DA9E1000EA4DBD /* CodeEdit.entitlements */, B658FB3527DA9E1000EA4DBD /* Preview Content */, 043C321927E32295006AE443 /* MainMenu.xib */, + 90571F5F27E89210006E606C /* CodeEdit.swift */, ); path = CodeEdit; sourceTree = ""; @@ -492,6 +495,7 @@ files = ( 2B7A583527E4BA0100D25D4E /* AppDelegate.swift in Sources */, 2875A46D27E3BE5B007805F8 /* BreadcrumbsView.swift in Sources */, + 90571F6027E89210006E606C /* CodeEdit.swift in Sources */, 0485EB1D27E7338100138301 /* QuickOpenItem.swift in Sources */, 04540D5B27DD08C300E91B77 /* SettingsView.swift in Sources */, D72E1A8927E44D7C00EB11B9 /* WelcomeWindowView.swift in Sources */, diff --git a/CodeEdit.xcodeproj/xcshareddata/xcschemes/CodeEdit.xcscheme b/CodeEdit.xcodeproj/xcshareddata/xcschemes/CodeEdit.xcscheme index d92ea28491..0ca4d11bbe 100644 --- a/CodeEdit.xcodeproj/xcshareddata/xcschemes/CodeEdit.xcscheme +++ b/CodeEdit.xcodeproj/xcshareddata/xcschemes/CodeEdit.xcscheme @@ -70,6 +70,13 @@ ReferencedContainer = "container:CodeEdit.xcodeproj"> + + + + Bool { return true } - func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool { if flag { return false } - handleOpen() - return false } - func applicationShouldOpenUntitledFile(_ sender: NSApplication) -> Bool { return false } - func handleOpen() { let behavior = ReopenBehavior(rawValue: UserDefaults.standard.string(forKey: ReopenBehavior.storageKey) ?? ReopenBehavior.default.rawValue) ?? ReopenBehavior.default - switch behavior { case .welcome: openWelcome(self) @@ -73,7 +66,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject { CodeEditDocumentController.shared.newDocument(self) } } - func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply { CodeEditDocumentController.shared.documents.flatMap { doc in return doc.windowControllers @@ -86,29 +78,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject { } // MARK: - Open windows - - @IBAction func openPreferences(_ sender: Any) { - if let window = NSApp.windows.filter({ window in - return (window.contentView as? NSHostingView) != nil - }).first { - window.makeKeyAndOrderFront(self) - return - } - - let window = NSWindow( - contentRect: NSRect(x: 0, y: 0, width: 500, height: 400), - styleMask: [.titled, .closable], - backing: .buffered, defer: false) - window.center() - window.toolbar = NSToolbar() - window.title = "Settings" - window.toolbarStyle = .unifiedCompact - _ = NSWindowController(window: window) - let contentView = SettingsView() - window.contentView = NSHostingView(rootView: contentView) - window.makeKeyAndOrderFront(sender) + @objc func openPreferences(_ sender: Any) { + NSApp.sendAction(Selector(("showPreferencesWindow:")), to: nil, from: nil) + NSApplication.shared.mainMenu = menu } - @IBAction func openWelcome(_ sender: Any) { if let window = NSApp.windows.filter({ window in return (window.contentView as? NSHostingView) != nil @@ -116,7 +89,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject { window.makeKeyAndOrderFront(self) return } - let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 800, height: 460), styleMask: [.titled, .fullSizeContentView], backing: .buffered, defer: false) let windowController = NSWindowController(window: window) diff --git a/CodeEdit/CodeEdit.swift b/CodeEdit/CodeEdit.swift new file mode 100644 index 0000000000..fff6ea8950 --- /dev/null +++ b/CodeEdit/CodeEdit.swift @@ -0,0 +1,23 @@ +// +// CodeEdit.swift +// CodeEdit +// +// Created by 朱浩宇 on 2022/3/21. +// + +import SwiftUI + +@main +struct CodeEdit: App { + @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate + var body: some Scene { + Settings { + SettingsView() + .frame(width: 500) + .task { + try? await Task.sleep(nanoseconds: NSEC_PER_MSEC) + NSApp.keyWindow?.center() + } + } + } +} diff --git a/CodeEdit/Info.plist b/CodeEdit/Info.plist index 16de6697dc..34da852161 100644 --- a/CodeEdit/Info.plist +++ b/CodeEdit/Info.plist @@ -38,6 +38,8 @@ CFBundleTypeRole Editor + CFBundleURLName + austincondiff.CodeEdit.url CFBundleURLSchemes codeedit diff --git a/CodeEdit/MainMenu.xib b/CodeEdit/MainMenu.xib index 605193b449..7eb6ed570d 100644 --- a/CodeEdit/MainMenu.xib +++ b/CodeEdit/MainMenu.xib @@ -1,7 +1,7 @@ - + - + @@ -21,11 +21,7 @@ - - - - - + diff --git a/CodeEdit/Settings/GeneralSettingsView.swift b/CodeEdit/Settings/GeneralSettingsView.swift index 91d07a9f17..f13fa0e0e5 100644 --- a/CodeEdit/Settings/GeneralSettingsView.swift +++ b/CodeEdit/Settings/GeneralSettingsView.swift @@ -30,6 +30,7 @@ struct GeneralSettingsView: View { .onChange(of: appearance) { tag in tag.applyAppearance() } + .fixedSize() Picker("File Icon Style".localized(), selection: $fileIconStyle) { Text("Color".localized()) @@ -37,6 +38,7 @@ struct GeneralSettingsView: View { Text("Monochrome".localized()) .tag(FileIconStyle.monochrome) } + .fixedSize() Picker("Reopen Behavior".localized(), selection: $reopenBehavior) { Text("Welcome Screen".localized()) @@ -47,6 +49,7 @@ struct GeneralSettingsView: View { Text("New Document".localized()) .tag(ReopenBehavior.newDocument) } + .fixedSize() Picker("Editor Theme".localized(), selection: $editorTheme) { Text("Atelier Savanna (Auto)") @@ -63,7 +66,9 @@ struct GeneralSettingsView: View { Text("Ocean") .tag(CodeEditor.ThemeName.ocean) } + .fixedSize() } + .frame(width: 450) .padding() } } diff --git a/CodeEdit/Settings/SettingsView.swift b/CodeEdit/Settings/SettingsView.swift index 6549f479a9..c38478e7f1 100644 --- a/CodeEdit/Settings/SettingsView.swift +++ b/CodeEdit/Settings/SettingsView.swift @@ -15,8 +15,6 @@ struct SettingsView: View { Label("General".localized(), systemImage: "gearshape") } } - .padding() - .frame(width: 450, height: 250) } }