use std::path::PathBuf;
use std::sync::Arc;
use crate::captures::CaptureRepository;
use crate::config::types::ResolvedConfig;
use crate::index::IndexDb;
use crate::macros::MacroRepository;
use crate::templates::repository::TemplateRepository;
use crate::types::TypeRegistry;
use super::selector::SelectorCallback;
#[derive(Clone, Debug)]
pub struct CurrentNote {
pub path: String,
pub note_type: String,
pub title: Option<String>,
pub frontmatter: Option<serde_yaml::Value>,
pub content: String,
}
#[derive(Clone)]
pub struct VaultContext {
pub config: Arc<ResolvedConfig>,
pub template_repo: Arc<TemplateRepository>,
pub capture_repo: Arc<CaptureRepository>,
pub macro_repo: Arc<MacroRepository>,
pub type_registry: Arc<TypeRegistry>,
pub index_db: Option<Arc<IndexDb>>,
pub current_note: Option<CurrentNote>,
pub vault_root: PathBuf,
pub selector_callback: Option<SelectorCallback>,
}
impl VaultContext {
pub fn new(
config: ResolvedConfig,
template_repo: TemplateRepository,
capture_repo: CaptureRepository,
macro_repo: MacroRepository,
type_registry: TypeRegistry,
) -> Self {
let vault_root = config.vault_root.clone();
Self {
config: Arc::new(config),
template_repo: Arc::new(template_repo),
capture_repo: Arc::new(capture_repo),
macro_repo: Arc::new(macro_repo),
type_registry: Arc::new(type_registry),
index_db: None,
current_note: None,
vault_root,
selector_callback: None,
}
}
pub fn from_arcs(
config: Arc<ResolvedConfig>,
template_repo: Arc<TemplateRepository>,
capture_repo: Arc<CaptureRepository>,
macro_repo: Arc<MacroRepository>,
type_registry: Arc<TypeRegistry>,
) -> Self {
let vault_root = config.vault_root.clone();
Self {
config,
template_repo,
capture_repo,
macro_repo,
type_registry,
index_db: None,
current_note: None,
vault_root,
selector_callback: None,
}
}
pub fn with_index(mut self, index_db: Arc<IndexDb>) -> Self {
self.index_db = Some(index_db);
self
}
pub fn with_current_note(mut self, note: CurrentNote) -> Self {
self.current_note = Some(note);
self
}
pub fn with_selector(mut self, callback: SelectorCallback) -> Self {
self.selector_callback = Some(callback);
self
}
}