From b6fa5f21044e3fa0dc58d50d845e8596f0f9eb45 Mon Sep 17 00:00:00 2001 From: Dirk Van Haerenborgh Date: Sun, 31 Dec 2023 01:01:13 +0100 Subject: [PATCH] initial prefs window --- Cargo.lock | 22 - Cargo.toml | 3 - ...json => io.github.vhdirk.Terms.Devel.json} | 0 ...Terms.json => io.github.vhdirk.Terms.json} | 0 src/components/mod.rs | 2 + src/components/preferences_window/mod.rs | 11 + .../preferences_window/preferences_window.rs | 63 ++ .../preferences_window/preferences_window.ui | 741 ++++++++++++++++++ src/components/terminal/terminal.rs | 35 +- src/components/window/mod.rs | 4 +- src/components/window/window.rs | 2 +- 11 files changed, 844 insertions(+), 39 deletions(-) rename build-aux/{com.github.vhdirk.Terms.Devel.json => io.github.vhdirk.Terms.Devel.json} (100%) rename build-aux/{com.github.vhdirk.Terms.json => io.github.vhdirk.Terms.json} (100%) create mode 100644 src/components/preferences_window/mod.rs create mode 100644 src/components/preferences_window/preferences_window.rs create mode 100644 src/components/preferences_window/preferences_window.ui diff --git a/Cargo.lock b/Cargo.lock index 350d5f8..8b00475 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -259,7 +259,6 @@ version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" dependencies = [ - "jobserver", "libc", ] @@ -850,15 +849,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "jobserver" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d" -dependencies = [ - "libc", -] - [[package]] name = "js-sys" version = "0.3.66" @@ -1087,17 +1077,6 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" -[[package]] -name = "pcre2-sys" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f8f5556f23cf2c0b481949fdfc19a7cd9b27ddcb00ef3477b0f4935cbdaedf2" -dependencies = [ - "cc", - "libc", - "pkg-config", -] - [[package]] name = "pin-project-lite" version = "0.2.13" @@ -1443,7 +1422,6 @@ dependencies = [ "libpanel", "once_cell", "pango", - "pcre2-sys", "serde", "shell-quote", "tracing", diff --git a/Cargo.toml b/Cargo.toml index faa9075..70aabce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,8 +13,6 @@ tracing = { version = "0.1", features = ["log"] } tracing-subscriber = "0.3" serde = { version = "1.0.126", features = ["derive"] } once_cell = "1.13.0" -# anyhow = "1.0.56" -# clap = { version = "4.4.11", features = ["derive", "env", "string", "unicode"] } async-channel = "2.1.1" glib = { git = "https://github.com/gtk-rs/gtk-rs-core", version = "0.18", branch = "0.18" } @@ -29,7 +27,6 @@ vte = { git = "https://gitlab.gnome.org/World/Rust/vte4-rs", package = "vte4", v async-std = "1.12.0" shell-quote = "0.5.0" constcat = "0.4.0" -pcre2 = {package = "pcre2-sys", version = "0.2.6" } gsettings-macro = "0.1.20" [build-dependencies] diff --git a/build-aux/com.github.vhdirk.Terms.Devel.json b/build-aux/io.github.vhdirk.Terms.Devel.json similarity index 100% rename from build-aux/com.github.vhdirk.Terms.Devel.json rename to build-aux/io.github.vhdirk.Terms.Devel.json diff --git a/build-aux/com.github.vhdirk.Terms.json b/build-aux/io.github.vhdirk.Terms.json similarity index 100% rename from build-aux/com.github.vhdirk.Terms.json rename to build-aux/io.github.vhdirk.Terms.json diff --git a/src/components/mod.rs b/src/components/mod.rs index e58e636..a04e008 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -1,4 +1,5 @@ mod header_bar; +mod preferences_window; mod search_toolbar; mod session; mod terminal; @@ -7,6 +8,7 @@ mod window; mod workspace; pub use header_bar::*; +pub use preferences_window::*; pub use search_toolbar::*; pub use session::*; pub use terminal::*; diff --git a/src/components/preferences_window/mod.rs b/src/components/preferences_window/mod.rs new file mode 100644 index 0000000..8b80382 --- /dev/null +++ b/src/components/preferences_window/mod.rs @@ -0,0 +1,11 @@ +mod preferences_window; +use glib::subclass::prelude::*; +use preferences_window as imp; + +glib::wrapper! { + pub struct PreferencesWindow(ObjectSubclass) + @extends gtk::Widget, gtk::Window, adw::PreferencesWindow, + @implements gio::ActionGroup, gio::ActionMap; //, gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager; +} + +impl PreferencesWindow {} diff --git a/src/components/preferences_window/preferences_window.rs b/src/components/preferences_window/preferences_window.rs new file mode 100644 index 0000000..a266f56 --- /dev/null +++ b/src/components/preferences_window/preferences_window.rs @@ -0,0 +1,63 @@ +use adw::ffi::AdwPreferencesWindow; +use adw::subclass::prelude::*; +use glib::{clone, closure_local, RustClosure}; +use gtk::prelude::*; +use gtk::{gio, glib}; +use panel::subclass::prelude::*; +use std::cell::RefCell; + +use super::*; + +// var builder = new Gtk.Builder.from_resource ("/com/raggesilver/BlackBox/gtk/tab-menu.ui"); +// this.tab_view.menu_model = builder.get_object ("tab-menu") as GLib.Menu; + +// this.layout_box.append (this.header_bar_revealer); +// this.layout_box.append (this.tab_view); + +// this.overlay = new Gtk.Overlay (); +// this.overlay.child = this.layout_box; + +// this.content = this.overlay; + +// this.set_name ("blackbox-main-window"); + +#[derive(Debug, Default, gtk::CompositeTemplate)] +#[template(resource = "/io/github/vhdirk/Terms/gtk/preferences_window.ui")] +pub struct PreferencesWindow {} + +#[glib::object_subclass] +impl ObjectSubclass for PreferencesWindow { + const NAME: &'static str = "TermsPreferencesWindow"; + type Type = super::PreferencesWindow; + type ParentType = adw::PreferencesWindow; + + fn class_init(klass: &mut Self::Class) { + klass.bind_template(); + } + + fn instance_init(obj: &glib::subclass::InitializingObject) { + obj.init_template(); + } +} + +impl ObjectImpl for PreferencesWindow { + fn constructed(&self) { + self.parent_constructed(); + + self.setup_widgets(); + } +} + +impl WidgetImpl for PreferencesWindow {} +impl WindowImpl for PreferencesWindow {} +impl AdwWindowImpl for PreferencesWindow {} +impl PreferencesWindowImpl for PreferencesWindow {} +// impl WorkspaceImpl for PreferencesWindow {} + +impl PreferencesWindow { + fn setup_widgets(&self) { + self.connect_signals(); + } + + fn connect_signals(&self) {} +} diff --git a/src/components/preferences_window/preferences_window.ui b/src/components/preferences_window/preferences_window.ui new file mode 100644 index 0000000..7e0d651 --- /dev/null +++ b/src/components/preferences_window/preferences_window.ui @@ -0,0 +1,741 @@ + + + + + + + 2 + 100 + 1 + + + 100 + 5000 + 50 + + + 1 + 2 + 0.05 + + + 1 + 2 + 0.05 + + + 100 + 1 + + + 0 + 100 + 1 + + + 1 + + diff --git a/src/components/terminal/terminal.rs b/src/components/terminal/terminal.rs index 97fde4a..e5d89cc 100644 --- a/src/components/terminal/terminal.rs +++ b/src/components/terminal/terminal.rs @@ -1,9 +1,11 @@ use adw::subclass::prelude::*; use gio::prelude::*; use gio::SettingsBindFlags; +use glib::ffi::G_REGEX_MULTILINE; use glib::translate::FromGlib; use glib::translate::IntoGlib; use glib::ObjectExt; +use glib::ParamSpec; use glib::Variant; use gtk::glib; use gtk::CompositeTemplate; @@ -92,21 +94,34 @@ impl ObjectImpl for Terminal { } fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = Lazy::new(|| vec![Signal::builder("exit").param_types([i32::static_type()]).build()]); + static SIGNALS: Lazy> = Lazy::new(|| vec![Signal::builder("exit").param_types([i64::static_type()]).build()]); SIGNALS.as_ref() } fn properties() -> &'static [glib::ParamSpec] { - static PROPERTIES: Lazy> = Lazy::new(|| { - let mut scrollback = glib::ParamSpecInt::builder("user-scrollback-lines"); - scrollback.set_flags(glib::ParamFlags::READWRITE); - - vec![scrollback.build()] - }); + static PROPERTIES: Lazy> = Lazy::new(|| vec![glib::ParamSpecInt64::builder("user-scrollback-lines").readwrite().build()]); PROPERTIES.as_ref() } + fn set_property(&self, id: usize, value: &Value, pspec: &glib::ParamSpec) { + match pspec.name() { + "user-scrollback-lines" => { + if let Ok(lines) = value.get::() { + self.term.set_scrollback_lines(lines) + } + }, + _ => unimplemented!(), + } + } + + fn property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value { + match pspec.name() { + "user-scrollback-lines" => self.term.scrollback_lines().to_value(), + _ => unimplemented!(), + } + } + fn dispose(&self) { if let Some(spawn_handle) = self.ctx.borrow_mut().spawn_handle.take() { if spawn_handle.as_raw_source_id().is_some() { @@ -214,7 +229,7 @@ impl Terminal { fn setup_regexes(&self) { for reg_str in URL_REGEX_STRINGS { - if let Ok(reg) = vte::Regex::for_match(reg_str, pcre2::PCRE2_MULTILINE) { + if let Ok(reg) = vte::Regex::for_match(reg_str, G_REGEX_MULTILINE) { let id = self.term.match_add_regex(®, 0); self.term.match_set_cursor_name(id, "pointer") } @@ -241,6 +256,7 @@ impl Terminal { self.obj() .bind_property("user-scrollback-lines", &self.term.clone(), "scrollback-lines") + .sync_create() .build(); // Fallback scrolling makes it so that VTE handles scrolling on its own. We @@ -309,9 +325,6 @@ impl Terminal { // TODO: customize menu based on match_str dbg!("match {:?}, {:?}", match_str, tag); - // let builder = gtk::Builder::from_resource("/io/github/vhdirk/Terms/gtk/terminal_menu.ui"); - // let pop = builder.object::("popover").unwrap(); - let coords = self.term.translate_coordinates(self.obj().as_ref(), x, y).unwrap(); let r = gdk::Rectangle::new(coords.0 as i32, coords.1 as i32, 0, 0); diff --git a/src/components/window/mod.rs b/src/components/window/mod.rs index e4fc094..45ecb1c 100644 --- a/src/components/window/mod.rs +++ b/src/components/window/mod.rs @@ -2,11 +2,11 @@ mod window; use glib::subclass::prelude::*; use window as imp; -use super::{HeaderBar, Session, Terminal, TerminalInitArgs, TerminalPanel}; +use super::{HeaderBar, Session, TerminalInitArgs}; glib::wrapper! { pub struct Window(ObjectSubclass) - @extends gtk::Widget, gtk::Window, gtk::ApplicationWindow, adw::ApplicationWindow, //, panel::Workspace, + @extends gtk::Widget, gtk::Window, gtk::ApplicationWindow, adw::Window, adw::ApplicationWindow, //, panel::Workspace, @implements gio::ActionGroup, gio::ActionMap; //, gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager; } diff --git a/src/components/window/window.rs b/src/components/window/window.rs index e060259..25e132d 100644 --- a/src/components/window/window.rs +++ b/src/components/window/window.rs @@ -57,9 +57,9 @@ impl ObjectImpl for Window { impl WidgetImpl for Window {} impl WindowImpl for Window {} +impl AdwWindowImpl for Window {} impl ApplicationWindowImpl for Window {} impl AdwApplicationWindowImpl for Window {} -// impl WorkspaceImpl for Window {} impl Window { fn setup_widgets(&self) {