2021-10-28 10:15:59 +00:00
|
|
|
/* 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/. */
|
|
|
|
|
2021-10-31 09:58:20 +00:00
|
|
|
use glib::{ParamFlags, ParamSpec, Value};
|
2021-10-29 02:44:36 +00:00
|
|
|
use gtk::prelude::*;
|
|
|
|
use gtk::subclass::prelude::*;
|
|
|
|
use gtk::CompositeTemplate;
|
2021-10-31 09:58:20 +00:00
|
|
|
use once_cell::sync::Lazy;
|
|
|
|
use std::cell::RefCell;
|
2021-10-29 02:44:36 +00:00
|
|
|
|
|
|
|
#[derive(Default, CompositeTemplate)]
|
|
|
|
#[template(file = "./editor.ui")]
|
|
|
|
pub struct EchidnaCoreEditor {
|
|
|
|
#[template_child]
|
|
|
|
pub minimap: TemplateChild<sourceview::Map>,
|
|
|
|
#[template_child]
|
|
|
|
pub sourceview: TemplateChild<sourceview::View>,
|
2021-10-31 09:58:20 +00:00
|
|
|
pub file: RefCell<sourceview::File>,
|
2021-10-29 02:44:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[glib::object_subclass]
|
|
|
|
impl ObjectSubclass for EchidnaCoreEditor {
|
|
|
|
const NAME: &'static str = "EchidnaCoreEditor";
|
|
|
|
type Type = super::EchidnaCoreEditor;
|
|
|
|
type ParentType = gtk::Box;
|
|
|
|
|
|
|
|
fn class_init(class: &mut Self::Class) {
|
|
|
|
Self::bind_template(class);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
|
|
|
|
obj.init_template();
|
|
|
|
}
|
2021-10-28 10:15:59 +00:00
|
|
|
}
|
2021-10-29 02:44:36 +00:00
|
|
|
|
2021-10-31 09:58:20 +00:00
|
|
|
impl ObjectImpl for EchidnaCoreEditor {
|
|
|
|
fn properties() -> &'static [ParamSpec] {
|
|
|
|
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
|
|
|
|
vec![ParamSpec::new_object(
|
|
|
|
"file",
|
|
|
|
"file",
|
|
|
|
"the file of the editor",
|
|
|
|
sourceview::File::static_type(),
|
|
|
|
ParamFlags::READWRITE,
|
|
|
|
)]
|
|
|
|
});
|
|
|
|
|
|
|
|
PROPERTIES.as_ref()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, spec: &ParamSpec) {
|
|
|
|
match spec.name() {
|
|
|
|
"file" => {
|
|
|
|
let file: sourceview::File = value
|
|
|
|
.get()
|
|
|
|
.expect("The file needs to be a sourceview::File");
|
|
|
|
self.file.replace(file);
|
|
|
|
}
|
|
|
|
_ => unimplemented!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn property(&self, _obj: &Self::Type, _id: usize, spec: &ParamSpec) -> Value {
|
|
|
|
match spec.name() {
|
|
|
|
"file" => self.file.borrow().to_value(),
|
|
|
|
_ => unimplemented!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-29 02:44:36 +00:00
|
|
|
impl WidgetImpl for EchidnaCoreEditor {}
|
|
|
|
impl BoxImpl for EchidnaCoreEditor {}
|