mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-01 05:28:11 +08:00
Fix new document position (#421)
* Fix new document pos * All new documents are centered before deserialization * Move constructors to the top of to block * Fix merge (moving coe around is a bad idea) Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
committed by
Keavon Chambers
co-authored by
Keavon Chambers
parent
3fc6e05a12
commit
814b7f697f
@@ -150,6 +150,36 @@ impl From<DocumentOperation> for Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DocumentMessageHandler {
|
impl DocumentMessageHandler {
|
||||||
|
pub fn with_name(name: String, ipp: &InputPreprocessor) -> Self {
|
||||||
|
let mut document = Self {
|
||||||
|
graphene_document: GrapheneDocument::default(),
|
||||||
|
document_undo_history: Vec::new(),
|
||||||
|
document_redo_history: Vec::new(),
|
||||||
|
saved_document_identifier: 0,
|
||||||
|
name,
|
||||||
|
layer_data: vec![(vec![], LayerData::new(true))].into_iter().collect(),
|
||||||
|
layer_range_selection_reference: Vec::new(),
|
||||||
|
movement_handler: MovementMessageHandler::default(),
|
||||||
|
transform_layer_handler: TransformLayerMessageHandler::default(),
|
||||||
|
snapping_enabled: true,
|
||||||
|
};
|
||||||
|
document.graphene_document.root.transform = document.layerdata(&[]).calculate_offset_transform(ipp.viewport_bounds.size() / 2.);
|
||||||
|
document
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_name_and_content(name: String, serialized_content: String, ipp: &InputPreprocessor) -> Result<Self, EditorError> {
|
||||||
|
let mut document = Self::with_name(name, ipp);
|
||||||
|
let internal_document = GrapheneDocument::with_content(&serialized_content);
|
||||||
|
match internal_document {
|
||||||
|
Ok(handle) => {
|
||||||
|
document.graphene_document = handle;
|
||||||
|
Ok(document)
|
||||||
|
}
|
||||||
|
Err(DocumentError::InvalidFile(msg)) => Err(EditorError::Document(msg)),
|
||||||
|
_ => Err(EditorError::Document(String::from("Failed to open file"))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn select_layer(&mut self, path: &[LayerId]) -> Option<Message> {
|
fn select_layer(&mut self, path: &[LayerId]) -> Option<Message> {
|
||||||
if self.graphene_document.layer(path).ok()?.overlay {
|
if self.graphene_document.layer(path).ok()?.overlay {
|
||||||
return None;
|
return None;
|
||||||
@@ -307,34 +337,6 @@ impl DocumentMessageHandler {
|
|||||||
self.layers_sorted(Some(false))
|
self.layers_sorted(Some(false))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_name(name: String) -> Self {
|
|
||||||
Self {
|
|
||||||
graphene_document: GrapheneDocument::default(),
|
|
||||||
document_undo_history: Vec::new(),
|
|
||||||
document_redo_history: Vec::new(),
|
|
||||||
saved_document_identifier: 0,
|
|
||||||
name,
|
|
||||||
layer_data: vec![(vec![], LayerData::new(true))].into_iter().collect(),
|
|
||||||
layer_range_selection_reference: Vec::new(),
|
|
||||||
movement_handler: MovementMessageHandler::default(),
|
|
||||||
transform_layer_handler: TransformLayerMessageHandler::default(),
|
|
||||||
snapping_enabled: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn with_name_and_content(name: String, serialized_content: String) -> Result<Self, EditorError> {
|
|
||||||
let mut document = Self::with_name(name);
|
|
||||||
let internal_document = GrapheneDocument::with_content(&serialized_content);
|
|
||||||
match internal_document {
|
|
||||||
Ok(handle) => {
|
|
||||||
document.graphene_document = handle;
|
|
||||||
Ok(document)
|
|
||||||
}
|
|
||||||
Err(DocumentError::InvalidFile(msg)) => Err(EditorError::Document(msg)),
|
|
||||||
_ => Err(EditorError::Document(String::from("Failed to open file"))),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn layer_data(&mut self, path: &[LayerId]) -> &mut LayerData {
|
pub fn layer_data(&mut self, path: &[LayerId]) -> &mut LayerData {
|
||||||
layer_data(&mut self.layer_data, path)
|
layer_data(&mut self.layer_data, path)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -199,14 +199,14 @@ impl MessageHandler<DocumentsMessage, &InputPreprocessor> for DocumentsMessageHa
|
|||||||
}
|
}
|
||||||
NewDocument => {
|
NewDocument => {
|
||||||
let name = self.generate_new_document_name();
|
let name = self.generate_new_document_name();
|
||||||
let new_document = DocumentMessageHandler::with_name(name);
|
let new_document = DocumentMessageHandler::with_name(name, ipp);
|
||||||
self.load_document(new_document, responses);
|
self.load_document(new_document, responses);
|
||||||
}
|
}
|
||||||
OpenDocument => {
|
OpenDocument => {
|
||||||
responses.push_back(FrontendMessage::OpenDocumentBrowse.into());
|
responses.push_back(FrontendMessage::OpenDocumentBrowse.into());
|
||||||
}
|
}
|
||||||
OpenDocumentFile(name, serialized_contents) => {
|
OpenDocumentFile(name, serialized_contents) => {
|
||||||
let document = DocumentMessageHandler::with_name_and_content(name, serialized_contents);
|
let document = DocumentMessageHandler::with_name_and_content(name, serialized_contents, ipp);
|
||||||
match document {
|
match document {
|
||||||
Ok(document) => {
|
Ok(document) => {
|
||||||
self.load_document(document, responses);
|
self.load_document(document, responses);
|
||||||
|
|||||||
Reference in New Issue
Block a user