Repository: GraphiteEditor/Graphite
File: editor/src/tool/tool_message_handler.rs (Rust)

Code before:
	#[child]
	Line(LineMessage),
	#[child]
	Crop(CropMessage),
	#[child]
	Eyedropper(EyedropperMessage),
	#[child]
	Navigate(NavigateMessage),
	#[child]
	Path(PathMessage),
	#[child]
	Pen(PenMessage),
	#[child]
	Shape(ShapeMessage),
}

#[derive(Debug, Default)]
pub struct ToolMessageHandler {
	tool_state: ToolFsmState,
}
impl ToolMessageHandler {
	fn update_frontend_tool_options(&self, responses: &mut VecDeque<Message>, tool_type: ToolType) {
		responses.push_back(
			FrontendMessage::SetToolOptions {
				tool_name: tool_type.to_string(),
				tool_options: self.tool_state.document_tool_data.tool_options.get(&tool_type).map(|tool_options| *tool_options),
			}
			.into(),
		);
	}
}
impl MessageHandler<ToolMessage, (&DocumentMessageHandler, &InputPreprocessor)> for ToolMessageHandler {
	fn process_action(&mut self, message: ToolMessage, data: (&DocumentMessageHandler, &InputPreprocessor), responses: &mut VecDeque<Message>) {
		let (document, input) = data;
		use ToolMessage::*;
		match message {
			SelectPrimaryColor(color) => {
				let document_data = &mut self.tool_state.document_tool_data;
				document_data.primary_color = color;

				update_working_colors(&self.tool_state.document_tool_data, responses);
			}
			SelectSecondaryColor(color) => {
				let document_data = &mut self.tool_state.document_tool_data;
				document_data.secondary_color = color;

				update_working_colors(document_data, responses);
			}
			SelectTool(new_tool) => {
				let tool_data = &mut self.tool_state.tool_data;
				let document_data = &self.tool_state.document_tool_data;

Review comment (suggestion):
Consider moving this up into a `let` statement above. Possibly even two: `let tool_data = self.tool_state.document_tool_data;` and `let tool_options = tool_data.tool_options.get(&tool_type).map(|tool_options| *tool_options);`.

Code after:
	#[child]
	Line(LineMessage),
	#[child]
	Crop(CropMessage),
	#[child]
	Eyedropper(EyedropperMessage),
	#[child]
	Navigate(NavigateMessage),
	#[child]
	Path(PathMessage),
	#[child]
	Pen(PenMessage),
	#[child]
	Shape(ShapeMessage),
}

#[derive(Debug, Default)]
pub struct ToolMessageHandler {
	tool_state: ToolFsmState,
}
impl MessageHandler<ToolMessage, (&DocumentMessageHandler, &InputPreprocessor)> for ToolMessageHandler {
	fn process_action(&mut self, message: ToolMessage, data: (&DocumentMessageHandler, &InputPreprocessor), responses: &mut VecDeque<Message>) {
		let (document, input) = data;
		use ToolMessage::*;
		match message {
			SelectPrimaryColor(color) => {
				let document_data = &mut self.tool_state.document_tool_data;
				document_data.primary_color = color;

				update_working_colors(&self.tool_state.document_tool_data, responses);
			}
			SelectSecondaryColor(color) => {
				let document_data = &mut self.tool_state.document_tool_data;
				document_data.secondary_color = color;

				update_working_colors(document_data, responses);
			}
			SelectTool(new_tool) => {
				let tool_data = &mut self.tool_state.tool_data;
				let document_data = &self.tool_state.document_tool_data;
				let old_tool = tool_data.active_tool_type;

				// Do nothing if switching to the same tool
				if new_tool == old_tool {
					return;
				}

				// Get the Abort state of a tool's FSM
				let reset_message = |tool| match tool {
					ToolType::Ellipse => Some(EllipseMessage::Abort.into()),
					ToolType::Rectangle => Some(RectangleMessage::Abort.into()),