gtk/
dialog.rs

1// Copyright 2016, The Gtk-rs Project Developers.
2// See the COPYRIGHT file at the top-level directory of this distribution.
3// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>
4
5use auto::DialogExt;
6use glib::object::Cast;
7use glib::translate::*;
8use gtk_sys;
9use std::ptr;
10use Dialog;
11use DialogFlags;
12use IsA;
13use ResponseType;
14use Widget;
15use Window;
16
17impl Dialog {
18    pub fn new_with_buttons<T: IsA<Window>>(
19        title: Option<&str>,
20        parent: Option<&T>,
21        flags: DialogFlags,
22        buttons: &[(&str, ResponseType)],
23    ) -> Dialog {
24        assert_initialized_main_thread!();
25        let ret: Dialog = unsafe {
26            Widget::from_glib_none(gtk_sys::gtk_dialog_new_with_buttons(
27                title.to_glib_none().0,
28                parent.map(|p| p.as_ref()).to_glib_none().0,
29                flags.to_glib(),
30                ptr::null_mut(),
31            ))
32            .unsafe_cast()
33        };
34
35        ret.add_buttons(buttons);
36        ret
37    }
38}
39
40pub trait DialogExtManual: 'static {
41    fn add_buttons(&self, buttons: &[(&str, ResponseType)]);
42}
43
44impl<O: IsA<Dialog>> DialogExtManual for O {
45    fn add_buttons(&self, buttons: &[(&str, ResponseType)]) {
46        for &(text, id) in buttons {
47            //FIXME: self.add_button don't work on 1.8
48            O::add_button(self, text, id);
49        }
50    }
51}