Menu bar definition in backend (#681)

* initial menu layout working

* removed api.rs functions

* no action shortcut for no-op

* code review

* nitpicks
This commit is contained in:
mfish33 2022-06-18 18:46:23 -06:00 committed by Keavon Chambers
parent 9bd27ec3f8
commit 5d6d2b22bc
35 changed files with 781 additions and 475 deletions

View file

@ -117,6 +117,9 @@ impl JsEditorHandle {
let message = MovementMessage::TranslateCanvas { delta: (0., 0.).into() };
self.dispatch(message);
let message = MenuBarMessage::SendLayout;
self.dispatch(message);
}
/// Displays a dialog with an error message
@ -125,11 +128,6 @@ impl JsEditorHandle {
self.dispatch(message);
}
/// Intentionally panic for debugging purposes
pub fn intentional_panic(&self) {
panic!();
}
/// Answer whether or not the editor has crashed
pub fn has_crashed(&self) -> bool {
EDITOR_HAS_CRASHED.load(Ordering::SeqCst)
@ -147,23 +145,6 @@ impl JsEditorHandle {
GRAPHITE_DOCUMENT_VERSION.to_string()
}
/// Get the constant `i32::MAX`
#[wasm_bindgen]
pub fn i32_max(&self) -> i32 {
i32::MAX
}
/// Get the constant `i32::MIN`
#[wasm_bindgen]
pub fn i32_min(&self) -> i32 {
i32::MIN
}
/// Request that the Node Graph panel be shown or hidden by toggling the visibility state
pub fn toggle_node_graph_visibility(&self) {
self.dispatch(WorkspaceMessage::NodeGraphToggleVisibility);
}
/// Update layout of a given UI
pub fn update_layout(&self, layout_target: JsValue, widget_id: u64, value: JsValue) -> Result<(), JsValue> {
match (from_value(layout_target), from_value(value)) {
@ -181,16 +162,6 @@ impl JsEditorHandle {
self.dispatch(message);
}
pub fn request_new_document_dialog(&self) {
let message = DialogMessage::RequestNewDocumentDialog;
self.dispatch(message);
}
pub fn open_document(&self) {
let message = PortfolioMessage::OpenDocument;
self.dispatch(message);
}
pub fn open_document_file(&self, document_name: String, document_serialized_content: String) {
let message = PortfolioMessage::OpenDocumentFile {
document_name,
@ -209,49 +180,16 @@ impl JsEditorHandle {
self.dispatch(message);
}
pub fn save_document(&self) {
let message = DocumentMessage::SaveDocument;
self.dispatch(message);
}
pub fn trigger_auto_save(&self, document_id: u64) {
let message = PortfolioMessage::AutoSaveDocument { document_id };
self.dispatch(message);
}
pub fn close_document(&self, document_id: u64) {
let message = ToolMessage::AbortCurrentTool;
self.dispatch(message);
let message = PortfolioMessage::CloseDocument { document_id };
self.dispatch(message);
}
pub fn close_all_documents(&self) {
let message = PortfolioMessage::CloseAllDocuments;
self.dispatch(message);
}
pub fn close_active_document_with_confirmation(&self) {
let message = PortfolioMessage::CloseActiveDocumentWithConfirmation;
self.dispatch(message);
}
pub fn close_document_with_confirmation(&self, document_id: u64) {
let message = PortfolioMessage::CloseDocumentWithConfirmation { document_id };
self.dispatch(message);
}
pub fn close_all_documents_with_confirmation(&self) {
let message = DialogMessage::CloseAllDocumentsWithConfirmation;
self.dispatch(message);
}
pub fn request_about_graphite_dialog(&self) {
let message = DialogMessage::RequestAboutGraphiteDialog;
self.dispatch(message);
}
pub fn request_about_graphite_dialog_with_localized_commit_date(&self, localized_commit_date: String) {
let message = DialogMessage::RequestAboutGraphiteDialogWithLocalizedCommitDate { localized_commit_date };
self.dispatch(message);
@ -262,21 +200,6 @@ impl JsEditorHandle {
self.dispatch(message);
}
pub fn log_level_info(&self) {
let message = GlobalMessage::LogInfo;
self.dispatch(message);
}
pub fn log_level_debug(&self) {
let message = GlobalMessage::LogDebug;
self.dispatch(message);
}
pub fn log_level_trace(&self) {
let message = GlobalMessage::LogTrace;
self.dispatch(message);
}
/// Send new bounds when document panel viewports get resized or moved within the editor
/// [left, top, right, bottom]...
pub fn bounds_of_viewports(&self, bounds_of_viewports: &[f64]) {
@ -426,30 +349,6 @@ impl JsEditorHandle {
self.dispatch(message);
}
/// Undo history one step
pub fn undo(&self) {
let message = DocumentMessage::Undo;
self.dispatch(message);
}
/// Redo history one step
pub fn redo(&self) {
let message = DocumentMessage::Redo;
self.dispatch(message);
}
/// Cut selected layers
pub fn cut(&self) {
let message = PortfolioMessage::Cut { clipboard: Clipboard::Device };
self.dispatch(message);
}
/// Copy selected layers
pub fn copy(&self) {
let message = PortfolioMessage::Copy { clipboard: Clipboard::Device };
self.dispatch(message);
}
/// Paste layers from a serialized json representation
pub fn paste_serialized_data(&self, data: String) {
let message = PortfolioMessage::PasteSerializedData { data };
@ -462,24 +361,12 @@ impl JsEditorHandle {
self.dispatch(message);
}
/// Select all layers
pub fn select_all_layers(&self) {
let message = DocumentMessage::SelectAllLayers;
self.dispatch(message);
}
/// Deselect all layers
pub fn deselect_all_layers(&self) {
let message = DocumentMessage::DeselectAllLayers;
self.dispatch(message);
}
/// Reorder selected layer
pub fn reorder_selected_layers(&self, relative_index_offset: isize) {
let message = DocumentMessage::ReorderSelectedLayers { relative_index_offset };
self.dispatch(message);
}
/// Move a layer to be next to the specified neighbor
pub fn move_layer_in_tree(&self, folder_path: Vec<LayerId>, insert_index: isize) {
let message = DocumentMessage::MoveSelectedLayersTo {
@ -496,12 +383,6 @@ impl JsEditorHandle {
self.dispatch(message);
}
/// Export the document
pub fn export_document(&self) {
let message = DialogMessage::RequestExportDialog;
self.dispatch(message);
}
/// Translates document (in viewport coords)
pub fn translate_canvas(&self, delta_x: f64, delta_y: f64) {
let message = MovementMessage::TranslateCanvas { delta: (delta_x, delta_y).into() };