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 editor/src/messages/input_mapper/input_mappings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ pub fn input_mappings(zoom_with_scroll: bool) -> Mapping {
//
// DocumentMessage
entry!(KeyDown(Space); modifiers=[Control], action_dispatch=DocumentMessage::GraphViewOverlayToggle),
entry!(KeyDown(KeyQ); action_dispatch=DocumentMessage::ToggleDocumentMode),
entry!(KeyDownNoRepeat(Escape); action_dispatch=DocumentMessage::Escape),
entry!(KeyDown(Delete); action_dispatch=DocumentMessage::DeleteSelectedLayers),
entry!(KeyDown(Backspace); action_dispatch=DocumentMessage::DeleteSelectedLayers),
Expand Down
6 changes: 5 additions & 1 deletion editor/src/messages/portfolio/document/document_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::messages::input_mapper::utility_types::input_keyboard::Key;
use crate::messages::portfolio::document::data_panel::DataPanelMessage;
use crate::messages::portfolio::document::overlays::utility_types::{OverlayContext, OverlaysType};
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
use crate::messages::portfolio::document::utility_types::misc::{AlignAggregate, AlignAxis, FlipAxis, GridSnapping};
use crate::messages::portfolio::document::utility_types::misc::{AlignAggregate, AlignAxis, DocumentMode, FlipAxis, GridSnapping};
use crate::messages::portfolio::utility_types::PanelType;
use crate::messages::prelude::*;
use glam::{DAffine2, IVec2};
Expand Down Expand Up @@ -187,6 +187,10 @@ pub enum DocumentMessage {
SetRenderMode {
render_mode: RenderMode,
},
ToggleDocumentMode,
SetDocumentMode {
document_mode: DocumentMode,
},
AddTransaction,
StartTransaction,
EndTransaction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::messages::portfolio::document::overlays::grid_overlays::{grid_overlay
use crate::messages::portfolio::document::overlays::utility_types::{OverlaysType, OverlaysVisibilitySettings, Pivot};
use crate::messages::portfolio::document::properties_panel::properties_panel_message_handler::PropertiesPanelMessageContext;
use crate::messages::portfolio::document::utility_types::document_metadata::{DocumentMetadata, LayerNodeIdentifier};
use crate::messages::portfolio::document::utility_types::misc::{AlignAggregate, AlignAxis, FlipAxis, PTZ};
use crate::messages::portfolio::document::utility_types::misc::{AlignAggregate, AlignAxis, DocumentMode, FlipAxis, PTZ};
use crate::messages::portfolio::document::utility_types::network_interface::{FlowType, InputConnector, NodeTemplate};
use crate::messages::portfolio::utility_types::{PanelType, PersistentData};
use crate::messages::prelude::*;
Expand Down Expand Up @@ -115,6 +115,9 @@ pub struct DocumentMessageHandler {
/// The name of the document, which is displayed in the tab and title bar of the editor.
#[serde(skip)]
pub name: String,
/// The current editor-only mode for the active document.
#[serde(skip)]
pub document_mode: DocumentMode,
/// The path of the to the document file.
#[serde(skip)]
pub(crate) path: Option<PathBuf>,
Expand Down Expand Up @@ -173,6 +176,7 @@ impl Default for DocumentMessageHandler {
// Fields omitted from the saved document format
// =============================================
name: DEFAULT_DOCUMENT_NAME.to_string(),
document_mode: DocumentMode::default(),
path: None,
breadcrumb_network_path: Vec::new(),
selection_network_path: Vec::new(),
Expand Down Expand Up @@ -1108,6 +1112,15 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
self.render_mode = render_mode;
responses.add_front(NodeGraphMessage::RunDocumentGraph);
}
DocumentMessage::ToggleDocumentMode => {
self.document_mode = match self.document_mode {
DocumentMode::MaskMode => DocumentMode::DesignMode,
_ => DocumentMode::MaskMode,
};
}
DocumentMessage::SetDocumentMode { document_mode } => {
self.document_mode = document_mode;
}
Comment on lines +1115 to +1123
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When changing the document_mode, it is important to notify the frontend so that any UI elements (like the status bar or document bar) can refresh their state. Even if no UI currently displays this mode, adding PortfolioMessage::UpdateDocumentWidgets ensures consistency with how other document-level states (like render mode or snapping) are handled.

			DocumentMessage::ToggleDocumentMode => {
				self.document_mode = match self.document_mode {
					DocumentMode::MaskMode => DocumentMode::DesignMode,
					_ => DocumentMode::MaskMode,
				};
				responses.add(PortfolioMessage::UpdateDocumentWidgets);
			}
			DocumentMessage::SetDocumentMode { document_mode } => {
				if self.document_mode != document_mode {
					self.document_mode = document_mode;
					responses.add(PortfolioMessage::UpdateDocumentWidgets);
				}
			}

DocumentMessage::AddTransaction => {
// Reverse order since they are added to the front
responses.add_front(DocumentMessage::CommitTransaction);
Expand Down Expand Up @@ -1463,6 +1476,8 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
SaveDocument,
SelectAllLayers,
SetSnapping,
ToggleDocumentMode,
SetDocumentMode,
ToggleGridVisibility,
ToggleOverlaysVisibility,
ToggleSnapping,
Expand Down
17 changes: 10 additions & 7 deletions editor/src/messages/portfolio/document/utility_types/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,23 @@ pub enum AlignAggregate {
Center,
}

// #[derive(Default, PartialEq, Eq, Clone, Copy, Debug, serde::Serialize, serde::Deserialize)]
// pub enum DocumentMode {
// #[default]
// DesignMode,
// SelectMode,
// GuideMode,
// }
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
#[derive(Default, PartialEq, Eq, Clone, Copy, Debug, serde::Serialize, serde::Deserialize)]
pub enum DocumentMode {
#[default]
DesignMode,
SelectMode,
GuideMode,
MaskMode,
}

// impl fmt::Display for DocumentMode {
// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// match self {
// DocumentMode::DesignMode => write!(f, "Design Mode"),
// DocumentMode::SelectMode => write!(f, "Select Mode"),
// DocumentMode::GuideMode => write!(f, "Guide Mode"),
// DocumentMode::MaskMode => write!(f, "Mask Mode"),
// }
// }
// }
Comment on lines 41 to 50
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The Display implementation for DocumentMode is currently commented out. Since the enum is now active and being used for groundwork, it is better to enable this implementation and ensure it includes the new MaskMode variant. This avoids leaving dead code in the repository.

Suggested change
// impl fmt::Display for DocumentMode {
// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// match self {
// DocumentMode::DesignMode => write!(f, "Design Mode"),
// DocumentMode::SelectMode => write!(f, "Select Mode"),
// DocumentMode::GuideMode => write!(f, "Guide Mode"),
// DocumentMode::MaskMode => write!(f, "Mask Mode"),
// }
// }
// }
impl fmt::Display for DocumentMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
DocumentMode::DesignMode => write!(f, "Design Mode"),
DocumentMode::SelectMode => write!(f, "Select Mode"),
DocumentMode::GuideMode => write!(f, "Guide Mode"),
DocumentMode::MaskMode => write!(f, "Mask Mode"),
}
}
}

Expand Down
Loading