cleaned up
This commit is contained in:
parent
899ebf37b0
commit
96d803a870
|
@ -206,7 +206,10 @@ impl Calcifer {
|
|||
pub fn draw_content_panel(&mut self, ctx: &egui::Context) {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
if ui.add(egui::Button::new("open directory in terminal")).clicked() {
|
||||
if ui
|
||||
.add(egui::Button::new("open directory in terminal"))
|
||||
.clicked()
|
||||
{
|
||||
let mut path = self.tabs[self.selected_tab.to_index()].path.clone();
|
||||
path.pop();
|
||||
tools::send_command(format!("cd {}", path.display()));
|
||||
|
|
|
@ -2,14 +2,14 @@ use eframe::egui;
|
|||
use egui::Color32;
|
||||
use std::{cmp::min, fs, path::Path, path::PathBuf};
|
||||
|
||||
use crate::save_path;
|
||||
use crate::tools;
|
||||
use crate::Calcifer;
|
||||
use crate::DEFAULT_THEMES;
|
||||
use crate::MAX_TABS;
|
||||
use crate::TIME_LABELS;
|
||||
use crate::save_path;
|
||||
use tools::hex_str_to_color;
|
||||
use tools::file_tree;
|
||||
use tools::hex_str_to_color;
|
||||
|
||||
impl Calcifer {
|
||||
pub fn handle_confirm(&mut self) {
|
||||
|
@ -123,7 +123,7 @@ impl Calcifer {
|
|||
}
|
||||
|
||||
pub fn open_file(&mut self, path_option: Option<&Path>) {
|
||||
if let Some(path) = path_option.clone() {
|
||||
if let Some(path) = path_option {
|
||||
for (index, tab) in self.tabs.clone().iter().enumerate() {
|
||||
if tab.path == path {
|
||||
self.selected_tab = tools::TabNumber::from_index(index);
|
||||
|
@ -186,7 +186,13 @@ impl Calcifer {
|
|||
result
|
||||
}
|
||||
|
||||
pub fn list_files(&mut self, ui: &mut egui::Ui, file: &file_tree::File, depth: isize, n_files: &mut usize) {
|
||||
pub fn list_files(
|
||||
&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
file: &file_tree::File,
|
||||
depth: isize,
|
||||
n_files: &mut usize,
|
||||
) {
|
||||
*n_files += 1;
|
||||
|
||||
if let Some(folder_content) = &file.folder_content {
|
||||
|
@ -194,23 +200,19 @@ impl Calcifer {
|
|||
.default_open(depth > 0)
|
||||
.show(ui, |ui| {
|
||||
if !self.tree_dir_opened.contains(&file.name) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
for deeper_file in folder_content {
|
||||
self.list_files(ui, &deeper_file, depth - 1, n_files);
|
||||
self.list_files(ui, deeper_file, depth - 1, n_files);
|
||||
}
|
||||
});
|
||||
if collapsing_response.fully_closed() {
|
||||
self.tree_dir_opened.retain(|s| s != &file.name);
|
||||
} else {
|
||||
if !self.tree_dir_opened.contains(&file.name) {
|
||||
} else if !self.tree_dir_opened.contains(&file.name) {
|
||||
self.tree_dir_opened.push(file.name.clone());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ui.button(&file.name).clicked() {
|
||||
} else if ui.button(&file.name).clicked() {
|
||||
self.open_file(Some(&file.path));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
25
src/main.rs
25
src/main.rs
|
@ -6,8 +6,8 @@ use eframe::egui;
|
|||
use egui::FontFamily::Proportional;
|
||||
use egui::FontId;
|
||||
use egui::TextStyle::{Body, Button, Heading, Monospace, Small};
|
||||
use std::{ops::Range, path::PathBuf, sync::Arc, thread, time};
|
||||
use homedir::get_my_home;
|
||||
use std::{ops::Range, path::PathBuf, sync::Arc, thread, time};
|
||||
|
||||
use calcifer::code_editor::themes::DEFAULT_THEMES;
|
||||
|
||||
|
@ -17,10 +17,7 @@ const TITLE: &str = " debug";
|
|||
#[cfg(not(debug_assertions))]
|
||||
const TITLE: &str = "";
|
||||
|
||||
|
||||
const ALLOWED_FILE_EXTENSIONS: [&str; 6] = [
|
||||
"", "rs", "toml", "txt", "project", "sh",
|
||||
];
|
||||
const ALLOWED_FILE_EXTENSIONS: [&str; 6] = ["", "rs", "toml", "txt", "project", "sh"];
|
||||
const PROJECT_EXTENSION: &str = "project";
|
||||
const TERMINAL_HEIGHT: f32 = 200.0;
|
||||
const TERMINAL_RANGE: Range<f32> = 100.0..500.0;
|
||||
|
@ -254,11 +251,23 @@ impl eframe::App for Calcifer {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
fn save_path() -> PathBuf {
|
||||
if TITLE.is_empty() {
|
||||
get_my_home().unwrap().unwrap().as_path().join(".calcifer").join("save.json").to_path_buf()
|
||||
get_my_home()
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.as_path()
|
||||
.join(".calcifer")
|
||||
.join("save.json")
|
||||
.to_path_buf()
|
||||
} else {
|
||||
get_my_home().unwrap().unwrap().as_path().join(".calcifer").join("debug").join("save.json").to_path_buf()
|
||||
get_my_home()
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.as_path()
|
||||
.join(".calcifer")
|
||||
.join("debug")
|
||||
.join("save.json")
|
||||
.to_path_buf()
|
||||
}
|
||||
}
|
|
@ -14,7 +14,6 @@ pub struct File {
|
|||
pub folder_open: bool,
|
||||
}
|
||||
|
||||
|
||||
impl File {
|
||||
pub fn new_file(name: String, path: PathBuf) -> Self {
|
||||
Self {
|
||||
|
@ -26,7 +25,6 @@ impl File {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn generate_file_tree(path: &Path, depth: isize) -> Option<File> {
|
||||
if let Some(file_name) = path.file_name() {
|
||||
if file_name.to_string_lossy().starts_with('.') {
|
||||
|
@ -52,7 +50,10 @@ pub fn generate_file_tree(path: &Path, depth: isize) -> Option<File> {
|
|||
|
||||
match fs::read_dir(path) {
|
||||
Err(err) => {
|
||||
return Some(File::new_file(format!("Error reading directory: {}", err), path.to_path_buf()));
|
||||
Some(File::new_file(
|
||||
format!("Error reading directory: {}", err),
|
||||
path.to_path_buf(),
|
||||
))
|
||||
}
|
||||
Ok(entries) => {
|
||||
let mut paths: Vec<Result<fs::DirEntry, io::Error>> = entries
|
||||
|
@ -60,7 +61,7 @@ pub fn generate_file_tree(path: &Path, depth: isize) -> Option<File> {
|
|||
.collect();
|
||||
|
||||
paths.sort_by(|a, b| match (a, b) {
|
||||
(Ok(entry_a), Ok(entry_b)) => tools::sort_directories_first(&entry_a, &entry_b),
|
||||
(Ok(entry_a), Ok(entry_b)) => tools::sort_directories_first(entry_a, entry_b),
|
||||
(Err(_), Ok(_)) => std::cmp::Ordering::Greater,
|
||||
(Ok(_), Err(_)) => std::cmp::Ordering::Less,
|
||||
(Err(_), Err(_)) => std::cmp::Ordering::Equal,
|
||||
|
@ -88,12 +89,12 @@ pub fn generate_file_tree(path: &Path, depth: isize) -> Option<File> {
|
|||
return None;
|
||||
}
|
||||
|
||||
return Some(File {
|
||||
Some(File {
|
||||
name,
|
||||
path: path.to_path_buf(),
|
||||
folder_content: Some(folder_content),
|
||||
folder_open: false,
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,10 +11,10 @@ use std::{
|
|||
|
||||
//my tools;
|
||||
pub mod confirm;
|
||||
pub mod file_tree;
|
||||
pub mod search;
|
||||
pub mod settings;
|
||||
pub mod shortcuts;
|
||||
pub mod file_tree;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub mod terminal;
|
||||
|
|
|
@ -6,12 +6,6 @@ pub struct Line {
|
|||
}
|
||||
|
||||
impl Line {
|
||||
fn output(text: String) -> Self {
|
||||
Self {
|
||||
text: remove_line_break(text),
|
||||
error: false,
|
||||
}
|
||||
}
|
||||
fn error(text: String) -> Self {
|
||||
Self {
|
||||
text: remove_line_break(text),
|
||||
|
@ -36,15 +30,14 @@ impl CommandEntry {
|
|||
}
|
||||
|
||||
pub fn update(&mut self) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send_command(command: String) -> CommandEntry {
|
||||
pub fn send_command(_command: String) -> CommandEntry {
|
||||
return CommandEntry::new("windows>".to_string(), "hello there".to_string());
|
||||
}
|
||||
|
||||
|
||||
fn remove_line_break(input: String) -> String {
|
||||
let mut text = input.clone();
|
||||
while text.ends_with('\n') {
|
||||
|
|
Loading…
Reference in a new issue