extern crate gtk;
extern crate mg;
extern crate mg_settings;
#[macro_use]
extern crate mg_settings_macros;
extern crate relm;
#[macro_use]
extern crate relm_derive;
use gtk::traits::{
LabelExt,
OrientableExt,
WidgetExt,
};
use gtk::Orientation::Vertical;
use mg::{
AppClose,
CustomCommand,
DarkTheme,
Mg,
NoSettings,
SetMode,
StatusBarItem,
Title,
Variables, Modes, Mode,
};
use relm::Widget;
use relm_derive::widget;
use AppCommand::*;
use Msg::*;
pub struct Model {
text: String,
}
#[derive(Msg)]
pub enum Msg {
Command(AppCommand),
}
#[derive(Commands)]
pub enum AppCommand {
Insert,
Normal,
Open(String),
Quit,
}
static MODES: Modes = &[
Mode { name: "insert", prefix: "i", show_count: false },
];
#[widget]
impl Widget for Win {
fn init_view(&mut self) {
self.widgets.entry.grab_focus();
}
fn model() -> Model {
Model {
text: "Mg App".to_string(),
}
}
fn update(&mut self, event: Msg) {
match event {
Command(command) => {
match command {
Insert | Normal => (),
Open(url) => self.model.text = format!("Opening URL {}", url),
Quit => gtk::main_quit(),
}
},
}
}
view! {
#[name="mg"]
Mg<AppCommand, NoSettings>(&MODES, Ok("examples/main.conf".into()), None, vec![]) {
DarkTheme: true,
Title: "First Mg Program".to_string(),
Variables: vec![("url", Box::new(|| "http://duckduckgo.com/lite".to_string()))],
gtk::Box {
orientation: Vertical,
gtk::Label {
text: &self.model.text,
},
#[name="entry"]
gtk::Entry {
},
},
StatusBarItem {
text: "Rightmost",
},
StatusBarItem {
text: "Test",
},
AppClose => Command(Quit),
CustomCommand(Insert) => mg@SetMode("insert"),
CustomCommand(Normal) => mg@SetMode("normal"),
CustomCommand(ref command) => Command(command.clone()),
}
}
}
fn main() {
Win::run(()).unwrap();
}