added search window

This commit is contained in:
Penwing 2024-01-22 09:11:54 +01:00
parent 4257648e86
commit 5769965c6c
4 changed files with 157 additions and 4 deletions

View file

@ -1 +1,13 @@
# Calcifer # Calcifer
My cutsom code editor (only the features I want inside)
# 1.0 :
Added a File Tree
Added Tabs
Added an Embedded Terminal
Added Syntax Highlighting
Added Themes
# 1.1 :
Better Terminal

View file

@ -5,6 +5,7 @@ mod calcifer;
use eframe::egui; use eframe::egui;
use egui_code_editor::ColorTheme; use egui_code_editor::ColorTheme;
use std::{path::Path, sync::Arc}; use std::{path::Path, sync::Arc};
use tools::Demo;
const TERMINAL_HEIGHT : f32 = 200.0; const TERMINAL_HEIGHT : f32 = 200.0;
const RED : egui::Color32 = egui::Color32::from_rgb(235, 108, 99); const RED : egui::Color32 = egui::Color32::from_rgb(235, 108, 99);
@ -37,7 +38,7 @@ fn main() -> Result<(), eframe::Error> {
} }
eframe::run_native( eframe::run_native(
"Calcifer", "Calcifer v1.1",
options, options,
Box::new(move |_cc| Box::from(Calcifer::from_app_state(app_state))), Box::new(move |_cc| Box::from(Calcifer::from_app_state(app_state))),
) )
@ -47,9 +48,14 @@ fn main() -> Result<(), eframe::Error> {
struct Calcifer { struct Calcifer {
selected_tab : tools::TabNumber, selected_tab : tools::TabNumber,
tabs: Vec<tools::Tab>, tabs: Vec<tools::Tab>,
command: String, command: String,
command_history: Vec<tools::CommandEntry>, command_history: Vec<tools::CommandEntry>,
theme: ColorTheme, theme: ColorTheme,
search: tools::search::SearchWindow,
searching: bool,
} }
@ -58,9 +64,14 @@ impl Default for Calcifer {
Self { Self {
selected_tab: tools::TabNumber::Zero, selected_tab: tools::TabNumber::Zero,
tabs: vec![tools::Tab::default()], tabs: vec![tools::Tab::default()],
command: String::new(), command: String::new(),
command_history: Vec::new(), command_history: Vec::new(),
theme: tools::themes::CustomColorTheme::fire(), theme: tools::themes::CustomColorTheme::fire(),
search: tools::search::SearchWindow::default(),
searching: false,
} }
} }
} }
@ -79,12 +90,20 @@ impl eframe::App for Calcifer {
if ctx.input( |i| i.key_pressed(egui::Key::Z) && i.modifiers.ctrl) { if ctx.input( |i| i.key_pressed(egui::Key::Z) && i.modifiers.ctrl) {
self.undo(); self.undo();
} }
if ctx.input( |i| i.key_pressed(egui::Key::F) && i.modifiers.ctrl) {
self.searching = !self.searching.clone();
}
self.draw_settings(ctx); self.draw_settings(ctx);
self.draw_tree_panel(ctx); self.draw_tree_panel(ctx);
self.draw_terminal_panel(ctx); self.draw_terminal_panel(ctx);
self.draw_tab_panel(ctx); self.draw_tab_panel(ctx);
self.draw_content_panel(ctx); self.draw_content_panel(ctx);
if self.searching {
self.search.show(ctx, &mut self.searching, &mut self.tabs, &mut self.selected_tab);
}
} }
fn on_exit(&mut self, _gl : std::option::Option<&eframe::glow::Context>) { fn on_exit(&mut self, _gl : std::option::Option<&eframe::glow::Context>) {

View file

@ -1,9 +1,30 @@
use std::{process::Command, cmp::Ordering, env, path::PathBuf, fs::read_to_string, fs::write}; use std::{process::Command, cmp::Ordering, env, path::PathBuf, fs::read_to_string, fs::write};
use egui_code_editor::Syntax; use egui_code_editor::Syntax;
use eframe::egui::IconData; use eframe::egui;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
pub mod themes; pub mod themes;
pub mod search;
pub trait View {
fn ui(&mut self, ui: &mut egui::Ui);
}
/// Something to view
pub trait Demo {
/// Is the demo enabled for this integraton?
fn is_enabled(&self, _ctx: &egui::Context) -> bool {
true
}
/// `&'static` so we can also use it as a key to store open/close state.
fn name(&self) -> &str; //'static
/// Show windows, etc
fn show(&mut self, ctx: &egui::Context, open: &mut bool, tabs: &mut Vec<Tab>, selected_tab: &mut TabNumber);
}
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub enum TabNumber { pub enum TabNumber {
@ -125,7 +146,7 @@ pub fn loaded() {
println!("Tools loaded"); println!("Tools loaded");
} }
pub fn load_icon() -> IconData { pub fn load_icon() -> egui::IconData {
let (icon_rgba, icon_width, icon_height) = { let (icon_rgba, icon_width, icon_height) = {
let icon = include_bytes!("../../assets/icon.png"); let icon = include_bytes!("../../assets/icon.png");
let image = image::load_from_memory(icon) let image = image::load_from_memory(icon)
@ -136,7 +157,7 @@ pub fn load_icon() -> IconData {
(rgba, width, height) (rgba, width, height)
}; };
IconData { egui::IconData {
rgba: icon_rgba, rgba: icon_rgba,
width: icon_width, width: icon_width,
height: icon_height, height: icon_height,

101
src/tools/search.rs Normal file
View file

@ -0,0 +1,101 @@
use eframe::egui;
use crate::tools::{View, Demo, Tab, TabNumber};
pub struct Selection {
pub start: usize,
pub end: usize,
}
impl Default for Selection {
fn default() -> Self {
Self {
start: 0,
end: 0,
}
}
}
pub struct SearchWindow {
search_text: String,
result: Selection,
across_documents: bool,
replace_text: String,
}
impl Default for SearchWindow {
fn default() -> Self {
Self {
search_text: "".into(),
result: Selection::default(),
across_documents: false,
replace_text: "".into(),
}
}
}
impl Demo for SearchWindow {
fn name(&self) -> &str { //'static
"Search"
}
fn show(&mut self, ctx: &egui::Context, open: &mut bool, tabs: &mut Vec<Tab>, selected_tab: &mut TabNumber) {
egui::Window::new(self.name())
.open(open)
.vscroll(true)
.hscroll(true)
.show(ctx, |ui| self.ui(ui));
}
}
impl View for SearchWindow {
fn ui(&mut self, ui: &mut egui::Ui) {
ui.set_min_width(250.0);
ui.horizontal(|ui| {
let Self { search_text, .. } = self;
ui.add(egui::TextEdit::singleline(search_text).desired_width(120.0).lock_focus(true));
if ui.add(egui::Button::new("<")).clicked() {
self.find_previous();
}
if ui.add(egui::Button::new(">")).clicked() {
self.find_next();
}
});
ui.checkbox(&mut self.across_documents, "Across documents");
egui::CollapsingHeader::new("Replace")
.default_open(false)
.show(ui, |ui| {
ui.horizontal(|ui| {
let Self { replace_text, .. } = self;
ui.add(egui::TextEdit::singleline(replace_text).desired_width(120.0).lock_focus(true));
if ui.add(egui::Button::new("Replace")).clicked() {
self.replace_text();
}
});
});
}
}
impl SearchWindow {
fn find_previous(&self) {
println!("Searched for previous");
}
fn find_next(&self) {
println!("Searched for next");
}
fn replace_text(&self) {
println!("Searched to replace {} with {}", &self.search_text, &self.replace_text);
}
}