cleaner refactoring
This commit is contained in:
@@ -11,8 +11,9 @@
|
||||
<object class="GtkFrame">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_left">3</property>
|
||||
<property name="margin_right">3</property>
|
||||
<property name="margin_left">2</property>
|
||||
<property name="margin_right">2</property>
|
||||
<property name="margin_top">2</property>
|
||||
<property name="margin_bottom">2</property>
|
||||
<property name="label_xalign">0.94999998807907104</property>
|
||||
<property name="label_yalign">0.20000000298023224</property>
|
||||
@@ -44,14 +45,19 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="desc_btn">
|
||||
<property name="label" translatable="yes">Desc. </property>
|
||||
<object class="GtkMenuButton" id="desc_btn">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="valign">end</property>
|
||||
<property name="margin_right">5</property>
|
||||
<property name="margin_bottom">5</property>
|
||||
<property name="relief">none</property>
|
||||
<property name="direction">none</property>
|
||||
<property name="popover">desc_sheet</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
@@ -77,4 +83,11 @@
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkPopover" id="desc_sheet">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="relative_to">desc_btn</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
|
||||
52
src/grid.rs
52
src/grid.rs
@@ -24,7 +24,7 @@ impl Grid {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug,Clone)]
|
||||
struct CellWidget {
|
||||
eventbox: gtk::EventBox,
|
||||
position: gtk::Label,
|
||||
@@ -69,9 +69,16 @@ impl CellWidget {
|
||||
&targets,
|
||||
gdk::DragAction::MOVE,
|
||||
);
|
||||
let h = header.clone();
|
||||
let cell = CellWidget {
|
||||
eventbox,
|
||||
position,
|
||||
header,
|
||||
desc_btn
|
||||
};
|
||||
|
||||
let h = cell.header.clone();
|
||||
// Send data to the drop site
|
||||
eventbox.connect_drag_data_get(
|
||||
cell.eventbox.connect_drag_data_get(
|
||||
move |_,_,data,info,time| {
|
||||
println!("Send...");
|
||||
if let Some(to_send) = h.get_text() {
|
||||
@@ -79,72 +86,63 @@ impl CellWidget {
|
||||
}
|
||||
}
|
||||
);
|
||||
let h = header.clone();
|
||||
let b = desc_btn.clone();
|
||||
let c = cell.clone();
|
||||
// Empty the cell on successfull move
|
||||
eventbox.connect_drag_data_delete(
|
||||
cell.eventbox.connect_drag_data_delete(
|
||||
move |w,drag| {
|
||||
println!("Cleaning... {:#?}", (&drag.drag_drop_succeeded()));
|
||||
Self::set_content((&h,&b), None);
|
||||
Self::set_content(&c, None);
|
||||
}
|
||||
);
|
||||
|
||||
eventbox.drag_dest_set(
|
||||
cell.eventbox.drag_dest_set(
|
||||
gtk::DestDefaults::ALL,
|
||||
&targets,
|
||||
gdk::DragAction::MOVE,
|
||||
);
|
||||
// Retrieve data from the source
|
||||
let h = header.clone();
|
||||
let b = desc_btn.clone();
|
||||
eventbox.connect_drag_data_received(
|
||||
let c = cell.clone();
|
||||
cell.eventbox.connect_drag_data_received(
|
||||
move |w,_,_,_,data,_,_| {
|
||||
// Check if cell is not already occupied
|
||||
if !(h.get_text().unwrap().as_str() == "") {
|
||||
if !(c.header.get_text().unwrap().as_str() == "") {
|
||||
// TODO: Find what to do to abort, since
|
||||
// DragContext methods don't seem to work...
|
||||
println!("Overriding !!");
|
||||
} else {
|
||||
println!("Dropped !");
|
||||
if let Some(text) = data.get_text() {
|
||||
Self::set_content((&h,&b), Some(text.as_str()));
|
||||
Self::set_content(&c, Some(text.as_str()));
|
||||
} else {
|
||||
eprintln!("No data !");
|
||||
}
|
||||
};
|
||||
}
|
||||
);
|
||||
let cell = CellWidget {
|
||||
eventbox,
|
||||
position,
|
||||
header,
|
||||
desc_btn
|
||||
};
|
||||
cell
|
||||
}
|
||||
|
||||
/// Updates content of the Cell
|
||||
fn set_content(widgets: (>k::Label, >k::Button), data: Option<&str>) {
|
||||
fn set_content(&self, data: Option<&str>) {
|
||||
println!("Set content to {:?}", &data);
|
||||
// TODO: there is surely something cleaner...
|
||||
if let Some(name) = data {
|
||||
widgets.0.set_text(name);
|
||||
widgets.1.set_visible(true);
|
||||
self.header.set_text(name);
|
||||
self.desc_btn.set_visible(true);
|
||||
} else {
|
||||
widgets.0.set_text("");
|
||||
widgets.1.set_visible(false);
|
||||
self.header.set_text("");
|
||||
self.desc_btn.set_visible(false);
|
||||
};
|
||||
}
|
||||
|
||||
pub fn connect_clicked(&self, state: AppState) {
|
||||
let header = self.header.clone();
|
||||
let btn = self.desc_btn.clone();
|
||||
let c = self.clone();
|
||||
self.eventbox
|
||||
.connect_button_press_event(move |_,_| {
|
||||
let mut state = state.borrow_mut();
|
||||
if let Some(ref data) = state.pending.take() {
|
||||
println!("{:?}", data);
|
||||
Self::set_content((&header,&btn), Some(&data.name));
|
||||
Self::set_content(&c, Some(&data.name));
|
||||
};
|
||||
gtk::Inhibit(true)
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user