<!-- interface-name markdown-rs -->
<!-- interface-description Simple Markdown editor -->
<!-- interface-authors Nil Gradisnik -->
- <object class="GtkAboutDialog" id="about_dialog">
- <property name="can_focus">False</property>
- <property name="type_hint">dialog</property>
- <property name="program_name">Markdown Rust</property>
- <property name="version">0.1.0</property>
- <property name="comments" translatable="yes">Fast, simple, distraction free Markdown editor.</property>
- <property name="website">https://github.com/nilgradisnik/markdown-rs</property>
- <property name="website_label" translatable="yes">markdown-rs</property>
- <property name="authors">Nil Gradisnik <nil.gradisnik@gmail.com></property>
- <property name="logo_icon_name">text-x-generic</property>
- <property name="license_type">mit-x11</property>
- <child internal-child="vbox">
- <object class="GtkBox">
- <property name="can_focus">False</property>
- <property name="orientation">vertical</property>
- <property name="spacing">2</property>
- <child internal-child="action_area">
- <object class="GtkButtonBox">
- <property name="can_focus">False</property>
- <property name="layout_style">end</property>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <placeholder/>
- </child>
- </object>
- </child>
- <child>
- <placeholder/>
- </child>
+ <object class="GtkFileFilter" id="md_filter">
+ <mime-types>
+ <mime-type>text/markdown</mime-type>
+ </mime-types>
+ <patterns>
+ <pattern>*.md</pattern>
+ </patterns>
</object>
<object class="GtkApplicationWindow" id="window">
<property name="can_focus">False</property>
<placeholder/>
</child>
</object>
+ <object class="GtkAboutDialog" id="about_dialog">
+ <property name="can_focus">False</property>
+ <property name="type_hint">dialog</property>
+ <property name="transient_for">window</property>
+ <property name="attached_to">window</property>
+ <property name="program_name">Markdown Rust</property>
+ <property name="version">0.1.0</property>
+ <property name="comments" translatable="yes">Fast, simple, distraction free Markdown editor.</property>
+ <property name="website">https://github.com/nilgradisnik/markdown-rs</property>
+ <property name="website_label" translatable="yes">markdown-rs</property>
+ <property name="authors">Nil Gradisnik <nil.gradisnik@gmail.com></property>
+ <property name="logo_icon_name">text-x-generic</property>
+ <property name="license_type">mit-x11</property>
+ <child internal-child="vbox">
+ <object class="GtkBox">
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox">
+ <property name="can_focus">False</property>
+ <property name="layout_style">end</property>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <object class="GtkFileChooserDialog" id="file_chooser">
+ <property name="can_focus">False</property>
+ <property name="window_position">center-on-parent</property>
+ <property name="type_hint">dialog</property>
+ <property name="transient_for">window</property>
+ <property name="attached_to">window</property>
+ <property name="filter">md_filter</property>
+ <child internal-child="vbox">
+ <object class="GtkBox">
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox">
+ <property name="can_focus">False</property>
+ <property name="layout_style">end</property>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
</interface>
fn build_ui(application: >k::Application) {
let glade_src = include_str!("gtk-ui.glade");
let builder = Builder::new();
- builder.add_from_string(glade_src).expect("Couldn't add from string");
+ builder.add_from_string(glade_src).expect("Builder couldn't add from string");
let window: gtk::ApplicationWindow = builder.get_object("window").expect("Couldn't get window");
window.set_application(application);
let text_view: sourceview::View = builder.get_object("text_view").unwrap();
let markdown_view: gtk::TextView = builder.get_object("markdown_view").unwrap();
+ let file_chooser: gtk::FileChooserDialog = builder.get_object("file_chooser").unwrap();
+ file_chooser.add_buttons(&[
+ ("Open", gtk::ResponseType::Ok.into()),
+ ("Cancel", gtk::ResponseType::Cancel.into()),
+ ]);
+
let about_dialog: gtk::AboutDialog = builder.get_object("about_dialog").unwrap();
about_dialog.set_program_name(NAME);
about_dialog.set_version(VERSION);
about_dialog.set_authors(&[AUTHORS]);
about_dialog.set_comments(DESCRIPTION);
- open_button.connect_clicked(clone!(window, text_view, markdown_view => move |_| {
- let file_chooser = gtk::FileChooserDialog::new(Some("Open File"), Some(&window), gtk::FileChooserAction::Open);
- file_chooser.add_buttons(&[
- ("Open", gtk::ResponseType::Ok.into()),
- ("Cancel", gtk::ResponseType::Cancel.into()),
- ]);
+ open_button.connect_clicked(clone!(text_view, markdown_view => move |_| {
+ file_chooser.show();
+
if file_chooser.run() == gtk::ResponseType::Ok.into() {
let filename = file_chooser.get_filename().expect("Couldn't get filename");
let file = File::open(&filename).expect("Couldn't open file");
markdown_view.get_buffer().unwrap().set_text(&string_to_html(&contents));
}
- file_chooser.destroy();
+ file_chooser.hide();
}));
text_view.connect_key_release_event(clone!(text_view, markdown_view, live_button => move |_, _| {