fmt
This commit is contained in:
parent
1febc424a2
commit
23d81bf847
|
@ -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":[]}]}
|
|
@ -9,7 +9,7 @@ mkShell {
|
||||||
libXi
|
libXi
|
||||||
pkg-config
|
pkg-config
|
||||||
] ++ [
|
] ++ [
|
||||||
cargo
|
#cargo
|
||||||
rustc
|
rustc
|
||||||
atk
|
atk
|
||||||
gdk-pixbuf
|
gdk-pixbuf
|
||||||
|
@ -19,12 +19,12 @@ mkShell {
|
||||||
libGLU
|
libGLU
|
||||||
libxkbcommon
|
libxkbcommon
|
||||||
gtk3-x11
|
gtk3-x11
|
||||||
gnome.zenity
|
#gnome.zenity
|
||||||
];
|
];
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
latest.rustChannels.stable.rust
|
latest.rustChannels.stable.rust
|
||||||
xorg.libX11
|
xorg.libX11
|
||||||
wayland
|
# wayland
|
||||||
libxkbcommon
|
libxkbcommon
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
use egui::Color32;
|
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::core;
|
||||||
use crate::editor::themes::DEFAULT_THEMES;
|
use crate::editor::themes::DEFAULT_THEMES;
|
||||||
|
@ -45,14 +45,16 @@ impl Calcifer {
|
||||||
pub fn save_tab_as(&self) -> Option<PathBuf> {
|
pub fn save_tab_as(&self) -> Option<PathBuf> {
|
||||||
let default_path = self.home.join("untitled");
|
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()
|
default_path.to_string_lossy()
|
||||||
} else {
|
} else {
|
||||||
self.tabs[self.selected_tab].path.to_string_lossy()
|
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);
|
let path = PathBuf::from(path_string);
|
||||||
if let Err(err) = fs::write(&path, &self.tabs[self.selected_tab].code) {
|
if let Err(err) = fs::write(&path, &self.tabs[self.selected_tab].code) {
|
||||||
eprintln!("Error writing file: {}", err);
|
eprintln!("Error writing file: {}", err);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
use image::GenericImageView;
|
use image::GenericImageView;
|
||||||
|
use serde::Deserialize;
|
||||||
|
use serde::Serialize;
|
||||||
use std::{
|
use std::{
|
||||||
error::Error,
|
error::Error,
|
||||||
fs,
|
fs,
|
||||||
|
@ -7,8 +9,6 @@ use std::{
|
||||||
io::Write,
|
io::Write,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
use serde::Serialize;
|
|
||||||
use serde::Deserialize;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Default)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Default)]
|
||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
|
|
150
src/core/ui.rs
150
src/core/ui.rs
|
@ -22,8 +22,11 @@ impl Calcifer {
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
if ui.add(egui::Button::new("📁")).clicked() {
|
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)));
|
self.open_file(Some(&Path::new(&path_string)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +81,7 @@ impl Calcifer {
|
||||||
});
|
});
|
||||||
ui.separator();
|
ui.separator();
|
||||||
|
|
||||||
let mut init_update : bool = false;
|
let mut init_update: bool = false;
|
||||||
if self.file_tree.is_none() {
|
if self.file_tree.is_none() {
|
||||||
self.file_tree = Some(panels::generate_folder_entry(self.home.as_path()));
|
self.file_tree = Some(panels::generate_folder_entry(self.home.as_path()));
|
||||||
init_update = true
|
init_update = true
|
||||||
|
@ -248,7 +251,8 @@ impl Calcifer {
|
||||||
ui.with_layout(
|
ui.with_layout(
|
||||||
egui::Layout::left_to_right(egui::Align::TOP),
|
egui::Layout::left_to_right(egui::Align::TOP),
|
||||||
|ui| {
|
|ui| {
|
||||||
if ui.add(
|
if ui
|
||||||
|
.add(
|
||||||
egui::Label::new(
|
egui::Label::new(
|
||||||
egui::RichText::new(format!(
|
egui::RichText::new(format!(
|
||||||
" {}{}",
|
" {}{}",
|
||||||
|
@ -260,8 +264,14 @@ impl Calcifer {
|
||||||
.truncate(true)
|
.truncate(true)
|
||||||
.sense(egui::Sense::click()),
|
.sense(egui::Sense::click()),
|
||||||
)
|
)
|
||||||
.clicked() ||
|
.clicked()
|
||||||
ui.add_sized(ui.available_size(), egui::Label::new("").sense(egui::Sense::click())).clicked()
|
|| ui
|
||||||
|
.add_sized(
|
||||||
|
ui.available_size(),
|
||||||
|
egui::Label::new("")
|
||||||
|
.sense(egui::Sense::click()),
|
||||||
|
)
|
||||||
|
.clicked()
|
||||||
{
|
{
|
||||||
self.selected_tab = index;
|
self.selected_tab = index;
|
||||||
}
|
}
|
||||||
|
@ -287,11 +297,20 @@ impl Calcifer {
|
||||||
pub fn draw_content_panel(&mut self, ctx: &egui::Context) {
|
pub fn draw_content_panel(&mut self, ctx: &egui::Context) {
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
if self.selected_tab >= self.tabs.len() {
|
if self.selected_tab >= self.tabs.len() {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.style_mut().visuals.hyperlink_color = core::hex_str_to_color(self.theme.comments);
|
ui.style_mut().visuals.hyperlink_color =
|
||||||
if ui.link(self.tabs[self.selected_tab].path.to_string_lossy().to_string()).clicked() {
|
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();
|
let mut current_path = self.tabs[self.selected_tab].path.clone();
|
||||||
current_path.pop();
|
current_path.pop();
|
||||||
|
|
||||||
|
@ -348,7 +367,7 @@ impl Calcifer {
|
||||||
&mut current_tab.scroll_offset.clone(),
|
&mut current_tab.scroll_offset.clone(),
|
||||||
override_cursor.clone(),
|
override_cursor.clone(),
|
||||||
);
|
);
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeEditor::default()
|
CodeEditor::default()
|
||||||
|
@ -375,12 +394,28 @@ impl Calcifer {
|
||||||
.update_from_code(current_tab.code.clone());
|
.update_from_code(current_tab.code.clone());
|
||||||
panels::draw_project(ui, self.theme, &mut self.project_content);
|
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);
|
self.project_content.selected_item.category = min(
|
||||||
while self.project_content.categories[self.project_content.selected_item.category].content.is_empty() && self.project_content.selected_item.category > 0 {
|
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;
|
self.project_content.selected_item.category -= 1;
|
||||||
}
|
}
|
||||||
if !self.project_content.categories[self.project_content.selected_item.category].content.is_empty() {
|
if !self.project_content.categories[self.project_content.selected_item.category]
|
||||||
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);
|
.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 {
|
} else {
|
||||||
self.project_content.selected_item.row = 0;
|
self.project_content.selected_item.row = 0;
|
||||||
}
|
}
|
||||||
|
@ -400,10 +435,16 @@ impl Calcifer {
|
||||||
|
|
||||||
if delete_item {
|
if delete_item {
|
||||||
self.project_content.item_window.visible = false;
|
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]
|
[self.project_content.selected_item.category]
|
||||||
.content.remove(self.project_content.selected_item.row);
|
.content
|
||||||
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 {
|
.len()
|
||||||
|
&& self.project_content.selected_item.row > 0
|
||||||
|
{
|
||||||
self.project_content.selected_item.row -= 1;
|
self.project_content.selected_item.row -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -461,34 +502,57 @@ impl Calcifer {
|
||||||
if let Some(pos) = ctx.input(|i| i.pointer.interact_pos()) {
|
if let Some(pos) = ctx.input(|i| i.pointer.interact_pos()) {
|
||||||
match self.mouse_holder {
|
match self.mouse_holder {
|
||||||
panels::MouseHolder::TabHolder(index) => {
|
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 {
|
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 {
|
} 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(
|
let rect = egui::Rect::from_center_size(
|
||||||
snapped_pos,
|
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,
|
rect,
|
||||||
0.0,
|
egui::Label::new(
|
||||||
bg_color,
|
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 => {
|
panels::MouseHolder::None => {
|
||||||
if self.tab_rect.distance_to_pos(pos) == 0.0 {
|
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 let Some(index) = floor_f32(hover_pos) {
|
||||||
if index < self.tabs.len() {
|
if index < self.tabs.len() {
|
||||||
|
@ -499,32 +563,41 @@ impl Calcifer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.mouse_holder {
|
match self.mouse_holder {
|
||||||
panels::MouseHolder::TabHolder(initial_index) => {
|
panels::MouseHolder::TabHolder(initial_index) => {
|
||||||
if let Some(pos) = ctx.input(|i| i.pointer.interact_pos()) {
|
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 {
|
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 let Some(final_index) = floor_f32(hover_pos) {
|
||||||
if final_index == initial_index {
|
if final_index == initial_index {
|
||||||
return
|
return;
|
||||||
} else if final_index < initial_index {
|
} 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);
|
self.tabs.remove(initial_index + 1);
|
||||||
} else {
|
} 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);
|
self.tabs.remove(initial_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.selected_tab == initial_index {
|
if self.selected_tab == initial_index {
|
||||||
self.selected_tab = final_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;
|
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;
|
self.selected_tab -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -570,7 +643,6 @@ pub fn format_path(path: &Path) -> String {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn usize_to_f32(value: usize) -> f32 {
|
fn usize_to_f32(value: usize) -> f32 {
|
||||||
const MAX_F32: f32 = f32::MAX;
|
const MAX_F32: f32 = f32::MAX;
|
||||||
|
|
||||||
|
|
|
@ -9,14 +9,79 @@ impl Syntax {
|
||||||
comment: "//",
|
comment: "//",
|
||||||
comment_multiline: ["/*", "*/"],
|
comment_multiline: ["/*", "*/"],
|
||||||
keywords: BTreeSet::from([
|
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",
|
"let",
|
||||||
"var", "volatile", "while", "with", "yield",
|
"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([
|
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"]),
|
special: BTreeSet::from(["false", "null", "true"]),
|
||||||
}
|
}
|
||||||
|
|
31
src/main.rs
31
src/main.rs
|
@ -4,9 +4,9 @@ use egui::{
|
||||||
TextStyle::{Body, Button, Heading, Monospace, Small},
|
TextStyle::{Body, Button, Heading, Monospace, Small},
|
||||||
};
|
};
|
||||||
use homedir::get_my_home;
|
use homedir::get_my_home;
|
||||||
use std::{ops::Range, path::PathBuf, sync::Arc, thread, time};
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use std::{ops::Range, path::PathBuf, sync::Arc, thread, time};
|
||||||
|
|
||||||
mod core;
|
mod core;
|
||||||
mod editor;
|
mod editor;
|
||||||
|
@ -25,7 +25,13 @@ const TERMINAL_HEIGHT: f32 = 200.0;
|
||||||
const TERMINAL_RANGE: Range<f32> = 100.0..600.0;
|
const TERMINAL_RANGE: Range<f32> = 100.0..600.0;
|
||||||
const RED: egui::Color32 = egui::Color32::from_rgb(235, 108, 99);
|
const RED: egui::Color32 = egui::Color32::from_rgb(235, 108, 99);
|
||||||
const TIME_LABELS: [&str; 7] = [
|
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 ZOOM_FACTOR: f32 = 1.1;
|
||||||
const MAX_FPS: f32 = 30.0;
|
const MAX_FPS: f32 = 30.0;
|
||||||
|
@ -63,6 +69,8 @@ fn main() -> Result<(), eframe::Error> {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//panels::send_command("export RUSTFLAGS=--cfg=web_sys_unstable_apis".to_string());
|
||||||
|
|
||||||
eframe::run_native(
|
eframe::run_native(
|
||||||
&format!("Calcifer{}", TITLE),
|
&format!("Calcifer{}", TITLE),
|
||||||
options,
|
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.tabs[self.selected_tab].language == PROJECT_EXTENSION
|
||||||
{
|
{
|
||||||
self.project_content.item_window.visible = true;
|
self.project_content.item_window.visible = true;
|
||||||
|
@ -228,11 +237,11 @@ impl eframe::App for Calcifer {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.input(|i| i.zoom_delta() > 1.0) {
|
if ctx.input(|i| i.zoom_delta() > 1.0) {
|
||||||
self.zoom = (self.zoom*ZOOM_FACTOR).min(10.0);
|
self.zoom = (self.zoom * ZOOM_FACTOR).min(10.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.input(|i| i.zoom_delta() < 1.0) {
|
if ctx.input(|i| i.zoom_delta() < 1.0) {
|
||||||
self.zoom = (self.zoom/ZOOM_FACTOR).max(0.1);
|
self.zoom = (self.zoom / ZOOM_FACTOR).max(0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.input(|i| i.key_pressed(egui::Key::F) && i.modifiers.ctrl) {
|
if ctx.input(|i| i.key_pressed(egui::Key::F) && i.modifiers.ctrl) {
|
||||||
|
@ -272,11 +281,8 @@ impl eframe::App for Calcifer {
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.tabs.len() == 0 {
|
if self.tabs.len() == 0 {
|
||||||
egui::Context::send_viewport_cmd(
|
egui::Context::send_viewport_cmd(ctx, egui::ViewportCommand::Close);
|
||||||
ctx,
|
return;
|
||||||
egui::ViewportCommand::Close,
|
|
||||||
);
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.time_watch[0] = watch.elapsed().as_micros() as f32 / 1000.0;
|
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;
|
self.time_watch[6] = watch.elapsed().as_micros() as f32 / 1000.0;
|
||||||
|
|
||||||
if self.running_command {
|
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),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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::{
|
use std::{
|
||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
ffi::OsStr,
|
ffi::OsStr,
|
||||||
fs, io,
|
fs, io,
|
||||||
path::{Path, PathBuf},
|
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;
|
//use crate::ALLOWED_FILE_EXTENSIONS;
|
||||||
|
|
||||||
|
@ -42,7 +42,10 @@ impl FileEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_unique_id(path: PathBuf) -> String {
|
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();
|
let mut hasher = DefaultHasher::new();
|
||||||
now.hash(&mut hasher);
|
now.hash(&mut hasher);
|
||||||
|
@ -147,10 +150,10 @@ fn generate_entry(path: &Path) -> Option<FileEntry> {
|
||||||
if file_name.to_string_lossy().starts_with('.') {
|
if file_name.to_string_lossy().starts_with('.') {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
// let extension = path.extension().and_then(|ext| ext.to_str());
|
// let extension = path.extension().and_then(|ext| ext.to_str());
|
||||||
// if !ALLOWED_FILE_EXTENSIONS.contains(&extension.unwrap_or_default()) {
|
// if !ALLOWED_FILE_EXTENSIONS.contains(&extension.unwrap_or_default()) {
|
||||||
// return None;
|
// return None;
|
||||||
// }
|
// }
|
||||||
} else {
|
} else {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,9 @@ fn get_id() -> usize {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_project(ui: &mut egui::Ui, theme: ColorTheme, project: &mut Project) {
|
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() {
|
for (category_index, category) in project.categories.clone().into_iter().enumerate() {
|
||||||
let ui = &mut uis[category_index];
|
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,
|
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(
|
ui.add(
|
||||||
egui::Button::new(item.name.clone())
|
egui::Button::new(item.name.clone())
|
||||||
.fill(hex_str_to_color(theme.functions)),
|
.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 =
|
ui.style_mut().visuals.override_text_color =
|
||||||
Some(hex_str_to_color(theme.literals));
|
Some(hex_str_to_color(theme.literals));
|
||||||
if ui
|
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()
|
.clicked()
|
||||||
{
|
{
|
||||||
project.selected_item = Location {
|
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 =
|
ui.style_mut().visuals.override_text_color = Some(hex_str_to_color(theme.literals));
|
||||||
Some(hex_str_to_color(theme.literals));
|
|
||||||
if category.name != "+" && ui.add(egui::Button::new("+")).clicked() {
|
if category.name != "+" && ui.add(egui::Button::new("+")).clicked() {
|
||||||
project.categories[category_index]
|
project.categories[category_index]
|
||||||
.content
|
.content
|
||||||
.push(Item::new("item"));
|
.push(Item::new("item"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
let mut moved = false;
|
let mut moved = false;
|
||||||
let category = project.selected_item.category;
|
let category = project.selected_item.category;
|
||||||
|
|
|
@ -22,10 +22,10 @@ impl ProjectItemWindow {
|
||||||
|
|
||||||
if let Some(response) = maybe_response {
|
if let Some(response) = maybe_response {
|
||||||
if let Some(delete_option) = response.inner {
|
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 {
|
fn ui(&mut self, ui: &mut egui::Ui, item: &mut panels::Item) -> bool {
|
||||||
|
@ -43,6 +43,6 @@ impl ProjectItemWindow {
|
||||||
ui.available_size(),
|
ui.available_size(),
|
||||||
egui::TextEdit::multiline(&mut item.description),
|
egui::TextEdit::multiline(&mut item.description),
|
||||||
);
|
);
|
||||||
return delete_item.clone()
|
return delete_item.clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue