change register command to be UiCommand rather than direct handler

macos-click-through
keith 4 years ago
parent d85fc62c4d
commit c63dcbdf04

@ -1,18 +1,15 @@
use async_trait::async_trait; use async_trait::async_trait;
use log::{error, trace}; use log::trace;
use nvim_rs::{compat::tokio::Compat, Handler, Neovim}; use nvim_rs::{compat::tokio::Compat, Handler, Neovim};
use rmpv::Value; use rmpv::Value;
use tokio::process::ChildStdin; use tokio::process::ChildStdin;
use tokio::task; use tokio::task;
use super::events::handle_redraw_event_group; use super::events::handle_redraw_event_group;
use super::ui_commands::UiCommand;
use super::BRIDGE;
use crate::settings::SETTINGS; use crate::settings::SETTINGS;
#[cfg(windows)]
use crate::settings::windows_registry::{
register_rightclick_directory, register_rightclick_file, unregister_rightclick,
};
#[derive(Clone)] #[derive(Clone)]
pub struct NeovimHandler(); pub struct NeovimHandler();
@ -35,26 +32,10 @@ impl Handler for NeovimHandler {
SETTINGS.handle_changed_notification(arguments); SETTINGS.handle_changed_notification(arguments);
} }
"neovide.register_right_click" => { "neovide.register_right_click" => {
#[cfg(windows)] BRIDGE.queue_command(UiCommand::RegisterRightClick);
{
if unregister_rightclick() {
error!("Setup of Windows Registry failed during unregister. Try running as Admin?");
}
if !register_rightclick_directory() {
error!("Setup of Windows Registry failed during directory registration. Try running as Admin?");
}
if !register_rightclick_file() {
error!("Setup of Windows Registry failed during file registration. Try running as Admin?");
}
}
} }
"neovide.unregister_right_click" => { "neovide.unregister_right_click" => {
#[cfg(windows)] BRIDGE.queue_command(UiCommand::UnregisterRightClick);
{
if !unregister_rightclick() {
error!("Removal of Windows Registry failed, probably no Admin");
}
}
} }
_ => {} _ => {}
}) })

@ -80,6 +80,25 @@ fn build_nvim_cmd() -> Command {
} }
} }
pub fn build_neovide_command(channel: u64, num_args: u64, command: &str, event: &str) -> String {
let nargs: String = if num_args > 1 {
"+".to_string()
} else {
num_args.to_string()
};
if num_args == 0 {
return format!(
"command! -nargs={} -complete=expression {} call rpcnotify({}, 'neovide.{}')",
nargs, command, channel, event
);
} else {
return format!(
"command! -nargs={} -complete=expression {} call rpcnotify({}, 'neovide.{}', <args>)",
nargs, command, channel, event
);
};
}
pub fn create_nvim_command() -> Command { pub fn create_nvim_command() -> Command {
let mut cmd = build_nvim_cmd(); let mut cmd = build_nvim_cmd();
@ -105,25 +124,6 @@ async fn drain(receiver: &mut UnboundedReceiver<UiCommand>) -> Option<Vec<UiComm
} }
} }
fn build_neovide_command(channel: u64, num_args: u64, command: &str, event: &str) -> String {
let nargs: String = if num_args > 1 {
"+".to_string()
} else {
num_args.to_string()
};
if num_args == 0 {
return format!(
"command! -nargs={} -complete=expression {} call rpcnotify({}, 'neovide.{}')",
nargs, command, channel, event
);
} else {
return format!(
"command! -nargs={} -complete=expression {} call rpcnotify({}, 'neovide.{}', <args>)",
nargs, command, channel, event
);
};
}
async fn start_process(mut receiver: UnboundedReceiver<UiCommand>) { async fn start_process(mut receiver: UnboundedReceiver<UiCommand>) {
let (width, height) = window_geometry_or_default(); let (width, height) = window_geometry_or_default();
let (mut nvim, io_handler, _) = let (mut nvim, io_handler, _) =

@ -1,9 +1,13 @@
use log::trace; use log::{error, trace};
use nvim_rs::compat::tokio::Compat; use nvim_rs::compat::tokio::Compat;
use nvim_rs::Neovim; use nvim_rs::Neovim;
use tokio::process::ChildStdin; use tokio::process::ChildStdin;
use crate::editor::EDITOR; use crate::editor::EDITOR;
#[cfg(windows)]
use crate::settings::windows_registry::{
register_rightclick_directory, register_rightclick_file, unregister_rightclick,
};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum UiCommand { pub enum UiCommand {
@ -25,6 +29,10 @@ pub enum UiCommand {
FocusLost, FocusLost,
FocusGained, FocusGained,
Quit, Quit,
#[cfg(windows)]
RegisterRightClick,
#[cfg(windows)]
UnregisterRightClick,
} }
impl UiCommand { impl UiCommand {
@ -79,6 +87,32 @@ impl UiCommand {
UiCommand::FileDrop(path) => { UiCommand::FileDrop(path) => {
nvim.command(format!("e {}", path).as_str()).await.ok(); nvim.command(format!("e {}", path).as_str()).await.ok();
} }
#[cfg(windows)]
UiCommand::RegisterRightClick => {
if unregister_rightclick() {
let msg = "Could not unregister previous menu item. Possibly already registered or not running as Admin?";
nvim.err_writeln(msg).await.ok();
error!("{}", msg);
}
if !register_rightclick_directory() {
let msg = "Could not register directory context menu item. Possibly already registered or not running as Admin?";
nvim.err_writeln(msg).await.ok();
error!("{}", msg);
}
if !register_rightclick_file() {
let msg = "Could not register file context menu item. Possibly already registered or not running as Admin?";
nvim.err_writeln(msg).await.ok();
error!("{}", msg);
}
}
#[cfg(windows)]
UiCommand::UnregisterRightClick => {
if !unregister_rightclick() {
let msg = "Could not remove context menu items. Possibly already removed or not running as Admin?";
nvim.err_writeln(msg).await.ok();
error!("{}", msg);
}
}
} }
} }

Loading…
Cancel
Save