Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Move to GNOME 46 widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
david-swift committed May 20, 2024
1 parent d757872 commit c8f8701
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 23 deletions.
24 changes: 18 additions & 6 deletions Sources/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@ import CAdw
import CodeEditor
import Foundation

struct ContentView: View {
struct ContentView: WindowView {

@State("text")
private var text = ""
@State("width")
private var width = 400
@State("height")
private var height = 300
@State private var output: [String] = []
@State private var outputSignal: Signal = .init()
@State("sidebar")
private var sidebarVisible = false
@State private var selectedText = ""
@State private var copySignal: Signal = .init()
@State private var alertDialog = false
@State private var errorOutput = ""
@Binding var exportContent: String
var app: GTUIApp
var window: GTUIApplicationWindow
Expand All @@ -31,7 +37,7 @@ struct ContentView: View {
.halign(.start)
.padding()
}
.style("navigation-sidebar")
.sidebarStyle()
}
.topToolbar {
HeaderBar.start {
Expand All @@ -41,7 +47,7 @@ struct ContentView: View {
}
.headerBarTitle {
Text("History")
.style("heading")
.heading()
}
}
.toast("Copied \"\(selectedText)\"", signal: copySignal)
Expand All @@ -67,6 +73,8 @@ struct ContentView: View {
.toast(output.first ?? "Error", signal: outputSignal)
}
.trailingSidebar()
.alertDialog(visible: $alertDialog, heading: "An Error Occured", body: errorOutput)
.response("Close") { }
.onAppear {
text = importContent
}
Expand Down Expand Up @@ -99,9 +107,8 @@ struct ContentView: View {

let errorData = errors.fileHandleForReading.readDataToEndOfFile()
if let errorOutput = String(data: errorData, encoding: .utf8), !errorOutput.isEmpty {
let dialog = adw_message_dialog_new(window.pointer, "An Error Occured", errorOutput)
adw_message_dialog_add_response(dialog?.cast(), "close", "Close")
gtk_window_present(dialog?.cast())
self.errorOutput = errorOutput
alertDialog = true
}
}

Expand All @@ -114,4 +121,9 @@ struct ContentView: View {
copySignal.signal()
}

func window(_ window: Window) -> Window {
window
.size(width: $width, height: $height)
}

}
5 changes: 0 additions & 5 deletions Sources/Scripter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ struct Scripter: App {
Window(id: "main") { window in
ContentView(exportContent: $exportContent, app: app, window: window, importContent: importContent)
}
.defaultSize(width: 400, height: 300)
.quitShortcut()
.overlay {
FileDialog(importer: "importer", extensions: ["py"]) { url in
Expand All @@ -34,10 +33,6 @@ struct Scripter: App {
} onClose: {
exportContent = ""
}
AboutWindow(id: "about", appName: "Scripter", developer: "david-swift", version: "0.1.1")
.icon(.custom(name: "io.github.david_swift.Scripter"))
.website(.init(string: "https://github.com/david-swift/Scripter"))
.issues(.init(string: "https://github.com/david-swift/Scripter/issues"))
}
}

Expand Down
12 changes: 11 additions & 1 deletion Sources/ToolbarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Adwaita
struct ToolbarView: View {

@Binding var sidebarVisible: Bool
@State private var aboutDialog = false
var app: GTUIApp
var window: GTUIApplicationWindow
var run: () -> Void
Expand Down Expand Up @@ -41,10 +42,19 @@ struct ToolbarView: View {
}
MenuSection {
MenuButton("About") {
app.addWindow("about", parent: window)
aboutDialog = true
}
}
}
.aboutDialog(
visible: $aboutDialog,
app: "Scripter",
developer: "david-swift",
version: "0.1.2",
icon: .custom(name: "io.github.david_swift.Scripter"),
website: .init(string: "https://github.com/david-swift/Scripter"),
issues: .init(string: "https://github.com/david-swift/Scripter/issues")
)
}

@MenuBuilder var windowSection: MenuContent {
Expand Down
19 changes: 8 additions & 11 deletions io.github.david_swift.Scripter.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"app-id": "io.github.david_swift.Scripter",
"runtime": "org.gnome.Platform",
"runtime-version": "45",
"runtime-version": "46",
"sdk": "org.gnome.Sdk",
"sdk-extensions": [
"org.freedesktop.Sdk.Extension.swift"
"org.freedesktop.Sdk.Extension.swift5"
],
"command": "Scripter",
"finish-args": [
Expand All @@ -15,8 +15,8 @@
"--socket=wayland"
],
"build-options": {
"append-path": "/usr/lib/sdk/swift/bin",
"prepend-ld-library-path": "/usr/lib/sdk/swift/lib"
"append-path": "/usr/lib/sdk/swift5/bin",
"prepend-ld-library-path": "/usr/lib/sdk/swift5/lib"
},
"cleanup": [
"/include",
Expand All @@ -37,16 +37,13 @@
"buildsystem": "simple",
"sources": [
{
"type": "git",
"url": "https://github.com/david-swift/Scripter",
"branch": "main"
"type": "dir",
"path": "."
}
],
"build-commands": [
"swift build -c release --static-swift-stdlib",
"rm -r -f /app/bin",
"mkdir /app/bin",
"cp .build/release/Scripter /app/bin",
"swift build -c debug --static-swift-stdlib",
"install -Dm755 .build/debug/Scripter /app/bin/Scripter",
"install -Dm644 data/io.github.david_swift.Scripter.metainfo.xml $DESTDIR/app/share/metainfo/io.github.david_swift.Scripter.metainfo.xml",
"install -Dm644 data/io.github.david_swift.Scripter.desktop $DESTDIR/app/share/applications/io.github.david_swift.Scripter.desktop",
"install -Dm644 data/icons/io.github.david_swift.Scripter.svg $DESTDIR/app/share/icons/hicolor/scalable/apps/io.github.david_swift.Scripter.svg",
Expand Down

0 comments on commit c8f8701

Please sign in to comment.