From 4d116c5fba907a25c4782117e534eaa87901a556 Mon Sep 17 00:00:00 2001 From: david-swift Date: Tue, 15 Apr 2025 16:51:27 +0200 Subject: [PATCH] Update to use with Meta framework --- .../ISSUE_TEMPLATE/bug_report.yml | 0 .../ISSUE_TEMPLATE/component_request.yml | 10 +- .../ISSUE_TEMPLATE/feature_request.yml | 0 {.github => .gitea}/PULL_REQUEST_TEMPLATE.md | 3 - .gitea/workflows/docs.yml | 34 ++ {.github => .gitea}/workflows/swiftlint.yml | 8 +- CONTRIBUTING.md | 39 -- Contributors.md | 3 - Documentation/CodeEditor/README.md | 11 - Documentation/CodeEditor/enums/Language.md | 361 ------------------ .../CodeEditor/structs/CodeEditor.md | 77 ---- Makefile | 8 - Package.swift | 6 +- Sources/CodeEditor/CodeEditor.swift | 39 +- Sources/CodeEditor/Language.swift | 2 +- Tests/main.swift | 7 +- dev.aparoksha.Demo.json | 51 +++ 17 files changed, 117 insertions(+), 542 deletions(-) rename {.github => .gitea}/ISSUE_TEMPLATE/bug_report.yml (100%) rename {.github => .gitea}/ISSUE_TEMPLATE/component_request.yml (72%) rename {.github => .gitea}/ISSUE_TEMPLATE/feature_request.yml (100%) rename {.github => .gitea}/PULL_REQUEST_TEMPLATE.md (76%) create mode 100644 .gitea/workflows/docs.yml rename {.github => .gitea}/workflows/swiftlint.yml (74%) delete mode 100644 CONTRIBUTING.md delete mode 100644 Contributors.md delete mode 100644 Documentation/CodeEditor/README.md delete mode 100644 Documentation/CodeEditor/enums/Language.md delete mode 100644 Documentation/CodeEditor/structs/CodeEditor.md delete mode 100644 Makefile create mode 100644 dev.aparoksha.Demo.json diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.gitea/ISSUE_TEMPLATE/bug_report.yml similarity index 100% rename from .github/ISSUE_TEMPLATE/bug_report.yml rename to .gitea/ISSUE_TEMPLATE/bug_report.yml diff --git a/.github/ISSUE_TEMPLATE/component_request.yml b/.gitea/ISSUE_TEMPLATE/component_request.yml similarity index 72% rename from .github/ISSUE_TEMPLATE/component_request.yml rename to .gitea/ISSUE_TEMPLATE/component_request.yml index cca6a9a..63a6c7b 100644 --- a/.github/ISSUE_TEMPLATE/component_request.yml +++ b/.gitea/ISSUE_TEMPLATE/component_request.yml @@ -12,19 +12,11 @@ body: validations: required: false - - type: textarea - attributes: - label: Name the native widgets. - placeholder: >- - A list of the native widgets of Gtk/Libadwaita or AppKit, if you know them. - validations: - required: true - - type: textarea attributes: label: Describe your idea for the implementation. placeholder: >- - What could the implementation be like in Dvandva? + What could the implementation be like in Adwaita? validations: required: false diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.gitea/ISSUE_TEMPLATE/feature_request.yml similarity index 100% rename from .github/ISSUE_TEMPLATE/feature_request.yml rename to .gitea/ISSUE_TEMPLATE/feature_request.yml diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.gitea/PULL_REQUEST_TEMPLATE.md similarity index 76% rename from .github/PULL_REQUEST_TEMPLATE.md rename to .gitea/PULL_REQUEST_TEMPLATE.md index f0ed3f3..cce03ae 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.gitea/PULL_REQUEST_TEMPLATE.md @@ -1,5 +1,4 @@ ## Steps -- [ ] Add your name or username and a link to your GitHub profile into the [Contributors.md][1] file. - [ ] Build the project on your machine. If it does not compile, fix the errors. - [ ] Describe the purpose and approach of your pull request below. - [ ] Submit the pull request. Thank you very much for your contribution! @@ -10,5 +9,3 @@ _If there is a related issue, add the link._ ## Approach _Describe how this pull request solves the problem or adds the feature._ - -[1]: /Contributors.md diff --git a/.gitea/workflows/docs.yml b/.gitea/workflows/docs.yml new file mode 100644 index 0000000..bb1b42a --- /dev/null +++ b/.gitea/workflows/docs.yml @@ -0,0 +1,34 @@ +name: Deploy Docs + +on: + push: + branches: ["main"] + +jobs: + publish: + runs-on: david-macbook + steps: + - uses: actions/checkout@v4 + - name: Build Docs + run: | + xcrun xcodebuild docbuild \ + -scheme CodeEditor \ + -destination 'generic/platform=macOS' \ + -derivedDataPath "$PWD/.derivedData" \ + -skipPackagePluginValidation + xcrun docc process-archive transform-for-static-hosting \ + "$PWD/.derivedData/Build/Products/Debug/CodeEditor.doccarchive" \ + --output-path "docs" \ + --hosting-base-path "/" + - name: Modify Docs + run: | + echo "

