Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
d0rianb committed Mar 20, 2022
1 parent fffb659 commit d8368a3
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 21 deletions.
3 changes: 3 additions & 0 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
- logging
- shortcup helper menu
- double clic
- open file with drag and drop

- Scripting language (why not ?)

BUGS:
- cmd+any doesn't work anymore after ^ or ¨ char has been pressed
Expand Down
1 change: 0 additions & 1 deletion src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use speedy2d::color::Color;
use speedy2d::dimen::Vector2;
use speedy2d::Graphics2D;
use speedy2d::window::UserEventSender;
use speedy2d::window::VirtualKeyCode::V;

use crate::animation::{Animation, EasingFunction};
use crate::cursor::Cursor;
Expand Down
4 changes: 2 additions & 2 deletions src/contextual_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl ContextualMenu {

fn move_up(&mut self) {
if !self.is_focus() { return; }
let mut index = self.focus_index as i32 - 1;
let index = self.focus_index as i32 - 1;
let start_y = if let Some(animation) = &self.focus_y_animation { animation.value } else { self.get_item_offset_y(self.focus_index as usize) };
self.set_focus(index as isize);
self.focus_y_animation = Some(Animation::new(start_y, self.get_item_offset_y(self.focus_index as usize), ANIMATION_DURATION, EasingFunction::EaseOut, self.event_sender.clone().unwrap()));
Expand Down Expand Up @@ -287,7 +287,7 @@ impl ContextualMenu {

pub fn toggle_loader(&mut self) {
let es = self.event_sender.clone().unwrap();
let mut item = self.get_focused_item();
let item = self.get_focused_item();
match item.loader {
None => item.start_loader(es),
Some(_) => {}
Expand Down
1 change: 0 additions & 1 deletion src/editable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ pub trait Editable {
fn copy(&mut self);

fn paste(&mut self);

}
16 changes: 11 additions & 5 deletions src/editor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::{cmp, env, fs};
use std::cell::RefCell;
use std::io::{Read, Seek, SeekFrom, Write};
use std::ops::Add;
use std::rc::Rc;
use std::path::{Path, PathBuf};
use std::time::Instant;
Expand All @@ -17,7 +15,7 @@ use clipboard::ClipboardProvider;
use clipboard::ClipboardContext;
use lazy_static::lazy_static;
use regex::Regex;
use ifmt::{iformat, iprintln};
use ifmt::iformat;

use serde_yaml;

Expand Down Expand Up @@ -54,6 +52,7 @@ pub struct Editor {
pub menu: ContextualMenu,
pub cached_prefs: Option<serde_yaml::Value>,
pub stats: Stats,
pub should_edit_file: bool, // so the input does not trigger file specific events
}

impl Editor {
Expand Down Expand Up @@ -81,6 +80,7 @@ impl Editor {
padding,
font,
stats: Stats::default(),
should_edit_file: true
}
}
}
Expand Down Expand Up @@ -369,7 +369,7 @@ impl Editable for Editor {

impl Editor {
fn quit(&mut self) {
if let Some(filepath) = &mut self.filepath { } else { self.filepath = Some("newfile.txt".into()); }
if let Some(_filepath) = &mut self.filepath { } else { self.filepath = Some("newfile.txt".into()); }
self.save();
std::process::exit(0)
}
Expand All @@ -383,6 +383,10 @@ impl Editor {
}

fn send_event(&self, event: EditorEvent) {
match event {
EditorEvent::SetDirty(_, _) | EditorEvent::LoadFile(_) => if !self.should_edit_file { return; }
_ => {}
}
self.event_sender.as_ref().unwrap().send_event(event).unwrap();
}

Expand Down Expand Up @@ -562,13 +566,14 @@ impl Editor {
menu
}

#[warn(unused_labels)]
fn get_focus_menu_id(&mut self) -> Option<MenuId> {
if !self.menu.is_focus() { return Option::None }
let mut id = self.menu.id;
let mut last_menu_focused = false;
'menus: while !last_menu_focused {
let menu = self.get_menu(id);
let mut items_submenu = menu.items.iter().map(|i| i.sub_menu.as_ref()).clone();
let items_submenu = menu.items.iter().map(|i| i.sub_menu.as_ref()).clone();
'items: for (i, sub_menu) in items_submenu.enumerate() {
if let Some(sub_menu) = sub_menu {
if sub_menu.is_focus() {
Expand Down Expand Up @@ -711,6 +716,7 @@ impl Editor {
}

fn get_stats(&self) -> Vec<String> {
// TODO: get stats of selection if there is one instead of the whole file
let words_count = self.lines.iter().fold(0, |acc, line| acc + line.get_word_count());
let char_count = self.lines.iter().fold(0, |acc, line| acc + line.buffer.len());
let update_duration = self.stats.update_duration.as_micros() as f64 / 1000.;
Expand Down
2 changes: 1 addition & 1 deletion src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use crate::{Animation, Editable, Editor, EditorEvent, FocusElement, MenuId};
use crate::menu_actions::{MenuAction, MenuActionFn};
use crate::animation::EasingFunction;
use crate::camera::Camera;
use crate::FocusElement::Menu;
use crate::render_helper::draw_rounded_rectangle_with_border;

pub const MIN_INPUT_WIDTH: f32 = 250.;
Expand Down Expand Up @@ -129,6 +128,7 @@ impl Input {
editor.set_offset(offset);
editor.set_event_sender(Some(es));
editor.camera.safe_zone_size = 30.;
editor.should_edit_file = false;
let blank_text_layout = editor.lines[0].formatted_text_block.clone();
Self {
editor,
Expand Down
2 changes: 0 additions & 2 deletions src/loader.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use itertools::GroupBy;
use lazy_static::lazy_static;
use speedy2d::color::Color;
use speedy2d::dimen::Vector2;
use speedy2d::Graphics2D;
use speedy2d::window::UserEventSender;
use crate::{Animation, EditorEvent};
use crate::animation::EasingFunction;
use crate::render_helper::draw_rounded_line;

const TWO_PI: f32 = std::f32::consts::TAU;
const HALF_PI: f32 = std::f32::consts::PI / 2.;
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod menu_actions;
mod stats;
mod open_ai_wrapper;
mod loader;
mod tesl;

use std::thread;
use std::env;
Expand Down Expand Up @@ -81,6 +82,7 @@ impl WindowHandler<EditorEvent> for EditorWindowHandler {
});
}

#[warn(unreachable_patterns)]
fn on_user_event(&mut self, helper: &mut WindowHelper<EditorEvent>, user_event: EditorEvent) {
match user_event {
EditorEvent::Redraw => helper.request_redraw(),
Expand Down Expand Up @@ -112,7 +114,7 @@ impl WindowHandler<EditorEvent> for EditorWindowHandler {
},
EditorEvent::MenuItemUnselected(_item, key) => self.editor.add_char(key),
EditorEvent::LoadFile(path) => set_app_title(helper, &path),
EditorEvent::SetDirty(path, is_dirty) => set_app_title(helper, &if !is_dirty { path } else { path + " °" }),
EditorEvent::SetDirty(path, is_dirty) => set_app_title(helper, &if !is_dirty { path } else { path + " *" }),
EditorEvent::OAIResponse(menu_id, choices) => self.editor.get_menu(menu_id).async_callback(choices),
_ => {}
}
Expand Down
5 changes: 1 addition & 4 deletions src/open_ai_wrapper.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use std::{fs, thread};
use std::io::Read;
use std::time::Duration;

use hyper_tls::HttpsConnector;
use hyper::body::Buf;
use tokio;
use serde::{Serialize, Deserialize};
use serde_json::Value;
use speedy2d::window::UserEventSender;

use crate::{EditorEvent, MenuId};
use crate::EditorEvent;
use crate::editor::Editor;
use crate::contextual_menu::ContextualMenu;

Expand Down
4 changes: 1 addition & 3 deletions src/range.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::cell::RefCell;
use std::cmp;
use std::fmt::{Debug, Formatter};
use std::rc::Rc;
use std::slice::Split;

use speedy2d::color::Color;
use speedy2d::dimen::Vector2;
Expand Down Expand Up @@ -130,7 +128,7 @@ impl Range {
for range_str in line.split(",") {
if range_str == line { break; }
let numbers: Vec<&str> = range_str.trim().split("-").collect();
let mut parsed_number = numbers
let parsed_number = numbers
.iter()
.map(|n| n.parse::<u32>());
if parsed_number.clone().any(|n| n.is_err()) { continue }
Expand Down
1 change: 0 additions & 1 deletion src/render_helper.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use lazy_static::lazy_static;
use speedy2d::color::Color;
use speedy2d::dimen::Vector2;
use speedy2d::Graphics2D;
Expand Down

0 comments on commit d8368a3

Please sign in to comment.