<property name="window_position">center</property>
<property name="default_width">800</property>
<property name="default_height">480</property>
+ <property name="icon_name">text-x-generic</property>
<property name="has_resize_grip">True</property>
+ <property name="show_menubar">False</property>
<child>
<object class="GtkBox" id="v_box">
<property name="visible">True</property>
<property name="icon_name">document-open</property>
</object>
</child>
- <child>
- <object class="GtkToolButton" id="about_button">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="tooltip_text" translatable="yes">About</property>
- <property name="use_underline">True</property>
- <property name="stock_id">gtk-about</property>
- </object>
- <packing>
- <property name="pack_type">end</property>
- <property name="position">3</property>
- </packing>
- </child>
</object>
</child>
</object>
// http://gtk-rs.org
+extern crate comrak;
extern crate gio;
extern crate gtk;
-extern crate sourceview;
-extern crate comrak;
#[macro_use]
extern crate horrorshow;
+extern crate sourceview;
mod preview;
mod utils;
-use std::env::args;
-
use gio::prelude::*;
use gtk::prelude::*;
use gtk::Builder;
+use gio::MenuExt;
-use utils::{buffer_to_string, open_file, set_title, configure_sourceview};
+use std::env::args;
+
+use utils::{buffer_to_string, configure_sourceview, open_file, set_title};
const NAME: &str = env!("CARGO_PKG_NAME");
const VERSION: &str = env!("CARGO_PKG_VERSION");
);
}
+fn build_system_menu(application: >k::Application) {
+ let menu = gio::Menu::new();
+
+ menu.append("About", "app.about");
+ menu.append("Quit", "app.quit");
+
+ application.set_app_menu(&menu);
+}
+
+fn add_actions(application: >k::Application, window: >k::ApplicationWindow, about_dialog: >k::AboutDialog) {
+ let quit = gio::SimpleAction::new("quit", 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();
+ }));
+
+ application.add_action(&about);
+ application.add_action(&quit);
+}
+
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("Builder 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);
header_bar.set_title(NAME);
let open_button: gtk::ToolButton = builder.get_object("open_button").unwrap();
- let about_button: gtk::ToolButton = builder.get_object("about_button").unwrap();
let text_view: sourceview::View = builder.get_object("text_view").unwrap();
let text_buffer: sourceview::Buffer = builder.get_object("text_buffer").unwrap();
Inhibit(true)
}));
- about_button.connect_clicked(clone!(about_dialog => move |_| {
- about_dialog.show();
- }));
-
about_dialog.connect_delete_event(clone!(about_dialog => move |_, _| {
about_dialog.hide();
Inhibit(true)
Inhibit(false)
}));
+ build_system_menu(application);
+ add_actions(application, &window, &about_dialog);
+
window.show_all();
}
fn main() {
- let application = gtk::Application::new("com.github.markdown-rs", gio::ApplicationFlags::empty())
- .expect("Initialization failed...");
+ let application =
+ gtk::Application::new("com.github.markdown-rs", gio::ApplicationFlags::empty())
+ .expect("Initialization failed...");
application.connect_startup(move |app| {
build_ui(app);