|
| 1 | +#![cfg_attr( |
| 2 | + not(debug_assertions), |
| 3 | + windows_subsystem = "windows" |
| 4 | +)] // hide console window on Windows in release |
| 5 | +#![allow(rustdoc::missing_crate_level_docs)] |
| 6 | + |
| 7 | +use binc::node_id::NodeId; |
| 8 | +use binc::node_store::Node; |
| 9 | +use bincgui::app::{create_toolbar, Application}; |
| 10 | +use eframe::egui::Ui; |
| 11 | +use eframe::{egui, Storage}; |
| 12 | +use eframe::egui::UiKind::Frame; |
| 13 | + |
| 14 | +fn main() -> eframe::Result { |
| 15 | + env_logger::init(); |
| 16 | + |
| 17 | + let options = eframe::NativeOptions { |
| 18 | + viewport: egui::ViewportBuilder::default().with_inner_size([900.0, 600.0]), |
| 19 | + ..Default::default() |
| 20 | + }; |
| 21 | + eframe::run_native( |
| 22 | + "Got issues", |
| 23 | + options, |
| 24 | + Box::new(|_cc| Ok(Box::new(IssuesApp::new()))), |
| 25 | + ) |
| 26 | +} |
| 27 | + |
| 28 | +struct IssuesApp { |
| 29 | + application: Application, |
| 30 | + search_string: String, |
| 31 | + found_issues: Vec<NodeId>, |
| 32 | +} |
| 33 | + |
| 34 | +impl IssuesApp { |
| 35 | + fn new() -> Self { |
| 36 | + Self { |
| 37 | + application: Application::new(), |
| 38 | + search_string: String::new(), |
| 39 | + found_issues: vec![], |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + fn update_search(&mut self) { |
| 44 | + self.found_issues = self.get_issues_for_search(&self.search_string); |
| 45 | + } |
| 46 | + |
| 47 | + fn get_issues_for_search(&self, search_string: &str) -> Vec<NodeId> { |
| 48 | + if !search_string.is_empty() { |
| 49 | + let terms = search_string.split(" "); |
| 50 | + |
| 51 | + if let Some(issue_id) = self.application.document.nodes.type_names.get_index("issue") { |
| 52 | + let mut issues = vec![]; |
| 53 | + let summary_id = self.application.document.nodes.attribute_names.get_index("summary"); |
| 54 | + |
| 55 | + for node in self.application.document.nodes.nodes() { |
| 56 | + if Some(issue_id) == node.type_id { |
| 57 | + if let Some(summary) = node.get_string_attribute(summary_id.unwrap()) { |
| 58 | + let mut found = true; |
| 59 | + let mut t = terms.clone(); |
| 60 | + while let Some(term) = t.next() { |
| 61 | + if !summary.to_lowercase().contains(&term.to_lowercase()) { |
| 62 | + found = false; |
| 63 | + break; |
| 64 | + } |
| 65 | + } |
| 66 | + if found { |
| 67 | + issues.push(node.id); |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | + return issues; |
| 73 | + } |
| 74 | + } |
| 75 | + vec![] |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +impl eframe::App for IssuesApp { |
| 80 | + fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { |
| 81 | + let summary_id = self.application.document.nodes.attribute_names.get_index("summary").unwrap_or(0); |
| 82 | + let permalink_id = self.application.document.nodes.attribute_names.get_index("permalink").unwrap_or(0); |
| 83 | + |
| 84 | + let frame = egui::Frame::default() |
| 85 | + .inner_margin(8.0) |
| 86 | + .fill(ctx.style().visuals.panel_fill); |
| 87 | + egui::TopBottomPanel::top("toolbar") |
| 88 | + .frame(frame) |
| 89 | + .show(ctx, |ui| { |
| 90 | + create_toolbar(&mut self.application, ui, |ui| {}); |
| 91 | + }); |
| 92 | + |
| 93 | + egui::CentralPanel::default().show(ctx, |ui| { |
| 94 | + |
| 95 | + ui.vertical_centered(|ui| { |
| 96 | + if ui.text_edit_singleline(&mut self.search_string).changed() { |
| 97 | + self.update_search(); |
| 98 | + } |
| 99 | + |
| 100 | + let f = egui::Frame::default() |
| 101 | + .inner_margin(16.0) |
| 102 | + .fill(ctx.style().visuals.panel_fill) |
| 103 | + .shadow(ctx.style().visuals.window_shadow) |
| 104 | + .stroke(ctx.style().visuals.widgets.noninteractive.bg_stroke); |
| 105 | + |
| 106 | + |
| 107 | + for id in &self.found_issues { |
| 108 | + f.show(ui, |ui| { |
| 109 | + let node = self.application.document.nodes.get(*id).unwrap(); |
| 110 | + let label = node.get_string_attribute(summary_id).unwrap_or("?".to_string()); |
| 111 | + let url = node.get_string_attribute(permalink_id) .unwrap_or("?".to_string()); |
| 112 | + ui.hyperlink_to(label, url); |
| 113 | + }); |
| 114 | + } |
| 115 | + }) |
| 116 | + }); |
| 117 | +} |
| 118 | + |
| 119 | +fn save(&mut self, _storage: &mut dyn Storage) { |
| 120 | + // Save app state here |
| 121 | + } |
| 122 | +} |
0 commit comments