mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-17 23:38:06 +08:00
Migrate dialogs to Rust and add a New File dialog (#623)
* Migrate coming soon and about dialog to Rust * Migrate confirm close and close all * Migrate dialog error * Improve keyboard navigation throughout UI * Cleanup and fix panic dialog * Reduce css spacing to better match old dialogs * Add new document modal * Fix crash when generating default name * Populate rust about graphite data on startup * Code review changes * Move one more :focus CSS rule into App.vue * Add a dialog message and move dialogs * Split out keyboard input navigation from this branch * Improvements including simplifying panic dialog code Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
committed by
Keavon Chambers
parent
7729b6219e
commit
f177f63217
@@ -509,7 +509,7 @@ impl DocumentMessageHandler {
|
||||
|
||||
pub fn load_default_font(&self, responses: &mut VecDeque<Message>) {
|
||||
if !self.graphene_document.font_cache.has_default() {
|
||||
responses.push_back(FrontendMessage::TriggerDefaultFontLoad.into())
|
||||
responses.push_back(FrontendMessage::TriggerFontLoadDefault.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -536,7 +536,7 @@ impl PropertyHolder for DocumentMessageHandler {
|
||||
checked: true,
|
||||
icon: "Grid".into(),
|
||||
tooltip: "Grid".into(),
|
||||
on_update: WidgetCallback::new(|_| FrontendMessage::DisplayDialogComingSoon { issue: Some(318) }.into()),
|
||||
on_update: WidgetCallback::new(|_| DialogMessage::RequestComingSoonDialog { issue: Some(318) }.into()),
|
||||
})),
|
||||
WidgetHolder::new(Widget::PopoverButton(PopoverButton {
|
||||
title: "Grid".into(),
|
||||
@@ -581,7 +581,7 @@ impl PropertyHolder for DocumentMessageHandler {
|
||||
value: "pixels".into(),
|
||||
icon: "ViewModePixels".into(),
|
||||
tooltip: "View Mode: Pixels".into(),
|
||||
on_update: WidgetCallback::new(|_| FrontendMessage::DisplayDialogComingSoon { issue: Some(320) }.into()),
|
||||
on_update: WidgetCallback::new(|_| DialogMessage::RequestComingSoonDialog { issue: Some(320) }.into()),
|
||||
..RadioEntryData::default()
|
||||
},
|
||||
],
|
||||
|
||||
@@ -21,7 +21,6 @@ pub enum PortfolioMessage {
|
||||
},
|
||||
CloseActiveDocumentWithConfirmation,
|
||||
CloseAllDocuments,
|
||||
CloseAllDocumentsWithConfirmation,
|
||||
CloseDocument {
|
||||
document_id: u64,
|
||||
},
|
||||
@@ -35,6 +34,9 @@ pub enum PortfolioMessage {
|
||||
clipboard: Clipboard,
|
||||
},
|
||||
NewDocument,
|
||||
NewDocumentWithName {
|
||||
name: String,
|
||||
},
|
||||
NextDocument,
|
||||
OpenDocument,
|
||||
OpenDocumentFile {
|
||||
@@ -59,11 +61,10 @@ pub enum PortfolioMessage {
|
||||
data: String,
|
||||
},
|
||||
PrevDocument,
|
||||
RequestAboutGraphiteDialog,
|
||||
SelectDocument {
|
||||
document_id: u64,
|
||||
},
|
||||
SetActiveDcoument {
|
||||
SetActiveDocument {
|
||||
document_id: u64,
|
||||
},
|
||||
UpdateDocumentBar,
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::frontend::utility_types::FrontendDocumentDetails;
|
||||
use crate::input::InputPreprocessorMessageHandler;
|
||||
use crate::layout::layout_message::LayoutTarget;
|
||||
use crate::layout::widgets::PropertyHolder;
|
||||
use crate::message_prelude::*;
|
||||
use crate::{dialog, message_prelude::*};
|
||||
|
||||
use graphene::Operation as DocumentOperation;
|
||||
|
||||
@@ -29,14 +29,13 @@ impl PortfolioMessageHandler {
|
||||
self.documents.get_mut(&self.active_document_id).unwrap()
|
||||
}
|
||||
|
||||
fn generate_new_document_name(&self) -> String {
|
||||
pub fn generate_new_document_name(&self) -> String {
|
||||
let mut doc_title_numbers = self
|
||||
.ordered_document_iterator()
|
||||
.map(|doc| {
|
||||
.filter_map(|doc| {
|
||||
doc.name
|
||||
.rsplit_once(DEFAULT_DOCUMENT_NAME)
|
||||
.map(|(prefix, number)| (prefix.is_empty()).then(|| number.trim().parse::<isize>().ok()).flatten().unwrap_or(1))
|
||||
.unwrap()
|
||||
})
|
||||
.collect::<Vec<isize>>();
|
||||
|
||||
@@ -168,9 +167,6 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessorMessageHandler> for Port
|
||||
// Create a new blank document
|
||||
responses.push_back(NewDocument.into());
|
||||
}
|
||||
CloseAllDocumentsWithConfirmation => {
|
||||
responses.push_back(FrontendMessage::DisplayConfirmationToCloseAllDocuments.into());
|
||||
}
|
||||
CloseDocument { document_id } => {
|
||||
let document_index = self.document_index(document_id);
|
||||
self.documents.remove(&document_id);
|
||||
@@ -222,7 +218,13 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessorMessageHandler> for Port
|
||||
responses.push_back(ToolMessage::AbortCurrentTool.into());
|
||||
responses.push_back(PortfolioMessage::CloseDocument { document_id }.into());
|
||||
} else {
|
||||
responses.push_back(FrontendMessage::DisplayConfirmationToCloseDocument { document_id }.into());
|
||||
let dialog = dialog::CloseDocument {
|
||||
document_name: target_document.name.clone(),
|
||||
document_id,
|
||||
};
|
||||
dialog.register_properties(responses, LayoutTarget::DialogDetails);
|
||||
responses.push_back(FrontendMessage::DisplayDialog { icon: "File".to_string() }.into());
|
||||
|
||||
// Select the document being closed
|
||||
responses.push_back(PortfolioMessage::SelectDocument { document_id }.into());
|
||||
}
|
||||
@@ -266,6 +268,12 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessorMessageHandler> for Port
|
||||
responses.push_back(ToolMessage::AbortCurrentTool.into());
|
||||
self.load_document(new_document, document_id, false, responses);
|
||||
}
|
||||
NewDocumentWithName { name } => {
|
||||
let new_document = DocumentMessageHandler::with_name(name, ipp);
|
||||
let document_id = generate_uuid();
|
||||
responses.push_back(ToolMessage::AbortCurrentTool.into());
|
||||
self.load_document(new_document, document_id, false, responses);
|
||||
}
|
||||
NextDocument => {
|
||||
let current_index = self.document_index(self.active_document_id);
|
||||
let next_index = (current_index + 1) % self.document_ids.len();
|
||||
@@ -303,7 +311,7 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessorMessageHandler> for Port
|
||||
self.load_document(document, document_id, true, responses);
|
||||
}
|
||||
Err(e) => responses.push_back(
|
||||
FrontendMessage::DisplayDialogError {
|
||||
DialogMessage::DisplayDialogError {
|
||||
title: "Failed to open document".to_string(),
|
||||
description: e.to_string(),
|
||||
}
|
||||
@@ -408,16 +416,14 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessorMessageHandler> for Port
|
||||
let prev_id = self.document_ids[prev_index];
|
||||
responses.push_back(PortfolioMessage::SelectDocument { document_id: prev_id }.into());
|
||||
}
|
||||
RequestAboutGraphiteDialog => {
|
||||
responses.push_back(FrontendMessage::DisplayDialogAboutGraphite.into());
|
||||
}
|
||||
|
||||
SelectDocument { document_id } => {
|
||||
let active_document = self.active_document();
|
||||
if !active_document.is_saved() {
|
||||
responses.push_back(PortfolioMessage::AutoSaveDocument { document_id: self.active_document_id }.into());
|
||||
}
|
||||
responses.push_back(ToolMessage::AbortCurrentTool.into());
|
||||
responses.push_back(SetActiveDcoument { document_id }.into());
|
||||
responses.push_back(SetActiveDocument { document_id }.into());
|
||||
|
||||
responses.push_back(FrontendMessage::UpdateActiveDocument { document_id }.into());
|
||||
responses.push_back(RenderDocument.into());
|
||||
@@ -428,7 +434,7 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessorMessageHandler> for Port
|
||||
responses.push_back(ToolMessage::DocumentIsDirty.into());
|
||||
responses.push_back(PortfolioMessage::UpdateDocumentBar.into());
|
||||
}
|
||||
SetActiveDcoument { document_id } => {
|
||||
SetActiveDocument { document_id } => {
|
||||
self.active_document_id = document_id;
|
||||
}
|
||||
UpdateDocumentBar => {
|
||||
@@ -457,7 +463,6 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessorMessageHandler> for Port
|
||||
let mut common = actions!(PortfolioMessageDiscriminant;
|
||||
NewDocument,
|
||||
CloseActiveDocumentWithConfirmation,
|
||||
CloseAllDocumentsWithConfirmation,
|
||||
CloseAllDocuments,
|
||||
NextDocument,
|
||||
PrevDocument,
|
||||
|
||||
Reference in New Issue
Block a user