2024-09-22 02:22:51 +02:00
|
|
|
use jni_toolbox::jni;
|
2024-09-23 00:26:11 +02:00
|
|
|
use crate::{errors::{ConnectionError, ControllerError, RemoteError}, Workspace};
|
2024-08-06 23:30:00 +02:00
|
|
|
|
2024-09-05 02:45:33 +02:00
|
|
|
/// Get the workspace id.
|
2024-09-23 18:12:13 +02:00
|
|
|
#[jni(package = "mp.code", class = "Workspace")]
|
2024-09-24 03:35:42 +02:00
|
|
|
fn get_workspace_id(workspace: &mut Workspace) -> String {
|
2024-09-23 00:26:11 +02:00
|
|
|
workspace.id()
|
2024-08-07 00:00:24 +02:00
|
|
|
}
|
|
|
|
|
2024-09-05 02:45:33 +02:00
|
|
|
/// Get a cursor controller by name and returns a pointer to it.
|
2024-09-23 18:12:13 +02:00
|
|
|
#[jni(package = "mp.code", class = "Workspace")]
|
2024-09-24 03:35:42 +02:00
|
|
|
fn get_cursor(workspace: &mut Workspace) -> crate::cursor::Controller {
|
2024-09-23 00:26:11 +02:00
|
|
|
workspace.cursor()
|
2024-08-07 00:00:24 +02:00
|
|
|
}
|
|
|
|
|
2024-09-05 02:45:33 +02:00
|
|
|
/// Get a buffer controller by name and returns a pointer to it.
|
2024-09-23 18:12:13 +02:00
|
|
|
#[jni(package = "mp.code", class = "Workspace")]
|
2024-09-24 03:35:42 +02:00
|
|
|
fn get_buffer(workspace: &mut Workspace, path: String) -> Option<crate::buffer::Controller> {
|
2024-09-15 01:56:51 +02:00
|
|
|
workspace.buffer_by_name(&path)
|
2024-08-06 23:30:00 +02:00
|
|
|
}
|
|
|
|
|
2024-09-05 02:45:33 +02:00
|
|
|
/// Get the filetree.
|
2024-09-23 18:12:13 +02:00
|
|
|
#[jni(package = "mp.code", class = "Workspace")]
|
2024-09-24 03:35:42 +02:00
|
|
|
fn get_file_tree(workspace: &mut Workspace, filter: Option<String>, strict: bool) -> Vec<String> {
|
2024-09-23 00:26:11 +02:00
|
|
|
workspace.filetree(filter.as_deref(), strict)
|
2024-08-07 01:34:13 +02:00
|
|
|
}
|
|
|
|
|
2024-09-17 02:40:03 +02:00
|
|
|
/// Gets a list of the active buffers.
|
2024-09-23 18:12:13 +02:00
|
|
|
#[jni(package = "mp.code", class = "Workspace")]
|
2024-09-24 03:35:42 +02:00
|
|
|
fn active_buffers(workspace: &mut Workspace) -> Vec<String> {
|
2024-09-23 00:26:11 +02:00
|
|
|
workspace.buffer_list()
|
2024-09-17 02:40:03 +02:00
|
|
|
}
|
|
|
|
|
2024-09-25 17:36:20 +02:00
|
|
|
/// Gets a list of the active buffers.
|
|
|
|
#[jni(package = "mp.code", class = "Workspace")]
|
|
|
|
fn user_list(workspace: &mut Workspace) -> Vec<String> {
|
|
|
|
workspace.user_list()
|
|
|
|
}
|
|
|
|
|
2024-09-17 02:40:03 +02:00
|
|
|
/// Create a new buffer.
|
2024-09-23 00:26:11 +02:00
|
|
|
#[jni(package = "mp.code", class = "Workspace")]
|
2024-09-24 03:35:42 +02:00
|
|
|
fn create_buffer(workspace: &mut Workspace, path: String) -> Result<(), RemoteError> {
|
2024-09-23 00:26:11 +02:00
|
|
|
super::tokio().block_on(workspace.create(&path))
|
2024-09-17 02:40:03 +02:00
|
|
|
}
|
|
|
|
|
2024-09-05 02:45:33 +02:00
|
|
|
/// Attach to a buffer and return a pointer to its [crate::buffer::Controller].
|
2024-09-23 18:12:13 +02:00
|
|
|
#[jni(package = "mp.code", class = "Workspace")]
|
2024-09-24 03:35:42 +02:00
|
|
|
fn attach_to_buffer(workspace: &mut Workspace, path: String) -> Result<crate::buffer::Controller, ConnectionError> {
|
2024-09-16 00:20:03 +02:00
|
|
|
super::tokio().block_on(workspace.attach(&path))
|
2024-08-07 01:34:13 +02:00
|
|
|
}
|
|
|
|
|
2024-09-05 02:45:33 +02:00
|
|
|
/// Detach from a buffer.
|
2024-09-23 18:12:13 +02:00
|
|
|
#[jni(package = "mp.code", class = "Workspace")]
|
2024-09-24 03:35:42 +02:00
|
|
|
fn detach_from_buffer(workspace: &mut Workspace, path: String) -> crate::workspace::DetachResult {
|
2024-09-17 17:37:22 +02:00
|
|
|
workspace.detach(&path)
|
2024-08-08 02:45:52 +02:00
|
|
|
}
|
|
|
|
|
2024-09-05 02:45:33 +02:00
|
|
|
/// Update the local buffer list.
|
2024-09-23 00:26:11 +02:00
|
|
|
#[jni(package = "mp.code", class = "Workspace")]
|
2024-09-24 03:35:42 +02:00
|
|
|
fn fetch_buffers(workspace: &mut Workspace) -> Result<(), RemoteError> {
|
2024-09-23 00:26:11 +02:00
|
|
|
super::tokio().block_on(workspace.fetch_buffers())
|
2024-08-07 01:34:13 +02:00
|
|
|
}
|
|
|
|
|
2024-09-05 02:45:33 +02:00
|
|
|
/// Update the local user list.
|
2024-09-23 00:26:11 +02:00
|
|
|
#[jni(package = "mp.code", class = "Workspace")]
|
2024-09-24 03:35:42 +02:00
|
|
|
fn fetch_users(workspace: &mut Workspace) -> Result<(), RemoteError> {
|
2024-09-23 00:26:11 +02:00
|
|
|
super::tokio().block_on(workspace.fetch_users())
|
2024-08-07 01:34:13 +02:00
|
|
|
}
|
|
|
|
|
2024-09-05 02:45:33 +02:00
|
|
|
/// List users attached to a buffer.
|
2024-09-23 18:12:13 +02:00
|
|
|
#[jni(package = "mp.code", class = "Workspace")]
|
2024-09-24 03:35:42 +02:00
|
|
|
fn list_buffer_users(workspace: &mut Workspace, path: String) -> Result<Vec<crate::api::User>, RemoteError> {
|
2024-09-23 00:26:11 +02:00
|
|
|
super::tokio().block_on(workspace.list_buffer_users(&path))
|
2024-08-07 01:34:13 +02:00
|
|
|
}
|
|
|
|
|
2024-09-05 02:45:33 +02:00
|
|
|
/// Delete a buffer.
|
2024-09-23 00:26:11 +02:00
|
|
|
#[jni(package = "mp.code", class = "Workspace")]
|
2024-09-24 03:35:42 +02:00
|
|
|
fn delete_buffer(workspace: &mut Workspace, path: String) -> Result<(), RemoteError> {
|
2024-09-23 00:26:11 +02:00
|
|
|
super::tokio().block_on(workspace.delete(&path))
|
2024-08-07 01:34:13 +02:00
|
|
|
}
|
2024-08-07 10:22:01 +02:00
|
|
|
|
2024-09-05 02:45:33 +02:00
|
|
|
/// Receive a workspace event if present.
|
2024-09-23 18:12:13 +02:00
|
|
|
#[jni(package = "mp.code", class = "Workspace")]
|
2024-09-24 03:35:42 +02:00
|
|
|
fn event(workspace: &mut Workspace) -> Result<crate::api::Event, ControllerError> {
|
2024-09-23 00:26:11 +02:00
|
|
|
super::tokio().block_on(workspace.event())
|
2024-08-09 14:11:13 +02:00
|
|
|
}
|
|
|
|
|
2024-08-08 00:29:54 +02:00
|
|
|
/// Called by the Java GC to drop a [Workspace].
|
2024-09-23 00:26:11 +02:00
|
|
|
#[jni(package = "mp.code", class = "Workspace")]
|
|
|
|
fn free(input: jni::sys::jlong) {
|
|
|
|
let _ = unsafe { Box::from_raw(input as *mut crate::Workspace) };
|
2024-08-08 00:29:54 +02:00
|
|
|
}
|