mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-05 05:18:12 +08:00
Replace globals with editor environment (#3656)
Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::application::Editor;
|
||||
use crate::consts::{
|
||||
VIEWPORT_ROTATE_SNAP_INTERVAL, VIEWPORT_SCROLL_RATE, VIEWPORT_ZOOM_LEVELS, VIEWPORT_ZOOM_MIN_FRACTION_COVER, VIEWPORT_ZOOM_MOUSE_RATE, VIEWPORT_ZOOM_SCALE_MAX, VIEWPORT_ZOOM_SCALE_MIN,
|
||||
VIEWPORT_ZOOM_TO_FIT_PADDING_SCALE_FACTOR,
|
||||
@@ -8,7 +9,6 @@ use crate::messages::input_mapper::utility_types::input_mouse::ViewportPosition;
|
||||
use crate::messages::portfolio::document::navigation::utility_types::NavigationOperation;
|
||||
use crate::messages::portfolio::document::utility_types::misc::PTZ;
|
||||
use crate::messages::portfolio::document::utility_types::network_interface::NodeNetworkInterface;
|
||||
use crate::messages::portfolio::utility_types::KeyboardPlatformLayout;
|
||||
use crate::messages::prelude::*;
|
||||
use crate::messages::tool::utility_types::{HintData, HintGroup, HintInfo};
|
||||
use glam::{DAffine2, DVec2};
|
||||
@@ -176,9 +176,7 @@ impl MessageHandler<NavigationMessage, NavigationMessageContext<'_>> for Navigat
|
||||
}
|
||||
NavigationMessage::CanvasPanMouseWheel { use_y_as_x } => {
|
||||
// On Mac, the OS already converts Shift+scroll into horizontal scrolling
|
||||
let keyboard_platform = GLOBAL_PLATFORM.get().copied().unwrap_or_default().as_keyboard_platform_layout();
|
||||
|
||||
let delta = if use_y_as_x && keyboard_platform == KeyboardPlatformLayout::Standard {
|
||||
let delta = if use_y_as_x && !Editor::environment().is_mac() {
|
||||
(ipp.mouse.scroll_delta.y, 0.).into()
|
||||
} else {
|
||||
ipp.mouse.scroll_delta.as_dvec2()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::document::utility_types::document_metadata::LayerNodeIdentifier;
|
||||
use super::document::utility_types::network_interface;
|
||||
use super::utility_types::{PanelType, PersistentData};
|
||||
use crate::application::generate_uuid;
|
||||
use crate::application::{Editor, generate_uuid};
|
||||
use crate::consts::{DEFAULT_DOCUMENT_NAME, DEFAULT_STROKE_WIDTH, FILE_EXTENSION};
|
||||
use crate::messages::animation::TimingInformation;
|
||||
use crate::messages::clipboard::utility_types::ClipboardContent;
|
||||
@@ -101,9 +101,17 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
|
||||
|
||||
// Messages
|
||||
PortfolioMessage::Init => {
|
||||
// Initialize the frontend with environment information
|
||||
responses.add(FrontendMessage::UpdatePlatform {
|
||||
platform: Editor::environment().into(),
|
||||
});
|
||||
|
||||
// Tell frontend to load persistent preferences
|
||||
responses.add(FrontendMessage::TriggerLoadPreferences);
|
||||
|
||||
// Before loading any documents, initially prepare the welcome screen buttons layout
|
||||
responses.add(PortfolioMessage::RequestWelcomeScreenButtonsLayout);
|
||||
|
||||
// Tell frontend to load the current document
|
||||
responses.add(FrontendMessage::TriggerLoadFirstAutoSaveDocument);
|
||||
|
||||
@@ -128,15 +136,13 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
|
||||
shortcut: action_shortcut_manual!(Key::Shift, Key::MouseLeft),
|
||||
});
|
||||
|
||||
// Before loading any documents, initially prepare the welcome screen buttons layout
|
||||
responses.add(PortfolioMessage::RequestWelcomeScreenButtonsLayout);
|
||||
|
||||
// Request status bar info layout
|
||||
responses.add(PortfolioMessage::RequestStatusBarInfoLayout);
|
||||
|
||||
// Tell frontend to finish loading persistent documents
|
||||
responses.add(FrontendMessage::TriggerLoadRestAutoSaveDocuments);
|
||||
|
||||
// Tell frontend to load documented passed in as launch arguments
|
||||
responses.add(FrontendMessage::TriggerOpenLaunchDocuments);
|
||||
}
|
||||
PortfolioMessage::DocumentPassMessage { document_id, message } => {
|
||||
|
||||
@@ -82,37 +82,6 @@ impl FontCatalogStyle {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Copy, Default, Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub enum Platform {
|
||||
#[default]
|
||||
Unknown,
|
||||
Windows,
|
||||
Mac,
|
||||
Linux,
|
||||
}
|
||||
|
||||
impl Platform {
|
||||
pub fn as_keyboard_platform_layout(&self) -> KeyboardPlatformLayout {
|
||||
match self {
|
||||
Platform::Mac => KeyboardPlatformLayout::Mac,
|
||||
Platform::Windows | Platform::Linux => KeyboardPlatformLayout::Standard,
|
||||
Platform::Unknown => {
|
||||
warn!("The platform has not been set, remember to send `GlobalsMessage::SetPlatform` during editor initialization.");
|
||||
KeyboardPlatformLayout::Standard
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Copy, Default, Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub enum KeyboardPlatformLayout {
|
||||
/// Standard keyboard mapping used by Windows and Linux
|
||||
#[default]
|
||||
Standard,
|
||||
/// Keyboard mapping used by Macs where Command is sometimes used in favor of Control
|
||||
Mac,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Copy, Debug, Default, serde::Serialize, serde::Deserialize)]
|
||||
pub enum PanelType {
|
||||
#[default]
|
||||
|
||||
Reference in New Issue
Block a user