mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-21 05:28:13 +08:00
Export current document as SVG when pressing Ctrl+Shift+S (#160)
* Export current document when pressing Ctrl+Shift+S * Use a blob for download * Add Ctrl + E shortcut, match on lower case * Don't mount element in DOM * Polish some keybindings * Add initialization for MappingEntries * Implement svg coloring * Add newline after svg tag * Add spaces to svg style format * Fix more svg formatting * Add space before /> * Remove duplicate whitespace
This commit is contained in:
@@ -15,6 +15,7 @@ pub enum DocumentMessage {
|
||||
ToggleLayerVisibility(Vec<LayerId>),
|
||||
ToggleLayerExpansion(Vec<LayerId>),
|
||||
SelectDocument(usize),
|
||||
ExportDocument,
|
||||
RenderDocument,
|
||||
Undo,
|
||||
}
|
||||
@@ -69,6 +70,17 @@ impl MessageHandler<DocumentMessage, ()> for DocumentMessageHandler {
|
||||
assert!(id < self.documents.len(), "Tried to select a document that was not initialized");
|
||||
self.active_document = id;
|
||||
}
|
||||
ExportDocument => responses.push_back(
|
||||
FrontendMessage::ExportDocument {
|
||||
//TODO: Add canvas size instead of using 1080p per default
|
||||
document: format!(
|
||||
r#"<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1920 1080">{}{}</svg>"#,
|
||||
"\n",
|
||||
self.active_document_mut().document.render_root(),
|
||||
),
|
||||
}
|
||||
.into(),
|
||||
),
|
||||
ToggleLayerVisibility(path) => {
|
||||
responses.push_back(DocumentOperation::ToggleVisibility { path }.into());
|
||||
}
|
||||
@@ -96,5 +108,5 @@ impl MessageHandler<DocumentMessage, ()> for DocumentMessageHandler {
|
||||
message => todo!("document_action_handler does not implement: {}", message.to_discriminant().global_name()),
|
||||
}
|
||||
}
|
||||
advertise_actions!(DocumentMessageDiscriminant; Undo, RenderDocument);
|
||||
advertise_actions!(DocumentMessageDiscriminant; Undo, RenderDocument, ExportDocument);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ pub enum FrontendMessage {
|
||||
ExpandFolder { path: Vec<LayerId>, children: Vec<LayerPanelEntry> },
|
||||
SetActiveTool { tool_name: String },
|
||||
UpdateCanvas { document: String },
|
||||
ExportDocument { document: String },
|
||||
EnableTextInput,
|
||||
DisableTextInput,
|
||||
}
|
||||
|
||||
@@ -37,6 +37,14 @@ impl KeyMappingEntries {
|
||||
fn push(&mut self, entry: MappingEntry) {
|
||||
self.0.push(entry)
|
||||
}
|
||||
|
||||
fn key_array() -> [Self; NUMBER_OF_KEYS] {
|
||||
let mut array: [KeyMappingEntries; NUMBER_OF_KEYS] = unsafe { std::mem::zeroed() };
|
||||
for key in array.iter_mut() {
|
||||
*key = KeyMappingEntries::default();
|
||||
}
|
||||
array
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -52,7 +60,7 @@ macro_rules! modifiers {
|
||||
let mut state = KeyStates::new();
|
||||
$(
|
||||
state.set(Key::$m as usize);
|
||||
),*
|
||||
)*
|
||||
state
|
||||
}};
|
||||
}
|
||||
@@ -70,8 +78,8 @@ macro_rules! entry {
|
||||
macro_rules! mapping {
|
||||
//[$(<action=$action:expr; message=$key:expr; $(modifiers=[$($m:ident),* $(,)?];)?>)*] => {{
|
||||
[$($entry:expr),* $(,)?] => {{
|
||||
let mut up: [KeyMappingEntries; NUMBER_OF_KEYS] = Default::default();
|
||||
let mut down: [KeyMappingEntries; NUMBER_OF_KEYS] = Default::default();
|
||||
let mut up = KeyMappingEntries::key_array();
|
||||
let mut down = KeyMappingEntries::key_array();
|
||||
let mut pointer_move: KeyMappingEntries = Default::default();
|
||||
$(
|
||||
let arr = match $entry.trigger {
|
||||
@@ -98,8 +106,6 @@ impl Default for Mapping {
|
||||
entry! {action=RectangleMessage::Abort, key_down=KeyEscape},
|
||||
entry! {action=RectangleMessage::LockAspectRatio, key_down=KeyShift},
|
||||
entry! {action=RectangleMessage::UnlockAspectRatio, key_up=KeyShift},
|
||||
entry! {action=RectangleMessage::LockAspectRatio, key_down=KeyCaps},
|
||||
entry! {action=RectangleMessage::UnlockAspectRatio, key_up=KeyCaps},
|
||||
// Ellipse
|
||||
entry! {action=EllipseMessage::Center, key_down=KeyAlt},
|
||||
entry! {action=EllipseMessage::UnCenter, key_up=KeyAlt},
|
||||
@@ -110,8 +116,6 @@ impl Default for Mapping {
|
||||
entry! {action=EllipseMessage::Abort, key_down=KeyEscape},
|
||||
entry! {action=EllipseMessage::LockAspectRatio, key_down=KeyShift},
|
||||
entry! {action=EllipseMessage::UnlockAspectRatio, key_up=KeyShift},
|
||||
entry! {action=EllipseMessage::LockAspectRatio, key_down=KeyCaps},
|
||||
entry! {action=EllipseMessage::UnlockAspectRatio, key_up=KeyCaps},
|
||||
// Shape
|
||||
entry! {action=ShapeMessage::Center, key_down=KeyAlt},
|
||||
entry! {action=ShapeMessage::UnCenter, key_up=KeyAlt},
|
||||
@@ -122,8 +126,6 @@ impl Default for Mapping {
|
||||
entry! {action=ShapeMessage::Abort, key_down=KeyEscape},
|
||||
entry! {action=ShapeMessage::LockAspectRatio, key_down=KeyShift},
|
||||
entry! {action=ShapeMessage::UnlockAspectRatio, key_up=KeyShift},
|
||||
entry! {action=ShapeMessage::LockAspectRatio, key_down=KeyCaps},
|
||||
entry! {action=ShapeMessage::UnlockAspectRatio, key_up=KeyCaps},
|
||||
// Line
|
||||
entry! {action=LineMessage::Center, key_down=KeyAlt},
|
||||
entry! {action=LineMessage::UnCenter, key_up=KeyAlt},
|
||||
@@ -136,8 +138,6 @@ impl Default for Mapping {
|
||||
entry! {action=LineMessage::UnlockAngle, key_up=KeyControl},
|
||||
entry! {action=LineMessage::SnapToAngle, key_down=KeyShift},
|
||||
entry! {action=LineMessage::UnSnapToAngle, key_up=KeyShift},
|
||||
entry! {action=LineMessage::SnapToAngle, key_down=KeyCaps},
|
||||
entry! {action=LineMessage::UnSnapToAngle, key_up=KeyCaps},
|
||||
// Pen
|
||||
entry! {action=PenMessage::MouseMove, message=InputMapperMessage::PointerMove},
|
||||
entry! {action=PenMessage::DragStart, key_down=Lmb},
|
||||
@@ -147,6 +147,8 @@ impl Default for Mapping {
|
||||
entry! {action=PenMessage::Confirm, key_down=KeyEnter},
|
||||
// Document Actions
|
||||
entry! {action=DocumentMessage::Undo, key_down=KeyZ, modifiers=[KeyControl]},
|
||||
entry! {action=DocumentMessage::ExportDocument, key_down=KeyS, modifiers=[KeyControl, KeyShift]},
|
||||
entry! {action=DocumentMessage::ExportDocument, key_down=KeyE, modifiers=[KeyControl]},
|
||||
// Tool Actions
|
||||
entry! {action=ToolMessage::SelectTool(ToolType::Rectangle), key_down=KeyM},
|
||||
entry! {action=ToolMessage::SelectTool(ToolType::Ellipse), key_down=KeyE},
|
||||
|
||||
@@ -16,16 +16,32 @@ pub enum Key {
|
||||
Mmb,
|
||||
|
||||
// Keyboard keys
|
||||
KeyR,
|
||||
KeyM,
|
||||
KeyA,
|
||||
KeyB,
|
||||
KeyC,
|
||||
KeyD,
|
||||
KeyE,
|
||||
KeyF,
|
||||
KeyG,
|
||||
KeyH,
|
||||
KeyI,
|
||||
KeyJ,
|
||||
KeyK,
|
||||
KeyL,
|
||||
KeyM,
|
||||
KeyN,
|
||||
KeyO,
|
||||
KeyP,
|
||||
KeyQ,
|
||||
KeyR,
|
||||
KeyS,
|
||||
KeyT,
|
||||
KeyU,
|
||||
KeyV,
|
||||
KeyW,
|
||||
KeyX,
|
||||
KeyZ,
|
||||
KeyY,
|
||||
KeyEnter,
|
||||
KeyZ,
|
||||
Key0,
|
||||
Key1,
|
||||
Key2,
|
||||
@@ -36,8 +52,8 @@ pub enum Key {
|
||||
Key7,
|
||||
Key8,
|
||||
Key9,
|
||||
KeyEnter,
|
||||
KeyShift,
|
||||
KeyCaps,
|
||||
KeyControl,
|
||||
KeyAlt,
|
||||
KeyEscape,
|
||||
|
||||
Reference in New Issue
Block a user