This commit is contained in:
WanderingPenwing 2024-08-07 11:40:44 +02:00
parent 1febc424a2
commit 23d81bf847
14 changed files with 1845 additions and 1688 deletions

View file

@ -1 +1 @@
{"categories":[{"name":"to do","content":[{"name":"update workflow .yml","description":"make a workflow compiling the calcifer and put the linux in calcifer-{version}\nand the windows in calcifer_windows_{version}\n\nupdate nix\nupdate jiji","id":5},{"name":"draggable item for project mode","description":"// Hello there","id":2}]},{"name":"in progress","content":[]},{"name":"done","content":[{"name":"move .project file","description":"// Hello there","id":4},{"name":"move config","description":"config from .calcifer/save.json\nto .config/calcifer/state.json","id":1},{"name":"add id to textarea per tab","description":"to improve undo, make each code area of each tab have a unique id (no more undo into another tab)","id":1},{"name":"file tree id ?","description":"// Hello there","id":1},{"name":"open dir in tree ?","description":"// Hello there","id":2},{"name":"fix tab title","description":"// Hello there","id":2},{"name":"when closing last tab","description":"close tab and THEN close calcifer (to save no tab in save.json)","id":1},{"name":"draggable tabs","description":"// Hello there","id":2},{"name":"repair build.rs","description":"// Hello there","id":1},{"name":"export copy paste fix","description":"// Hello there","id":1}]},{"name":"+","content":[]}]}
{"categories":[{"name":"to do","content":[{"name":"update workflow .yml","description":"make a workflow compiling the calcifer and put the linux in calcifer-{version}\nand the windows in calcifer_windows_{version}\n\nupdate nix\nupdate jiji","id":5},{"name":"draggable item for project mode","description":"// Hello there","id":2}]},{"name":"in progress","content":[]},{"name":"done","content":[{"name":"move .project file","description":"// Hello there","id":4},{"name":"move config","description":"config from .calcifer/save.json\nto .config/calcifer/state.json","id":1},{"name":"add id to textarea per tab","description":"to improve undo, make each code area of each tab have a unique id (no more undo into another tab)","id":1},{"name":"file tree id ?","description":"// Hello there","id":1},{"name":"open dir in tree ?","description":"// Hello there","id":2},{"name":"fix tab title","description":"// Hello there","id":2},{"name":"when closing last tab","description":"close tab and THEN close calcifer (to save no tab in save.json)","id":1},{"name":"draggable tabs","description":"// Hello there","id":2},{"name":"repair build.rs","description":"// Hello there","id":1},{"name":"export copy paste fix","description":"// Hello there","id":1}]},{"name":"bug","content":[{"name":"ctrl f ","description":"I had crash when going up in the selection","id":1}]},{"name":"+","content":[]}]}

View file

