-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move pages into separate modules and use declaration merging to declare fields for template children.
- Loading branch information
Showing
5 changed files
with
167 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright Sebastian Wiesner <[email protected]> | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0.If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Alternatively, the contents of this file may be used under the terms | ||
// of the GNU General Public License Version 2 or later, as described below: | ||
// | ||
// This program is free software; you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation; either version 2 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
import GObject from "gi://GObject"; | ||
import Gtk from "gi://Gtk"; | ||
import Adw from "gi://Adw"; | ||
|
||
import type { ExtensionMetadata } from "@girs/gnome-shell/extensions/extension"; | ||
|
||
import { getTemplate } from "./template.js"; | ||
|
||
const LICENSE = `Copyright Sebastian Wiesner <[email protected]> | ||
This programm is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
Alternatively, this program may be used under the terms | ||
of the GNU General Public License Version 2 or later, as described below: | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details.`; | ||
|
||
interface AboutPageChildren { | ||
_extensionName: Gtk.Label; | ||
_extensionDescription: Gtk.Label; | ||
_linkGithub: Gtk.LinkButton; | ||
_linkIssues: Gtk.LinkButton; | ||
_extensionLicense: Gtk.TextView; | ||
} | ||
|
||
class TypescriptTemplateAboutPage extends Adw.PreferencesPage { | ||
constructor(metadata: ExtensionMetadata) { | ||
super(); | ||
const children = this as unknown as AboutPageChildren; | ||
children._extensionName.set_text(metadata.name); | ||
children._extensionDescription.set_text(metadata.description); | ||
if (metadata.url) { | ||
children._linkGithub.set_uri(metadata.url); | ||
children._linkIssues.set_uri(`${metadata.url}/issues`); | ||
} else { | ||
children._linkGithub.visible = false; | ||
children._linkIssues.visible = false; | ||
} | ||
children._extensionLicense.buffer.set_text(LICENSE, -1); | ||
} | ||
} | ||
|
||
export default GObject.registerClass( | ||
{ | ||
GTypeName: "TypescriptTemplateAboutPage", | ||
Template: getTemplate("AboutPage"), | ||
InternalChildren: [ | ||
"extensionName", | ||
"extensionDescription", | ||
"linkGithub", | ||
"linkIssues", | ||
"extensionLicense", | ||
], | ||
}, | ||
TypescriptTemplateAboutPage, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright Sebastian Wiesner <[email protected]> | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0.If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Alternatively, the contents of this file may be used under the terms | ||
// of the GNU General Public License Version 2 or later, as described below: | ||
// | ||
// This program is free software; you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation; either version 2 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
import GObject from "gi://GObject"; | ||
import Gio from "gi://Gio"; | ||
import Adw from "gi://Adw"; | ||
|
||
import { getTemplate } from "./template.js"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging | ||
interface TypescriptTemplateGeneralPage { | ||
_sayHello: Adw.SwitchRow; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging | ||
class TypescriptTemplateGeneralPage extends Adw.PreferencesPage { | ||
constructor(settings: Gio.Settings) { | ||
super(); | ||
|
||
settings.bind( | ||
"say-hello", | ||
this._sayHello, | ||
"active", | ||
Gio.SettingsBindFlags.DEFAULT, | ||
); | ||
} | ||
} | ||
|
||
export default GObject.registerClass( | ||
{ | ||
GTypeName: "TypescriptTemplateGeneralPage", | ||
Template: getTemplate("GeneralPage"), | ||
InternalChildren: ["sayHello"], | ||
}, | ||
TypescriptTemplateGeneralPage, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright Sebastian Wiesner <[email protected]> | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0.If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Alternatively, the contents of this file may be used under the terms | ||
// of the GNU General Public License Version 2 or later, as described below: | ||
// | ||
// This program is free software; you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation; either version 2 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
import GLib from "gi://GLib"; | ||
|
||
export const getTemplate = (name: string): string => | ||
GLib.uri_resolve_relative( | ||
import.meta.url, | ||
`ui/${name}.ui`, | ||
GLib.UriFlags.NONE, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,104 +17,13 @@ | |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
import GObject from "gi://GObject"; | ||
import GLib from "gi://GLib"; | ||
import Gio from "gi://Gio"; | ||
import Gtk from "gi://Gtk"; | ||
import Adw from "gi://Adw"; | ||
|
||
import { ExtensionPreferences } from "resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js"; | ||
|
||
import type { ExtensionMetadata } from "@girs/gnome-shell/extensions/extension"; | ||
|
||
const LICENSE = `Copyright Sebastian Wiesner <[email protected]> | ||
This programm is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
Alternatively, this program may be used under the terms | ||
of the GNU General Public License Version 2 or later, as described below: | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details.`; | ||
|
||
const getTemplate = (name: string): string => | ||
GLib.uri_resolve_relative( | ||
import.meta.url, | ||
`ui/${name}.ui`, | ||
GLib.UriFlags.NONE, | ||
); | ||
|
||
interface GeneralPageChildren { | ||
_sayHello: Adw.SwitchRow; | ||
} | ||
|
||
const GeneralPage = GObject.registerClass( | ||
{ | ||
GTypeName: "TypescriptTemplateGeneralPage", | ||
Template: getTemplate("GeneralPage"), | ||
InternalChildren: ["sayHello"], | ||
}, | ||
class TypescriptTemplateGeneralPage extends Adw.PreferencesPage { | ||
constructor(settings: Gio.Settings) { | ||
super(); | ||
|
||
const children = this as unknown as GeneralPageChildren; | ||
settings.bind( | ||
"say-hello", | ||
children._sayHello, | ||
"active", | ||
Gio.SettingsBindFlags.DEFAULT, | ||
); | ||
} | ||
}, | ||
); | ||
|
||
interface AboutPageChildren { | ||
_extensionName: Gtk.Label; | ||
_extensionDescription: Gtk.Label; | ||
_linkGithub: Gtk.LinkButton; | ||
_linkIssues: Gtk.LinkButton; | ||
_extensionLicense: Gtk.TextView; | ||
} | ||
|
||
const AboutPage = GObject.registerClass( | ||
{ | ||
GTypeName: "TypescriptTemplateAboutPage", | ||
Template: getTemplate("AboutPage"), | ||
InternalChildren: [ | ||
"extensionName", | ||
"extensionDescription", | ||
"linkGithub", | ||
"linkIssues", | ||
"extensionLicense", | ||
], | ||
}, | ||
class TypescriptTemplateAboutPage extends Adw.PreferencesPage { | ||
constructor(metadata: ExtensionMetadata) { | ||
super(); | ||
const children = this as unknown as AboutPageChildren; | ||
children._extensionName.set_text(metadata.name); | ||
children._extensionDescription.set_text(metadata.description); | ||
if (metadata.url) { | ||
children._linkGithub.set_uri(metadata.url); | ||
children._linkIssues.set_uri(`${metadata.url}/issues`); | ||
} else { | ||
children._linkGithub.visible = false; | ||
children._linkIssues.visible = false; | ||
} | ||
children._extensionLicense.buffer.set_text(LICENSE, -1); | ||
} | ||
}, | ||
); | ||
import AboutPage from "./lib/prefs/about_page.js"; | ||
import GeneralPage from "./lib/prefs/general_page.js"; | ||
|
||
export default class HelloWorldPreferences extends ExtensionPreferences { | ||
override fillPreferencesWindow( | ||
|