finished item edit window, and lateral item movement

This commit is contained in:
Penwing 2024-02-02 18:55:39 +01:00
parent afec8f6426
commit 95bfd219e9
5 changed files with 768 additions and 735 deletions

View file

@ -42,10 +42,10 @@ impl Calcifer {
ui.separator(); ui.separator();
self.profiler_visible = self.toggle(ui, self.profiler_visible, ""); self.profiler_visible = self.toggle(ui, self.profiler_visible, "");
// if self.tabs[self.selected_tab.to_index()].language == PROJECT_EXTENSION { if self.tabs[self.selected_tab.to_index()].language == PROJECT_EXTENSION {
// ui.separator(); ui.separator();
// self.project_mode = self.toggle(ui, self.project_mode, "c"); self.project_content.item_window.visible = self.toggle(ui, self.project_content.item_window.visible, "🖊");
// } }
}); });
}); });
} }
@ -141,10 +141,13 @@ impl Calcifer {
ui.style_mut().visuals.hyperlink_color = ui.style_mut().visuals.hyperlink_color =
core::hex_str_to_color(self.theme.keywords); core::hex_str_to_color(self.theme.keywords);
let mut running_command = false;
for entry in &mut self.command_history { for entry in &mut self.command_history {
ui.label(""); ui.label("");
ui.horizontal(|ui| { ui.horizontal(|ui| {
if !entry.finished { if !entry.finished {
running_command = true;
entry.update(); entry.update();
let _ = ui.link("(⌛)"); let _ = ui.link("(⌛)");
} else if ui.link("(🗐)").clicked() { } else if ui.link("(🗐)").clicked() {
@ -165,6 +168,8 @@ impl Calcifer {
); );
} }
} }
self.running_command = running_command;
}); });
}); });
}); });
@ -243,8 +248,7 @@ impl Calcifer {
}); });
ui.separator(); ui.separator();
if self.project_mode if self.tabs[self.selected_tab.to_index()].language == PROJECT_EXTENSION
&& self.tabs[self.selected_tab.to_index()].language == PROJECT_EXTENSION
{ {
self.draw_project_file(ui); self.draw_project_file(ui);
} else { } else {
@ -289,11 +293,16 @@ impl Calcifer {
pub fn draw_windows(&mut self, ctx: &egui::Context) { pub fn draw_windows(&mut self, ctx: &egui::Context) {
if self.project_content.item_window.visible { if self.project_content.item_window.visible {
if self.project_content.categories.len() > 1 && self.project_content.categories[self.project_content.selected_item.category].content.len() > 0 {
self.project_content.item_window.show( self.project_content.item_window.show(
ctx, ctx,
&mut self.project_content.categories[self.project_content.selected_item.category] &mut self.project_content.categories[self.project_content.selected_item.category]
.content[self.project_content.selected_item.row], .content[self.project_content.selected_item.row],
); );
} else {
self.project_content.item_window.visible = false;
}
} }
if self.search_menu.visible { if self.search_menu.visible {
self.search_menu self.search_menu

View file

@ -63,11 +63,11 @@ struct Calcifer {
command: String, command: String,
command_history: Vec<panels::CommandEntry>, command_history: Vec<panels::CommandEntry>,
running_command: bool,
theme: editor::ColorTheme, theme: editor::ColorTheme,
font_size: f32, font_size: f32,
project_mode: bool,
project_content: panels::Project, project_content: panels::Project,
home: PathBuf, home: PathBuf,
@ -100,11 +100,11 @@ impl Default for Calcifer {
command: String::new(), command: String::new(),
command_history: Vec::new(), command_history: Vec::new(),
running_command: false,
theme: editor::themes::DEFAULT_THEMES[0], theme: editor::themes::DEFAULT_THEMES[0],
font_size: 14.0, font_size: 14.0,
project_mode: true,
project_content: panels::Project::new(), project_content: panels::Project::new(),
home: get_my_home().unwrap().unwrap(), home: get_my_home().unwrap().unwrap(),

View file

@ -73,7 +73,7 @@ impl Item {
fn new(name: &str) -> Self { fn new(name: &str) -> Self {
Self { Self {
name: name.to_string(), name: name.to_string(),
description: "".to_string(), description: "// Hello there".to_string(),
id: get_id(), id: get_id(),
} }
} }
@ -108,6 +108,7 @@ pub fn draw_project(ui: &mut egui::Ui, theme: ColorTheme, project: &mut Project)
if ui.add(egui::Button::new("+")).clicked() { if ui.add(egui::Button::new("+")).clicked() {
project.add_category(); project.add_category();
} }
continue;
} else { } else {
let response = ui.add( let response = ui.add(
egui::TextEdit::singleline(&mut project.categories[category_index].name) egui::TextEdit::singleline(&mut project.categories[category_index].name)
@ -118,6 +119,8 @@ pub fn draw_project(ui: &mut egui::Ui, theme: ColorTheme, project: &mut Project)
} }
} }
ui.separator();
for (item_index, item) in category.content.iter().enumerate() { for (item_index, item) in category.content.iter().enumerate() {
if project.selected_item if project.selected_item
== (Location { == (Location {
@ -159,7 +162,45 @@ pub fn draw_project(ui: &mut egui::Ui, theme: ColorTheme, project: &mut Project)
let category = project.selected_item.category.clone(); let category = project.selected_item.category.clone();
let row = project.selected_item.row.clone(); let row = project.selected_item.row.clone();
if ui.input(|i| i.key_pressed(egui::Key::ArrowLeft)) && project.selected_item.category > 0 { if ui.input(|i| i.key_pressed(egui::Key::ArrowLeft) && i.modifiers.shift) && project.selected_item.category > 0 {
moved = true;
if !project.was_moving {
let temp = project.categories[category].content[row].clone();
project.categories[category - 1].content.push(temp);
project.categories[category].content.remove(row);
project.selected_item.category -= 1;
project.selected_item.row = project.categories[category - 1].content.len() - 1;
}
} else if ui.input(|i| i.key_pressed(egui::Key::ArrowRight) && i.modifiers.shift) && project.selected_item.category < project.categories.len() - 2 {
moved = true;
if !project.was_moving {
let temp = project.categories[category].content[row].clone();
project.categories[category + 1].content.push(temp);
project.categories[category].content.remove(row);
project.selected_item.category += 1;
project.selected_item.row = project.categories[category + 1].content.len() - 1;
}
} else if ui.input(|i| i.key_pressed(egui::Key::ArrowUp) && i.modifiers.shift)
&& project.selected_item.row > 0
{
moved = true;
if !project.was_moving {
let temp = project.categories[category].content[row].clone();
project.categories[category].content[row] =
project.categories[category].content[row - 1].clone();
project.categories[category].content[row - 1] = temp.clone();
project.selected_item.row -= 1;
}
} else if ui.input(|i| i.key_pressed(egui::Key::ArrowDown) && i.modifiers.shift) {
moved = true;
if !project.was_moving {
let temp = project.categories[category].content[row].clone();
project.categories[category].content[row] =
project.categories[category].content[row + 1].clone();
project.categories[category].content[row + 1] = temp.clone();
project.selected_item.row += 1;
}
} else if ui.input(|i| i.key_pressed(egui::Key::ArrowLeft)) && project.selected_item.category > 0 {
moved = true; moved = true;
if !project.was_moving { if !project.was_moving {
project.selected_item.category -= 1; project.selected_item.category -= 1;
@ -191,32 +232,6 @@ pub fn draw_project(ui: &mut egui::Ui, theme: ColorTheme, project: &mut Project)
if !project.was_moving { if !project.was_moving {
project.selected_item.row += 1; project.selected_item.row += 1;
} }
} else if ui.input(|i| i.key_pressed(egui::Key::ArrowLeft) && i.modifiers.shift) {
moved = true;
if !project.was_moving {}
} else if ui.input(|i| i.key_pressed(egui::Key::ArrowRight) && i.modifiers.shift) {
moved = true;
if !project.was_moving {}
} else if ui.input(|i| i.key_pressed(egui::Key::ArrowUp) && i.modifiers.shift)
&& project.selected_item.row > 0
{
moved = true;
if !project.was_moving {
let temp = project.categories[category].content[row].clone();
project.categories[category].content[row] =
project.categories[category].content[row - 1].clone();
project.categories[category].content[row - 1] = temp.clone();
project.selected_item.row -= 1;
}
} else if ui.input(|i| i.key_pressed(egui::Key::ArrowDown) && i.modifiers.shift) {
moved = true;
if !project.was_moving {
let temp = project.categories[category].content[row].clone();
project.categories[category].content[row] =
project.categories[category].content[row + 1].clone();
project.categories[category].content[row + 1] = temp.clone();
project.selected_item.row += 1;
}
} }
project.was_moving = moved; project.was_moving = moved;

View file

@ -13,7 +13,7 @@ impl ProjectItemWindow {
pub fn show(&mut self, ctx: &egui::Context, item: &mut panels::Item) { pub fn show(&mut self, ctx: &egui::Context, item: &mut panels::Item) {
let mut visible = self.visible; let mut visible = self.visible;
egui::Window::new("Project Item") egui::Window::new("Item")
.open(&mut visible) .open(&mut visible)
.vscroll(true) .vscroll(true)
.hscroll(true) .hscroll(true)
@ -23,6 +23,9 @@ impl ProjectItemWindow {
fn ui(&mut self, ui: &mut egui::Ui, item: &mut panels::Item) { fn ui(&mut self, ui: &mut egui::Ui, item: &mut panels::Item) {
ui.set_min_width(250.0); ui.set_min_width(250.0);
ui.label(item.name.clone()); ui.set_min_height(250.0);
ui.add(egui::TextEdit::singleline(&mut item.name).desired_width(f32::INFINITY));
ui.separator();
ui.add_sized(ui.available_size(), egui::TextEdit::multiline(&mut item.description));
} }
} }

View file

@ -32,5 +32,11 @@ impl ShortcutsWindow {
ui.label("Tab on selection : add indent of selection"); ui.label("Tab on selection : add indent of selection");
ui.label("Shift+Tab on selection : remove indent of selection"); ui.label("Shift+Tab on selection : remove indent of selection");
ui.label("Ctrl+E : comment selection"); ui.label("Ctrl+E : comment selection");
ui.separator();
ui.label("Alt+Arrows : move between tabs");
ui.separator();
ui.label("Enter (project_mode) : edit item");
ui.label("Arrows (project_mode) : change selected item");
ui.label("Shift+Arrows (project_mode) : move selected item");
} }
} }