Update to use with Meta framework
Some checks failed
Deploy Docs / publish (push) Waiting to run
SwiftLint / SwiftLint (push) Failing after 3s

This commit is contained in:
david-swift 2025-04-15 16:51:27 +02:00
parent e59178e38f
commit 4d116c5fba
17 changed files with 117 additions and 542 deletions

View File

@ -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

View File

@ -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

34
.gitea/workflows/docs.yml Normal file
View File

@ -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 "<script>window.location.href += \"/documentation/codeeditor\"</script><p>Please enable JavaScript to view the documentation <a href='/documentation/codeeditor'>here</a>.</p>" > 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/'

View File

@ -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:

View File

@ -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

View File

@ -1,3 +0,0 @@
# Contributors
- [david-swift](https://github.com/david-swift)

View File

@ -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)

View File

@ -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.

View File

@ -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.

View File

@ -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

View File

@ -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"
)
]

View File

@ -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>(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<Data>(_ 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<GtkTextIter> = .allocate(capacity: 1)
let endIter: UnsafeMutablePointer<GtkTextIter> = .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.

View File

@ -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

View File

@ -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()

51
dev.aparoksha.Demo.json Normal file
View File

@ -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"
]
}
]
}