diff --git a/apps/desktop-gpui/locales/de.toml b/apps/desktop-gpui/locales/de.toml index 45eff4f62c3..430ca7b4f03 100644 --- a/apps/desktop-gpui/locales/de.toml +++ b/apps/desktop-gpui/locales/de.toml @@ -36,6 +36,7 @@ title = "Ablage" open_file = "Datei öffnen…" open_recent = "Benutzte Dokumente" import_media = "Medien importieren…" +export = "Exportieren…" [menu.edit] copy = "Kopieren" diff --git a/apps/desktop-gpui/locales/en.toml b/apps/desktop-gpui/locales/en.toml index a082fe8ada8..a572fe43ba6 100644 --- a/apps/desktop-gpui/locales/en.toml +++ b/apps/desktop-gpui/locales/en.toml @@ -36,6 +36,7 @@ title = "File" open_file = "Open File…" open_recent = "Open Recent" import_media = "Import Media…" +export = "Export…" [menu.edit] copy = "Copy" diff --git a/apps/desktop-gpui/locales/es.toml b/apps/desktop-gpui/locales/es.toml index aa9765c5ecb..7967755a4e4 100644 --- a/apps/desktop-gpui/locales/es.toml +++ b/apps/desktop-gpui/locales/es.toml @@ -36,6 +36,7 @@ title = "Archivo" open_file = "Abrir archivo…" open_recent = "Abrir recientes" import_media = "Importar contenido…" +export = "Exportar…" [menu.edit] copy = "Copiar" diff --git a/apps/desktop-gpui/locales/fr.toml b/apps/desktop-gpui/locales/fr.toml index 4598f0abb6a..348d2747ec1 100644 --- a/apps/desktop-gpui/locales/fr.toml +++ b/apps/desktop-gpui/locales/fr.toml @@ -36,6 +36,7 @@ title = "Fichier" open_file = "Ouvrir un fichier…" open_recent = "Ouvrir l'élément récent" import_media = "Importer des médias…" +export = "Exporter…" [menu.edit] copy = "Copier" diff --git a/apps/desktop-gpui/locales/hi.toml b/apps/desktop-gpui/locales/hi.toml index c8cb7c8996f..7c8052538b6 100644 --- a/apps/desktop-gpui/locales/hi.toml +++ b/apps/desktop-gpui/locales/hi.toml @@ -36,6 +36,7 @@ title = "फ़ाइल" open_file = "फ़ाइल खोलें…" open_recent = "हालिया खोलें" import_media = "मीडिया इम्पोर्ट करें…" +export = "एक्सपोर्ट करें…" [menu.edit] copy = "कॉपी" diff --git a/apps/desktop-gpui/locales/ja.toml b/apps/desktop-gpui/locales/ja.toml index 7aa20e9aecc..02474e1cc15 100644 --- a/apps/desktop-gpui/locales/ja.toml +++ b/apps/desktop-gpui/locales/ja.toml @@ -36,6 +36,7 @@ title = "ファイル" open_file = "ファイルを開く…" open_recent = "最近使った項目を開く" import_media = "メディアを読み込む…" +export = "書き出す…" [menu.edit] copy = "コピー" diff --git a/apps/desktop-gpui/locales/zh-CN.toml b/apps/desktop-gpui/locales/zh-CN.toml index 8abaafc6c27..d3486c584ab 100644 --- a/apps/desktop-gpui/locales/zh-CN.toml +++ b/apps/desktop-gpui/locales/zh-CN.toml @@ -36,6 +36,7 @@ title = "文件" open_file = "打开文件…" open_recent = "打开最近使用" import_media = "导入媒体…" +export = "导出…" [menu.edit] copy = "拷贝" diff --git a/apps/desktop-gpui/src/editor_window.rs b/apps/desktop-gpui/src/editor_window.rs index 8a5adc5330e..8fa984441c3 100644 --- a/apps/desktop-gpui/src/editor_window.rs +++ b/apps/desktop-gpui/src/editor_window.rs @@ -12966,6 +12966,13 @@ impl Render for EditorWindow { .bg(self.root_bg()) .text_color(Hsla::from(theme.gray_12)) .track_focus(&self.focus) + .on_action( + cx.listener(|this, _: &crate::menus::ExportEditor, window, cx| { + if this.project_ready() { + this.open_export(window, cx); + } + }), + ) .capture_key_down(cx.listener(Self::capture_playback_key)) .on_key_down(cx.listener(Self::on_key)) // Only the cropper needs key-*up*: its nudge loop runs until every diff --git a/apps/desktop-gpui/src/i18n/tests.rs b/apps/desktop-gpui/src/i18n/tests.rs index 94539acfa56..5fe538d8765 100644 --- a/apps/desktop-gpui/src/i18n/tests.rs +++ b/apps/desktop-gpui/src/i18n/tests.rs @@ -28,6 +28,7 @@ fn english_matches_the_literals_it_replaced() { (tr::menu::file::open_prompt(), "Open Recording".into()), (tr::menu::file::open_recent(), "Open Recent".into()), (tr::menu::file::import_media(), "Import Media…".into()), + (tr::menu::file::export(), "Export…".into()), (tr::menu::file::title(), "File".into()), (tr::menu::edit::copy(), "Copy".into()), (tr::menu::edit::cut(), "Cut".into()), diff --git a/apps/desktop-gpui/src/menus.rs b/apps/desktop-gpui/src/menus.rs index ed1cb3e2b41..83e13305c8c 100644 --- a/apps/desktop-gpui/src/menus.rs +++ b/apps/desktop-gpui/src/menus.rs @@ -136,6 +136,9 @@ actions!( OpenSettings, OpenFile, ImportMedia, + /// File > Export… -- ⇧⌘E. Only an open editor handles it, so the item is + /// disabled everywhere else. + ExportEditor, Changelog, HelpDashboard, HelpDocs, @@ -340,6 +343,7 @@ pub(crate) fn bindings() -> Vec { KeyBinding::new("cmd-m", Minimize, None), KeyBinding::new("ctrl-cmd-f", ToggleFullscreen, None), KeyBinding::new("secondary-,", OpenSettings, None), + KeyBinding::new("shift-cmd-e", ExportEditor, None), ] } @@ -380,6 +384,8 @@ pub fn build_menus(update_status: &updates::UpdateStatus, settings_enabled: bool MenuItem::action(tr::menu::file::open_file(), OpenFile), MenuItem::action(tr::menu::file::import_media(), ImportMedia), MenuItem::separator(), + MenuItem::action(tr::menu::file::export(), ExportEditor), + MenuItem::separator(), MenuItem::action(tr::menu::file::close_window(), CloseWindow), ], }, @@ -1312,6 +1318,7 @@ mod tests { ("cmd-m", &Minimize), ("ctrl-cmd-f", &ToggleFullscreen), (settings, &OpenSettings), + ("shift-cmd-e", &ExportEditor), ]; let bindings = bindings(); assert_eq!(bindings.len(), expected.len()); @@ -1359,6 +1366,8 @@ mod tests { "Open File…".into(), "Import Media…".into(), "-".into(), + "Export…".into(), + "-".into(), "Close Window".into(), ]; assert_eq!( diff --git a/apps/desktop-gpui/src/screenshot_editor.rs b/apps/desktop-gpui/src/screenshot_editor.rs index 27d6519647c..a75f8f251a4 100644 --- a/apps/desktop-gpui/src/screenshot_editor.rs +++ b/apps/desktop-gpui/src/screenshot_editor.rs @@ -4537,6 +4537,13 @@ impl Render for ScreenshotEditorWindow { .id("screenshot-editor-root") .track_focus(&self.focus) .key_context("ScreenshotEditor") + .when(self.crop.is_none(), |root| { + root.on_action( + cx.listener(|this, _: &crate::menus::ExportEditor, window, cx| { + this.export_image(ExportDestination::File, window, cx); + }), + ) + }) .on_key_down(cx.listener(|this, event: &gpui::KeyDownEvent, window, cx| { this.on_key(event, window, cx); })) diff --git a/apps/desktop-gpui/src/tray/mac_mode_picker.rs b/apps/desktop-gpui/src/tray/mac_mode_picker.rs index 843c9a0698f..c8c33feeb11 100644 --- a/apps/desktop-gpui/src/tray/mac_mode_picker.rs +++ b/apps/desktop-gpui/src/tray/mac_mode_picker.rs @@ -20,11 +20,15 @@ use objc2_app_kit::{ NSForegroundColorAttributeName, NSImage, NSImageScaling, NSImageView, NSMenu, NSMenuItem, NSStringDrawing, NSTrackingArea, NSTrackingAreaOptions, NSView, NSWindow, }; +use objc2_core_graphics::CGAffineTransformMake; use objc2_foundation::{ MainThreadMarker, NSArray, NSData, NSDictionary, NSPoint, NSRect, NSRunLoop, NSSize, NSString, - NSTimer, + NSTimer, NSValue, ns_string, +}; +use objc2_quartz_core::{ + CABasicAnimation, CALayer, CAMediaTiming, CAMediaTimingFunction, CATransaction, CATransform3D, + kCACornerCurveContinuous, kCAMediaTimingFunctionEaseOut, }; -use objc2_quartz_core::{CALayer, CATransaction, kCACornerCurveContinuous}; use super::mac::{post, set_status_mode}; use super::{TrayItem, mode_heading, mode_name, mode_picker_icon}; @@ -47,6 +51,8 @@ const PICKER_H: f64 = 41.0; const PILL_W: f64 = 42.0; const PILL_H: f64 = 29.0; const PILL_GAP: f64 = 4.0; +/// Minimum touch target height. Only the hit test uses it; the visual pill stays `PILL_H`. +const PILL_HIT_MIN_H: f64 = 36.0; const CAPSULE_PAD: f64 = 3.0; const RIGHT_INSET: f64 = 12.0; const TITLE_INSET: f64 = 18.0; @@ -55,6 +61,8 @@ const PILL_RADIUS: f64 = 14.0; const CAPSULE_RADIUS: f64 = 17.0; /// Optical nudge for a pill's glyph, left of its centred position. const STUDIO_ICON_NUDGE: f64 = -1.0; +const PRESS_SCALE: f64 = 0.85; +const PRESS_DURATION: f64 = 0.25; thread_local! { /// The live picker and its menu item, read by the key hook. Set on every rebuild. @@ -103,7 +111,8 @@ struct PickerIvars { selected: Cell, focused: Cell>, flash: Cell, - pressed: Cell, + /// The pill the mouse went down on, until mouse-up. + pressed: Cell>, /// `actions` index of the first pill; pill `i` posts `tag_base + i`. tag_base: isize, capsule: RefCell>>, @@ -178,17 +187,19 @@ define_class!( #[unsafe(method(mouseExited:))] fn mouse_exited(&self, _event: &NSEvent) { - if self.ivars().pressed.get() { - return; - } + self.release_press(); self.ivars().focused.set(None); self.refresh(); } #[unsafe(method(mouseDown:))] fn mouse_down(&self, event: &NSEvent) { - self.ivars().pressed.set(true); - self.update_focus(self.pill_at(event)); + let hit = self.pill_at(event); + self.ivars().pressed.set(hit); + self.update_focus(hit); + if let Some(i) = hit { + self.set_icon_pressed(i, true); + } } #[unsafe(method(mouseDragged:))] @@ -198,7 +209,7 @@ define_class!( #[unsafe(method(mouseUp:))] fn mouse_up(&self, event: &NSEvent) { - self.ivars().pressed.set(false); + self.release_press(); // The release point chooses the pill; a release outside the menu // changes nothing, so the shown and applied modes stay in sync. match self.pill_at(event) { @@ -220,7 +231,7 @@ impl ModePickerView { selected: Cell::new(selected), focused: Cell::new(None), flash: Cell::new(false), - pressed: Cell::new(false), + pressed: Cell::new(None), tag_base, capsule: RefCell::new(None), pills: RefCell::new(Vec::new()), @@ -269,6 +280,7 @@ impl ModePickerView { view.setImage(Some(&image)); } view.setImageScaling(NSImageScaling::ScaleNone); + view.setWantsLayer(true); this.addSubview(&view); this.ivars().icons.borrow_mut().push(view); } @@ -320,12 +332,18 @@ impl ModePickerView { } fn clear_focus(&self) { - if self.ivars().pressed.get() { - return; - } + self.release_press(); self.update_focus(None); } + /// Ends any mouse press, animating its icon back to rest. Safe to call when + /// no press is active. + fn release_press(&self) { + if let Some(i) = self.ivars().pressed.replace(None) { + self.set_icon_pressed(i, false); + } + } + // -- geometry ---------------------------------------------------------- fn capsule_rect(&self) -> NSRect { @@ -334,7 +352,7 @@ impl ModePickerView { let bounds = self.bounds(); NSRect::new( NSPoint::new( - bounds.size.width - RIGHT_INSET - w, + picker_width() - RIGHT_INSET - w, (bounds.size.height - h) / 2.0, ), NSSize::new(w, h), @@ -365,12 +383,15 @@ impl ModePickerView { } fn pill_at_point(&self, p: NSPoint) -> Option { + let bounds = self.bounds(); (0..PICKER_MODES.len()).find(|&i| { let r = self.pill_rect(i); + let hit_h = PILL_HIT_MIN_H.max(r.size.height).min(bounds.size.height); + let hit_y = r.origin.y + r.size.height / 2.0 - hit_h / 2.0; p.x >= r.origin.x - PILL_GAP / 2.0 && p.x <= r.origin.x + r.size.width + PILL_GAP / 2.0 - && p.y >= r.origin.y - && p.y <= r.origin.y + r.size.height + && p.y >= hit_y + && p.y <= hit_y + hit_h }) } @@ -394,6 +415,35 @@ impl ModePickerView { self.setNeedsDisplay(true); } + /// Scales pill `i`'s icon about its center, animated, for a press or release. + fn set_icon_pressed(&self, i: usize, pressed: bool) { + let icons = self.ivars().icons.borrow(); + let Some(layer) = icons.get(i).and_then(|icon| icon.layer()) else { + return; + }; + let scale = if pressed { PRESS_SCALE } else { 1.0 }; + let size = layer.bounds().size; + let inset_x = size.width * (1.0 - scale) / 2.0; + let inset_y = size.height * (1.0 - scale) / 2.0; + let to = CATransform3D::new_affine_transform(CGAffineTransformMake( + scale, 0.0, 0.0, scale, inset_x, inset_y, + )); + let from = + unsafe { layer.presentationLayer() }.map_or(layer.transform(), |p| p.transform()); + layer.setTransform(to); + + let anim = CABasicAnimation::animationWithKeyPath(Some(ns_string!("transform"))); + unsafe { + anim.setFromValue(Some(&NSValue::new(from))); + anim.setToValue(Some(&NSValue::new(to))); + } + anim.setDuration(PRESS_DURATION); + anim.setTimingFunction(Some(&CAMediaTimingFunction::functionWithName(unsafe { + kCAMediaTimingFunctionEaseOut + }))); + layer.addAnimation_forKey(&anim, Some(ns_string!("press"))); + } + /// The only place state becomes layer properties. fn sync(&self) { let appearance = self.effectiveAppearance(); @@ -471,17 +521,19 @@ impl ModePickerView { let shown = focused.unwrap_or(selected); let mut font = heading_font(); - if shown != selected { + let color = if shown != selected { font = italic(&font); - } + NSColor::secondaryLabelColor() + } else { + NSColor::labelColor() + }; - let secondary = NSColor::secondaryLabelColor(); let subtitle = NSString::from_str(mode_heading(PICKER_MODES[shown].0)); let attrs = NSDictionary::from_slices( &[unsafe { NSFontAttributeName }, unsafe { NSForegroundColorAttributeName }], - &[&*font as &AnyObject, &*secondary as &AnyObject], + &[&*font as &AnyObject, &*color as &AnyObject], ); let size = unsafe { subtitle.sizeWithAttributes(Some(&attrs)) };