mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-12-23 10:11:54 +00: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:
parent
e54fedc6a5
commit
720a04b501
2 changed files with 32 additions and 30 deletions
|
|
@ -150,6 +150,36 @@ impl From<DocumentOperation> for Message {
|
|||
}
|
||||
|
||||
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> {
|
||||
if self.graphene_document.layer(path).ok()?.overlay {
|
||||
return None;
|
||||
|
|
@ -307,34 +337,6 @@ impl DocumentMessageHandler {
|
|||
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 {
|
||||
layer_data(&mut self.layer_data, path)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -199,14 +199,14 @@ impl MessageHandler<DocumentsMessage, &InputPreprocessor> for DocumentsMessageHa
|
|||
}
|
||||
NewDocument => {
|
||||
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);
|
||||
}
|
||||
OpenDocument => {
|
||||
responses.push_back(FrontendMessage::OpenDocumentBrowse.into());
|
||||
}
|
||||
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 {
|
||||
Ok(document) => {
|
||||
self.load_document(document, responses);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue