2023-04-13 10:53:51 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
use strum_macros::Display;
|
|
|
|
|
|
|
|
use flowy_derive::{Flowy_Event, ProtoBuf_Enum};
|
|
|
|
use lib_dispatch::prelude::AFPlugin;
|
|
|
|
|
|
|
|
use crate::{
|
2023-04-28 06:08:53 +00:00
|
|
|
event_handler::{
|
2023-06-03 12:43:46 +00:00
|
|
|
apply_action_handler, close_document_handler, convert_data_to_document,
|
|
|
|
create_document_handler, get_document_data_handler, open_document_handler,
|
2023-04-28 06:08:53 +00:00
|
|
|
},
|
2023-04-13 10:53:51 +00:00
|
|
|
manager::DocumentManager,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn init(document_manager: Arc<DocumentManager>) -> AFPlugin {
|
|
|
|
let mut plugin = AFPlugin::new()
|
|
|
|
.name(env!("CARGO_PKG_NAME"))
|
|
|
|
.state(document_manager);
|
|
|
|
|
2023-05-23 08:13:12 +00:00
|
|
|
plugin = plugin.event(DocumentEvent::CreateDocument, create_document_handler);
|
|
|
|
plugin = plugin.event(DocumentEvent::OpenDocument, open_document_handler);
|
|
|
|
plugin = plugin.event(DocumentEvent::CloseDocument, close_document_handler);
|
|
|
|
plugin = plugin.event(DocumentEvent::ApplyAction, apply_action_handler);
|
|
|
|
plugin = plugin.event(DocumentEvent::GetDocumentData, get_document_data_handler);
|
2023-06-03 12:43:46 +00:00
|
|
|
plugin = plugin.event(
|
|
|
|
DocumentEvent::ConvertDataToDocument,
|
|
|
|
convert_data_to_document,
|
|
|
|
);
|
2023-04-13 10:53:51 +00:00
|
|
|
|
|
|
|
plugin
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, Display, ProtoBuf_Enum, Flowy_Event)]
|
|
|
|
#[event_err = "FlowyError"]
|
2023-05-23 08:13:12 +00:00
|
|
|
pub enum DocumentEvent {
|
|
|
|
#[event(input = "CreateDocumentPayloadPB")]
|
2023-05-16 06:58:24 +00:00
|
|
|
CreateDocument = 0,
|
|
|
|
|
2023-05-23 08:13:12 +00:00
|
|
|
#[event(input = "OpenDocumentPayloadPB", output = "DocumentDataPB")]
|
2023-05-16 06:58:24 +00:00
|
|
|
OpenDocument = 1,
|
2023-04-13 10:53:51 +00:00
|
|
|
|
2023-05-23 08:13:12 +00:00
|
|
|
#[event(input = "CloseDocumentPayloadPB")]
|
2023-05-16 06:58:24 +00:00
|
|
|
CloseDocument = 2,
|
2023-04-13 10:53:51 +00:00
|
|
|
|
2023-05-23 08:13:12 +00:00
|
|
|
#[event(input = "ApplyActionPayloadPB")]
|
2023-05-16 06:58:24 +00:00
|
|
|
ApplyAction = 3,
|
2023-04-17 02:12:04 +00:00
|
|
|
|
2023-05-23 08:13:12 +00:00
|
|
|
#[event(input = "GetDocumentDataPayloadPB")]
|
2023-05-16 06:58:24 +00:00
|
|
|
GetDocumentData = 4,
|
2023-06-03 12:43:46 +00:00
|
|
|
|
|
|
|
#[event(input = "ConvertDataPayloadPB", output = "DocumentDataPB")]
|
|
|
|
ConvertDataToDocument = 5,
|
2023-04-13 10:53:51 +00:00
|
|
|
}
|