2023-06-14 14:16:33 +00:00
|
|
|
use std::sync::Arc;
|
2023-04-04 00:41:16 +00:00
|
|
|
|
2023-06-14 14:16:33 +00:00
|
|
|
use strum_macros::Display;
|
|
|
|
|
|
|
|
use flowy_derive::{Flowy_Event, ProtoBuf_Enum};
|
2023-04-04 00:41:16 +00:00
|
|
|
use lib_dispatch::prelude::*;
|
2023-05-23 15:55:21 +00:00
|
|
|
|
2023-06-14 14:16:33 +00:00
|
|
|
use crate::event_handler::*;
|
2023-07-05 12:57:09 +00:00
|
|
|
use crate::manager::FolderManager;
|
2023-04-04 00:41:16 +00:00
|
|
|
|
2023-07-05 12:57:09 +00:00
|
|
|
pub fn init(folder: Arc<FolderManager>) -> AFPlugin {
|
2023-04-04 00:41:16 +00:00
|
|
|
AFPlugin::new().name("Flowy-Folder").state(folder)
|
|
|
|
// Workspace
|
|
|
|
.event(FolderEvent::CreateWorkspace, create_workspace_handler)
|
|
|
|
.event(
|
2023-06-05 05:10:14 +00:00
|
|
|
FolderEvent::GetCurrentWorkspace,
|
2023-06-07 06:52:35 +00:00
|
|
|
read_current_workspace_setting_handler,
|
2023-04-04 00:41:16 +00:00
|
|
|
)
|
2023-06-05 05:10:14 +00:00
|
|
|
.event(FolderEvent::ReadAllWorkspaces, read_workspaces_handler)
|
2023-04-04 00:41:16 +00:00
|
|
|
.event(FolderEvent::OpenWorkspace, open_workspace_handler)
|
2023-06-03 05:40:12 +00:00
|
|
|
.event(FolderEvent::ReadWorkspaceViews, read_workspace_views_handler)
|
2023-04-04 00:41:16 +00:00
|
|
|
// View
|
|
|
|
.event(FolderEvent::CreateView, create_view_handler)
|
2023-06-14 14:16:33 +00:00
|
|
|
.event(FolderEvent::CreateOrphanView, create_orphan_view_handler)
|
2023-04-04 00:41:16 +00:00
|
|
|
.event(FolderEvent::ReadView, read_view_handler)
|
|
|
|
.event(FolderEvent::UpdateView, update_view_handler)
|
|
|
|
.event(FolderEvent::DeleteView, delete_view_handler)
|
|
|
|
.event(FolderEvent::DuplicateView, duplicate_view_handler)
|
|
|
|
.event(FolderEvent::SetLatestView, set_latest_view_handler)
|
|
|
|
.event(FolderEvent::CloseView, close_view_handler)
|
2023-06-05 08:09:18 +00:00
|
|
|
.event(FolderEvent::MoveView, move_view_handler)
|
2023-04-04 00:41:16 +00:00
|
|
|
// Trash
|
|
|
|
.event(FolderEvent::ReadTrash, read_trash_handler)
|
|
|
|
.event(FolderEvent::PutbackTrash, putback_trash_handler)
|
|
|
|
.event(FolderEvent::DeleteTrash, delete_trash_handler)
|
|
|
|
.event(FolderEvent::RestoreAllTrash, restore_all_trash_handler)
|
|
|
|
.event(FolderEvent::DeleteAllTrash, delete_all_trash_handler)
|
2023-05-31 06:08:54 +00:00
|
|
|
.event(FolderEvent::ImportData, import_data_handler)
|
2023-07-05 12:57:09 +00:00
|
|
|
.event(FolderEvent::GetFolderSnapshots, get_folder_snapshots_handler)
|
2023-04-04 00:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)]
|
|
|
|
#[event_err = "FlowyError"]
|
|
|
|
pub enum FolderEvent {
|
|
|
|
/// Create a new workspace
|
|
|
|
#[event(input = "CreateWorkspacePayloadPB", output = "WorkspacePB")]
|
|
|
|
CreateWorkspace = 0,
|
|
|
|
|
2023-06-03 05:40:12 +00:00
|
|
|
/// Read the current opening workspace. Currently, we only support one workspace
|
2023-04-04 00:41:16 +00:00
|
|
|
#[event(output = "WorkspaceSettingPB")]
|
2023-06-05 05:10:14 +00:00
|
|
|
GetCurrentWorkspace = 1,
|
2023-04-04 00:41:16 +00:00
|
|
|
|
2023-06-05 05:10:14 +00:00
|
|
|
/// Return a list of workspaces that the current user can access.
|
2023-04-04 00:41:16 +00:00
|
|
|
#[event(input = "WorkspaceIdPB", output = "RepeatedWorkspacePB")]
|
2023-06-05 05:10:14 +00:00
|
|
|
ReadAllWorkspaces = 2,
|
2023-04-04 00:41:16 +00:00
|
|
|
|
|
|
|
/// Delete the workspace
|
|
|
|
#[event(input = "WorkspaceIdPB")]
|
|
|
|
DeleteWorkspace = 3,
|
|
|
|
|
|
|
|
/// Open the workspace and mark it as the current workspace
|
|
|
|
#[event(input = "WorkspaceIdPB", output = "WorkspacePB")]
|
|
|
|
OpenWorkspace = 4,
|
|
|
|
|
2023-06-05 05:10:14 +00:00
|
|
|
/// Return a list of views of the current workspace.
|
|
|
|
/// Only the first level of child views are included.
|
2023-04-04 00:41:16 +00:00
|
|
|
#[event(input = "WorkspaceIdPB", output = "RepeatedViewPB")]
|
2023-06-03 05:40:12 +00:00
|
|
|
ReadWorkspaceViews = 5,
|
2023-04-04 00:41:16 +00:00
|
|
|
|
|
|
|
/// Create a new view in the corresponding app
|
|
|
|
#[event(input = "CreateViewPayloadPB", output = "ViewPB")]
|
2023-05-31 06:08:54 +00:00
|
|
|
CreateView = 10,
|
2023-04-04 00:41:16 +00:00
|
|
|
|
|
|
|
/// Return the view info
|
|
|
|
#[event(input = "ViewIdPB", output = "ViewPB")]
|
2023-05-31 06:08:54 +00:00
|
|
|
ReadView = 11,
|
2023-04-04 00:41:16 +00:00
|
|
|
|
|
|
|
/// Update the view's properties including the name,description, etc.
|
|
|
|
#[event(input = "UpdateViewPayloadPB", output = "ViewPB")]
|
2023-05-31 06:08:54 +00:00
|
|
|
UpdateView = 12,
|
2023-04-04 00:41:16 +00:00
|
|
|
|
|
|
|
/// Move the view to the trash folder
|
|
|
|
#[event(input = "RepeatedViewIdPB")]
|
2023-05-31 06:08:54 +00:00
|
|
|
DeleteView = 13,
|
2023-04-04 00:41:16 +00:00
|
|
|
|
|
|
|
/// Duplicate the view
|
|
|
|
#[event(input = "ViewPB")]
|
2023-05-31 06:08:54 +00:00
|
|
|
DuplicateView = 14,
|
2023-04-04 00:41:16 +00:00
|
|
|
|
|
|
|
/// Close and release the resources that are used by this view.
|
|
|
|
/// It should get called when the 'View' page get destroy
|
|
|
|
#[event(input = "ViewIdPB")]
|
2023-05-31 06:08:54 +00:00
|
|
|
CloseView = 15,
|
2023-04-04 00:41:16 +00:00
|
|
|
|
2023-06-14 14:16:33 +00:00
|
|
|
/// Create a new view in the corresponding app
|
|
|
|
#[event(input = "CreateOrphanViewPayloadPB", output = "ViewPB")]
|
|
|
|
CreateOrphanView = 16,
|
|
|
|
|
2023-04-04 00:41:16 +00:00
|
|
|
#[event()]
|
2023-05-31 06:08:54 +00:00
|
|
|
CopyLink = 20,
|
2023-04-04 00:41:16 +00:00
|
|
|
|
|
|
|
/// Set the current visiting view
|
|
|
|
#[event(input = "ViewIdPB")]
|
2023-05-31 06:08:54 +00:00
|
|
|
SetLatestView = 21,
|
2023-04-04 00:41:16 +00:00
|
|
|
|
|
|
|
/// Move the view or app to another place
|
2023-06-05 08:09:18 +00:00
|
|
|
#[event(input = "MoveViewPayloadPB")]
|
|
|
|
MoveView = 22,
|
2023-04-04 00:41:16 +00:00
|
|
|
|
|
|
|
/// Read the trash that was deleted by the user
|
|
|
|
#[event(output = "RepeatedTrashPB")]
|
2023-05-31 06:08:54 +00:00
|
|
|
ReadTrash = 23,
|
2023-04-04 00:41:16 +00:00
|
|
|
|
|
|
|
/// Put back the trash to the origin folder
|
|
|
|
#[event(input = "TrashIdPB")]
|
2023-05-31 06:08:54 +00:00
|
|
|
PutbackTrash = 24,
|
2023-04-04 00:41:16 +00:00
|
|
|
|
|
|
|
/// Delete the trash from the disk
|
|
|
|
#[event(input = "RepeatedTrashIdPB")]
|
2023-05-31 06:08:54 +00:00
|
|
|
DeleteTrash = 25,
|
2023-04-04 00:41:16 +00:00
|
|
|
|
|
|
|
/// Put back all the trash to its original folder
|
|
|
|
#[event()]
|
2023-05-31 06:08:54 +00:00
|
|
|
RestoreAllTrash = 26,
|
2023-04-04 00:41:16 +00:00
|
|
|
|
|
|
|
/// Delete all the trash from the disk
|
|
|
|
#[event()]
|
2023-05-31 06:08:54 +00:00
|
|
|
DeleteAllTrash = 27,
|
|
|
|
|
|
|
|
#[event(input = "ImportPB")]
|
|
|
|
ImportData = 30,
|
2023-07-05 12:57:09 +00:00
|
|
|
|
|
|
|
#[event()]
|
|
|
|
GetFolderSnapshots = 31,
|
2023-04-04 00:41:16 +00:00
|
|
|
}
|