Make save dialog work

This commit is contained in:
daa 2017-04-01 21:25:33 +03:00
parent 0cd782991c
commit b5b3d115e3

View File

@ -1,8 +1,8 @@
use ui::{SH, Ui}; use ui::{SH, Ui};
use neovim_lib::{NeovimApi, CallError, Value}; use neovim_lib::{NeovimApi, CallError, Value};
use gtk; use gtk;
use gtk::prelude::DialogExtManual; use gtk::prelude::*;
use gtk::{DialogExt, MessageDialog, MessageType, ButtonsType}; use gtk::{MessageDialog, MessageType, ButtonsType};
pub fn can_close_window(ui: &Ui) -> bool { pub fn can_close_window(ui: &Ui) -> bool {
match get_changed_buffers() { match get_changed_buffers() {
@ -33,18 +33,33 @@ fn show_not_saved_dlg(ui: &Ui, changed_bufs: &Vec<String>) -> bool {
ButtonsType::None, ButtonsType::None,
&format!("Save changes to '{}'?", changed_files)); &format!("Save changes to '{}'?", changed_files));
const ACCEPT_ID: i32 = 1; const SAVE_ID: i32 = 0;
const CLOSE_ID: i32 = 2; const CLOSE_WITHOUT_SAVE: i32 = 1;
const REJECT_ID: i32 = 3; const CANCEL_ID: i32 = 2;
dlg.add_buttons(&[("_Yes", ACCEPT_ID), ("_No", CLOSE_ID), ("_Cancel", REJECT_ID)]); dlg.add_buttons(&[("_Yes", SAVE_ID), ("_No", CLOSE_WITHOUT_SAVE), ("_Cancel", CANCEL_ID)]);
match dlg.run() { let res = match dlg.run() {
ACCEPT_ID => true, SAVE_ID => {
CLOSE_ID => true, SHELL!(shell = {
REJECT_ID => false, let mut nvim = shell.nvim();
match nvim.command("wa") {
Err(ref err) => {
println!("Error: {}", err);
false
}
_ => true
}
})
},
CLOSE_WITHOUT_SAVE => true,
CANCEL_ID => false,
_ => false, _ => false,
} };
dlg.destroy();
res
} }
fn get_changed_buffers() -> Result<Vec<String>, CallError> { fn get_changed_buffers() -> Result<Vec<String>, CallError> {