Cleanup of variable naming
This commit is contained in:
parent
0656f8abc5
commit
eab498f795
|
|
@ -193,7 +193,7 @@
|
|||
<script lang="ts">
|
||||
import { defineComponent } from "vue";
|
||||
import { makeModifiersBitfield } from "@/utilities/input";
|
||||
import { ResponseType, registerResponseHandler, Response, UpdateCanvas, SetActiveTool, ExportDocument, SetCanvasZoom, SetRotation } from "../../utilities/response-handler";
|
||||
import { ResponseType, registerResponseHandler, Response, UpdateCanvas, SetActiveTool, ExportDocument, SetCanvasZoom, SetCanvasRotation } from "../../utilities/response-handler";
|
||||
import LayoutRow from "../layout/LayoutRow.vue";
|
||||
import LayoutCol from "../layout/LayoutCol.vue";
|
||||
import WorkingColors from "../widgets/WorkingColors.vue";
|
||||
|
|
@ -296,8 +296,8 @@ export default defineComponent({
|
|||
zoomWidget.setValue(updateData.new_zoom * 100);
|
||||
}
|
||||
});
|
||||
registerResponseHandler(ResponseType.SetRotation, (responseData: Response) => {
|
||||
const updateData = responseData as SetRotation;
|
||||
registerResponseHandler(ResponseType.SetCanvasRotation, (responseData: Response) => {
|
||||
const updateData = responseData as SetCanvasRotation;
|
||||
if (updateData) {
|
||||
const rotationWidget = this.$refs.rotation as typeof NumberInput;
|
||||
const newRotation = updateData.new_radians * (180 / Math.PI);
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ import Minimap from "../panels/Minimap.vue";
|
|||
import IconButton from "../widgets/buttons/IconButton.vue";
|
||||
import PopoverButton, { PopoverButtonIcon } from "../widgets/buttons/PopoverButton.vue";
|
||||
import { MenuDirection } from "../widgets/floating-menus/FloatingMenu.vue";
|
||||
import { ResponseType, registerResponseHandler, Response, PromptConfirmationToCloseDocument } from "../../utilities/response-handler";
|
||||
import { ResponseType, registerResponseHandler, Response, DisplayConfirmationToCloseDocument } from "../../utilities/response-handler";
|
||||
|
||||
const wasm = import("../../../wasm/pkg");
|
||||
|
||||
|
|
@ -187,13 +187,11 @@ export default defineComponent({
|
|||
},
|
||||
mounted() {
|
||||
// TODO: Move these somewhere more appropriate to act upon all panels
|
||||
|
||||
registerResponseHandler(ResponseType.PromptConfirmationToCloseDocument, (responseData: Response) => {
|
||||
const promptData = responseData as PromptConfirmationToCloseDocument;
|
||||
this.closeDocumentWithConfirmation(promptData.document_index);
|
||||
registerResponseHandler(ResponseType.DisplayConfirmationToCloseDocument, (responseData: Response) => {
|
||||
const data = responseData as DisplayConfirmationToCloseDocument;
|
||||
this.closeDocumentWithConfirmation(data.document_index);
|
||||
});
|
||||
|
||||
registerResponseHandler(ResponseType.PromptConfirmationToCloseAllDocuments, (_responseData: Response) => {
|
||||
registerResponseHandler(ResponseType.DisplayConfirmationToCloseAllDocuments, (_responseData: Response) => {
|
||||
this.closeAllDocumentsWithConfirmation();
|
||||
});
|
||||
},
|
||||
|
|
|
|||
|
|
@ -65,7 +65,6 @@ export default defineComponent({
|
|||
this.documents = documentListData.open_documents;
|
||||
}
|
||||
});
|
||||
|
||||
registerResponseHandler(ResponseType.SetActiveDocument, (responseData: Response) => {
|
||||
const documentData = responseData as SetActiveDocument;
|
||||
if (documentData) this.activeDocument = documentData.document_index;
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ export enum ResponseType {
|
|||
UpdateOpenDocumentsList = "UpdateOpenDocumentsList",
|
||||
UpdateWorkingColors = "UpdateWorkingColors",
|
||||
SetCanvasZoom = "SetCanvasZoom",
|
||||
SetRotation = "SetRotation",
|
||||
PromptConfirmationToCloseDocument = "PromptConfirmationToCloseDocument",
|
||||
PromptConfirmationToCloseAllDocuments = "PromptConfirmationToCloseAllDocuments",
|
||||
SetCanvasRotation = "SetCanvasRotation",
|
||||
DisplayConfirmationToCloseDocument = "DisplayConfirmationToCloseDocument",
|
||||
DisplayConfirmationToCloseAllDocuments = "DisplayConfirmationToCloseAllDocuments",
|
||||
}
|
||||
|
||||
export function registerResponseHandler(responseType: ResponseType, callback: ResponseCallback) {
|
||||
|
|
@ -62,23 +62,23 @@ function parseResponse(responseType: string, data: any): Response {
|
|||
case "UpdateCanvas":
|
||||
return newUpdateCanvas(data.UpdateCanvas);
|
||||
case "SetCanvasZoom":
|
||||
return newSetZoom(data.SetCanvasZoom);
|
||||
case "SetRotation":
|
||||
return newSetRotation(data.SetRotation);
|
||||
return newSetCanvasZoom(data.SetCanvasZoom);
|
||||
case "SetCanvasRotation":
|
||||
return newSetCanvasRotation(data.SetCanvasRotation);
|
||||
case "ExportDocument":
|
||||
return newExportDocument(data.ExportDocument);
|
||||
case "UpdateWorkingColors":
|
||||
return newUpdateWorkingColors(data.UpdateWorkingColors);
|
||||
case "PromptConfirmationToCloseDocument":
|
||||
return newPromptConfirmationToCloseDocument(data.PromptConfirmationToCloseDocument);
|
||||
case "PromptConfirmationToCloseAllDocuments":
|
||||
return newPromptConfirmationToCloseAllDocuments(data.PromptConfirmationToCloseAllDocuments);
|
||||
case "DisplayConfirmationToCloseDocument":
|
||||
return newDisplayConfirmationToCloseDocument(data.DisplayConfirmationToCloseDocument);
|
||||
case "DisplayConfirmationToCloseAllDocuments":
|
||||
return newDisplayConfirmationToCloseAllDocuments(data.DisplayConfirmationToCloseAllDocuments);
|
||||
default:
|
||||
throw new Error(`Unrecognized origin/responseType pair: ${origin}, '${responseType}'`);
|
||||
}
|
||||
}
|
||||
|
||||
export type Response = SetActiveTool | UpdateCanvas | DocumentChanged | CollapseFolder | ExpandFolder | UpdateWorkingColors | SetCanvasZoom | SetRotation;
|
||||
export type Response = SetActiveTool | UpdateCanvas | DocumentChanged | CollapseFolder | ExpandFolder | UpdateWorkingColors | SetCanvasZoom | SetCanvasRotation;
|
||||
|
||||
export interface UpdateOpenDocumentsList {
|
||||
open_documents: Array<string>;
|
||||
|
|
@ -127,16 +127,16 @@ function newSetActiveDocument(input: any): SetActiveDocument {
|
|||
};
|
||||
}
|
||||
|
||||
export interface PromptConfirmationToCloseDocument {
|
||||
export interface DisplayConfirmationToCloseDocument {
|
||||
document_index: number;
|
||||
}
|
||||
function newPromptConfirmationToCloseDocument(input: any): PromptConfirmationToCloseDocument {
|
||||
function newDisplayConfirmationToCloseDocument(input: any): DisplayConfirmationToCloseDocument {
|
||||
return {
|
||||
document_index: input.document_index,
|
||||
};
|
||||
}
|
||||
|
||||
function newPromptConfirmationToCloseAllDocuments(_input: any): {} {
|
||||
function newDisplayConfirmationToCloseAllDocuments(_input: any): {} {
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
@ -186,16 +186,16 @@ function newExpandFolder(input: any): ExpandFolder {
|
|||
export interface SetCanvasZoom {
|
||||
new_zoom: number;
|
||||
}
|
||||
function newSetZoom(input: any): SetCanvasZoom {
|
||||
function newSetCanvasZoom(input: any): SetCanvasZoom {
|
||||
return {
|
||||
new_zoom: input.new_zoom,
|
||||
};
|
||||
}
|
||||
|
||||
export interface SetRotation {
|
||||
export interface SetCanvasRotation {
|
||||
new_radians: number;
|
||||
}
|
||||
function newSetRotation(input: any): SetRotation {
|
||||
function newSetCanvasRotation(input: any): SetCanvasRotation {
|
||||
return {
|
||||
new_radians: input.new_radians,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ pub fn set_zoom(new_zoom: f64) -> Result<(), JsValue> {
|
|||
/// Sets the rotation to the new value (in radians)
|
||||
#[wasm_bindgen]
|
||||
pub fn set_rotation(new_radians: f64) -> Result<(), JsValue> {
|
||||
let ev = DocumentMessage::SetRotation(new_radians);
|
||||
let ev = DocumentMessage::SetCanvasRotation(new_radians);
|
||||
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(ev)).map_err(convert_error)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ impl Dispatcher {
|
|||
| Message::Document(DocumentMessage::RenderDocument)
|
||||
| Message::Frontend(FrontendMessage::UpdateCanvas { .. })
|
||||
| Message::Frontend(FrontendMessage::SetCanvasZoom { .. })
|
||||
| Message::Frontend(FrontendMessage::SetRotation { .. })
|
||||
| Message::Frontend(FrontendMessage::SetCanvasRotation { .. })
|
||||
| Message::Document(DocumentMessage::DispatchOperation { .. })
|
||||
) || MessageDiscriminant::from(&message).local_name().ends_with("MouseMove"))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ pub enum DocumentMessage {
|
|||
SetCanvasZoom(f64),
|
||||
MultiplyCanvasZoom(f64),
|
||||
WheelCanvasZoom,
|
||||
SetRotation(f64),
|
||||
SetCanvasRotation(f64),
|
||||
NudgeSelectedLayers(f64, f64),
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ impl From<DocumentOperation> for Message {
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct DocumentMessageHandler {
|
||||
documents: Vec<Document>,
|
||||
active_document: usize,
|
||||
active_document_index: usize,
|
||||
translating: bool,
|
||||
rotating: bool,
|
||||
zooming: bool,
|
||||
|
|
@ -80,10 +80,10 @@ pub struct DocumentMessageHandler {
|
|||
|
||||
impl DocumentMessageHandler {
|
||||
pub fn active_document(&self) -> &Document {
|
||||
&self.documents[self.active_document]
|
||||
&self.documents[self.active_document_index]
|
||||
}
|
||||
pub fn active_document_mut(&mut self) -> &mut Document {
|
||||
&mut self.documents[self.active_document]
|
||||
&mut self.documents[self.active_document_index]
|
||||
}
|
||||
fn filter_document_responses(&self, document_responses: &mut Vec<DocumentResponse>) -> bool {
|
||||
let len = document_responses.len();
|
||||
|
|
@ -166,7 +166,7 @@ impl Default for DocumentMessageHandler {
|
|||
fn default() -> Self {
|
||||
Self {
|
||||
documents: vec![Document::default()],
|
||||
active_document: 0,
|
||||
active_document_index: 0,
|
||||
translating: false,
|
||||
rotating: false,
|
||||
zooming: false,
|
||||
|
|
@ -185,15 +185,25 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
|
|||
AddFolder(path) => responses.push_back(DocumentOperation::AddFolder { path }.into()),
|
||||
SelectDocument(id) => {
|
||||
assert!(id < self.documents.len(), "Tried to select a document that was not initialized");
|
||||
self.active_document = id;
|
||||
responses.push_back(FrontendMessage::SetActiveDocument { document_index: self.active_document }.into());
|
||||
self.active_document_index = id;
|
||||
responses.push_back(
|
||||
FrontendMessage::SetActiveDocument {
|
||||
document_index: self.active_document_index,
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
responses.push_back(RenderDocument.into());
|
||||
}
|
||||
CloseActiveDocumentWithConfirmation => {
|
||||
responses.push_back(FrontendMessage::PromptConfirmationToCloseDocument { document_index: self.active_document }.into());
|
||||
responses.push_back(
|
||||
FrontendMessage::DisplayConfirmationToCloseDocument {
|
||||
document_index: self.active_document_index,
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
CloseAllDocumentsWithConfirmation => {
|
||||
responses.push_back(FrontendMessage::PromptConfirmationToCloseAllDocuments.into());
|
||||
responses.push_back(FrontendMessage::DisplayConfirmationToCloseAllDocuments.into());
|
||||
}
|
||||
CloseAllDocuments => {
|
||||
// Empty the list of internal document data
|
||||
|
|
@ -213,19 +223,24 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
|
|||
|
||||
// Last tab was closed, so create a new blank tab
|
||||
if self.documents.is_empty() {
|
||||
self.active_document = 0;
|
||||
self.active_document_index = 0;
|
||||
responses.push_back(DocumentMessage::NewDocument.into());
|
||||
}
|
||||
// The currently selected doc is being closed
|
||||
else if id == self.active_document {
|
||||
else if id == self.active_document_index {
|
||||
// The currently selected tab was the rightmost tab
|
||||
if id == self.documents.len() {
|
||||
self.active_document -= 1;
|
||||
self.active_document_index -= 1;
|
||||
}
|
||||
|
||||
let lp = self.active_document_mut().layer_panel(&[]).expect("Could not get panel for active doc");
|
||||
responses.push_back(FrontendMessage::ExpandFolder { path: Vec::new(), children: lp }.into());
|
||||
responses.push_back(FrontendMessage::SetActiveDocument { document_index: self.active_document }.into());
|
||||
responses.push_back(
|
||||
FrontendMessage::SetActiveDocument {
|
||||
document_index: self.active_document_index,
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
responses.push_back(
|
||||
FrontendMessage::UpdateCanvas {
|
||||
document: self.active_document_mut().document.render_root(),
|
||||
|
|
@ -234,9 +249,14 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
|
|||
);
|
||||
}
|
||||
// Active doc will move one space to the left
|
||||
else if id < self.active_document {
|
||||
self.active_document -= 1;
|
||||
responses.push_back(FrontendMessage::SetActiveDocument { document_index: self.active_document }.into());
|
||||
else if id < self.active_document_index {
|
||||
self.active_document_index -= 1;
|
||||
responses.push_back(
|
||||
FrontendMessage::SetActiveDocument {
|
||||
document_index: self.active_document_index,
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
}
|
||||
NewDocument => {
|
||||
|
|
@ -266,7 +286,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
|
|||
_ => format!("Untitled Document {}", new_doc_title_num),
|
||||
};
|
||||
|
||||
self.active_document = self.documents.len();
|
||||
self.active_document_index = self.documents.len();
|
||||
let new_document = Document::with_name(name);
|
||||
self.documents.push(new_document);
|
||||
|
||||
|
|
@ -281,14 +301,14 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
|
|||
}
|
||||
.into(),
|
||||
);
|
||||
responses.push_back(SelectDocument(self.active_document).into());
|
||||
responses.push_back(SelectDocument(self.active_document_index).into());
|
||||
}
|
||||
NextDocument => {
|
||||
let id = (self.active_document + 1) % self.documents.len();
|
||||
let id = (self.active_document_index + 1) % self.documents.len();
|
||||
responses.push_back(SelectDocument(id).into());
|
||||
}
|
||||
PrevDocument => {
|
||||
let id = (self.active_document + self.documents.len() - 1) % self.documents.len();
|
||||
let id = (self.active_document_index + self.documents.len() - 1) % self.documents.len();
|
||||
responses.push_back(SelectDocument(id).into());
|
||||
}
|
||||
ExportDocument => responses.push_back(
|
||||
|
|
@ -444,7 +464,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
|
|||
layerdata.rotation += rotation;
|
||||
layerdata.snap_rotate = snapping;
|
||||
responses.push_back(
|
||||
FrontendMessage::SetRotation {
|
||||
FrontendMessage::SetCanvasRotation {
|
||||
new_radians: layerdata.snapped_angle(),
|
||||
}
|
||||
.into(),
|
||||
|
|
@ -506,11 +526,11 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
|
|||
layerdata.translation += transformed_delta;
|
||||
self.create_document_transform_from_layerdata(&ipp.viewport_size, responses);
|
||||
}
|
||||
SetRotation(new) => {
|
||||
SetCanvasRotation(new) => {
|
||||
let layerdata = self.layerdata_mut(&vec![]);
|
||||
layerdata.rotation = new;
|
||||
self.create_document_transform_from_layerdata(&ipp.viewport_size, responses);
|
||||
responses.push_back(FrontendMessage::SetRotation { new_radians: new }.into());
|
||||
responses.push_back(FrontendMessage::SetCanvasRotation { new_radians: new }.into());
|
||||
}
|
||||
NudgeSelectedLayers(x, y) => {
|
||||
let paths: Vec<Vec<LayerId>> = self.selected_layers_sorted();
|
||||
|
|
@ -546,7 +566,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
|
|||
ZoomCanvasBegin,
|
||||
SetCanvasZoom,
|
||||
MultiplyCanvasZoom,
|
||||
SetRotation,
|
||||
SetCanvasRotation,
|
||||
WheelCanvasZoom,
|
||||
WheelCanvasTranslate,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -13,15 +13,15 @@ pub enum FrontendMessage {
|
|||
SetActiveTool { tool_name: String },
|
||||
SetActiveDocument { document_index: usize },
|
||||
UpdateOpenDocumentsList { open_documents: Vec<String> },
|
||||
PromptConfirmationToCloseDocument { document_index: usize },
|
||||
PromptConfirmationToCloseAllDocuments,
|
||||
DisplayConfirmationToCloseDocument { document_index: usize },
|
||||
DisplayConfirmationToCloseAllDocuments,
|
||||
UpdateCanvas { document: String },
|
||||
ExportDocument { document: String },
|
||||
EnableTextInput,
|
||||
DisableTextInput,
|
||||
UpdateWorkingColors { primary: Color, secondary: Color },
|
||||
SetCanvasZoom { new_zoom: f64 },
|
||||
SetRotation { new_radians: f64 },
|
||||
SetCanvasRotation { new_radians: f64 },
|
||||
}
|
||||
|
||||
pub struct FrontendMessageHandler {
|
||||
|
|
@ -48,6 +48,6 @@ impl MessageHandler<FrontendMessage, ()> for FrontendMessageHandler {
|
|||
EnableTextInput,
|
||||
DisableTextInput,
|
||||
SetCanvasZoom,
|
||||
SetRotation,
|
||||
SetCanvasRotation,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue