Update UI. Fix quotes input.

This commit is contained in:
daa84 2017-03-07 17:12:22 +03:00
parent 841a588a8b
commit bde70d7797
2 changed files with 26 additions and 18 deletions

View File

@ -10,7 +10,9 @@ pub fn keyval_to_input_string(val: &str, state: gdk::ModifierType) -> String {
let mut input = String::new(); let mut input = String::new();
if state.contains(gdk::SHIFT_MASK) { if state.contains(gdk::SHIFT_MASK) {
input.push_str("S-"); if val != "\"" {
input.push_str("S-");
}
} }
if state.contains(gdk::CONTROL_MASK) { if state.contains(gdk::CONTROL_MASK) {
input.push_str("C-"); input.push_str("C-");

View File

@ -9,7 +9,7 @@ use pango;
use pango::FontDescription; use pango::FontDescription;
use gtk; use gtk;
use gtk::prelude::*; use gtk::prelude::*;
use gtk::{ApplicationWindow, DrawingArea, Grid, ToolButton, Image, Toolbar, IconSize}; use gtk::{ApplicationWindow, HeaderBar, DrawingArea, ToolButton, Image};
use gdk::{ModifierType, Event, EventKey, EventConfigure, EventButton, EventMotion, EventType}; use gdk::{ModifierType, Event, EventKey, EventConfigure, EventButton, EventMotion, EventType};
use gdk_sys; use gdk_sys;
use glib; use glib;
@ -46,6 +46,7 @@ pub struct Ui {
nvim: Option<Neovim>, nvim: Option<Neovim>,
drawing_area: DrawingArea, drawing_area: DrawingArea,
window: Option<ApplicationWindow>, window: Option<ApplicationWindow>,
header_bar: HeaderBar,
cur_attrs: Option<Attrs>, cur_attrs: Option<Attrs>,
bg_color: Color, bg_color: Color,
fg_color: Color, fg_color: Color,
@ -64,6 +65,7 @@ impl Ui {
model: UiModel::empty(), model: UiModel::empty(),
drawing_area: DrawingArea::new(), drawing_area: DrawingArea::new(),
window: None, window: None,
header_bar: HeaderBar::new(),
nvim: None, nvim: None,
cur_attrs: None, cur_attrs: None,
bg_color: COLOR_BLACK, bg_color: COLOR_BLACK,
@ -91,30 +93,23 @@ impl Ui {
} }
pub fn init(&mut self, app: &gtk::Application) { pub fn init(&mut self, app: &gtk::Application) {
let grid = Grid::new(); self.header_bar.set_show_close_button(true);
let button_bar = Toolbar::new();
button_bar.set_icon_size(IconSize::SmallToolbar);
button_bar.set_hexpand(true);
let save_image = Image::new_from_icon_name("document-save", 50); let save_image = Image::new_from_icon_name("document-save", 50);
let save_btn = ToolButton::new(Some(&save_image), None); let save_btn = ToolButton::new(Some(&save_image), None);
save_btn.connect_clicked(|_| save_all()); save_btn.connect_clicked(|_| edit_save_all());
button_bar.add(&save_btn); self.header_bar.pack_start(&save_btn);
let exit_image = Image::new_from_icon_name("application-exit", 50); let paste_image = Image::new_from_icon_name("edit-paste", 50);
let exit_btn = ToolButton::new(Some(&exit_image), None); let paste_btn = ToolButton::new(Some(&paste_image), None);
exit_btn.connect_clicked(|_| quit()); paste_btn.connect_clicked(|_| edit_paste());
button_bar.add(&exit_btn); self.header_bar.pack_start(&paste_btn);
grid.attach(&button_bar, 0, 0, 1, 1);
self.drawing_area.set_size_request(500, 300); self.drawing_area.set_size_request(500, 300);
self.drawing_area.set_hexpand(true); self.drawing_area.set_hexpand(true);
self.drawing_area.set_vexpand(true); self.drawing_area.set_vexpand(true);
grid.attach(&self.drawing_area, 0, 1, 1, 1);
self.drawing_area self.drawing_area
.set_events((gdk_sys::GDK_BUTTON_RELEASE_MASK | gdk_sys::GDK_BUTTON_PRESS_MASK | .set_events((gdk_sys::GDK_BUTTON_RELEASE_MASK | gdk_sys::GDK_BUTTON_PRESS_MASK |
gdk_sys::GDK_BUTTON_MOTION_MASK) gdk_sys::GDK_BUTTON_MOTION_MASK)
@ -127,7 +122,8 @@ impl Ui {
self.window = Some(ApplicationWindow::new(app)); self.window = Some(ApplicationWindow::new(app));
let window = self.window.as_ref().unwrap(); let window = self.window.as_ref().unwrap();
window.add(&grid); window.set_titlebar(Some(&self.header_bar));
window.add(&self.drawing_area);
window.show_all(); window.show_all();
window.connect_key_press_event(gtk_key_press); window.connect_key_press_event(gtk_key_press);
window.connect_delete_event(gtk_delete); window.connect_delete_event(gtk_delete);
@ -192,7 +188,17 @@ fn gtk_motion_notify(_: &DrawingArea, ev: &EventMotion) -> Inhibit {
Inhibit(false) Inhibit(false)
} }
fn save_all() { fn edit_paste() {
UI.with(|ui_cell| {
let mut ui = ui_cell.borrow_mut();
if let Err(e) = ui.nvim().input("\"*p") {
println!("Error paste from clipboard {}", e);
}
});
}
fn edit_save_all() {
UI.with(|ui_cell| { UI.with(|ui_cell| {
let mut ui = ui_cell.borrow_mut(); let mut ui = ui_cell.borrow_mut();