Skip to content

Commit

Permalink
Fix Sourcelist, DnD and events for Gtk4 port - stage 1 (#2)
Browse files Browse the repository at this point in the history
* First compilable version

* Emulate previous appearance of Plugins view

* Update ci.yml

* Update io.elementary.code.yml

* Bump glib dependency for libpeas-2

* Rename non-functional Flatpak manifest

* Sync checkbutton with plugin loaded on show

* Action when checkbox toggled

* Fix double parenting

* Sort plugins by name

* Use bind_model and factory

* Lose unused entities

* Cleanup and code style

* Fix initial appearance of preferences dialog

* Add some comments

* Lose commented out code

* Make activate and deactivate methods mandatory to implement

* Fix Flatpak build for OS8

* Fix ci.yml

* Add libgit2-glib-1.0-dev to ci.yml

* Split SourceList into one file per class

* Fix changed namespace

* Remove DnD code

* Replace Gdk.EventKey

* Use GestureClick

* Handle showing context menu

* Handle search_entry focus in

* Handle window close request
  • Loading branch information
jeremypw authored Dec 30, 2024
1 parent 923fc28 commit 90cd82e
Show file tree
Hide file tree
Showing 32 changed files with 2,618 additions and 2,786 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jobs:
- name: Install Dependencies
run: |
apt update
apt install -y exuberant-ctags libeditorconfig-dev libgail-3-dev libgee-0.8-dev libgranite-7-dev libgtk-4-dev libgtksourceview-5-dev libgtkspell3-3-dev libadwaita-1-dev libpeas-2-dev libsoup-3.0-dev libvala-dev libvte-2.91-dev meson valac polkitd libpolkit-gobject-1-dev
apt install -y exuberant-ctags libeditorconfig-dev libgail-3-dev libgee-0.8-dev libgranite-7-dev libgtk-4-dev libgtksourceview-5-dev libgtkspell3-3-dev libadwaita-1-dev libpeas-2-dev libsoup2.4-dev libvala-dev libvte-2.91-gtk4-dev meson valac polkitd libpolkit-gobject-1-dev libgit2-glib-1.0-dev
- name: Build
env:
DESTDIR: out
Expand Down
19 changes: 17 additions & 2 deletions io.elementary.code.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
app-id: io.elementary.code
runtime: io.elementary.Sdk # The outline plugin requires libvala which is only in the SDK, not the runtime
runtime-version: "7.1"
runtime-version: 'daily'
sdk: io.elementary.Sdk
command: io.elementary.code
finish-args:
Expand Down Expand Up @@ -31,7 +31,22 @@ modules:
sources:
- type: git
url: https://gitlab.gnome.org/GNOME/gtksourceview.git
tag: "4.8.4"
tag: '4.8.4'

- name: libpeas
buildsystem: meson
config-opts:
- -Dlua51=false
- -Dgjs=false
sources:
- type: archive
url: https://download.gnome.org/sources/libpeas/2.0/libpeas-2.0.5.tar.xz
sha256: 376f2f73d731b54e13ddbab1d91b6382cf6a980524def44df62add15489de6dd
x-checker-data:
type: gnome
versions:
<: '2.0.6'
name: libpeas

- name: git2-glib
buildsystem: meson
Expand Down
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ gtk_dep = dependency('gtk4', version: '>=4.14.2')
granite_dep = dependency('granite-7', version: '>=7.0.0')
adwaita_dep = dependency('libadwaita-1', version: '>=1.0.0')
gtksourceview_dep = dependency('gtksourceview-5')
peas_dep = dependency('libpeas-2')
git_dep = dependency('libgit2-glib-1.0')
fontconfig_dep = dependency('fontconfig')
pangofc_dep = dependency('pangoft2')
Expand All @@ -56,6 +57,7 @@ dependencies = [
granite_dep,
adwaita_dep,
gtksourceview_dep,
peas_dep,
git_dep,
fontconfig_dep,
pangofc_dep,
Expand Down
4 changes: 2 additions & 2 deletions plugins/brackets-completion/brackets-completion.vala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
END LICENSE
***/

public class Scratch.Plugins.BracketsCompletion : Peas.ExtensionBase, Peas.Activatable {
public class Scratch.Plugins.BracketsCompletion : Peas.ExtensionBase, Scratch.Services.ActivatablePlugin {
Gee.HashMap<string, string> brackets;
Gee.HashMap<uint, string> keys;
const string[] VALID_NEXT_CHARS = {
Expand Down Expand Up @@ -278,6 +278,6 @@ public class Scratch.Plugins.BracketsCompletion : Peas.ExtensionBase, Peas.Activ
[ModuleInit]
public void peas_register_types (GLib.TypeModule module) {
var objmodule = module as Peas.ObjectModule;
objmodule.register_extension_type (typeof (Peas.Activatable),
objmodule.register_extension_type (typeof (Scratch.Services.ActivatablePlugin),
typeof (Scratch.Plugins.BracketsCompletion));
}
4 changes: 2 additions & 2 deletions plugins/detect-indent/detect-indent.vala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public class Scratch.Plugins.DetectIndent: Peas.ExtensionBase, Peas.Activatable {
public class Scratch.Plugins.DetectIndent: Peas.ExtensionBase, Scratch.Services.ActivatablePlugin {
const int MAX_LINES = 500;

Scratch.Services.Interface plugins;
Expand Down Expand Up @@ -79,7 +79,7 @@ public class Scratch.Plugins.DetectIndent: Peas.ExtensionBase, Peas.Activatable
public void peas_register_types (GLib.TypeModule module) {
var objmodule = module as Peas.ObjectModule;
objmodule.register_extension_type (
typeof (Peas.Activatable),
typeof (Scratch.Services.ActivatablePlugin),
typeof (Scratch.Plugins.DetectIndent)
);
}
4 changes: 2 additions & 2 deletions plugins/editorconfig/editorconfig.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Boston, MA 02110-1301 USA
*/

public class Scratch.Plugins.EditorConfigPlugin: Peas.ExtensionBase, Peas.Activatable {
public class Scratch.Plugins.EditorConfigPlugin: Peas.ExtensionBase, Scratch.Services.ActivatablePlugin {
Scratch.Services.Interface plugins;
public Object object { owned get; construct; }
private Code.FormatBar format_bar;
Expand Down Expand Up @@ -91,5 +91,5 @@ public class Scratch.Plugins.EditorConfigPlugin: Peas.ExtensionBase, Peas.Activa
[ModuleInit]
public void peas_register_types (GLib.TypeModule module) {
var objmodule = module as Peas.ObjectModule;
objmodule.register_extension_type (typeof (Peas.Activatable), typeof (Scratch.Plugins.EditorConfigPlugin));
objmodule.register_extension_type (typeof (Scratch.Services.ActivatablePlugin), typeof (Scratch.Plugins.EditorConfigPlugin));
}
4 changes: 2 additions & 2 deletions plugins/fuzzy-search/fuzzy-search.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/


public class Scratch.Plugins.FuzzySearch: Peas.ExtensionBase, Peas.Activatable {
public class Scratch.Plugins.FuzzySearch: Peas.ExtensionBase, Scratch.Services.ActivatablePlugin {
public Object object { owned get; construct; }
private const uint ACCEL_KEY = Gdk.Key.F;
private const Gdk.ModifierType ACCEL_MODTYPE = Gdk.ModifierType.MOD1_MASK;
Expand Down Expand Up @@ -158,7 +158,7 @@ public class Scratch.Plugins.FuzzySearch: Peas.ExtensionBase, Peas.Activatable {
public void peas_register_types (GLib.TypeModule module) {
var objmodule = module as Peas.ObjectModule;
objmodule.register_extension_type (
typeof (Peas.Activatable),
typeof (Scratch.Services.ActivatablePlugin),
typeof (Scratch.Plugins.FuzzySearch)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
END LICENSE
***/

public class Scratch.Plugins.HighlightSelectedWords : Peas.ExtensionBase, Peas.Activatable {
public class Scratch.Plugins.HighlightSelectedWords : Peas.ExtensionBase, Scratch.Services.ActivatablePlugin {
Scratch.Widgets.SourceView current_source;
Scratch.MainWindow? main_window = null;
Gtk.SourceSearchContext? current_search_context = null;
Expand Down Expand Up @@ -151,6 +151,6 @@ public class Scratch.Plugins.HighlightSelectedWords : Peas.ExtensionBase, Peas.A
[ModuleInit]
public void peas_register_types (TypeModule module) {
var objmodule = module as Peas.ObjectModule;
objmodule.register_extension_type (typeof (Peas.Activatable),
objmodule.register_extension_type (typeof (Scratch.Services.ActivatablePlugin),
typeof (Scratch.Plugins.HighlightSelectedWords));
}
4 changes: 2 additions & 2 deletions plugins/markdown-actions/markdown-actions.vala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
END LICENSE
***/

public class Code.Plugins.MarkdownActions : Peas.ExtensionBase, Peas.Activatable {
public class Code.Plugins.MarkdownActions : Peas.ExtensionBase, Scratch.Services.ActivatablePlugin {
Scratch.Widgets.SourceView current_source;
Scratch.Services.Interface plugins;

Expand Down Expand Up @@ -243,6 +243,6 @@ public class Code.Plugins.MarkdownActions : Peas.ExtensionBase, Peas.Activatable
[ModuleInit]
public void peas_register_types (TypeModule module) {
var objmodule = module as Peas.ObjectModule;
objmodule.register_extension_type (typeof (Peas.Activatable),
objmodule.register_extension_type (typeof (Scratch.Services.ActivatablePlugin),
typeof (Code.Plugins.MarkdownActions));
}
2 changes: 1 addition & 1 deletion plugins/pastebin/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module_files = [
'pastebin.vala'
]

soup_dep = dependency('libsoup-2.4')
soup_dep = dependency('libsoup-3.0')

module_deps = [
codecore_dep,
Expand Down
21 changes: 14 additions & 7 deletions plugins/pastebin/pastebin.vala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace Scratch.Services {
string paste_private, string paste_expire_date,
string paste_format) {

link = null;
if (paste_code.length == 0) { link = "No text to paste"; return false; }

string api_url = "https://pastebin.com/api/api_post.php";
Expand All @@ -50,15 +51,21 @@ namespace Scratch.Services {
"api_paste_expire_date", paste_expire_date,
"api_paste_format", paste_format);

message.set_request ("application/x-www-form-urlencoded", Soup.MemoryUse.COPY, request.data);
message.set_request_body_from_bytes ("application/x-www-form-urlencoded", new Bytes (request.data));
message.set_flags (Soup.MessageFlags.NO_REDIRECT);

session.send_message (message);
Bytes output;
try {
output = session.send_and_read (message);
} catch (Error e) {
return false;
}


var output = (string) message.response_body.data;
link = output;
var output_s = (string) output.get_data ();
link = output_s;

if (Uri.parse_scheme (output) == null || message.status_code != 200) {
if (Uri.parse_scheme (output_s) == null || message.status_code != 200) {
// A URI was not returned
return false;
}
Expand All @@ -68,7 +75,7 @@ namespace Scratch.Services {
}
}

public class Scratch.Plugins.Pastebin : Peas.ExtensionBase, Peas.Activatable {
public class Scratch.Plugins.Pastebin : Peas.ExtensionBase, Scratch.Services.ActivatablePlugin {
GLib.MenuItem? menuitem = null;
GLib.Menu? share_menu = null;
public Object object { owned get; construct; }
Expand Down Expand Up @@ -147,6 +154,6 @@ public class Scratch.Plugins.Pastebin : Peas.ExtensionBase, Peas.Activatable {
[ModuleInit]
public void peas_register_types (GLib.TypeModule module) {
var objmodule = module as Peas.ObjectModule;
objmodule.register_extension_type (typeof (Peas.Activatable),
objmodule.register_extension_type (typeof (Scratch.Services.ActivatablePlugin),
typeof (Scratch.Plugins.Pastebin));
}
4 changes: 2 additions & 2 deletions plugins/preserve-indent/preserve-indent.vala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
END LICENSE
***/

public class Scratch.Plugins.PreserveIndent : Peas.ExtensionBase, Peas.Activatable {
public class Scratch.Plugins.PreserveIndent : Peas.ExtensionBase, Scratch.Services.ActivatablePlugin {

private Scratch.Services.Interface plugins;
private Gee.TreeSet<weak Services.Document> documents;
Expand Down Expand Up @@ -244,6 +244,6 @@ public class Scratch.Plugins.PreserveIndent : Peas.ExtensionBase, Peas.Activatab
[ModuleInit]
public void peas_register_types (GLib.TypeModule module) {
var objmodule = module as Peas.ObjectModule;
objmodule.register_extension_type (typeof (Peas.Activatable),
objmodule.register_extension_type (typeof (Scratch.Services.ActivatablePlugin),
typeof (Scratch.Plugins.PreserveIndent));
}
4 changes: 2 additions & 2 deletions plugins/spell/spell.vala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>
*/

public class Scratch.Plugins.Spell: Peas.ExtensionBase, Peas.Activatable {
public class Scratch.Plugins.Spell: Peas.ExtensionBase, Scratch.Services.ActivatablePlugin {

Scratch.Services.Interface plugins;

Expand Down Expand Up @@ -160,7 +160,7 @@ public class Scratch.Plugins.Spell: Peas.ExtensionBase, Peas.Activatable {
public void peas_register_types (GLib.TypeModule module) {
var objmodule = module as Peas.ObjectModule;
objmodule.register_extension_type (
typeof (Peas.Activatable),
typeof (Scratch.Services.ActivatablePlugin),
typeof (Scratch.Plugins.Spell)
);
}
4 changes: 2 additions & 2 deletions plugins/vim-emulation/vim-emulation.vala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
END LICENSE
***/

public class Scratch.Plugins.VimEmulation : Peas.ExtensionBase, Peas.Activatable {
public class Scratch.Plugins.VimEmulation : Peas.ExtensionBase, Scratch.Services.ActivatablePlugin {
public enum Mode {
COMMAND,
INSERT,
Expand Down Expand Up @@ -298,6 +298,6 @@ public class Scratch.Plugins.VimEmulation : Peas.ExtensionBase, Peas.Activatable
[ModuleInit]
public void peas_register_types (GLib.TypeModule module) {
var objmodule = module as Peas.ObjectModule;
objmodule.register_extension_type (typeof (Peas.Activatable),
objmodule.register_extension_type (typeof (Scratch.Services.ActivatablePlugin),
typeof (Scratch.Plugins.VimEmulation));
}
4 changes: 2 additions & 2 deletions plugins/word-completion/plugin.vala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
*/

public class Scratch.Plugins.Completion : Peas.ExtensionBase, Peas.Activatable {
public class Scratch.Plugins.Completion : Peas.ExtensionBase, Scratch.Services.ActivatablePlugin {
public Object object { owned get; construct; }

private List<Gtk.SourceView> text_view_list = new List<Gtk.SourceView> ();
Expand Down Expand Up @@ -185,6 +185,6 @@ public class Scratch.Plugins.Completion : Peas.ExtensionBase, Peas.Activatable {
[ModuleInit]
public void peas_register_types (GLib.TypeModule module) {
var objmodule = module as Peas.ObjectModule;
objmodule.register_extension_type (typeof (Peas.Activatable),
objmodule.register_extension_type (typeof (Scratch.Services.ActivatablePlugin),
typeof (Scratch.Plugins.Completion));
}
9 changes: 7 additions & 2 deletions src/Dialogs/PreferencesDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ public class Scratch.Dialogs.Preferences : Granite.Dialog {
main_box.add (stackswitcher);
main_box.add (stack);

plugins.hook_preferences_dialog (this);
plugins.hook_preferences_dialog (this); // Unused?

if (Peas.Engine.get_default ().get_plugin_list ().length () > 0) {
if (plugins.get_n_plugins () > 0) {
var pbox = plugins.get_view ();
pbox.vexpand = true;

Expand All @@ -160,6 +160,11 @@ public class Scratch.Dialogs.Preferences : Granite.Dialog {
close_button.clicked.connect (() => {
destroy ();
});

//Ensure appearance correct after using libpeas-2
realize.connect (() => {
stack.set_visible_child_name ("behavior");
});
}

private class SettingSwitch : Gtk.Grid {
Expand Down
2 changes: 1 addition & 1 deletion src/FolderManager/FileView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* SourceList that displays folders and their contents.
*/
public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.PaneSwitcher {
public class Scratch.FolderManager.FileView : Code.Widgets.SourceList.Window, Code.PaneSwitcher {
public const string ACTION_GROUP = "file-view";
public const string ACTION_PREFIX = ACTION_GROUP + ".";
public const string ACTION_LAUNCH_APP_WITH_FILE_PATH = "launch-app-with-file-path";
Expand Down
Loading

0 comments on commit 90cd82e

Please sign in to comment.