Add character palette menu item

This commit is contained in:
Antonio Scandurra
2022-07-19 14:51:57 +02:00
parent e5602b0ad4
commit 456a390166
8 changed files with 43 additions and 9 deletions
+9
View File
@@ -1195,6 +1195,11 @@ impl MutableAppContext {
.set_menus(menus, &self.keystroke_matcher);
}
fn show_character_palette(&self, window_id: usize) {
let (_, window) = &self.presenters_and_platform_windows[&window_id];
window.show_character_palette();
}
fn prompt(
&self,
window_id: usize,
@@ -3489,6 +3494,10 @@ impl<'a, T: View> ViewContext<'a, T> {
self.app.platform()
}
pub fn show_character_palette(&self) {
self.app.show_character_palette(self.window_id);
}
pub fn prompt(
&self,
level: PromptLevel,
+1
View File
@@ -99,6 +99,7 @@ pub trait Window: WindowContext {
fn activate(&self);
fn set_title(&mut self, title: &str);
fn set_edited(&mut self, edited: bool);
fn show_character_palette(&self);
}
pub trait WindowContext {
+10 -8
View File
@@ -12,10 +12,19 @@ use cocoa::{
};
use std::{borrow::Cow, ffi::CStr, os::raw::c_char};
const BACKSPACE_KEY: u16 = 0x7f;
const SPACE_KEY: u16 = b' ' as u16;
const ENTER_KEY: u16 = 0x0d;
const NUMPAD_ENTER_KEY: u16 = 0x03;
const ESCAPE_KEY: u16 = 0x1b;
const TAB_KEY: u16 = 0x09;
const SHIFT_TAB_KEY: u16 = 0x19;
pub fn key_to_native(key: &str) -> Cow<str> {
use cocoa::appkit::*;
let code = match key {
"backspace" => 0x7F,
"space" => SPACE_KEY,
"backspace" => BACKSPACE_KEY,
"up" => NSUpArrowFunctionKey,
"down" => NSDownArrowFunctionKey,
"left" => NSLeftArrowFunctionKey,
@@ -243,13 +252,6 @@ unsafe fn get_key_text(
let mut input = None;
let first_char = unmodified_chars.chars().next()?;
use cocoa::appkit::*;
const BACKSPACE_KEY: u16 = 0x7f;
const ENTER_KEY: u16 = 0x0d;
const NUMPAD_ENTER_KEY: u16 = 0x03;
const ESCAPE_KEY: u16 = 0x1b;
const TAB_KEY: u16 = 0x09;
const SHIFT_TAB_KEY: u16 = 0x19;
const SPACE_KEY: u16 = b' ' as u16;
#[allow(non_upper_case_globals)]
let unmodified_chars = match first_char as u16 {
+9
View File
@@ -1,3 +1,4 @@
use super::{geometry::RectFExt, renderer::Renderer};
use crate::{
executor,
geometry::{
@@ -448,6 +449,14 @@ impl platform::Window for Window {
// so we have to move it again.
self.0.borrow().move_traffic_light();
}
fn show_character_palette(&self) {
unsafe {
let app = NSApplication::sharedApplication(nil);
let window = self.0.borrow().native_window;
let _: () = msg_send![app, orderFrontCharacterPalette: window];
}
}
}
impl platform::WindowContext for Window {
+2
View File
@@ -274,6 +274,8 @@ impl super::Window for Window {
fn on_should_close(&mut self, callback: Box<dyn FnMut() -> bool>) {
self.should_close_handler = Some(callback);
}
fn show_character_palette(&self) {}
}
pub fn platform() -> Platform {