@ -9,7 +9,7 @@ mkShell {
libXi
pkg-config
] ++ [
cargo
#cargo
rustc
atk
gdk-pixbuf
@ -19,12 +19,12 @@ mkShell {
libGLU
libxkbcommon
gtk3-x11
gnome.zenity
#gnome.zenity
];
buildInputs = [
latest.rustChannels.stable.rust
xorg.libX11
wayland
# wayland
libxkbcommon
];

View file

@ -1,6 +1,6 @@
use eframe::egui;
use egui::Color32;
use std::{cmp::min, cmp::max, fs, path::Path, path::PathBuf};
use std::{cmp::max, cmp::min, fs, path::Path, path::PathBuf};
use crate::core;
use crate::editor::themes::DEFAULT_THEMES;
@ -45,14 +45,16 @@ impl Calcifer {
pub fn save_tab_as(&self) -> Option<PathBuf> {
let default_path = self.home.join("untitled");
let save_path = if self.tabs[self.selected_tab].path.file_name().map_or(true, |name| name.to_string_lossy() == "untitled")
let save_path = if self.tabs[self.selected_tab]
.path
.file_name()
.map_or(true, |name| name.to_string_lossy() == "untitled")
{
default_path.to_string_lossy()
} else {
self.tabs[self.selected_tab].path.to_string_lossy()
};
if let Some(path_string) = tinyfiledialogs::save_file_dialog("Save as", &save_path)
{
if let Some(path_string) = tinyfiledialogs::save_file_dialog("Save as", &save_path) {
let path = PathBuf::from(path_string);
if let Err(err) = fs::write(&path, &self.tabs[self.selected_tab].code) {
eprintln!("Error writing file: {}", err);

View file

@ -1,5 +1,7 @@
use eframe::egui;
use image::GenericImageView;
use serde::Deserialize;
use serde::Serialize;
use std::{
error::Error,
fs,
@ -7,8 +9,6 @@ use std::{
io::Write,
path::{Path, PathBuf},
};
use serde::Serialize;
use serde::Deserialize;
#[derive(Serialize, Deserialize, Debug, PartialEq, Default)]
pub struct AppState {

View file

@ -22,8 +22,11 @@ impl Calcifer {
.show(ctx, |ui| {
ui.vertical(|ui| {
if ui.add(egui::Button::new("📁")).clicked() {
if let Some(path_string) = tinyfiledialogs::open_file_dialog("Open File", &self.home.to_string_lossy(), None)
{
if let Some(path_string) = tinyfiledialogs::open_file_dialog(
"Open File",
&self.home.to_string_lossy(),
None,
) {
self.open_file(Some(&Path::new(&path_string)));
}
}
@ -248,7 +251,8 @@ impl Calcifer {
ui.with_layout(
egui::Layout::left_to_right(egui::Align::TOP),
|ui| {
if ui.add(
if ui
.add(
egui::Label::new(
egui::RichText::new(format!(
" {}{}",
@ -260,8 +264,14 @@ impl Calcifer {
.truncate(true)
.sense(egui::Sense::click()),
)
.clicked() ||
ui.add_sized(ui.available_size(), egui::Label::new("").sense(egui::Sense::click())).clicked()
.clicked()
|| ui
.add_sized(
ui.available_size(),
egui::Label::new("")
.sense(egui::Sense::click()),
)
.clicked()
{
self.selected_tab = index;
}
@ -287,11 +297,20 @@ impl Calcifer {
pub fn draw_content_panel(&mut self, ctx: &egui::Context) {
egui::CentralPanel::default().show(ctx, |ui| {
if self.selected_tab >= self.tabs.len() {
return
return;
}
ui.horizontal(|ui| {
ui.style_mut().visuals.hyperlink_color = core::hex_str_to_color(self.theme.comments);
if ui.link(self.tabs[self.selected_tab].path.to_string_lossy().to_string()).clicked() {
ui.style_mut().visuals.hyperlink_color =
core::hex_str_to_color(self.theme.comments);
if ui
.link(
self.tabs[self.selected_tab]
.path
.to_string_lossy()
.to_string(),
)
.clicked()
{
let mut current_path = self.tabs[self.selected_tab].path.clone();
current_path.pop();
@ -348,7 +367,7 @@ impl Calcifer {
&mut current_tab.scroll_offset.clone(),
override_cursor.clone(),
);
return
return;
}
CodeEditor::default()
@ -375,12 +394,28 @@ impl Calcifer {
.update_from_code(current_tab.code.clone());
panels::draw_project(ui, self.theme, &mut self.project_content);
self.project_content.selected_item.category = min(self.project_content.categories.len() - 2, self.project_content.selected_item.category);
while self.project_content.categories[self.project_content.selected_item.category].content.is_empty() && self.project_content.selected_item.category > 0 {
self.project_content.selected_item.category = min(
self.project_content.categories.len() - 2,
self.project_content.selected_item.category,
);
while self.project_content.categories[self.project_content.selected_item.category]
.content
.is_empty()
&& self.project_content.selected_item.category > 0
{
self.project_content.selected_item.category -= 1;
}
if !self.project_content.categories[self.project_content.selected_item.category].content.is_empty() {
self.project_content.selected_item.row = min(self.project_content.categories[self.project_content.selected_item.category].content.len() - 1, self.project_content.selected_item.row);
if !self.project_content.categories[self.project_content.selected_item.category]
.content
.is_empty()
{
self.project_content.selected_item.row = min(
self.project_content.categories[self.project_content.selected_item.category]
.content
.len()
- 1,
self.project_content.selected_item.row,
);
} else {
self.project_content.selected_item.row = 0;
}
@ -400,10 +435,16 @@ impl Calcifer {
if delete_item {
self.project_content.item_window.visible = false;
self.project_content.categories
self.project_content.categories[self.project_content.selected_item.category]
.content
.remove(self.project_content.selected_item.row);
if self.project_content.selected_item.row
>= self.project_content.categories
[self.project_content.selected_item.category]
.content.remove(self.project_content.selected_item.row);
if self.project_content.selected_item.row >= self.project_content.categories[self.project_content.selected_item.category].content.len() && self.project_content.selected_item.row > 0 {
.content
.len()
&& self.project_content.selected_item.row > 0
{
self.project_content.selected_item.row -= 1;
}
}
@ -461,34 +502,57 @@ impl Calcifer {
if let Some(pos) = ctx.input(|i| i.pointer.interact_pos()) {
match self.mouse_holder {
panels::MouseHolder::TabHolder(index) => {
let snapped_pos = egui::Pos2::new(pos.x, (self.tab_rect.max.y + self.tab_rect.min.y) / 2.0);
let snapped_pos = egui::Pos2::new(
pos.x,
(self.tab_rect.max.y + self.tab_rect.min.y) / 2.0,
);
egui::Area::new(egui::Id::new("mouse_holder")).fixed_pos(snapped_pos).show(ctx, |ui| {
egui::Area::new(egui::Id::new("mouse_holder"))
.fixed_pos(snapped_pos)
.show(ctx, |ui| {
let (bg_color, text_color) = if self.selected_tab == index {
(core::hex_str_to_color(self.theme.functions), core::hex_str_to_color(self.theme.bg))
(
core::hex_str_to_color(self.theme.functions),
core::hex_str_to_color(self.theme.bg),
)
} else {
(core::hex_str_to_color(self.theme.bg), core::hex_str_to_color(self.theme.comments))
(
core::hex_str_to_color(self.theme.bg),
core::hex_str_to_color(self.theme.comments),
)
};
let rect = egui::Rect::from_center_size(
snapped_pos,
egui::Vec2::new((self.tab_rect.max.x - self.tab_rect.min.x) / usize_to_f32(self.tab_area_size()), self.tab_rect.max.y - self.tab_rect.min.y)
egui::Vec2::new(
(self.tab_rect.max.x - self.tab_rect.min.x)
/ usize_to_f32(self.tab_area_size()),
self.tab_rect.max.y - self.tab_rect.min.y,
),
);
ui.painter().rect_filled(
ui.painter().rect_filled(rect, 0.0, bg_color);
let unsaved_indicator =
if self.tabs[index].saved { "" } else { "~ " };
let _ = ui.put(
rect,
0.0,
bg_color,
egui::Label::new(
egui::RichText::new(format!(
" {}{}",
unsaved_indicator,
self.tabs[index].get_name()
))
.color(text_color),
),
);
let unsaved_indicator = if self.tabs[index].saved { "" } else { "~ " };
let _ = ui.put(rect, egui::Label::new(egui::RichText::new(format!(" {}{}", unsaved_indicator, self.tabs[index].get_name())).color(text_color)));
});
}
panels::MouseHolder::None => {
if self.tab_rect.distance_to_pos(pos) == 0.0 {
let hover_pos : f32 = (pos.x - self.tab_rect.min.x) / ((self.tab_rect.max.x - self.tab_rect.min.x) / usize_to_f32(self.tab_area_size()));
let hover_pos: f32 = (pos.x - self.tab_rect.min.x)
/ ((self.tab_rect.max.x - self.tab_rect.min.x)
/ usize_to_f32(self.tab_area_size()));
if let Some(index) = floor_f32(hover_pos) {
if index < self.tabs.len() {
@ -499,32 +563,41 @@ impl Calcifer {
}
}
}
return
return;
}
match self.mouse_holder {
panels::MouseHolder::TabHolder(initial_index) => {
if let Some(pos) = ctx.input(|i| i.pointer.interact_pos()) {
let snapped_pos = egui::Pos2::new(pos.x, (self.tab_rect.max.y + self.tab_rect.min.y) / 2.0);
let snapped_pos =
egui::Pos2::new(pos.x, (self.tab_rect.max.y + self.tab_rect.min.y) / 2.0);
if self.tab_rect.distance_to_pos(snapped_pos) == 0.0 {
let hover_pos : f32 = (pos.x - self.tab_rect.min.x) / ((self.tab_rect.max.x - self.tab_rect.min.x) / usize_to_f32(self.tab_area_size()));
let hover_pos: f32 = (pos.x - self.tab_rect.min.x)
/ ((self.tab_rect.max.x - self.tab_rect.min.x)
/ usize_to_f32(self.tab_area_size()));
if let Some(final_index) = floor_f32(hover_pos) {
if final_index == initial_index {
return
return;
} else if final_index < initial_index {
self.tabs.insert(final_index, self.tabs[initial_index].clone());
self.tabs
.insert(final_index, self.tabs[initial_index].clone());
self.tabs.remove(initial_index + 1);
} else {
self.tabs.insert(final_index + 1, self.tabs[initial_index].clone());
self.tabs
.insert(final_index + 1, self.tabs[initial_index].clone());
self.tabs.remove(initial_index);
}
if self.selected_tab == initial_index {
self.selected_tab = final_index;
} else if self.selected_tab < initial_index && self.selected_tab >= final_index {
} else if self.selected_tab < initial_index
&& self.selected_tab >= final_index
{
self.selected_tab += 1;
} else if self.selected_tab > initial_index && self.selected_tab <= final_index {
} else if self.selected_tab > initial_index
&& self.selected_tab <= final_index
{
self.selected_tab -= 1;
}
}
@ -570,7 +643,6 @@ pub fn format_path(path: &Path) -> String {
)
}
fn usize_to_f32(value: usize) -> f32 {
const MAX_F32: f32 = f32::MAX;

View file

@ -9,14 +9,79 @@ impl Syntax {
comment: "//",
comment_multiline: ["/*", "*/"],
keywords: BTreeSet::from([
"&&", "||", "!", "let", "var", "abstract", "arguments", "await", "break", "case", "catch", "class", "const", "continue",
"debugger", "default", "delete", "do", "else", "enum", "eval", "export", "extends", "final", "finally", "for", "function",
"goto", "if", "implements", "import", "in", "instanceof", "interface", "let", "native", "new", "package", "private", "protected",
"public", "return", "static", "super", "switch", "synchronized", "this","throw", "throws", "transient", "try", "typeof",
"var", "volatile", "while", "with", "yield",
"&&",
"||",
"!",
"let",
"var",
"abstract",
"arguments",
"await",
"break",
"case",
"catch",
"class",
"const",
"continue",
"debugger",
"default",
"delete",
"do",
"else",
"enum",
"eval",
"export",
"extends",
"final",
"finally",
"for",
"function",
"goto",
"if",
"implements",
"import",
"in",
"instanceof",
"interface",
"let",
"native",
"new",
"package",
"private",
"protected",
"public",
"return",
"static",
"super",
"switch",
"synchronized",
"this",
"throw",
"throws",
"transient",
"try",
"typeof",
"var",
"volatile",
"while",
"with",
"yield",
]),
types: BTreeSet::from([
"Boolean", "Number", "BigInt", "Undefined", "Null", "String", "Symbol", "byte", "char", "float", "int", "long", "short", "void",
"Boolean",
"Number",
"BigInt",
"Undefined",
"Null",
"String",
"Symbol",
"byte",
"char",
"float",
"int",
"long",
"short",
"void",
]),
special: BTreeSet::from(["false", "null", "true"]),
}

View file

@ -4,9 +4,9 @@ use egui::{
TextStyle::{Body, Button, Heading, Monospace, Small},
};
use homedir::get_my_home;
use std::{ops::Range, path::PathBuf, sync::Arc, thread, time};
use std::env;
use std::time::Duration;
use std::{ops::Range, path::PathBuf, sync::Arc, thread, time};
mod core;
mod editor;
@ -25,7 +25,13 @@ const TERMINAL_HEIGHT: f32 = 200.0;
const TERMINAL_RANGE: Range<f32> = 100.0..600.0;
const RED: egui::Color32 = egui::Color32::from_rgb(235, 108, 99);
const TIME_LABELS: [&str; 7] = [
"input", "settings", "tree", "terminal+tray", "tabs", "content", "windows",
"input",
"settings",
"tree",
"terminal+tray",
"tabs",
"content",
"windows",
];
const ZOOM_FACTOR: f32 = 1.1;
const MAX_FPS: f32 = 30.0;
@ -63,6 +69,8 @@ fn main() -> Result<(), eframe::Error> {
None
};
//panels::send_command("export RUSTFLAGS=--cfg=web_sys_unstable_apis".to_string());
eframe::run_native(
&format!("Calcifer{}", TITLE),
options,
@ -205,7 +213,8 @@ impl eframe::App for Calcifer {
}
}
if ctx.input(|i| i.key_pressed(egui::Key::Enter)) && ctx.memory(|m| m.focus() == None)
if ctx.input(|i| i.key_pressed(egui::Key::Enter))
&& ctx.memory(|m| m.focus() == None)
&& self.tabs[self.selected_tab].language == PROJECT_EXTENSION
{
self.project_content.item_window.visible = true;
@ -272,11 +281,8 @@ impl eframe::App for Calcifer {
}
if self.tabs.len() == 0 {
egui::Context::send_viewport_cmd(
ctx,
egui::ViewportCommand::Close,
);
return
egui::Context::send_viewport_cmd(ctx, egui::ViewportCommand::Close);
return;
}
self.time_watch[0] = watch.elapsed().as_micros() as f32 / 1000.0;
@ -314,7 +320,10 @@ impl eframe::App for Calcifer {
self.time_watch[6] = watch.elapsed().as_micros() as f32 / 1000.0;
if self.running_command {
egui::Context::request_repaint_after(ctx, Duration::from_secs_f32(RUNNING_COMMAND_REFRESH_DELAY));
egui::Context::request_repaint_after(
ctx,
Duration::from_secs_f32(RUNNING_COMMAND_REFRESH_DELAY),
);
}
}

View file

@ -1,14 +1,14 @@
use std::hash::DefaultHasher;
use std::hash::Hash;
use std::hash::Hasher;
use std::time::SystemTime;
use std::time::UNIX_EPOCH;
use std::{
cmp::Ordering,
ffi::OsStr,
fs, io,
path::{Path, PathBuf},
};
use std::hash::DefaultHasher;
use std::time::UNIX_EPOCH;
use std::time::SystemTime;
use std::hash::Hasher;
use std::hash::Hash;
//use crate::ALLOWED_FILE_EXTENSIONS;
@ -42,7 +42,10 @@ impl FileEntry {
}
fn generate_unique_id(path: PathBuf) -> String {
let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs();
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs();
let mut hasher = DefaultHasher::new();
now.hash(&mut hasher);

View file

@ -123,7 +123,9 @@ fn get_id() -> usize {
}
pub fn draw_project(ui: &mut egui::Ui, theme: ColorTheme, project: &mut Project) {
ui.columns(max(MAX_PROJECT_COLUMNS, project.categories.len() + 1) , |uis| {
ui.columns(
max(MAX_PROJECT_COLUMNS, project.categories.len() + 1),
|uis| {
for (category_index, category) in project.categories.clone().into_iter().enumerate() {
let ui = &mut uis[category_index];
@ -151,7 +153,8 @@ pub fn draw_project(ui: &mut egui::Ui, theme: ColorTheme, project: &mut Project)
row: item_index,
})
{
ui.style_mut().visuals.override_text_color = Some(hex_str_to_color(theme.bg));
ui.style_mut().visuals.override_text_color =
Some(hex_str_to_color(theme.bg));
ui.add(
egui::Button::new(item.name.clone())
.fill(hex_str_to_color(theme.functions)),
@ -160,7 +163,10 @@ pub fn draw_project(ui: &mut egui::Ui, theme: ColorTheme, project: &mut Project)
ui.style_mut().visuals.override_text_color =
Some(hex_str_to_color(theme.literals));
if ui
.add(egui::Button::new(item.name.clone()).fill(hex_str_to_color(theme.bg)))
.add(
egui::Button::new(item.name.clone())
.fill(hex_str_to_color(theme.bg)),
)
.clicked()
{
project.selected_item = Location {
@ -170,15 +176,15 @@ pub fn draw_project(ui: &mut egui::Ui, theme: ColorTheme, project: &mut Project)
}
}
}
ui.style_mut().visuals.override_text_color =
Some(hex_str_to_color(theme.literals));
ui.style_mut().visuals.override_text_color = Some(hex_str_to_color(theme.literals));
if category.name != "+" && ui.add(egui::Button::new("+")).clicked() {
project.categories[category_index]
.content
.push(Item::new("item"));
}
}
});
},
);
let mut moved = false;
let category = project.selected_item.category;

View file

@ -22,10 +22,10 @@ impl ProjectItemWindow {
if let Some(response) = maybe_response {
if let Some(delete_option) = response.inner {
return delete_option
return delete_option;
}
}
return false
return false;
}
fn ui(&mut self, ui: &mut egui::Ui, item: &mut panels::Item) -> bool {
@ -43,6 +43,6 @@ impl ProjectItemWindow {
ui.available_size(),
egui::TextEdit::multiline(&mut item.description),
);
return delete_item.clone()
return delete_item.clone();
}
}