Skip to content
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

GObject.ParamSpec.* blurb and nick are nullable #224

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
8 changes: 8 additions & 0 deletions examples/gio-2-action-entries/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
import GObject from 'gi://GObject';
import System from 'system';

console.log('GJS Version:', System.version);

if(System.version < 18200) {
console.log('GJS version 1.82.0 or higher is required for this example, skipping example');
System.exit(0);
}

export class ExampleApplication extends Gio.Application {
static {
Expand Down
8 changes: 8 additions & 0 deletions examples/gio-2-iterate/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import GLib from 'gi://GLib'
import Gio from 'gi://Gio'
import System from 'system';

console.log('GJS Version:', System.version);

if(System.version < 18200) {
console.log('GJS version 1.82.0 or higher is required for this example, skipping example');
System.exit(0);
}

Gio._promisify(Gio.File.prototype, 'enumerate_children_async', 'enumerate_children_finish')

Expand Down
121 changes: 121 additions & 0 deletions examples/gobject-param-spec/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import GObject from 'gi://GObject';
import System from 'system';

console.log('GJS Version:', System.version);

if(System.version < 18200) {
console.log('GJS version 1.82.0 or higher is required for nullable nick and blurb in GObject.ParamSpec, skipping example');
System.exit(0);
}

// Example class demonstrating different ParamSpec usages
class ExampleObject extends GObject.Object {
static {
GObject.registerClass({
GTypeName: 'ExampleObject',
Properties: {
// Property with all fields
'full-property': GObject.ParamSpec.string(
'full-property', // name (required)
'Full Property', // nick (optional)
'A complete property', // blurb (optional)
GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
'default value'
),

// Property with null nick and blurb
'minimal-property': GObject.ParamSpec.string(
'minimal-property',
null, // nick can be null
null, // blurb can be null
GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
''
),

// Number property with null documentation
'count': GObject.ParamSpec.int(
'count',
null, // nick can be null
null, // blurb can be null
GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
0, // minimum
100, // maximum
0 // default value
),

// Boolean property with partial documentation
'active': GObject.ParamSpec.boolean(
'active',
'Active', // providing nick
null, // but blurb can still be null
GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
false
)
}
}, this);
}

// Property values
private _fullProperty: string = 'default value';
private _minimalProperty: string = '';
private _count: number = 0;
private _active: boolean = false;

// Property getters/setters
get full_property(): string {
return this._fullProperty;
}

set full_property(value: string) {
this._fullProperty = value;
}

get minimal_property(): string {
return this._minimalProperty;
}

set minimal_property(value: string) {
this._minimalProperty = value;
}

get count(): number {
return this._count;
}

set count(value: number) {
this._count = value;
}

get active(): boolean {
return this._active;
}

set active(value: boolean) {
this._active = value;
}
}

// Create and test the object
const obj = new ExampleObject();

// Test property access and type safety
obj.full_property = 'New Value';
obj.minimal_property = 'Test';
obj.count = 42;
obj.active = true;

// Print current values
console.log('Full Property:', obj.full_property);
console.log('Minimal Property:', obj.minimal_property);
console.log('Count:', obj.count);
console.log('Active:', obj.active);

// Get property info using GObject introspection
const properties = ExampleObject.list_properties();

console.log('\nProperty Information:');
for (const pspec of properties) {
console.log(`\nProperty: ${pspec.get_name()}`);
console.log(`Nick: ${pspec.get_nick() || '(null)'}`);
console.log(`Blurb: ${pspec.get_blurb() || '(null)'}`);
}
24 changes: 24 additions & 0 deletions examples/gobject-param-spec/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@ts-for-gir-example/gobject-param-spec",
"version": "4.0.0-beta.19",
"description": "Example demonstrating GObject.ParamSpec with nullable fields",
"type": "module",
"private": true,
"scripts": {
"build:app": "tsc",
"build": "yarn build:app",
"start:app": "gjs -m dist/main.js",
"start": "yarn build && yarn start:app",
"validate": "yarn validate:types",
"validate:types": "tsc --noEmit",
"clear": "rm -rf dist"
},
"devDependencies": {
"typescript": "^5.6.3"
},
"dependencies": {
"@girs/gjs": "workspace:^",
"@girs/glib-2.0": "workspace:^",
"@girs/gobject-2.0": "workspace:^"
}
}
18 changes: 18 additions & 0 deletions examples/gobject-param-spec/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"lib": ["ESNext"],
"types": ["@girs/gjs", "@girs/gjs/dom", "@girs/gobject-2.0", "@girs/glib-2.0"],
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitThis": true,
"alwaysStrict": true,
"outDir": "./dist"
},
"files": [
"main.ts"
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"test:girs:packages": "yarn build:types:packages && yarn validate:types:packages",
"test:girs:packages:gtk4": "yarn build:types:packages:gtk4 && yarn validate:types:packages",
"test:examples": "yarn build:examples && yarn validate:examples && yarn test:examples:cli-apps",
"test:examples:cli-apps": "yarn workspace @ts-for-gir-example/glib-2-spawn-command-example run start && yarn workspace @ts-for-gir-example/gio-2-cat-example run start",
"test:examples:cli-apps": "yarn workspace @ts-for-gir-example/glib-2-spawn-command-example run start && yarn workspace @ts-for-gir-example/gio-2-cat-example run start && yarn workspace @ts-for-gir-example/gobject-param-spec run start && yarn workspace @ts-for-gir-example/gio-2-async run start && yarn workspace @ts-for-gir-example/gio-2-action-entries run start && yarn workspace @ts-for-gir-example/gio-2-iterate run start",
"test:tests": "yarn workspaces foreach -v --all --parallel --include '@ts-for-gir-test/*' run test",
"build": "yarn workspaces foreach --recursive --topological-dev --parallel --verbose --from @ts-for-gir/cli run build",
"build:examples": "yarn workspaces foreach -v --all --include '@ts-for-gir-example/*' --parallel run build",
Expand Down
Loading
Loading