killing of the buffer now works amazingly well

This commit is contained in:
filipriec
2025-05-25 22:24:26 +02:00
parent d8f9372bbd
commit 32210a5f7c
7 changed files with 38 additions and 18 deletions

View File

@@ -8,11 +8,13 @@ pub enum AppView {
Admin,
AddTable,
AddLogic,
Form(String),
Form, // Remove the String parameter
Scratch,
}
impl AppView {
/// Returns the display name for the view.
/// For Form, pass the current table name to get dynamic naming.
pub fn display_name(&self) -> &str {
match self {
AppView::Intro => "Intro",
@@ -21,12 +23,25 @@ impl AppView {
AppView::Admin => "Admin_Panel",
AppView::AddTable => "Add_Table",
AppView::AddLogic => "Add_Logic",
AppView::Form(name) => name.as_str(),
AppView::Form => "Form", // Default fallback
AppView::Scratch => "*scratch*",
}
}
/// Returns the display name with dynamic context (for Form buffers)
pub fn display_name_with_context(&self, current_table_name: Option<&str>) -> String {
match self {
AppView::Form => {
current_table_name
.unwrap_or("Data Form")
.to_string()
}
_ => self.display_name().to_string(),
}
}
}
// Rest of BufferState implementation remains the same
#[derive(Debug, Clone)]
pub struct BufferState {
pub history: Vec<AppView>,
@@ -80,7 +95,7 @@ impl BufferState {
true
}
pub fn close_buffer_with_intro_fallback(&mut self) -> String {
pub fn close_buffer_with_intro_fallback(&mut self, current_table_name: Option<&str>) -> String {
let current_view_cloned = self.get_active_view().cloned();
if let Some(AppView::Intro) = current_view_cloned {
return "Cannot close intro buffer".to_string();
@@ -88,7 +103,7 @@ impl BufferState {
let closed_name = current_view_cloned
.as_ref()
.map(|v| v.display_name().to_string())
.map(|v| v.display_name_with_context(current_table_name))
.unwrap_or_else(|| "Unknown".to_string());
if self.close_active_buffer() {