Skip to content

Notepad: Adding Swift-based Notepad.exe to Examples. #358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_subdirectory(Calculator)
add_subdirectory(HelloWorld)
add_subdirectory(Notepad)
add_subdirectory(UICatalog)

10 changes: 10 additions & 0 deletions Examples/Notepad/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
add_executable(Notepad
Notepad.swift)
add_custom_command(TARGET Notepad POST_BUILD
COMMAND
${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist $<TARGET_FILE_DIR:Notepad>)
# FIXME(SR-12683) `@main` requires `-parse-as-library`
target_compile_options(Notepad PRIVATE
-parse-as-library)
target_link_libraries(Notepad PRIVATE
SwiftWin32)
23 changes: 23 additions & 0 deletions Examples/Notepad/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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>ApplicationSceneManifest</key>
<dict>
<key>ApplicationSupportsMultipleScenes</key>
<false/>
<key>SceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>SceneConfigurationName</key>
<string>Default Configuration</string>
<key>SceneDelegateClassName</key>
<string>Notepad.Notepad</string>
</dict>
</array>
</dict>
</dict>
</dict>
</plist>
36 changes: 36 additions & 0 deletions Examples/Notepad/Notepad.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright © 2020 Puyan Lotfi <puyan AT puyan DOT org>
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
**/

import SwiftWin32

@main
final class Notepad: ApplicationDelegate {
var window: Window?
lazy var textview: TextView =
TextView(frame: Rect(x: 10.0, y: 10.0, width: 750.0, height: 750.0))
}

extension Notepad: SceneDelegate {
func scene(
_ scene: Scene, willConnectTo session: SceneSession,
options: Scene.ConnectionOptions
) {
guard let windowScene = scene as? WindowScene else { return }

self.window = Window(windowScene: windowScene)
self.window?.makeKeyAndVisible()
self.window?.addSubview(self.textview)

self.textview.text = """
He piled upon the whale’s white hump the sum of all the general rage and
hate felt by his whole race from Adam down; and then, as if his chest had
been a mortar, he burst his hot heart’s shell upon it.
"""

self.window?.makeKeyAndVisible()
}
}
1 change: 1 addition & 0 deletions Examples/Notepad/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@