Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/desktop-gpui/locales/de.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ title = "Ablage"
open_file = "Datei öffnen…"
open_recent = "Benutzte Dokumente"
import_media = "Medien importieren…"
export = "Exportieren…"

[menu.edit]
copy = "Kopieren"
Expand Down
1 change: 1 addition & 0 deletions apps/desktop-gpui/locales/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ title = "File"
open_file = "Open File…"
open_recent = "Open Recent"
import_media = "Import Media…"
export = "Export…"

[menu.edit]
copy = "Copy"
Expand Down
1 change: 1 addition & 0 deletions apps/desktop-gpui/locales/es.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ title = "Archivo"
open_file = "Abrir archivo…"
open_recent = "Abrir recientes"
import_media = "Importar contenido…"
export = "Exportar…"

[menu.edit]
copy = "Copiar"
Expand Down
1 change: 1 addition & 0 deletions apps/desktop-gpui/locales/fr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions apps/desktop-gpui/locales/hi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ title = "फ़ाइल"
open_file = "फ़ाइल खोलें…"
open_recent = "हालिया खोलें"
import_media = "मीडिया इम्पोर्ट करें…"
export = "एक्सपोर्ट करें…"

[menu.edit]
copy = "कॉपी"
Expand Down
1 change: 1 addition & 0 deletions apps/desktop-gpui/locales/ja.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ title = "ファイル"
open_file = "ファイルを開く…"
open_recent = "最近使った項目を開く"
import_media = "メディアを読み込む…"
export = "書き出す…"

[menu.edit]
copy = "コピー"
Expand Down
1 change: 1 addition & 0 deletions apps/desktop-gpui/locales/zh-CN.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ title = "文件"
open_file = "打开文件…"
open_recent = "打开最近使用"
import_media = "导入媒体…"
export = "导出…"

[menu.edit]
copy = "拷贝"
Expand Down
7 changes: 7 additions & 0 deletions apps/desktop-gpui/src/editor_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions apps/desktop-gpui/src/i18n/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
9 changes: 9 additions & 0 deletions apps/desktop-gpui/src/menus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -340,6 +343,7 @@ pub(crate) fn bindings() -> Vec<KeyBinding> {
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),
]
}

Expand Down Expand Up @@ -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),
],
},
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -1359,6 +1366,8 @@ mod tests {
"Open File…".into(),
"Import Media…".into(),
"-".into(),
"Export…".into(),
"-".into(),
"Close Window".into(),
];
assert_eq!(
Expand Down
7 changes: 7 additions & 0 deletions apps/desktop-gpui/src/screenshot_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}))
Expand Down
92 changes: 72 additions & 20 deletions apps/desktop-gpui/src/tray/mac_mode_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -103,7 +111,8 @@ struct PickerIvars {
selected: Cell<usize>,
focused: Cell<Option<usize>>,
flash: Cell<bool>,
pressed: Cell<bool>,
/// The pill the mouse went down on, until mouse-up.
pressed: Cell<Option<usize>>,
/// `actions` index of the first pill; pill `i` posts `tag_base + i`.
tag_base: isize,
capsule: RefCell<Option<Retained<CALayer>>>,
Expand Down Expand Up @@ -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:))]
Expand All @@ -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) {
Expand All @@ -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()),
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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),
Expand Down Expand Up @@ -365,12 +383,15 @@ impl ModePickerView {
}

fn pill_at_point(&self, p: NSPoint) -> Option<usize> {
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
})
}

Expand All @@ -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();
Expand Down Expand Up @@ -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)) };
Expand Down
Loading