Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CodeEdit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -96,6 +97,7 @@
34EE19BD27E0469C00F152CE /* BlurView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurView.swift; sourceTree = "<group>"; };
5E3C6A3427E72AE000A7CA0D /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = "<group>"; };
70F2E28327E848720002BA81 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
90571F5F27E89210006E606C /* CodeEdit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeEdit.swift; sourceTree = "<group>"; };
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 = "<group>"; };
B658FB3327DA9E1000EA4DBD /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -267,6 +269,7 @@
B658FB3827DA9E1000EA4DBD /* CodeEdit.entitlements */,
B658FB3527DA9E1000EA4DBD /* Preview Content */,
043C321927E32295006AE443 /* MainMenu.xib */,
90571F5F27E89210006E606C /* CodeEdit.swift */,
);
path = CodeEdit;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
7 changes: 7 additions & 0 deletions CodeEdit.xcodeproj/xcshareddata/xcschemes/CodeEdit.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@
ReferencedContainer = "container:CodeEdit.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<EnvironmentVariables>
<EnvironmentVariable
key = "OS_ACTIVITY_MODE"
value = "disable"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
48 changes: 10 additions & 38 deletions CodeEdit/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,54 @@ import SwiftUI

class CodeEditApplication: NSApplication {
let strongDelegate = AppDelegate()

override init() {
super.init()
self.delegate = strongDelegate
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

}

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
private(set) var menu: NSMenu! = nil
func applicationWillFinishLaunching(_ notification: Notification) {
_ = CodeEditDocumentController.shared
let nib = NSNib(nibNamed: NSNib.Name("MainMenu"), bundle: Bundle.main)
nib?.instantiate(withOwner: NSApplication.shared, topLevelObjects: nil)
NSApplication.shared.mainMenu?.items
.first { $0.title == "CodeEdit" }?.submenu?.items
.first { $0.title == "Preferences" }?.action = #selector(openPreferences(_:))
menu = NSApplication.shared.mainMenu
}

func applicationDidFinishLaunching(_ notification: Notification) {
if let appearanceString = UserDefaults.standard.string(forKey: Appearances.storageKey) {
Appearances(rawValue: appearanceString)?.applyAppearance()
}

DispatchQueue.main.async {
if NSApp.windows.isEmpty {
self.handleOpen()
}
}
}

func applicationWillTerminate(_ aNotification: Notification) {
}

func applicationSupportsSecureRestorableState(_ app: NSApplication) -> 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)
Expand All @@ -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
Expand All @@ -86,37 +78,17 @@ 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<SettingsView>) != 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<WelcomeWindowView>) != nil
}).first {
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)
Expand Down
23 changes: 23 additions & 0 deletions CodeEdit/CodeEdit.swift
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
}
2 changes: 2 additions & 0 deletions CodeEdit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>austincondiff.CodeEdit.url</string>
<key>CFBundleURLSchemes</key>
<array>
<string>codeedit</string>
Expand Down
10 changes: 3 additions & 7 deletions CodeEdit/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="19529" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="19529"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication"/>
Expand All @@ -21,11 +21,7 @@
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
<menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW">
<connections>
<action selector="openPreferences:" target="-1" id="B4U-I4-Bxm"/>
</connections>
</menuItem>
<menuItem title="Preferences" keyEquivalent="," id="BOF-NM-1cW"/>
<menuItem isSeparatorItem="YES" id="wFC-TO-SCJ"/>
<menuItem title="Services" id="NMo-om-nkz">
<modifierMask key="keyEquivalentModifierMask"/>
Expand Down
5 changes: 5 additions & 0 deletions CodeEdit/Settings/GeneralSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ struct GeneralSettingsView: View {
.onChange(of: appearance) { tag in
tag.applyAppearance()
}
.fixedSize()

Picker("File Icon Style".localized(), selection: $fileIconStyle) {
Text("Color".localized())
.tag(FileIconStyle.color)
Text("Monochrome".localized())
.tag(FileIconStyle.monochrome)
}
.fixedSize()

Picker("Reopen Behavior".localized(), selection: $reopenBehavior) {
Text("Welcome Screen".localized())
Expand All @@ -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)")
Expand All @@ -63,7 +66,9 @@ struct GeneralSettingsView: View {
Text("Ocean")
.tag(CodeEditor.ThemeName.ocean)
}
.fixedSize()
}
.frame(width: 450)
.padding()
}
}
Expand Down
2 changes: 0 additions & 2 deletions CodeEdit/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ struct SettingsView: View {
Label("General".localized(), systemImage: "gearshape")
}
}
.padding()
.frame(width: 450, height: 250)
}
}

Expand Down