use std::sync::{Arc, RwLock};
use crate::editing::application::ApplicationInfo;
use crate::editing::completion::{Completer, EmptyCompleter};
mod buffer;
mod complete;
mod cursor;
mod digraph;
mod register;
pub use self::buffer::{BufferStore, SharedBuffer};
pub use self::complete::CompletionStore;
pub use self::cursor::{AdjustStore, CursorStore, GlobalAdjustable};
pub use self::digraph::DigraphStore;
pub use self::register::{RegisterCell, RegisterError, RegisterPutFlags, RegisterStore};
pub struct Store<I: ApplicationInfo> {
pub buffers: BufferStore<I>,
pub completions: CompletionStore,
pub digraphs: DigraphStore,
pub registers: RegisterStore,
pub completer: Box<dyn Completer<I>>,
pub cursors: CursorStore<I>,
pub application: I::Store,
}
pub type SharedStore<I> = Arc<RwLock<Store<I>>>;
impl<I> Store<I>
where
I: ApplicationInfo,
{
pub fn new(application: I::Store) -> Self {
Store {
buffers: BufferStore::new(),
completions: CompletionStore::default(),
digraphs: DigraphStore::default(),
registers: RegisterStore::default(),
cursors: CursorStore::default(),
completer: Box::new(EmptyCompleter),
application,
}
}
pub fn shared(self) -> SharedStore<I> {
return Arc::new(RwLock::new(self));
}
pub fn load_buffer(&mut self, id: I::ContentId) -> SharedBuffer<I> {
self.buffers.load(id)
}
}
impl<I> Default for Store<I>
where
I: ApplicationInfo,
I::Store: Default,
{
fn default() -> Self {
Store::new(I::Store::default())
}
}