Merge pull request #2265 from zed-industries/fix-menu-bar-greying-out

Fix too-agressive menu bar greying
This commit is contained in:
Mikayla Maki 2023-03-10 16:05:07 -08:00 committed by GitHub
commit 87ac409e51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 14 deletions

View file

@ -1323,7 +1323,7 @@ impl MutableAppContext {
pub fn is_action_available(&self, action: &dyn Action) -> bool {
let action_type = action.as_any().type_id();
if let Some(window_id) = self.cx.platform.key_window_id() {
if let Some(window_id) = self.cx.platform.main_window_id() {
if let Some(focused_view_id) = self.focused_view_id(window_id) {
for view_id in self.ancestors(window_id, focused_view_id) {
if let Some(view) = self.views.get(&(window_id, view_id)) {

View file

@ -77,9 +77,9 @@ pub(crate) fn setup_menu_handlers(foreground_platform: &dyn ForegroundPlatform,
let cx = app.0.clone();
move |action| {
let mut cx = cx.borrow_mut();
if let Some(key_window_id) = cx.cx.platform.key_window_id() {
if let Some(view_id) = cx.focused_view_id(key_window_id) {
cx.handle_dispatch_action_from_effect(key_window_id, Some(view_id), action);
if let Some(main_window_id) = cx.cx.platform.main_window_id() {
if let Some(view_id) = cx.focused_view_id(main_window_id) {
cx.handle_dispatch_action_from_effect(main_window_id, Some(view_id), action);
return;
}
}

View file

@ -58,7 +58,7 @@ pub trait Platform: Send + Sync {
options: WindowOptions,
executor: Rc<executor::Foreground>,
) -> Box<dyn Window>;
fn key_window_id(&self) -> Option<usize>;
fn main_window_id(&self) -> Option<usize>;
fn add_status_item(&self) -> Box<dyn Window>;

View file

@ -587,8 +587,8 @@ impl platform::Platform for MacPlatform {
Box::new(Window::open(id, options, executor, self.fonts()))
}
fn key_window_id(&self) -> Option<usize> {
Window::key_window_id()
fn main_window_id(&self) -> Option<usize> {
Window::main_window_id()
}
fn add_status_item(&self) -> Box<dyn platform::Window> {

View file

@ -604,12 +604,12 @@ impl Window {
}
}
pub fn key_window_id() -> Option<usize> {
pub fn main_window_id() -> Option<usize> {
unsafe {
let app = NSApplication::sharedApplication(nil);
let key_window: id = msg_send![app, keyWindow];
if msg_send![key_window, isKindOfClass: WINDOW_CLASS] {
let id = get_window_state(&*key_window).borrow().id;
let main_window: id = msg_send![app, mainWindow];
if msg_send![main_window, isKindOfClass: WINDOW_CLASS] {
let id = get_window_state(&*main_window).borrow().id;
Some(id)
} else {
None

View file

@ -157,7 +157,7 @@ impl super::Platform for Platform {
}))
}
fn key_window_id(&self) -> Option<usize> {
fn main_window_id(&self) -> Option<usize> {
None
}

View file

@ -577,8 +577,13 @@ fn open_telemetry_log_file(
workspace.with_local_workspace(&app_state.clone(), cx, move |_, cx| {
cx.spawn_weak(|workspace, mut cx| async move {
let workspace = workspace.upgrade(&cx)?;
async fn fetch_log_string(app_state: &Arc<AppState>) -> Option<String> {
let path = app_state.client.telemetry_log_file_path()?;
let log = app_state.fs.load(&path).await.log_err()?;
app_state.fs.load(&path).await.log_err()
}
let log = fetch_log_string(&app_state).await.unwrap_or_else(|| "// No data has been collected yet".to_string());
const MAX_TELEMETRY_LOG_LEN: usize = 5 * 1024 * 1024;
let mut start_offset = log.len().saturating_sub(MAX_TELEMETRY_LOG_LEN);