Please enable JavaScript to view the documentation here.

" > docs/index.html; + sed -i '' 's/,2px/,10px/g' docs/css/index.*.css + - name: Upload + uses: wangyucode/sftp-upload-action@v2.0.4 + with: + host: 'volans.uberspace.de' + username: 'akforum' + password: ${{ secrets.password }} + localDir: 'docs' + remoteDir: '/var/www/virtual/akforum/codeeditor.aparoksha.dev/' \ No newline at end of file diff --git a/.github/workflows/swiftlint.yml b/.gitea/workflows/swiftlint.yml similarity index 74% rename from .github/workflows/swiftlint.yml rename to .gitea/workflows/swiftlint.yml index 5348bdb..ed7c3ad 100644 --- a/.github/workflows/swiftlint.yml +++ b/.gitea/workflows/swiftlint.yml @@ -3,17 +3,17 @@ name: SwiftLint on: push: paths: - - '.github/workflows/swiftlint.yml' + - '.gitea/workflows/swiftlint.yml' - '.swiftlint.yml' - '**/*.swift' pull_request: paths: - - '.github/workflows/swiftlint.yml' + - '.gitea/workflows/swiftlint.yml' - '.swiftlint.yml' - '**/*.swift' workflow_dispatch: paths: - - '.github/workflows/swiftlint.yml' + - '.gitea/workflows/swiftlint.yml' - '.swiftlint.yml' - '**/*.swift' @@ -21,7 +21,7 @@ jobs: SwiftLint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: SwiftLint uses: norio-nomura/action-swiftlint@3.2.1 with: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index c43eec3..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,39 +0,0 @@ -# Contributing - -Thank you very much for taking the time for contributing to this project. - -## Report a Bug -Just open a new issue on GitHub and describe the bug. It helps if your description is detailed. Thank you very much for your contribution! - -## Suggest a New Feature -Just open a new issue on GitHub and describe the idea. Thank you very much for your contribution! - -## Pull Requests -I am happy for every pull request, you do not have to follow these guidelines. However, it might help you to understand the project structure and make it easier for me to merge your pull request. Thank you very much for your contribution! - -### 1. Fork & Clone this Project -Start by clicking on the `Fork` button at the top of the page. Then, clone this repository to your computer. - -### 2. Open the Project -Open the project folder in GNOME Builder, Xcode or another IDE. - -### 3. Understand the Project Structure -- The `README.md` file contains a description of the app or package. -- The `Contributors.md` file contains the names or user names of all the contributors with a link to their GitHub profile. -- The `LICENSE.md` contains an GPL-3.0 license. -- `CONTRIBUTING.md` is this file. -- Directory `Icons` that contains PNG and PXD (Pixelmator Pro) files for the images used in the app and guides. -- Directory `Documentation` that contains the documentation generated with [SourceDocs][1]. -- `Sources` contains the source code of the project. -- `Tests` contains an example application. - -### 4. Edit the Code -Edit the code. If you add a new type, add documentation in the code. - -### 5. Commit to the Fork -Commit and push the fork. - -### 6. Pull Request -Open GitHub to submit a pull request. Thank you very much for your contribution! - -[1]: https://github.com/SourceDocs/SourceDocs diff --git a/Contributors.md b/Contributors.md deleted file mode 100644 index 3cf3f03..0000000 --- a/Contributors.md +++ /dev/null @@ -1,3 +0,0 @@ -# Contributors - -- [david-swift](https://github.com/david-swift) diff --git a/Documentation/CodeEditor/README.md b/Documentation/CodeEditor/README.md deleted file mode 100644 index c875bee..0000000 --- a/Documentation/CodeEditor/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Reference Documentation - -## Structs - -- [CodeEditor](structs/CodeEditor.md) - -## Enums - -- [Language](enums/Language.md) - -This file was generated by [SourceDocs](https://github.com/eneko/SourceDocs) \ No newline at end of file diff --git a/Documentation/CodeEditor/enums/Language.md b/Documentation/CodeEditor/enums/Language.md deleted file mode 100644 index cd6f1b3..0000000 --- a/Documentation/CodeEditor/enums/Language.md +++ /dev/null @@ -1,361 +0,0 @@ -**ENUM** - -# `Language` - -A language available in the code editor. - -## Cases -### `abnf` - -### `actionscript` - -### `ada` - -### `ansforth94` - -### `asciidoc` - -### `asp` - -### `automake` - -### `awk` - -### `bennugd` - -### `bibtex` - -### `blueprint` - -### `bluespec` - -### `boo` - -### `c` - -### `cSharp` - -### `cpp` - -### `cg` - -### `changelog` - -### `changes` - -### `cpphdr` - -### `cmake` - -### `chdr` - -### `cobol` - -### `commonlisp` - -### `css` - -### `csv` - -### `cuda` - -### `d` - -### `dart` - -### `def` - -### `desktop` - -### `diff` - -### `dtl` - -### `docbook` - -### `docker` - -### `dosbatch` - -### `dpatch` - -### `dtd` - -### `eiffel` - -### `erb` - -### `erbHtml` - -### `erbJs` - -### `erlang` - -### `fsharp` - -### `fcl` - -### `fish` - -### `ftl` - -### `forth` - -### `fortran` - -### `gap` - -### `gdbLog` - -### `gdscript` - -### `genie` - -### `gettextTranslation` - -### `go` - -### `gradle` - -### `dot` - -### `groovy` - -### `gtkDoc` - -### `gtkrc` - -### `haddock` - -### `haskell` - -### `haxe` - -### `html` - -### `idl` - -### `idlExelis` - -### `imagej` - -### `ini` - -### `j` - -### `jade` - -### `java` - -### `js` - -### `jsVal` - -### `jsExpr` - -### `jsFn` - -### `jsLit` - -### `jsMod` - -### `jsSt` - -### `jsdoc` - -### `json` - -### `jsx` - -### `julia` - -### `kotlin` - -### `latex` - -### `lean` - -### `less` - -### `lex` - -### `libtool` - -### `haskellLiterate` - -### `llvm` - -### `logcat` - -### `logtalk` - -### `lua` - -### `m4` - -### `makefile` - -### `mallard` - -### `markdown` - -### `matlab` - -### `maxima` - -### `mediawiki` - -### `meson` - -### `modelica` - -### `mxml` - -### `nemerle` - -### `netrexx` - -### `nix` - -### `nsis` - -### `objc` - -### `objj` - -### `ocaml` - -### `ocl` - -### `octave` - -### `ooc` - -### `opal` - -### `openclGlsl` - -### `pascal` - -### `perl` - -### `php` - -### `pig` - -### `pkgconfig` - -### `plain` - -### `powershell` - -### `prolog` - -### `proto` - -### `puppet` - -### `python3` - -### `python` - -### `r` - -### `reasonml` - -### `rst` - -### `rpmspec` - -### `ruby` - -### `rust` - -### `scala` - -### `scheme` - -### `scilab` - -### `scss` - -### `sh` - -### `solidity` - -### `sparql` - -### `spice` - -### `sql` - -### `sml` - -### `star` - -### `sweave` - -### `swift` - -### `systemverilog` - -### `tcl` - -### `tera` - -### `terraform` - -### `texinfo` - -### `thrift` - -### `todotxt` - -### `toml` - -### `twig` - -### `t2t` - -### `typescript` - -### `typescriptJsExpr` - -### `typescriptJsFn` - -### `typescriptJsLit` - -### `typescriptJsMod` - -### `typescriptJsSt` - -### `typescriptJsx` - -### `typescriptTypeExpr` - -### `typescriptTypeGen` - -### `typescriptTypeLit` - -### `vala` - -### `vbnet` - -### `verilog` - -### `vhdl` - -### `xml` - -### `xslt` - -### `yacc` - -### `yaml` - -### `yara` - -## Properties -### `languageName` - -The name of the language for the backend. diff --git a/Documentation/CodeEditor/structs/CodeEditor.md b/Documentation/CodeEditor/structs/CodeEditor.md deleted file mode 100644 index be3102b..0000000 --- a/Documentation/CodeEditor/structs/CodeEditor.md +++ /dev/null @@ -1,77 +0,0 @@ -**STRUCT** - -# `CodeEditor` - -A text or code editor widget. - -## Properties -### `text` - -The editor's content. - -### `padding` - -The padding between the border and the content. - -### `paddingEdges` - -The edges affected by the padding. - -### `numbers` - -Whether the line numbers are visible. - -### `language` - -The programming language for syntax highlighting. - -## Methods -### `init(text:)` - -Initialize a code editor. -- Parameter text: The editor's content. - -### `container(modifiers:)` - -Get the editor's view storage. -- Parameter modifiers: The view modifiers. -- Returns: The view storage. - -### `update(_:modifiers:updateProperties:)` - -Update a view storage to the editor. -- Parameters: - - storage: The view storage. - - modifiers: The view modifiers. - - updateProperties: Whether to update the view's properties. - -### `getText(buffer:)` - -Get the text view's content. -- Parameter buffer: The text view's buffer. -- Returns: The content. - -### `setLanguage(buffer:)` - -Get the text view's programming language. -- Parameter buffer: The text view's buffer. - -### `innerPadding(_:edges:)` - -Add padding between the editor's content and border. -- Parameters: - - padding: The padding's value. - - edges: The affected edges. -- Returns: The editor. - -### `lineNumbers(_:)` - -Set the visibility of line numbers. -- Parameter visible: Whether the numbers are visible. -- Returns: The editor. - -### `language(_:)` - -Set the syntax highlighting programming language. -- Parameter language: The programming language. -- Returns: The editor. diff --git a/Makefile b/Makefile deleted file mode 100644 index 3035ed5..0000000 --- a/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -docs: - @sourcedocs generate --min-acl private -r --spm-module CodeEditor --output-folder Documentation/CodeEditor - -swiftlint: - @swiftlint --autocorrect - -format: - @clang-format -i Sources/CCodeEditor/shim.h --style=file diff --git a/Package.swift b/Package.swift index 3d32a26..f443715 100644 --- a/Package.swift +++ b/Package.swift @@ -22,12 +22,12 @@ let package = Package( ) ], dependencies: [ - .package(url: "https://github.com/AparokshaUI/Adwaita", from: "0.2.0") + .package(url: "https://git.aparoksha.dev/aparoksha/adwaita-swift", branch: "main") ], targets: [ .target( name: "CodeEditor", - dependencies: [.product(name: "Adwaita", package: "Adwaita"), "CCodeEditor"] + dependencies: [.product(name: "Adwaita", package: "adwaita-swift"), "CCodeEditor"] ), .systemLibrary( name: "CCodeEditor", @@ -35,7 +35,7 @@ let package = Package( ), .executableTarget( name: "Test", - dependencies: ["CodeEditor", "Adwaita"], + dependencies: ["CodeEditor", .product(name: "Adwaita", package: "adwaita-swift")], path: "Tests" ) ] diff --git a/Sources/CodeEditor/CodeEditor.swift b/Sources/CodeEditor/CodeEditor.swift index e707339..55a50b8 100644 --- a/Sources/CodeEditor/CodeEditor.swift +++ b/Sources/CodeEditor/CodeEditor.swift @@ -9,7 +9,7 @@ import Adwaita import CCodeEditor /// A text or code editor widget. -public struct CodeEditor: Widget { +public struct CodeEditor: AdwaitaWidget { /// The editor's content. @Binding var text: String @@ -29,25 +29,28 @@ public struct CodeEditor: Widget { } /// Get the editor's view storage. - /// - Parameter modifiers: The view modifiers. + /// - Parameters: + /// - data: The widget data. + /// - type: The view render data type. /// - Returns: The view storage. - public func container(modifiers: [(View) -> View]) -> ViewStorage { + public func container(data: WidgetData, type: Data.Type) -> ViewStorage { let buffer = ViewStorage(gtk_source_buffer_new(nil)?.opaque()) let editor = ViewStorage( - gtk_source_view_new_with_buffer(buffer.pointer?.cast())?.opaque(), + gtk_source_view_new_with_buffer(buffer.opaquePointer?.cast())?.opaque(), content: ["buffer": [buffer]] ) - codeeditor_buffer_set_theme_adaptive(buffer.pointer?.cast()) - update(editor, modifiers: modifiers, updateProperties: true) + codeeditor_buffer_set_theme_adaptive(buffer.opaquePointer?.cast()) + update(editor, data: data, updateProperties: true, type: type) return editor } /// Update a view storage to the editor. /// - Parameters: /// - storage: The view storage. - /// - modifiers: The view modifiers. + /// - data: The widget data. /// - updateProperties: Whether to update the view's properties. - public func update(_ storage: ViewStorage, modifiers: [(View) -> View], updateProperties: Bool) { + /// - type: The view render data type. + public func update(_ storage: ViewStorage, data: WidgetData, updateProperties: Bool, type: Data.Type) { if let buffer = storage.content["buffer"]?.first { buffer.connectSignal(name: "changed") { let text = getText(buffer: buffer) @@ -57,25 +60,25 @@ public struct CodeEditor: Widget { } if updateProperties { if getText(buffer: buffer) != self.text { - gtk_text_buffer_set_text(buffer.pointer?.cast(), text, -1) + gtk_text_buffer_set_text(buffer.opaquePointer?.cast(), text, -1) } setLanguage(buffer: buffer) } } if updateProperties { if paddingEdges.contains(.top) { - gtk_text_view_set_top_margin(storage.pointer?.cast(), padding.cInt) + gtk_text_view_set_top_margin(storage.opaquePointer?.cast(), padding.cInt) } if paddingEdges.contains(.bottom) { - gtk_text_view_set_bottom_margin(storage.pointer?.cast(), padding.cInt) + gtk_text_view_set_bottom_margin(storage.opaquePointer?.cast(), padding.cInt) } if paddingEdges.contains(.leading) { - gtk_text_view_set_left_margin(storage.pointer?.cast(), padding.cInt) + gtk_text_view_set_left_margin(storage.opaquePointer?.cast(), padding.cInt) } if paddingEdges.contains(.trailing) { - gtk_text_view_set_right_margin(storage.pointer?.cast(), padding.cInt) + gtk_text_view_set_right_margin(storage.opaquePointer?.cast(), padding.cInt) } - gtk_source_view_set_show_line_numbers(storage.pointer?.cast(), numbers.cBool) + gtk_source_view_set_show_line_numbers(storage.opaquePointer?.cast(), numbers.cBool) } } @@ -85,10 +88,10 @@ public struct CodeEditor: Widget { func getText(buffer: ViewStorage) -> String { let startIter: UnsafeMutablePointer = .allocate(capacity: 1) let endIter: UnsafeMutablePointer = .allocate(capacity: 1) - gtk_text_buffer_get_start_iter(buffer.pointer?.cast(), startIter) - gtk_text_buffer_get_end_iter(buffer.pointer?.cast(), endIter) + gtk_text_buffer_get_start_iter(buffer.opaquePointer?.cast(), startIter) + gtk_text_buffer_get_end_iter(buffer.opaquePointer?.cast(), endIter) return .init( - cString: gtk_text_buffer_get_text(buffer.pointer?.cast(), startIter, endIter, true.cBool) + cString: gtk_text_buffer_get_text(buffer.opaquePointer?.cast(), startIter, endIter, true.cBool) ) } @@ -97,7 +100,7 @@ public struct CodeEditor: Widget { func setLanguage(buffer: ViewStorage) { let manager = gtk_source_language_manager_get_default() let language = gtk_source_language_manager_get_language(manager, language.languageName) - gtk_source_buffer_set_language(buffer.pointer?.cast(), language) + gtk_source_buffer_set_language(buffer.opaquePointer?.cast(), language) } /// Add padding between the editor's content and border. diff --git a/Sources/CodeEditor/Language.swift b/Sources/CodeEditor/Language.swift index 82468a5..03e37f6 100644 --- a/Sources/CodeEditor/Language.swift +++ b/Sources/CodeEditor/Language.swift @@ -6,7 +6,7 @@ // /// A language available in the code editor. -public enum Language: String { +public enum Language: String, CaseIterable { // swiftlint:disable missing_docs identifier_name diff --git a/Tests/main.swift b/Tests/main.swift index d3a9e5e..5170d55 100644 --- a/Tests/main.swift +++ b/Tests/main.swift @@ -13,9 +13,8 @@ import CodeEditor @main struct Test: App { - let id = "io.foo.Bar" + let app = AdwaitaApp(id: "dev.aparoksha.Demo") @State private var text = "" - var app: GTUIApp! var scene: Scene { Window(id: "main") { window in @@ -34,9 +33,7 @@ struct Test: App { .style("suggested-action") } } - .onAppear { - window.setDefaultSize(width: 300, height: 250) - } + .topBarStyle(.raised) } .closeShortcut() .quitShortcut() diff --git a/dev.aparoksha.Demo.json b/dev.aparoksha.Demo.json new file mode 100644 index 0000000..8284527 --- /dev/null +++ b/dev.aparoksha.Demo.json @@ -0,0 +1,51 @@ +{ + "app-id": "dev.aparoksha.Demo", + "runtime": "org.gnome.Platform", + "runtime-version": "48", + "sdk": "org.gnome.Sdk", + "sdk-extensions": [ + "org.freedesktop.Sdk.Extension.swift6" + ], + "command": "Test", + "finish-args": [ + "--share=network", + "--share=ipc", + "--socket=fallback-x11", + "--device=dri", + "--socket=wayland" + ], + "build-options": { + "append-path": "/usr/lib/sdk/swift6/bin", + "prepend-ld-library-path": "/usr/lib/sdk/swift6/lib" + }, + "cleanup": [ + "/include", + "/lib/pkgconfig", + "/man", + "/share/doc", + "/share/gtk-doc", + "/share/man", + "/share/pkgconfig", + "/share/vala", + "*.la", + "*.a" + ], + "modules": [ + { + "name": "Test", + "builddir": true, + "buildsystem": "simple", + "sources": [ + { + "type": "dir", + "path": "." + } + ], + "build-commands": [ + "swift build -c debug --static-swift-stdlib", + "install -Dm755 .build/debug/Test /app/bin/Test", + "swiftlint Sources" + ] + } + ] +}