|
|
@ -9,7 +9,7 @@ use sqlite::Transaction; |
|
|
|
use title::Title; |
|
|
|
use title::Title; |
|
|
|
use widget::Widget; |
|
|
|
use widget::Widget; |
|
|
|
|
|
|
|
|
|
|
|
use gtk::{glib::GString, Box}; |
|
|
|
use gtk::{glib::GString, prelude::WidgetExt, Box, GestureClick}; |
|
|
|
use std::sync::Arc; |
|
|
|
use std::sync::Arc; |
|
|
|
|
|
|
|
|
|
|
|
pub struct Label { |
|
|
|
pub struct Label { |
|
|
@ -23,13 +23,55 @@ pub struct Label { |
|
|
|
impl Label { |
|
|
|
impl Label { |
|
|
|
// Construct
|
|
|
|
// Construct
|
|
|
|
pub fn new(name: GString, is_pinned: bool) -> Label { |
|
|
|
pub fn new(name: GString, is_pinned: bool) -> Label { |
|
|
|
// Components
|
|
|
|
// Init components
|
|
|
|
let pin = Arc::new(Pin::new(is_pinned)); |
|
|
|
let pin = Arc::new(Pin::new(is_pinned)); |
|
|
|
let title = Arc::new(Title::new()); |
|
|
|
let title = Arc::new(Title::new()); |
|
|
|
|
|
|
|
|
|
|
|
// GTK
|
|
|
|
// Init GTK
|
|
|
|
let widget = Arc::new(Widget::new(name, pin.gobject(), title.gobject())); |
|
|
|
let widget = Arc::new(Widget::new(name, pin.gobject(), title.gobject())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Init events:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Await for widget realize to continue this feature
|
|
|
|
|
|
|
|
widget.gobject().connect_realize({ |
|
|
|
|
|
|
|
let pin = pin.clone(); |
|
|
|
|
|
|
|
let title = title.clone(); |
|
|
|
|
|
|
|
let widget = widget.clone(); |
|
|
|
|
|
|
|
move |_| { |
|
|
|
|
|
|
|
// Init GestureClick listener
|
|
|
|
|
|
|
|
let controller = GestureClick::new(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Listen for double click
|
|
|
|
|
|
|
|
controller.connect_pressed({ |
|
|
|
|
|
|
|
let pin = pin.clone(); |
|
|
|
|
|
|
|
let title = title.clone(); |
|
|
|
|
|
|
|
move |_, count, _, _| { |
|
|
|
|
|
|
|
if count == 2 { |
|
|
|
|
|
|
|
// Toggle pin @TODO use action?
|
|
|
|
|
|
|
|
let is_pinned = !pin.is_pinned(); |
|
|
|
|
|
|
|
pin.pin(is_pinned); |
|
|
|
|
|
|
|
title.pin(is_pinned); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Label's parent contain native GTK paddings, that makes click event ignored
|
|
|
|
|
|
|
|
// try assign the controller to parent as the solution
|
|
|
|
|
|
|
|
match widget.gobject().parent() { |
|
|
|
|
|
|
|
// @TODO check for GtkGizmo type?
|
|
|
|
|
|
|
|
Some(parent) => { |
|
|
|
|
|
|
|
parent.add_controller(controller); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Assign controller to the current widget, drop notice
|
|
|
|
|
|
|
|
None => { |
|
|
|
|
|
|
|
widget.gobject().add_controller(controller); |
|
|
|
|
|
|
|
println!("Could not assign action to destination, please report"); |
|
|
|
|
|
|
|
// @TODO
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Result
|
|
|
|
// Result
|
|
|
|
Self { pin, title, widget } |
|
|
|
Self { pin, title, widget } |
|
|
|
} |
|
|
|
} |
|
|
|