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