Fixed my mistakes

This commit is contained in:
Javier Feliz 2025-09-03 20:40:41 -04:00
parent 9c48379dfa
commit 70c4272611

View File

@ -104,8 +104,7 @@ impl AppModel {
window.set_keyboard_mode(layerShell::KeyboardMode::OnDemand); window.set_keyboard_mode(layerShell::KeyboardMode::OnDemand);
window.set_layer(layerShell::Layer::Top); window.set_layer(layerShell::Layer::Top);
let entries = drun::all(); let entries: Vec<Box<dyn LauncherListItem>> = Vec::new();
let plugins: Vec<Box<dyn LauncherPlugin>> = vec![Box::from(plugins::drun::DrunPlugin {})]; let plugins: Vec<Box<dyn LauncherPlugin>> = vec![Box::from(plugins::drun::DrunPlugin {})];
let model: Rc<RefCell<AppModel>> = Rc::new(RefCell::new(AppModel { let model: Rc<RefCell<AppModel>> = Rc::new(RefCell::new(AppModel {
window, window,
@ -115,17 +114,13 @@ impl AppModel {
})); }));
// Populate the list // Populate the list
{ model.borrow_mut().populate_list();
let model_ref = model.borrow();
model_ref.populate_list();
}
// Connect search input signal // Connect search input signal
let model_clone = model.clone(); let model_clone = model.clone();
search_input.connect_changed(move |entry| { search_input.connect_changed(move |entry| {
let query = entry.text().to_string(); let query = entry.text().to_string();
println!("query: {query}"); println!("query: {query}");
model_clone.borrow().filter_list(&query); model_clone.borrow_mut().filter_list(&query);
}); });
// Add ESC key handler to close window // Add ESC key handler to close window
@ -141,6 +136,16 @@ impl AppModel {
}); });
model.borrow().window.add_controller(key_controller); model.borrow().window.add_controller(key_controller);
// Connect row activation signal to print app names
let model_clone_2 = model.clone();
list_box.connect_row_activated(move |_, row| {
let index = row.index() as usize;
let model_ref = model_clone_2.borrow();
if let Some(entry) = model_ref.entries.get(index) {
println!("Selected app: {}", entry.title());
}
});
model model
} }
@ -150,28 +155,36 @@ impl AppModel {
} }
} }
fn populate_list(&self) { fn render_list(&self) {
self.clear_list_ui(); self.clear_list_ui();
for entry in &self.entries {
for plugin in &self.plugins {
for entry in plugin.default_list() {
let list_item = ListItem::new(entry.title(), entry.icon()); let list_item = ListItem::new(entry.title(), entry.icon());
let widget = list_item.create_widget(); let widget = list_item.create_widget();
self.list_box.append(&widget); self.list_box.append(&widget);
} }
} }
fn populate_list(&mut self) {
self.entries.clear();
for plugin in &self.plugins {
for entry in plugin.default_list() {
self.entries.push(entry);
}
} }
fn filter_list(&self, query: &str) { self.render_list();
self.clear_list_ui(); }
fn filter_list(&mut self, query: &str) {
self.entries.clear();
for plugin in &self.plugins { for plugin in &self.plugins {
for entry in plugin.filter(query) { for entry in plugin.filter(query) {
let list_item = ListItem::new(entry.title(), entry.icon()); self.entries.push(entry);
let widget = list_item.create_widget();
self.list_box.append(&widget);
} }
} }
self.render_list();
} }
fn show(&self) { fn show(&self) {