~vpzom/savg

7509dee4b34853cc029c75fc52512fe7eaef2a6c — Colin Reeder 5 years ago 6d6bddc
Add delete functionality
1 files changed, 24 insertions(+), 0 deletions(-)

M src/main.rs
M src/main.rs => src/main.rs +24 -0
@@ 179,6 179,30 @@ fn main() {

    {
        let instance = instance.clone();
        window.connect_key_press_event(move |_, ev| {
            let key = ev.get_keyval();
            if key == gdk::enums::key::Delete {
                let mut selection = instance.selection.write().unwrap();
                let selection: &mut Option<_> = &mut selection;

                if let Some(selected) = selection {
                    let mut document = instance.document.write().unwrap();
                    
                    let pos = document.content.iter().position(|elem| elem.id() == *selected);

                    if let Some(pos) = pos {
                        document.content.remove(pos);
                        instance.queue_repaint();
                    }
                }
            }

            Inhibit(true)
        });
    }

    {
        let instance = instance.clone();
        let window = window.clone();
        save_item.connect_activate(move |_| {
            let dialog = gtk::FileChooserDialog::with_buttons(Some("Save File"), Some(&window), gtk::FileChooserAction::Save, &[(&gtk::STOCK_CANCEL, gtk::ResponseType::Cancel), (&gtk::STOCK_SAVE, gtk::ResponseType::Accept)]);