Starting point on conversion cmdline input to UiModel
This commit is contained in:
parent
333c28e066
commit
f58e398c48
@ -1,9 +1,46 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use gtk;
|
use gtk;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
|
||||||
//TODO: levels
|
use neovim_lib::Value;
|
||||||
|
|
||||||
|
use ui_model::{UiModel, Attrs};
|
||||||
|
|
||||||
|
pub struct Level {
|
||||||
|
model: UiModel,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Level {
|
||||||
|
const COLUMNS_STEP: u64 = 50;
|
||||||
|
|
||||||
|
pub fn from(
|
||||||
|
content: Vec<(HashMap<String, Value>, String)>,
|
||||||
|
pos: u64,
|
||||||
|
firstc: String,
|
||||||
|
prompt: String,
|
||||||
|
indent: u64,
|
||||||
|
level: u64,
|
||||||
|
) -> Self {
|
||||||
|
//TODO: double width chars
|
||||||
|
//TODO: multiline prompt
|
||||||
|
|
||||||
|
let content: Vec<(Attrs, Vec<char>)> = content
|
||||||
|
.iter()
|
||||||
|
.map(|c| (Attrs::from_value_map(&c.0), c.1.chars().collect()))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let width = content.iter().map(|c| c.1.len()).count() as u64 + indent + 1/*firstc*/;
|
||||||
|
let columns = ((width / Level::COLUMNS_STEP) + 1) * Level::COLUMNS_STEP;
|
||||||
|
|
||||||
|
let model = UiModel::new(1, columns);
|
||||||
|
Level { model }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct CmdLine {
|
pub struct CmdLine {
|
||||||
popover: gtk::Popover,
|
popover: gtk::Popover,
|
||||||
|
levels: Vec<Level>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CmdLine {
|
impl CmdLine {
|
||||||
@ -19,11 +56,13 @@ impl CmdLine {
|
|||||||
popover.add(&edit_frame);
|
popover.add(&edit_frame);
|
||||||
|
|
||||||
CmdLine {
|
CmdLine {
|
||||||
|
levels: Vec::new(),
|
||||||
popover,
|
popover,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn show(&self) {
|
pub fn show_level(&mut self, level: Level) {
|
||||||
|
self.levels.push(level);
|
||||||
self.popover.popup();
|
self.popover.popup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
src/shell.rs
10
src/shell.rs
@ -30,7 +30,7 @@ use cursor::Cursor;
|
|||||||
use ui::UiMutex;
|
use ui::UiMutex;
|
||||||
use popup_menu::{self, PopupMenu};
|
use popup_menu::{self, PopupMenu};
|
||||||
use tabline::Tabline;
|
use tabline::Tabline;
|
||||||
use cmd_line::CmdLine;
|
use cmd_line::{self, CmdLine};
|
||||||
use error;
|
use error;
|
||||||
use mode;
|
use mode;
|
||||||
use render;
|
use render;
|
||||||
@ -915,7 +915,9 @@ impl RedrawEvents for State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn on_put(&mut self, text: String) -> RepaintMode {
|
fn on_put(&mut self, text: String) -> RepaintMode {
|
||||||
RepaintMode::Area(self.model.put(&text, self.cur_attrs.as_ref()))
|
let ch = text.chars().last().unwrap_or(' ');
|
||||||
|
let double_width = text.is_empty();
|
||||||
|
RepaintMode::Area(self.model.put(ch, double_width, self.cur_attrs.as_ref()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_clear(&mut self) -> RepaintMode {
|
fn on_clear(&mut self) -> RepaintMode {
|
||||||
@ -1090,8 +1092,8 @@ impl RedrawEvents for State {
|
|||||||
indent: u64,
|
indent: u64,
|
||||||
level: u64,
|
level: u64,
|
||||||
) -> RepaintMode {
|
) -> RepaintMode {
|
||||||
self.cmd_line.show();
|
let level = cmd_line::Level::from(content, pos, firstc, prompt, indent, level);
|
||||||
// TODO: implement
|
self.cmd_line.show_level(level);
|
||||||
RepaintMode::Nothing
|
RepaintMode::Nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,16 +91,16 @@ impl UiModel {
|
|||||||
(self.cur_row, self.cur_col)
|
(self.cur_row, self.cur_col)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn put(&mut self, text: &str, attrs: Option<&Attrs>) -> ModelRect {
|
pub fn put(&mut self, ch: char, double_width: bool, attrs: Option<&Attrs>) -> ModelRect {
|
||||||
let mut changed_region = self.cur_point();
|
let mut changed_region = self.cur_point();
|
||||||
let line = &mut self.model[self.cur_row];
|
let line = &mut self.model[self.cur_row];
|
||||||
line.dirty_line = true;
|
line.dirty_line = true;
|
||||||
|
|
||||||
let cell = &mut line[self.cur_col];
|
let cell = &mut line[self.cur_col];
|
||||||
|
|
||||||
cell.ch = text.chars().last().unwrap_or(' ');
|
cell.ch = ch;
|
||||||
cell.attrs = attrs.map(Attrs::clone).unwrap_or_else(Attrs::new);
|
cell.attrs = attrs.map(Attrs::clone).unwrap_or_else(Attrs::new);
|
||||||
cell.attrs.double_width = text.is_empty();
|
cell.attrs.double_width = double_width;
|
||||||
cell.dirty = true;
|
cell.dirty = true;
|
||||||
self.cur_col += 1;
|
self.cur_col += 1;
|
||||||
if self.cur_col >= self.columns {
|
if self.cur_col >= self.columns {
|
||||||
|
Loading…
Reference in New Issue
Block a user