Skip to content
This repository has been archived by the owner on Apr 16, 2021. It is now read-only.

Commit

Permalink
Add a prefs widget with an about page
Browse files Browse the repository at this point in the history
We use a separate typescript config to isolate the prefs file from the
extension files; tsc compiles all files reachable from a single tsconfig
into a shared global namespaces whereas the prefs widget is normally
entirely indepdent.

The prefs widget doesn't do much since we have no settings, but it
serves as a place to show an About page, with license information and a
link to our Github page.

Also split the type decl files, move them to a subdirectory, and move
them to a subdirectory, for easier syncing with vscode search provider.
  • Loading branch information
swsnr committed Oct 2, 2020
1 parent 9113d13 commit cc0eec8
Show file tree
Hide file tree
Showing 14 changed files with 757 additions and 61 deletions.
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^3.0.1",
"@typescript-eslint/parser": "^3.0.1",
"concurrently": "^5.3.0",
"eslint": "^7.1.0",
"eslint-plugin-immutable": "^1.0.0",
"prettier": "^2.0.5",
"typescript": "^3.7.2"
},
"scripts": {
"compile": "tsc",
"package": "gnome-extensions pack --extra-source find-projects.py",
"format": "prettier *.ts *.json .eslintrc.json",
"lint": "eslint *.ts",
"compile:extension": "tsc --build tsconfig.extension.json",
"compile:prefs": "tsc --build tsconfig.prefs.json",
"clean": "rm *.js",
"compile": "concurrently yarn:compile:extension yarn:compile:prefs",
"package": "gnome-extensions pack --extra-source find-projects.py --extra-source prefs.ui --extra-source COPYING",
"format": "prettier **/*.ts **/*.json .eslintrc.json",
"lint": "eslint **/*.ts",
"run": "dbus-run-session -- gnome-shell --nested --wayland"
}
}
51 changes: 51 additions & 0 deletions prefs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (C) Sebastian Wiesner <[email protected]>

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

// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import ByteArray = imports.byteArray;
import Gtk = imports.gi.Gtk;

import ExtensionUtils = imports.misc.extensionUtils;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const Self = ExtensionUtils.getCurrentExtension()!;

// eslint-disable-next-line @typescript-eslint/no-empty-function,@typescript-eslint/no-unused-vars
function init(): void {}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function buildPrefsWidget(): imports.gi.Gtk.Widget {
// gnome-extensions pack adds the prefs.ui file to the top-level directory
const ui = Self.dir.get_child("prefs.ui").get_path();
if (!ui) {
throw new Error(`Fatal error, failed to find prefs.ui file!`);
}

const buildable = Gtk.Builder.new_from_file(ui);

const version = buildable.get_object<Gtk.Label>("about_version");
version.set_text(`Version ${Self.metadata.version}`);

const license = ByteArray.toString(
Self.dir.get_child("COPYING").load_contents(null)[1]
);
const license_buffer = buildable.get_object<Gtk.TextBuffer>(
"about_license_buffer"
);
license_buffer.set_text(license, -1);

const widget = buildable.get_object<Gtk.Widget>("prefs_widget");
widget.show_all();
return widget;
}
188 changes: 188 additions & 0 deletions prefs.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.36.0
jetbrains-search-provider - Jetbrains projects in Gnome Shell search
Copyright (C) Sebastian Wiesner <[email protected]>
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Author: Sebastian Wiesner <[email protected]>
-->
<interface>
<requires lib="gtk+" version="3.22"/>
<!-- interface-license-type gplv2 -->
<!-- interface-name jetbrains-search-provider -->
<!-- interface-description Jetbrains projects in Gnome Shell search -->
<!-- interface-copyright Sebastian Wiesner <[email protected]> -->
<!-- interface-authors Sebastian Wiesner <[email protected]> -->
<object class="GtkTextBuffer" id="about_license_buffer"/>
<object class="GtkNotebook" id="prefs_widget">
<property name="width_request">800</property>
<property name="height_request">800</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkBox" id="about_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_start">12</property>
<property name="margin_end">12</property>
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="about_name">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Jetbrains Search Provider</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="about_description">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Add recent projects from JetBrains IDEs to Gnome Shell search</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="about_no_affiliation">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">&lt;b&gt;Note:&lt;/b&gt; This extension is not affiliated with or endorsed by JetBrains.</property>
<property name="use_markup">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="about_version">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Version</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkLinkButton" id="about_github">
<property name="label" translatable="yes">GitHub</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="relief">none</property>
<property name="uri">https://github.com/lunaryorn/jetbrains-search-provider</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkLinkButton" id="about_issue_tracker">
<property name="label" translatable="yes">Issue Tracker</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="relief">none</property>
<property name="uri">https://github.com/lunaryorn/jetbrains-search-provider/issues</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="about_license_frame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="vexpand">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkAlignment">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">False</property>
<property name="vexpand">False</property>
<property name="left_padding">12</property>
<child>
<object class="GtkScrolledWindow" id="about_license_scrolling">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin_start">6</property>
<property name="margin_end">6</property>
<property name="margin_top">6</property>
<property name="margin_bottom">6</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTextView" id="about_license_text">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">False</property>
<property name="buffer">about_license_buffer</property>
<property name="monospace">True</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">6</property>
</packing>
</child>
</object>
</child>
<child type="tab">
<object class="GtkLabel" id="about_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">About</property>
</object>
<packing>
<property name="tab_fill">False</property>
</packing>
</child>
</object>
</interface>
16 changes: 16 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"target": "es2017",
// GJS doesn't have modules
"module": "none",
"lib": ["es2017"],
"removeComments": false,

/* Strict Type-Checking Options */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
}
}
8 changes: 8 additions & 0 deletions tsconfig.extension.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"outFile": "./extension.js"
},
"files": ["./extension.ts"],
"include": ["types/**/*.d.ts"]
}
23 changes: 9 additions & 14 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
{
"compilerOptions": {
"target": "es2017",
// GJS doesn't have modules
"module": "none",
"lib": ["es2017"],
"removeComments": false,

/* Strict Type-Checking Options */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
}
"files": [],
"references": [
{
"path": "./tsconfig.extension.json"
},
{
"path": "./tsconfig.prefs.json"
}
]
}
8 changes: 8 additions & 0 deletions tsconfig.prefs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"outFile": "./prefs.js"
},
"files": ["./prefs.ts"],
"include": ["types/**/*.d.ts"]
}
29 changes: 29 additions & 0 deletions types/bytearray.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Sebastian Wiesner <[email protected]>

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

declare namespace imports {
class ByteArray {
private constructor();
}

namespace byteArray {
function toString(array: ByteArray): string;
}
}
Loading

0 comments on commit cc0eec8

Please sign in to comment.