Skip to content

Commit

Permalink
Add Canvas and Editor settings to Settings
Browse files Browse the repository at this point in the history
So that user changes persist in the config file.
  • Loading branch information
epilys committed Mar 28, 2023
1 parent 18fa55d commit 945cb80
Show file tree
Hide file tree
Showing 10 changed files with 801 additions and 186 deletions.
6 changes: 4 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,10 @@ impl ApplicationImpl for ApplicationInner {
/// here. Widgets can't be created before `startup` has been called.
fn startup(&self, app: &Self::Type) {
self.parent_startup(app);
self.runtime.settings.register_singleton(app.clone());
self.runtime
.settings
.register_obj(app.upcast_ref::<glib::Object>().clone());
.register_singleton(CanvasSettings::new());
#[cfg(feature = "python")]
{
self.register_obj(app.upcast_ref());
Expand Down Expand Up @@ -394,7 +395,6 @@ impl ApplicationInner {
settings.connect_activate(
glib::clone!(@strong self.runtime.settings as settings, @weak obj as app => move |_, _| {
let w = settings.new_property_window(&app, false);
w.add_extra_obj(app.upcast_ref::<glib::Object>().clone(), None);
w.present();
}),
);
Expand Down Expand Up @@ -773,6 +773,8 @@ impl ApplicationInner {
}
}

impl_property_window!(Application);

// [ref:VERIFY] are apps supposed to have access to preset predefined colors?
// [ref:TODO] add fallback @defines in case a theme lacks a color
/// Named colors from GTK3 themes.
Expand Down
230 changes: 203 additions & 27 deletions src/app/settings.rs

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,12 +541,8 @@ glib::wrapper! {
@extends gtk::Widget, gtk::Container, gtk::Bin;
}

impl std::ops::Deref for Editor {
type Target = EditorInner;
fn deref(&self) -> &Self::Target {
self.imp()
}
}
impl_deref!(Editor, EditorInner);
impl_friendly_name!(Editor);

impl Editor {
pub const CLOSEABLE: &str = Workspace::CLOSEABLE;
Expand Down Expand Up @@ -611,8 +607,8 @@ impl Editor {
.build();
}
let settings = app.runtime.settings.clone();
settings.register_obj(ret.viewport.clone().upcast());
settings.register_obj(ret.clone().upcast());
settings.register_obj_with_singleton(ret.viewport.upcast_ref(), CanvasSettings::new());
settings.register_obj(ret.clone());
settings
.bind_property(Canvas::WARP_CURSOR, &ret.viewport, Canvas::WARP_CURSOR)
.flags(glib::BindingFlags::SYNC_CREATE)
Expand Down
14 changes: 0 additions & 14 deletions src/editor/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ impl EditorInner {
"Show total area",
"glyph.show.total-area",
);
new_accel_item(
&view_glyph_menu,
app,
"View settings",
"glyph.open.settings",
);
glyph_menu.append_section(None, &view_glyph_menu);
}
menumodel.append_submenu(Some("_Glyph"), &glyph_menu);
Expand All @@ -80,14 +74,6 @@ impl EditorInner {
gtk::gio::PropertyAction::new(action_name, &obj.imp().viewport, property);
action_group.add_action(&prop_action);
}
let settings = gtk::gio::SimpleAction::new("open.settings", None);
settings.connect_activate(
glib::clone!(@weak self.viewport as viewport, @weak app => move |_, _| {
let w = viewport.new_property_window(&app, false);
w.present();
}),
);
action_group.add_action(&settings);
}
{
let curve_menu = gio::Menu::new();
Expand Down
2 changes: 2 additions & 0 deletions src/glyphs/obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ impl From<GlyphMetadata> for Glyph {
}
}

impl_friendly_name!(GlyphMetadata, "Glyph Metadata");

impl CreatePropertyWindow for GlyphMetadata {
fn new_property_window(&self, app: &Application, create: bool) -> PropertyWindow {
if create {
Expand Down
44 changes: 34 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,17 @@ pub mod prelude {
pub use utils::{Either, FieldRef, UI_EDITABLE, UI_PATH, UI_READABLE};
// utility traits:
pub use utils::{Modified, StyleReadOnly};
pub use views::{canvas, Canvas, Collection, Overlay, Transformation, UnitPoint, ViewPoint};
pub use views::{
canvas, canvas::CanvasSettings, Canvas, Collection, Overlay, Transformation, UnitPoint,
ViewPoint,
};
pub use window::Workspace;

pub use glib::prelude::*;
pub use glib::subclass::Signal;
pub use glib::{
ParamFlags, ParamSpec, ParamSpecBoolean, ParamSpecDouble, ParamSpecString, Value,
ParamFlags, ParamSpec, ParamSpecBoolean, ParamSpecBoxed, ParamSpecDouble, ParamSpecObject,
ParamSpecString, Value,
};
pub use gtk::prelude::ToValue;
pub use gtk::subclass::prelude::*;
Expand Down Expand Up @@ -197,18 +201,38 @@ pub mod prelude {
};
}

#[macro_export]
macro_rules! impl_friendly_name {
($ty:ty) => {
impl $crate::utils::property_window::FriendlyNameInSettings for $ty {}
};
($ty:ty, $friendly_name:expr) => {
impl $crate::utils::property_window::FriendlyNameInSettings for $ty {
fn friendly_name(&self) -> Cow<'static, str> {
$friendly_name.into()
}

fn static_friendly_name() -> Cow<'static, str> {
$friendly_name.into()
}
}
};
}

#[macro_export]
macro_rules! impl_property_window {
($ty:ty) => {
impl $crate::utils::property_window::FriendlyNameInSettings for $ty {}
impl $crate::utils::property_window::CreatePropertyWindow for $ty {}
};
($ty:ty$(,)? $({ $friendly_name:expr })?) => {
impl $crate::utils::property_window::CreatePropertyWindow for $ty {
$(
fn friendly_name(&self) -> Cow<'static, str> {
$friendly_name
}
)*
}
$(
$crate::impl_friendly_name!($ty, $friendly_name);
)*
impl $crate::utils::property_window::CreatePropertyWindow for $ty {}
};
(delegate $ty:ty => { $($access:tt)+ }, $($field:tt)+) => {
impl $crate::utils::property_window::FriendlyNameInSettings for $ty {}
impl $crate::utils::property_window::CreatePropertyWindow for $ty {
fn new_property_window(
&self,
Expand Down Expand Up @@ -282,7 +306,7 @@ pub mod prelude {
/// The convention is that property names are stored as type constant string slices.
#[macro_export]
macro_rules! inherit_property {
($t:ty, $($prop:ident),*) => {
($t:ty, $($prop:ident),+$(,)?) => {
$(
pub const $prop: &str = <$t>::$prop;
)*
Expand Down
2 changes: 1 addition & 1 deletion src/ufo/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ glib::wrapper! {
}

impl_deref!(FontInfo, FontInfoInner);
impl_property_window!(FontInfo, { "Font Metadata".into() });
impl_property_window!(FontInfo, { "Font Metadata" });

impl FontInfo {
pub const MODIFIED: &str = "modified";
Expand Down
8 changes: 7 additions & 1 deletion src/utils/property_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ impl PropertyChoice {

impl_deref!(PropertyChoice, PropertyChoiceInner);

pub trait CreatePropertyWindow: glib::object::ObjectExt {
pub trait CreatePropertyWindow: glib::object::ObjectExt + FriendlyNameInSettings {
fn new_property_window(&self, app: &Application, _create: bool) -> PropertyWindow
where
Self: glib::IsA<glib::Object>,
Expand All @@ -1144,8 +1144,14 @@ pub trait CreatePropertyWindow: glib::object::ObjectExt {
.type_(PropertyWindowType::Modify)
.build()
}
}

pub trait FriendlyNameInSettings: glib::object::ObjectExt + glib::IsA<glib::Object> {
fn friendly_name(&self) -> Cow<'static, str> {
self.type_().name().into()
}

fn static_friendly_name() -> Cow<'static, str> {
Self::static_type().name().into()
}
}
Loading

0 comments on commit 945cb80

Please sign in to comment.