first pass of merging in warp (doesn't build)
This commit is contained in:
@@ -2,14 +2,12 @@ use std::path::PathBuf;
|
||||
|
||||
use futures_util::future::LocalBoxFuture;
|
||||
|
||||
use super::menu::MenuItemPropertyChanges;
|
||||
use crate::keymap::Keystroke;
|
||||
use crate::modals::ModalId;
|
||||
use crate::windowing::state::ApplicationStage;
|
||||
use crate::windowing::{WindowCallbackDispatcher, WindowManager};
|
||||
use crate::{
|
||||
keymap::Keystroke, notification, AppContext, ClosedWindowData, SingletonEntity, WindowId,
|
||||
};
|
||||
|
||||
use super::menu::MenuItemPropertyChanges;
|
||||
use crate::{notification, AppContext, ClosedWindowData, SingletonEntity, WindowId};
|
||||
|
||||
pub type AppInitCallbackFn =
|
||||
Box<dyn FnOnce(&mut crate::AppContext, LocalBoxFuture<'static, crate::App>)>;
|
||||
@@ -27,7 +25,8 @@ pub struct AppCallbacks {
|
||||
pub on_resigned_active: Option<Box<dyn FnMut(&mut AppContext)>>,
|
||||
pub on_will_terminate: Option<Box<dyn FnMut(&mut AppContext)>>,
|
||||
/// Callback on whether the app will proceed with termination.
|
||||
pub on_should_terminate_app: Option<Box<dyn FnMut(&mut AppContext) -> ApproveTerminateResult>>,
|
||||
pub on_should_terminate_app:
|
||||
Option<Box<dyn FnMut(TerminationRequestSource, &mut AppContext) -> ApproveTerminateResult>>,
|
||||
/// Callback on whether the window will proceed with closing.
|
||||
pub on_should_close_window:
|
||||
Option<Box<dyn FnMut(WindowId, &mut AppContext) -> ApproveTerminateResult>>,
|
||||
@@ -68,6 +67,22 @@ pub enum ApproveTerminateResult {
|
||||
Cancel,
|
||||
}
|
||||
|
||||
/// Who asked the app to terminate.
|
||||
///
|
||||
/// Platform code passes this through to `on_should_terminate_app` so the
|
||||
/// application can decide whether it is appropriate to interrupt the
|
||||
/// termination, e.g. with a confirmation dialog. Blocking a system-initiated
|
||||
/// termination (logout / restart / scheduled OS update) makes the OS treat the
|
||||
/// app as refusing to quit, which can abort the whole system operation.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum TerminationRequestSource {
|
||||
/// The user asked the app to quit (menu, keyboard shortcut, Dock, …).
|
||||
User,
|
||||
/// The system asked the app to quit (logout, restart, shutdown, or a
|
||||
/// scheduled OS update).
|
||||
System,
|
||||
}
|
||||
|
||||
impl AppCallbackDispatcher {
|
||||
pub fn new(callbacks: AppCallbacks, ui_app: crate::App) -> Self {
|
||||
Self { callbacks, ui_app }
|
||||
@@ -105,7 +120,12 @@ impl AppCallbackDispatcher {
|
||||
// click on/interact with a notification.
|
||||
// TODO(CORE-2322): implement desktop notifications on Windows
|
||||
#[cfg_attr(
|
||||
any(target_os = "linux", target_os = "windows", target_family = "wasm"),
|
||||
any(
|
||||
target_os = "linux",
|
||||
target_os = "freebsd",
|
||||
target_os = "windows",
|
||||
target_family = "wasm"
|
||||
),
|
||||
allow(dead_code)
|
||||
)]
|
||||
pub fn notification_clicked(&mut self, response: notification::NotificationResponse) {
|
||||
@@ -138,9 +158,12 @@ impl AppCallbackDispatcher {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn should_terminate_app(&mut self) -> ApproveTerminateResult {
|
||||
pub fn should_terminate_app(
|
||||
&mut self,
|
||||
source: TerminationRequestSource,
|
||||
) -> ApproveTerminateResult {
|
||||
if let Some(callback) = &mut self.callbacks.on_should_terminate_app {
|
||||
self.ui_app.update(|ctx| callback(ctx))
|
||||
self.ui_app.update(|ctx| callback(source, ctx))
|
||||
} else {
|
||||
ApproveTerminateResult::Terminate
|
||||
}
|
||||
@@ -294,7 +317,12 @@ impl AppCallbackDispatcher {
|
||||
// application menus, so these never get called.
|
||||
// TODO(CORE-2691): implement native Windows OS app menus
|
||||
#[cfg_attr(
|
||||
any(target_os = "linux", target_os = "windows", target_family = "wasm"),
|
||||
any(
|
||||
target_os = "linux",
|
||||
target_os = "freebsd",
|
||||
target_os = "windows",
|
||||
target_family = "wasm"
|
||||
),
|
||||
allow(dead_code)
|
||||
)]
|
||||
impl AppCallbackDispatcher {
|
||||
@@ -316,7 +344,12 @@ impl AppCallbackDispatcher {
|
||||
// native platform modals on these platforms, so these never get called.
|
||||
// TODO(CORE-2323): implement native Windows OS modal
|
||||
#[cfg_attr(
|
||||
any(target_os = "linux", target_os = "windows", target_family = "wasm"),
|
||||
any(
|
||||
target_os = "linux",
|
||||
target_os = "freebsd",
|
||||
target_os = "windows",
|
||||
target_family = "wasm"
|
||||
),
|
||||
allow(dead_code)
|
||||
)]
|
||||
impl AppCallbackDispatcher {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use std::{fmt, path::PathBuf, sync::Arc};
|
||||
use std::fmt;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug, Clone, thiserror::Error)]
|
||||
pub enum FilePickerError {
|
||||
@@ -28,8 +30,8 @@ impl FileType {
|
||||
pub fn extensions(&self) -> &[&str] {
|
||||
match self {
|
||||
FileType::Image => &["png", "jpg", "jpeg"],
|
||||
FileType::Yaml => &["yaml"],
|
||||
FileType::Markdown => &["md"],
|
||||
FileType::Yaml => &["yaml", "yml"],
|
||||
FileType::Markdown => &["md", "markdown"],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,3 +148,7 @@ impl SaveFilePickerConfiguration {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "file_picker_tests.rs"]
|
||||
mod tests;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn yaml_file_type_accepts_both_yaml_and_yml() {
|
||||
assert_eq!(FileType::Yaml.extensions(), &["yaml", "yml"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn markdown_file_type_accepts_md_and_markdown() {
|
||||
assert_eq!(FileType::Markdown.extensions(), &["md", "markdown"]);
|
||||
}
|
||||
@@ -84,7 +84,7 @@ pub struct MenuItemPropertyChanges {
|
||||
impl MenuItemPropertyChanges {
|
||||
/// Returns a struct that unconditionally sets all properties, to be used
|
||||
/// when initializing a menu item for the first time.
|
||||
#[cfg_attr(target_os = "linux", allow(dead_code))]
|
||||
#[cfg_attr(any(target_os = "linux", target_os = "freebsd"), allow(dead_code))]
|
||||
pub fn for_new_item(props: MenuItemProperties, submenu: Submenu) -> Self {
|
||||
Self {
|
||||
name: Some(props.name),
|
||||
|
||||
@@ -7,48 +7,43 @@ pub mod test;
|
||||
#[cfg(target_family = "wasm")]
|
||||
pub mod wasm;
|
||||
|
||||
use std::any::Any;
|
||||
use std::collections::HashSet;
|
||||
use std::ops::Range;
|
||||
use std::path::Path;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use galaxy_util::path::ShellFamily;
|
||||
|
||||
use anyhow::Result;
|
||||
pub use app::AppCallbacks;
|
||||
use async_task::Runnable;
|
||||
use derivative::Derivative;
|
||||
pub use file_picker::{
|
||||
FilePickerCallback, FilePickerConfiguration, FileType, SaveFilePickerCallback,
|
||||
SaveFilePickerConfiguration,
|
||||
};
|
||||
use galaxy_util::path::ShellFamily;
|
||||
use lazy_static::lazy_static;
|
||||
use pathfinder_geometry::rect::{RectF, RectI};
|
||||
use pathfinder_geometry::vector::{Vector2F, Vector2I};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::fonts::SubpixelAlignment;
|
||||
use crate::accessibility::AccessibilityContent;
|
||||
use crate::fonts::canvas::RasterFormat;
|
||||
use crate::fonts::{
|
||||
FamilyId, FontId, GlyphId, Metrics, Properties, RasterizedGlyph, SubpixelAlignment,
|
||||
};
|
||||
use crate::keymap::Keystroke;
|
||||
use crate::modals::{AlertDialog, ModalId};
|
||||
use crate::notification::{NotificationSendError, RequestPermissionsOutcome};
|
||||
|
||||
use crate::notification::{NotificationSendError, RequestPermissionsOutcome, UserNotification};
|
||||
use crate::rendering::{GPUPowerPreference, OnGPUDeviceSelected};
|
||||
use crate::text_layout::{ClipConfig, StyleAndFont, TextAlignment, TextFrame};
|
||||
use crate::{
|
||||
accessibility::AccessibilityContent,
|
||||
fonts::{
|
||||
canvas::RasterFormat, FamilyId, FontId, GlyphId, Metrics, Properties, RasterizedGlyph,
|
||||
},
|
||||
notification::UserNotification,
|
||||
text_layout::Line,
|
||||
windowing::WindowCallbacks,
|
||||
Scene, WindowId,
|
||||
};
|
||||
use crate::text_layout::{ClipConfig, Line, StyleAndFont, TextAlignment, TextFrame};
|
||||
use crate::windowing::WindowCallbacks;
|
||||
use crate::{
|
||||
geometry, rendering, AppContext, ApplicationBundleInfo, Clipboard, DisplayId, DisplayIdx,
|
||||
OptionalPlatformWindow,
|
||||
OptionalPlatformWindow, Scene, WindowId,
|
||||
};
|
||||
use anyhow::Result;
|
||||
use async_task::Runnable;
|
||||
use lazy_static::lazy_static;
|
||||
use pathfinder_geometry::vector::Vector2I;
|
||||
use pathfinder_geometry::{
|
||||
rect::{RectF, RectI},
|
||||
vector::Vector2F,
|
||||
};
|
||||
use std::any::Any;
|
||||
use std::collections::HashSet;
|
||||
use std::path::Path;
|
||||
use std::{ops::Range, rc::Rc, sync::Arc};
|
||||
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
lazy_static! {
|
||||
@@ -262,6 +257,10 @@ pub trait Delegate: 'static {
|
||||
fn register_global_shortcut(&self, shortcut: Keystroke);
|
||||
fn unregister_global_shortcut(&self, shortcut: &Keystroke);
|
||||
|
||||
/// Show or hide the application's Dock icon (macOS only).
|
||||
/// Default no-op for platforms without a Dock concept.
|
||||
fn set_dock_icon_visible(&self, _visible: bool) {}
|
||||
|
||||
fn terminate_app(&self, termination_mode: TerminationMode);
|
||||
|
||||
/// Returns whether or not a screen reader is enabled, or None if we do not
|
||||
@@ -585,6 +584,13 @@ pub trait WindowManager {
|
||||
fn hide_window(&self, window_id: WindowId);
|
||||
fn set_window_bounds(&self, window_id: WindowId, bound: RectF);
|
||||
|
||||
/// Sets the per-window opacity, where `1.0` is fully opaque and `0.0` is fully
|
||||
/// transparent. Unlike `hide_window`, this leaves the window in the window list
|
||||
/// and does not change focus, key, or z-order. Useful for cheaply hiding a
|
||||
/// window during a drag without triggering AppKit's `orderOut:` machinery.
|
||||
/// Default is a no-op on platforms that don't support per-window alpha.
|
||||
fn set_window_alpha(&self, _window_id: WindowId, _alpha: f32) {}
|
||||
|
||||
/// Sets the background blur radius for all windows to the given `blur_radius_pixels` value.
|
||||
fn set_all_windows_background_blur_radius(&self, blur_radius_pixels: u8);
|
||||
|
||||
@@ -669,7 +675,7 @@ impl OperatingSystem {
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(target_family = "wasm")] {
|
||||
wasm::current_platform()
|
||||
} else if #[cfg(target_os = "linux")] {
|
||||
} else if #[cfg(any(target_os = "linux", target_os = "freebsd"))] {
|
||||
OperatingSystem::Linux
|
||||
} else if #[cfg(target_os = "macos")] {
|
||||
OperatingSystem::Mac
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use futures_util::future::LocalBoxFuture;
|
||||
|
||||
use crate::{assets::AssetProvider, integration::TestDriver, platform, AppContext};
|
||||
use crate::assets::AssetProvider;
|
||||
use crate::integration::TestDriver;
|
||||
use crate::{platform, AppContext};
|
||||
|
||||
pub struct App;
|
||||
|
||||
|
||||
@@ -1,33 +1,32 @@
|
||||
use crate::clipboard::InMemoryClipboard;
|
||||
use crate::fonts::FamilyId;
|
||||
use crate::geometry;
|
||||
use crate::keymap::Keystroke;
|
||||
use crate::modals::{AlertDialog, ModalId};
|
||||
use crate::platform::{
|
||||
self,
|
||||
file_picker::{FilePickerCallback, FilePickerConfiguration},
|
||||
Cursor, RequestNotificationPermissionsCallback, SendNotificationErrorCallback,
|
||||
WindowFocusBehavior, WindowOptions,
|
||||
};
|
||||
use crate::platform::{MicrophoneAccessState, TerminationMode, TextLayoutSystem};
|
||||
use crate::text_layout::TextAlignment;
|
||||
use crate::windowing::WindowCallbacks;
|
||||
use crate::{accessibility::AccessibilityContent, notification::UserNotification, Scene, WindowId};
|
||||
use crate::{ApplicationBundleInfo, DisplayId, DisplayIdx, OptionalPlatformWindow};
|
||||
use anyhow::Result;
|
||||
use parking_lot::Mutex;
|
||||
use pathfinder_geometry::rect::RectI;
|
||||
use pathfinder_geometry::vector::{vec2i, Vector2I};
|
||||
use pathfinder_geometry::{
|
||||
rect::RectF,
|
||||
vector::{vec2f, Vector2F},
|
||||
};
|
||||
use std::any::Any;
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use parking_lot::Mutex;
|
||||
use pathfinder_geometry::rect::{RectF, RectI};
|
||||
use pathfinder_geometry::vector::{vec2f, vec2i, Vector2F, Vector2I};
|
||||
|
||||
use crate::accessibility::AccessibilityContent;
|
||||
use crate::clipboard::InMemoryClipboard;
|
||||
use crate::fonts::FamilyId;
|
||||
use crate::keymap::Keystroke;
|
||||
use crate::modals::{AlertDialog, ModalId};
|
||||
use crate::notification::UserNotification;
|
||||
use crate::platform::file_picker::{FilePickerCallback, FilePickerConfiguration};
|
||||
use crate::platform::{
|
||||
self, Cursor, MicrophoneAccessState, RequestNotificationPermissionsCallback,
|
||||
SendNotificationErrorCallback, TerminationMode, TextLayoutSystem, WindowFocusBehavior,
|
||||
WindowOptions,
|
||||
};
|
||||
use crate::text_layout::TextAlignment;
|
||||
use crate::windowing::WindowCallbacks;
|
||||
use crate::{
|
||||
geometry, ApplicationBundleInfo, DisplayId, DisplayIdx, OptionalPlatformWindow, Scene, WindowId,
|
||||
};
|
||||
|
||||
pub struct AppDelegate {
|
||||
clipboard: InMemoryClipboard,
|
||||
cursor_shape: Mutex<Cursor>,
|
||||
|
||||
Reference in New Issue
Block a user