mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 23:08:05 +08:00
Fix all clippy lint errors
This commit is contained in:
@@ -7,6 +7,7 @@ pub use crate::tool::ToolMessageHandler;
|
||||
use crate::global::GlobalMessageHandler;
|
||||
use std::collections::VecDeque;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Dispatcher {
|
||||
input_preprocessor: InputPreprocessor,
|
||||
input_mapper: InputMapper,
|
||||
@@ -30,6 +31,10 @@ const SIDE_EFFECT_FREE_MESSAGES: &[MessageDiscriminant] = &[
|
||||
];
|
||||
|
||||
impl Dispatcher {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn handle_message<T: Into<Message>>(&mut self, message: T) {
|
||||
self.messages.push_back(message.into());
|
||||
|
||||
@@ -68,18 +73,6 @@ impl Dispatcher {
|
||||
list
|
||||
}
|
||||
|
||||
pub fn new() -> Dispatcher {
|
||||
Dispatcher {
|
||||
input_preprocessor: InputPreprocessor::default(),
|
||||
global_message_handler: GlobalMessageHandler::new(),
|
||||
input_mapper: InputMapper::default(),
|
||||
documents_message_handler: DocumentsMessageHandler::default(),
|
||||
tool_message_handler: ToolMessageHandler::default(),
|
||||
messages: VecDeque::new(),
|
||||
responses: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
fn log_message(&self, message: &Message) {
|
||||
use Message::*;
|
||||
if log::max_level() == log::LevelFilter::Trace
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
use std::collections::VecDeque;
|
||||
|
||||
use super::document_message_handler::CopyBufferEntry;
|
||||
pub use super::layer_panel::*;
|
||||
use super::movement_handler::{MovementMessage, MovementMessageHandler};
|
||||
use super::overlay_message_handler::OverlayMessageHandler;
|
||||
@@ -187,7 +186,7 @@ impl DocumentMessageHandler {
|
||||
}
|
||||
|
||||
pub fn deserialize_document(serialized_content: &str) -> Result<Self, DocumentError> {
|
||||
log::info!("Deserialising: {:?}", serialized_content);
|
||||
log::info!("Deserializing: {:?}", serialized_content);
|
||||
serde_json::from_str(serialized_content).map_err(|e| DocumentError::InvalidFile(e.to_string()))
|
||||
}
|
||||
|
||||
@@ -210,8 +209,8 @@ impl DocumentMessageHandler {
|
||||
|
||||
pub fn is_unmodified_default(&self) -> bool {
|
||||
self.serialize_root().len() == Self::default().serialize_root().len()
|
||||
&& self.document_undo_history.len() == 0
|
||||
&& self.document_redo_history.len() == 0
|
||||
&& self.document_undo_history.is_empty()
|
||||
&& self.document_redo_history.is_empty()
|
||||
&& self.name.starts_with(DEFAULT_DOCUMENT_NAME)
|
||||
}
|
||||
|
||||
@@ -437,7 +436,7 @@ impl DocumentMessageHandler {
|
||||
Some((document, layer_data)) => {
|
||||
let document = std::mem::replace(&mut self.graphene_document, document);
|
||||
let layer_data = std::mem::replace(&mut self.layer_data, layer_data);
|
||||
self.document_undo_history.push((document.clone(), layer_data.clone()));
|
||||
self.document_undo_history.push((document, layer_data));
|
||||
Ok(())
|
||||
}
|
||||
None => Err(EditorError::NoTransactionInProgress),
|
||||
@@ -645,7 +644,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
|
||||
// Fill the selection range
|
||||
self.layer_data
|
||||
.iter()
|
||||
.filter(|(target, _)| self.graphene_document.layer_is_between(&target, &selected, &self.layer_range_selection_reference))
|
||||
.filter(|(target, _)| self.graphene_document.layer_is_between(target, &selected, &self.layer_range_selection_reference))
|
||||
.for_each(|(layer_path, _)| {
|
||||
paths.push(layer_path.clone());
|
||||
});
|
||||
@@ -664,7 +663,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
|
||||
}
|
||||
|
||||
// Don't create messages for empty operations
|
||||
if paths.len() > 0 {
|
||||
if !paths.is_empty() {
|
||||
// Add or set our selected layers
|
||||
if ctrl {
|
||||
responses.push_front(AddSelectedLayers(paths).into());
|
||||
|
||||
@@ -249,7 +249,7 @@ impl MessageHandler<DocumentsMessage, &InputPreprocessor> for DocumentsMessageHa
|
||||
.document_ids
|
||||
.iter()
|
||||
.filter_map(|id| {
|
||||
self.documents.get(&id).map(|doc| FrontendDocumentDetails {
|
||||
self.documents.get(id).map(|doc| FrontendDocumentDetails {
|
||||
is_saved: doc.is_saved(),
|
||||
id: *id,
|
||||
name: doc.name.clone(),
|
||||
@@ -314,7 +314,7 @@ impl MessageHandler<DocumentsMessage, &InputPreprocessor> for DocumentsMessageHa
|
||||
.document_ids
|
||||
.iter()
|
||||
.filter_map(|id| {
|
||||
self.documents.get(&id).map(|doc| FrontendDocumentDetails {
|
||||
self.documents.get(id).map(|doc| FrontendDocumentDetails {
|
||||
is_saved: doc.is_saved(),
|
||||
id: *id,
|
||||
name: doc.name.clone(),
|
||||
@@ -356,7 +356,7 @@ impl MessageHandler<DocumentsMessage, &InputPreprocessor> for DocumentsMessageHa
|
||||
self.copy_buffer[clipboard as usize].clear();
|
||||
for path in paths {
|
||||
let document = self.active_document();
|
||||
match (document.graphene_document.layer(&path).map(|t| t.clone()), document.layer_data(&path).clone()) {
|
||||
match (document.graphene_document.layer(&path).map(|t| t.clone()), *document.layer_data(&path)) {
|
||||
(Ok(layer), layer_data) => {
|
||||
self.copy_buffer[clipboard as usize].push(CopyBufferEntry { layer, layer_data });
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ pub struct OverlayMessageHandler {
|
||||
}
|
||||
|
||||
impl MessageHandler<OverlayMessage, (&mut LayerData, &Document, &InputPreprocessor)> for OverlayMessageHandler {
|
||||
fn process_action(&mut self, message: OverlayMessage, data: (&mut LayerData, &Document, &InputPreprocessor), responses: &mut VecDeque<Message>) {
|
||||
let (layer_data, document, ipp) = data;
|
||||
fn process_action(&mut self, message: OverlayMessage, _data: (&mut LayerData, &Document, &InputPreprocessor), responses: &mut VecDeque<Message>) {
|
||||
// let (layer_data, document, ipp) = data;
|
||||
use OverlayMessage::*;
|
||||
match message {
|
||||
DispatchOperation(operation) => match self.overlays_graphene_document.handle_operation(&operation) {
|
||||
|
||||
@@ -13,12 +13,6 @@ pub enum GlobalMessage {
|
||||
#[derive(Debug, Default)]
|
||||
pub struct GlobalMessageHandler {}
|
||||
|
||||
impl GlobalMessageHandler {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl MessageHandler<GlobalMessage, ()> for GlobalMessageHandler {
|
||||
fn process_action(&mut self, message: GlobalMessage, _data: (), _responses: &mut VecDeque<Message>) {
|
||||
use GlobalMessage::*;
|
||||
|
||||
@@ -197,7 +197,7 @@ macro_rules! bit_ops {
|
||||
macro_rules! bit_ops_assign {
|
||||
($(($op:ident, $func:ident)),* $(,)?) => {
|
||||
$(impl<const LENGTH: usize> $op for BitVector<LENGTH> {
|
||||
fn $func(&mut self, right: Self) {
|
||||
fn $func(&mut self, right: Self) {
|
||||
for (left, right) in self.0.iter_mut().zip(right.0.iter()) {
|
||||
$op::$func(left, right);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ impl ViewportBounds {
|
||||
|
||||
#[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
||||
pub struct ScrollDelta {
|
||||
// TODO: Switch these to `f64` values (not trivial because floats don't provide PartialEq, Eq, and Hash)
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
pub z: i32,
|
||||
|
||||
@@ -58,13 +58,11 @@ impl SnapHandler {
|
||||
.unwrap_or(0.),
|
||||
);
|
||||
|
||||
// Do not move if over snap tolerance
|
||||
let clamped_closest_move = DVec2::new(
|
||||
// Clamp, do not move if over snap tolerance
|
||||
DVec2::new(
|
||||
if closest_move.x.abs() > SNAP_TOLERANCE { 0. } else { closest_move.x },
|
||||
if closest_move.y.abs() > SNAP_TOLERANCE { 0. } else { closest_move.y },
|
||||
);
|
||||
|
||||
clamped_closest_move
|
||||
)
|
||||
} else {
|
||||
DVec2::ZERO
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for Line {
|
||||
fn actions(&self) -> ActionList {
|
||||
use LineToolFsmState::*;
|
||||
match self.fsm_state {
|
||||
Ready => actions!(LineMessageDiscriminant; DragStart),
|
||||
Ready => actions!(LineMessageDiscriminant; DragStart),
|
||||
Drawing => actions!(LineMessageDiscriminant; DragStop, Redraw, Abort),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,7 +303,7 @@ impl Fsm for PathToolFsmState {
|
||||
}
|
||||
}
|
||||
|
||||
fn calculate_total_overlays_per_type(shapes_to_draw: &Vec<VectorManipulatorShape>) -> (usize, usize, usize) {
|
||||
fn calculate_total_overlays_per_type(shapes_to_draw: &[VectorManipulatorShape]) -> (usize, usize, usize) {
|
||||
let (mut total_anchors, mut total_handles, mut total_anchor_handle_lines) = (0, 0, 0);
|
||||
|
||||
for shape_to_draw in shapes_to_draw {
|
||||
|
||||
Reference in New Issue
Block a user