]> OzVa Git service - gn-editor/commitdiff
FileChooserDialog added to glade
authorNil Gradisnik <nil@layer.com>
Sun, 3 Dec 2017 07:19:41 +0000 (23:19 -0800)
committerNil Gradisnik <nil@layer.com>
Sun, 3 Dec 2017 07:19:41 +0000 (23:19 -0800)
src/gtk-ui.glade
src/main.rs

index a5d0585f987b317aacdbb8f9283e0939b5a4d1f0..aea537bdc672e38ceabdf3607ae81caf4c869d8d 100644 (file)
@@ -33,47 +33,13 @@ Author: Nil Gradisnik
   <!-- 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 &lt;nil.gradisnik@gmail.com&gt;</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>
@@ -240,4 +206,86 @@ Author: Nil Gradisnik
       <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 &lt;nil.gradisnik@gmail.com&gt;</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>
index 84150d6fbb6646c4a10556a990edd31e18429ae7..da9a694127845cab060d181922c3172c7c11298b 100644 (file)
@@ -44,7 +44,7 @@ macro_rules! clone {
 fn build_ui(application: &gtk::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);
@@ -57,18 +57,21 @@ fn build_ui(application: &gtk::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");
@@ -81,7 +84,7 @@ fn build_ui(application: &gtk::Application) {
             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 |_, _| {