use crate::Key;
use std::cell::Cell;
use std::rc::Rc;
#[derive(Clone, Debug)]
pub struct KeyEvent {
key: Key,
shift_key: bool,
ctrl_key: bool,
alt_key: bool,
meta_key: bool,
consumed: Rc<Cell<bool>>,
}
impl KeyEvent {
pub fn new(key: Key, shift_key: bool, ctrl_key: bool, alt_key: bool, meta_key: bool) -> Self {
Self {
key,
shift_key,
ctrl_key,
alt_key,
meta_key,
consumed: Rc::new(Cell::new(false)),
}
}
pub fn key(&self) -> Key {
self.key
}
pub fn shift_key(&self) -> bool {
self.shift_key
}
pub fn ctrl_key(&self) -> bool {
self.ctrl_key
}
pub fn alt_key(&self) -> bool {
self.alt_key
}
pub fn meta_key(&self) -> bool {
self.meta_key
}
pub fn consume(&self) {
self.consumed.set(true);
}
pub fn consumed(&self) -> bool {
self.consumed.get()
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct FileDrop {
paths: Vec<String>,
}
impl FileDrop {
pub fn new(joined: &str) -> Self {
Self {
paths: joined
.split('\0')
.filter(|path| !path.is_empty())
.map(str::to_owned)
.collect(),
}
}
pub fn paths(&self) -> &[String] {
&self.paths
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct RangeRequest {
start: u32,
count: u32,
}
impl RangeRequest {
pub fn new(start: u32, count: u32) -> Self {
Self { start, count }
}
pub fn start(&self) -> usize {
self.start as usize
}
pub fn count(&self) -> usize {
self.count as usize
}
}