]> OzVa Git service - gn-editor/commitdiff
Cleanup
authorNil Gradisnik <nil@layer.com>
Sun, 7 Jan 2018 18:32:08 +0000 (10:32 -0800)
committerNil Gradisnik <nil@layer.com>
Sun, 7 Jan 2018 18:32:08 +0000 (10:32 -0800)
src/gtk-ui.glade
src/main.rs
src/utils.rs

index c4c0fc53ebb432984348fc9bd9bafb01c2d8e16b..9bc7938e6f237cbde7d3b74010f878fc71685eb6 100644 (file)
@@ -132,6 +132,7 @@ Author: Nil Gradisnik
             <property name="label" translatable="yes">Open</property>
             <property name="use_underline">True</property>
             <property name="icon_name">document-open</property>
+            <accelerator key="o" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
           </object>
         </child>
       </object>
index 2ae908d580662fca69ff41f83f9af5691e4dad57..9a3619eda123625413cf545a394772681ac225e9 100644 (file)
@@ -9,6 +9,7 @@ extern crate sourceview;
 extern crate webkit2gtk;
 
 mod preview;
+#[macro_use]
 mod utils;
 
 use gio::prelude::*;
@@ -30,44 +31,23 @@ const VERSION: &str = env!("CARGO_PKG_VERSION");
 const AUTHORS: &str = env!("CARGO_PKG_AUTHORS");
 const DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
 
-// http://gtk-rs.org/tuto/closures
-macro_rules! clone {
-    (@param _) => ( _ );
-    (@param $x:ident) => ( $x );
-    ($($n:ident),+ => move || $body:expr) => (
-        {
-            $( let $n = $n.clone(); )+
-            move || $body
-        }
-    );
-    ($($n:ident),+ => move |$($p:tt),+| $body:expr) => (
-        {
-            $( let $n = $n.clone(); )+
-            move |$(clone!(@param $p),)+| $body
-        }
-    );
-}
-
-fn build_system_menu(application: &gtk::Application) {
+fn build_system_menu(
+    application: &gtk::Application,
+    window: &gtk::ApplicationWindow,
+    about_dialog: &gtk::AboutDialog,
+) {
     let menu = gio::Menu::new();
 
     menu.append("About", "app.about");
     menu.append("Quit", "app.quit");
 
     application.set_app_menu(&menu);
-}
 
-fn add_actions(
-    application: &gtk::Application,
-    window: &gtk::ApplicationWindow,
-    about_dialog: &gtk::AboutDialog,
-) {
     let quit = gio::SimpleAction::new("quit", None);
+    let about = gio::SimpleAction::new("about", None);
     quit.connect_activate(clone!(window => move |_, _| {
         window.destroy();
     }));
-
-    let about = gio::SimpleAction::new("about", None);
     about.connect_activate(clone!(about_dialog => move |_, _| {
         about_dialog.show();
     }));
@@ -134,26 +114,26 @@ fn build_ui(application: &gtk::Application) {
 
         if file_chooser.run() == gtk::ResponseType::Ok.into() {
             let filename = file_chooser.get_filename().expect("Couldn't get filename");
-            let contents = open_file(&filename);
             set_title(&header_bar, &filename);
+
+            let contents = open_file(&filename);
             text_buffer.set_text(&contents);
         }
 
         file_chooser.hide();
     }));
 
-    about_dialog.connect_delete_event(clone!(about_dialog => move |_, _| {
-        about_dialog.hide();
+    about_dialog.connect_delete_event(move |dialog, _| {
+        dialog.hide();
         Inhibit(true)
-    }));
+    });
 
-    window.connect_delete_event(clone!(window => move |_, _| {
-        window.destroy();
+    window.connect_delete_event(move |win, _| {
+        win.destroy();
         Inhibit(false)
-    }));
+    });
 
-    build_system_menu(application);
-    add_actions(application, &window, &about_dialog);
+    build_system_menu(application, &window, &about_dialog);
 
     window.show_all();
 }
index 4c75ada4eb37d229c264305c8c71f80d09a43076..57c98485e88ba0ca559e6657cc43988eae1b345f 100644 (file)
@@ -43,3 +43,21 @@ pub fn configure_sourceview(buff: &Buffer) {
         .get_scheme("classic")
         .map(|theme| buff.set_style_scheme(&theme));
 }
+
+// http://gtk-rs.org/tuto/closures
+macro_rules! clone {
+    (@param _) => ( _ );
+    (@param $x:ident) => ( $x );
+    ($($n:ident),+ => move || $body:expr) => (
+        {
+            $( let $n = $n.clone(); )+
+            move || $body
+        }
+    );
+    ($($n:ident),+ => move |$($p:tt),+| $body:expr) => (
+        {
+            $( let $n = $n.clone(); )+
+            move |$(clone!(@param $p),)+| $body
+        }
+    );
+}