2017-11-19 09:44:28 +00:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
2017-11-18 12:56:37 +00:00
|
|
|
use gtk;
|
|
|
|
use gtk::prelude::*;
|
|
|
|
|
2017-11-19 09:44:28 +00:00
|
|
|
use neovim_lib::Value;
|
|
|
|
|
|
|
|
use ui_model::{UiModel, Attrs};
|
|
|
|
|
|
|
|
pub struct Level {
|
|
|
|
model: UiModel,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Level {
|
|
|
|
const COLUMNS_STEP: u64 = 50;
|
2017-11-19 20:13:06 +00:00
|
|
|
const ROWS_STEP: u64 = 10;
|
2017-11-19 09:44:28 +00:00
|
|
|
|
|
|
|
pub fn from(
|
|
|
|
content: Vec<(HashMap<String, Value>, String)>,
|
|
|
|
pos: u64,
|
|
|
|
firstc: String,
|
|
|
|
prompt: String,
|
|
|
|
indent: u64,
|
|
|
|
level: u64,
|
|
|
|
) -> Self {
|
|
|
|
//TODO: double width chars
|
|
|
|
|
2017-11-19 20:13:06 +00:00
|
|
|
let prompt = prompt_lines(firstc, prompt, indent);
|
2017-11-19 09:44:28 +00:00
|
|
|
let content: Vec<(Attrs, Vec<char>)> = content
|
|
|
|
.iter()
|
|
|
|
.map(|c| (Attrs::from_value_map(&c.0), c.1.chars().collect()))
|
|
|
|
.collect();
|
|
|
|
|
2017-11-19 20:13:06 +00:00
|
|
|
let width = (content.iter().map(|c| c.1.len()).count() + prompt.last().map_or(0, |p| p.len())) as u64;
|
2017-11-19 09:44:28 +00:00
|
|
|
let columns = ((width / Level::COLUMNS_STEP) + 1) * Level::COLUMNS_STEP;
|
2017-11-19 20:13:06 +00:00
|
|
|
let rows = ((prompt.len() as u64 / Level::ROWS_STEP) + 1) * Level::ROWS_STEP;
|
|
|
|
|
|
|
|
let model = UiModel::new(rows, columns);
|
2017-11-19 09:44:28 +00:00
|
|
|
|
|
|
|
Level { model }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-19 20:13:06 +00:00
|
|
|
fn prompt_lines(firstc: String, prompt: String, indent: u64) -> Vec<Vec<char>> {
|
|
|
|
if !firstc.is_empty() {
|
|
|
|
vec![firstc.chars().chain((0..indent).map(|_| ' ')).collect()]
|
|
|
|
} else if !prompt.is_empty() {
|
|
|
|
prompt.lines().map(|l| l.chars().collect()).collect()
|
|
|
|
} else {
|
|
|
|
vec![]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-18 12:56:37 +00:00
|
|
|
pub struct CmdLine {
|
2017-11-18 20:15:03 +00:00
|
|
|
popover: gtk::Popover,
|
2017-11-19 09:44:28 +00:00
|
|
|
levels: Vec<Level>,
|
2017-11-18 12:56:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl CmdLine {
|
2017-11-18 20:15:03 +00:00
|
|
|
pub fn new(drawing: >k::DrawingArea) -> Self {
|
|
|
|
let popover = gtk::Popover::new(Some(drawing));
|
|
|
|
popover.set_modal(false);
|
|
|
|
let edit_frame = gtk::Frame::new(None);
|
|
|
|
edit_frame.set_shadow_type(gtk::ShadowType::In);
|
|
|
|
let drawing_area = gtk::DrawingArea::new();
|
|
|
|
edit_frame.add(&drawing_area);
|
|
|
|
edit_frame.show_all();
|
|
|
|
|
|
|
|
popover.add(&edit_frame);
|
2017-11-18 12:56:37 +00:00
|
|
|
|
|
|
|
CmdLine {
|
2017-11-19 09:44:28 +00:00
|
|
|
levels: Vec::new(),
|
2017-11-18 20:15:03 +00:00
|
|
|
popover,
|
2017-11-18 12:56:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-19 09:44:28 +00:00
|
|
|
pub fn show_level(&mut self, level: Level) {
|
|
|
|
self.levels.push(level);
|
2017-11-18 20:15:03 +00:00
|
|
|
self.popover.popup();
|
2017-11-18 12:56:37 +00:00
|
|
|
}
|
|
|
|
}
|