diff --git a/src/lib.rs b/src/lib.rs index a2f55e7..853c4a7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,8 +75,8 @@ pub fn build_ui(app: >k::Application, config: Arc::>) { let about_window = builder.get_object::("about_window").expect("Resource file missing!"); about_window.set_transient_for(Some(&win)); - about_window.connect_delete_event(|a,_| { - a.hide(); + about_window.connect_delete_event(|win,_| { + win.hide(); Inhibit(true) }); @@ -87,12 +87,48 @@ pub fn build_ui(app: >k::Application, config: Arc::>) { }); // save_log - // let save_log = builder.get_object::("save_log").expect("Resource file missing!"); + let save_menu = builder.get_object::("save_menu").expect("Resource file missing!"); - // let tmp_log_area = log_area.clone(); - // save_log.connect_activate(move |_|{ - - // }); + let save_window = builder.get_object::("save_window").expect("Resource file missing!"); + save_window.set_transient_for(Some(&win)); + save_window.set_action(gtk::FileChooserAction::Save); + + save_window.connect_delete_event(|win,_| { + win.hide(); + Inhibit(true) + }); + + save_window.add_button("_Save", gtk::ResponseType::Apply); + save_window.add_button("_Cancel", gtk::ResponseType::Cancel); + + let tmp_log_area = log_area.clone(); + let tmp_bar = bar.clone(); + save_window.connect_response(move |win, res| { + match res { + gtk::ResponseType::Cancel => win.hide(), + gtk::ResponseType::Apply => { + if let Some(path) = win.get_filename() { + if let Some(buf) = tmp_log_area.get_buffer() { + let text = buf.get_text(&buf.get_start_iter(), &buf.get_end_iter(), false).unwrap().to_string(); + + match std::fs::write(path, text) { + Ok(_) => { + win.hide(); + }, + Err(_) => { + tmp_bar.push(1, "Failed to save!"); + } + } + } + } + }, + _ => () + } + }); + + save_menu.connect_activate(move |_|{ + save_window.show(); + }); // pankti let pankti = builder.get_object::("pankti").expect("Resource file missing!"); diff --git a/test.txt b/test.txt new file mode 100644 index 0000000..1fe5476 --- /dev/null +++ b/test.txt @@ -0,0 +1 @@ +Bhai ka area hai \ No newline at end of file diff --git a/ui/main_window.glade b/ui/main_window.glade index eb63bd1..9655ab8 100644 --- a/ui/main_window.glade +++ b/ui/main_window.glade @@ -36,9 +36,6 @@ - - - True @@ -52,6 +49,38 @@ 0.5 10 + + False + dialog + select-folder + + + False + vertical + 2 + + + False + end + + + + + + + + + False + False + 0 + + + + + + + + True False diff --git a/ui/main_window.glade~ b/ui/main_window.glade~ index 8bd12a6..9655ab8 100644 --- a/ui/main_window.glade~ +++ b/ui/main_window.glade~ @@ -2,7 +2,7 @@ - + False dialog Tarangam (तरंगम्) @@ -36,9 +36,6 @@ - - - True @@ -52,6 +49,38 @@ 0.5 10 + + False + dialog + select-folder + + + False + vertical + 2 + + + False + end + + + + + + + + + False + False + 0 + + + + + + + + True False