@ -50,7 +50,7 @@ use movement::Movement;
use crate ::{
use crate ::{
args ,
args ,
compositor ::{ self , Component , Compositor },
compositor ::{ self , Component , Compositor , EventResult },
filter_picker_entry ,
filter_picker_entry ,
job ::Callback ,
job ::Callback ,
keymap ::{ Keymaps , ReverseKeymap } ,
keymap ::{ Keymaps , ReverseKeymap } ,
@ -172,6 +172,11 @@ pub enum MappableCommand {
fun : fn ( cx : & mut Context ) ,
fun : fn ( cx : & mut Context ) ,
doc : & ' static str ,
doc : & ' static str ,
} ,
} ,
Component {
name : & ' static str ,
fun : fn ( & mut dyn crate ::compositor ::Component , & mut compositor ::Context ) -> EventResult ,
doc : & ' static str ,
} ,
}
}
macro_rules! static_commands {
macro_rules! static_commands {
@ -209,6 +214,7 @@ impl MappableCommand {
}
}
}
}
Self ::Static { fun , .. } = > ( fun ) ( cx ) ,
Self ::Static { fun , .. } = > ( fun ) ( cx ) ,
Self ::Component { .. } = > unimplemented! ( ) ,
}
}
}
}
@ -216,6 +222,7 @@ impl MappableCommand {
match & self {
match & self {
Self ::Typable { name , .. } = > name ,
Self ::Typable { name , .. } = > name ,
Self ::Static { name , .. } = > name ,
Self ::Static { name , .. } = > name ,
Self ::Component { .. } = > unimplemented! ( ) ,
}
}
}
}
@ -223,9 +230,18 @@ impl MappableCommand {
match & self {
match & self {
Self ::Typable { doc , .. } = > doc ,
Self ::Typable { doc , .. } = > doc ,
Self ::Static { doc , .. } = > doc ,
Self ::Static { doc , .. } = > doc ,
Self ::Component { .. } = > unimplemented! ( ) ,
}
}
}
}
// TODO: macro for this...
#[ allow(non_upper_case_globals) ]
pub const close_buffer_in_buffer_picker : Self = Self ::Component {
name : "close_buffer_in_buffer_picker" ,
fun : crate ::ui ::picker ::close_buffer_in_buffer_picker ,
doc : "Closes the currently focused buffer" ,
} ;
#[ rustfmt::skip ]
#[ rustfmt::skip ]
static_commands ! (
static_commands ! (
no_op , "Do nothing" ,
no_op , "Do nothing" ,
@ -503,6 +519,7 @@ impl fmt::Debug for MappableCommand {
. field ( name )
. field ( name )
. field ( args )
. field ( args )
. finish ( ) ,
. finish ( ) ,
Self ::Component { .. } = > unimplemented! ( ) ,
}
}
}
}
}
}
@ -2526,17 +2543,19 @@ fn file_picker_in_current_directory(cx: &mut Context) {
cx . push_layer ( Box ::new ( overlaid ( picker ) ) ) ;
cx . push_layer ( Box ::new ( overlaid ( picker ) ) ) ;
}
}
pub struct BufferMeta {
pub id : DocumentId ,
path : Option < PathBuf > ,
is_modified : bool ,
is_current : bool ,
focused_at : std ::time ::Instant ,
}
pub type BufferPicker = Picker < BufferMeta > ;
fn buffer_picker ( cx : & mut Context ) {
fn buffer_picker ( cx : & mut Context ) {
let current = view ! ( cx . editor ) . doc ;
let current = view ! ( cx . editor ) . doc ;
struct BufferMeta {
id : DocumentId ,
path : Option < PathBuf > ,
is_modified : bool ,
is_current : bool ,
focused_at : std ::time ::Instant ,
}
impl ui ::menu ::Item for BufferMeta {
impl ui ::menu ::Item for BufferMeta {
type Data = ( ) ;
type Data = ( ) ;
@ -2710,6 +2729,7 @@ impl ui::menu::Item for MappableCommand {
Some ( bindings ) = > format! ( "{} ({}) [{}]" , doc , fmt_binding ( bindings ) , name ) . into ( ) ,
Some ( bindings ) = > format! ( "{} ({}) [{}]" , doc , fmt_binding ( bindings ) , name ) . into ( ) ,
None = > format! ( "{} [{}]" , doc , name ) . into ( ) ,
None = > format! ( "{} [{}]" , doc , name ) . into ( ) ,
} ,
} ,
MappableCommand ::Component { .. } = > unimplemented! ( ) ,
}
}
}
}
}
}