2023-07-29 01:46:24 +00:00
|
|
|
use std::sync::Weak;
|
|
|
|
|
2023-04-13 10:53:51 +00:00
|
|
|
use strum_macros::Display;
|
|
|
|
|
|
|
|
use flowy_derive::{Flowy_Event, ProtoBuf_Enum};
|
|
|
|
use lib_dispatch::prelude::AFPlugin;
|
|
|
|
|
2023-07-05 12:57:09 +00:00
|
|
|
use crate::event_handler::get_snapshot_handler;
|
|
|
|
use crate::{event_handler::*, manager::DocumentManager};
|
2023-04-13 10:53:51 +00:00
|
|
|
|
2023-07-29 01:46:24 +00:00
|
|
|
pub fn init(document_manager: Weak<DocumentManager>) -> AFPlugin {
|
2023-07-05 12:57:09 +00:00
|
|
|
AFPlugin::new()
|
2023-04-13 10:53:51 +00:00
|
|
|
.name(env!("CARGO_PKG_NAME"))
|
2023-07-05 12:57:09 +00:00
|
|
|
.state(document_manager)
|
|
|
|
.event(DocumentEvent::CreateDocument, create_document_handler)
|
|
|
|
.event(DocumentEvent::OpenDocument, open_document_handler)
|
|
|
|
.event(DocumentEvent::CloseDocument, close_document_handler)
|
|
|
|
.event(DocumentEvent::ApplyAction, apply_action_handler)
|
|
|
|
.event(DocumentEvent::GetDocumentData, get_document_data_handler)
|
|
|
|
.event(
|
|
|
|
DocumentEvent::ConvertDataToDocument,
|
|
|
|
convert_data_to_document,
|
|
|
|
)
|
|
|
|
.event(DocumentEvent::Redo, redo_handler)
|
|
|
|
.event(DocumentEvent::Undo, undo_handler)
|
|
|
|
.event(DocumentEvent::CanUndoRedo, can_undo_redo_handler)
|
|
|
|
.event(DocumentEvent::GetDocumentSnapshots, get_snapshot_handler)
|
2023-09-12 12:49:03 +00:00
|
|
|
.event(DocumentEvent::CreateText, create_text_handler)
|
|
|
|
.event(DocumentEvent::ApplyTextDeltaEvent, apply_text_delta_handler)
|
2023-04-13 10:53:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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-07-05 12:57:09 +00:00
|
|
|
#[event(input = "OpenDocumentPayloadPB", output = "DocumentDataPB")]
|
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-06-15 02:37:51 +00:00
|
|
|
|
|
|
|
#[event(
|
|
|
|
input = "DocumentRedoUndoPayloadPB",
|
|
|
|
output = "DocumentRedoUndoResponsePB"
|
|
|
|
)]
|
|
|
|
Redo = 6,
|
|
|
|
|
|
|
|
#[event(
|
|
|
|
input = "DocumentRedoUndoPayloadPB",
|
|
|
|
output = "DocumentRedoUndoResponsePB"
|
|
|
|
)]
|
|
|
|
Undo = 7,
|
|
|
|
|
|
|
|
#[event(
|
|
|
|
input = "DocumentRedoUndoPayloadPB",
|
|
|
|
output = "DocumentRedoUndoResponsePB"
|
|
|
|
)]
|
|
|
|
CanUndoRedo = 8,
|
2023-07-05 12:57:09 +00:00
|
|
|
|
|
|
|
#[event(input = "OpenDocumentPayloadPB", output = "RepeatedDocumentSnapshotPB")]
|
|
|
|
GetDocumentSnapshots = 9,
|
2023-09-12 12:49:03 +00:00
|
|
|
|
|
|
|
#[event(input = "TextDeltaPayloadPB")]
|
|
|
|
CreateText = 10,
|
|
|
|
|
|
|
|
#[event(input = "TextDeltaPayloadPB")]
|
|
|
|
ApplyTextDeltaEvent = 11,
|
2023-04-13 10:53:51 +00:00
|
|
|
}
|