chore: draft of user_list for java but its broken

This commit is contained in:
əlemi 2024-09-21 13:18:53 +02:00
parent db77fce3ab
commit ba1a53c3a9
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 31 additions and 0 deletions

View file

@ -69,6 +69,16 @@ public final class Workspace {
return get_file_tree(this.ptr, filter.orElse(null), strict);
}
private static native String[] user_list(long self);
/**
* Get names of all users currently in this workspace
* @return an array containing user display names
*/
public String[] userList() {
return user_list(this.ptr);
}
private static native String[] active_buffers(long self);
/**

View file

@ -76,6 +76,27 @@ pub extern "system" fn Java_mp_code_Workspace_get_1file_1tree(
}).jexcept(&mut env).as_raw()
}
/// Get the user list.
#[no_mangle]
pub extern "system" fn Java_mp_code_Workspace_user_1list(
mut env: JNIEnv,
_class: JClass,
self_ptr: jlong,
) -> jobjectArray {
let workspace = unsafe { Box::leak(Box::from_raw(self_ptr as *mut Workspace)) };
let user_list = workspace.user_list();
env.find_class("java/lang/String")
.and_then(|class| env.new_object_array(user_list.len() as i32, class, JObject::null()))
.inspect(|arr| {
for (idx, path) in user_list.iter().enumerate() {
env.new_string(path)
.and_then(|path| env.set_object_array_element(arr, idx as i32, path))
.jexcept(&mut env)
}
}).jexcept(&mut env).as_raw()
}
/// Gets a list of the active buffers.
#[no_mangle]
pub extern "system" fn Java_mp_code_Workspace_active_1buffers(