Skip to content

Commit 254e9e6

Browse files
committed
[gui]
working on filtering options pretty messy
1 parent 58754b3 commit 254e9e6

File tree

4 files changed

+78
-76
lines changed

4 files changed

+78
-76
lines changed

function-grep/src/filter.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ pub trait HasFilterInformation {
113113
fn description(&self) -> String;
114114
/// what languages this filter works on
115115
fn supports(&self) -> Self::Supports;
116+
116117
fn attributes(&self) -> Attributes;
117118
// TODO: have filter creation informaton about types and fields for uis
118119
fn filter_info(&self) -> FilterInformation<Self::Supports> {
@@ -218,7 +219,6 @@ pub struct Many<T: Info<Supported = Language>> {
218219
pub filters: HashMap<String, T>,
219220
}
220221

221-
// TODO: merge with HasFilterInformation
222222
pub trait Info {
223223
type Supported;
224224
fn filter_name(&self) -> String;
@@ -244,16 +244,6 @@ impl<A: Info<Supported = All>, M: Info<Supported = Language>> SingleOrMany<A, M>
244244
Self::Single(s) => s.filter_name(),
245245
}
246246
}
247-
248-
#[must_use]
249-
pub fn supports(&self) -> SupportedLanguages {
250-
match self {
251-
Self::All(_) => SupportedLanguages::All,
252-
Self::Many(many) => SupportedLanguages::Many(many.filters.keys().cloned().collect()),
253-
// TODO: make Info carry not just the supported type but also a value for it
254-
Self::Single(_s) => todo!(),
255-
}
256-
}
257247
}
258248
impl<A: Info<Supported = All>, M: Info<Supported = Language>> Display for SingleOrMany<A, M> {
259249
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

function-grep/src/supported_languages.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ impl<'a> InstantiatedLanguage<'a> {
255255

256256
#[macro_export]
257257
/// Use to more easily make new [`SupportedLanguage`]s.
258+
///
258259
/// First provide the name (which is used as the type of the language), followed by the tree sitter
259260
/// languge in parenthesis, next you put the file extensions in brackets with a leading .
260261
/// to specify the query we use ?= variable -> string literal query.

git-function-history-gui/src/lib.rs

Lines changed: 50 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use function_history_backend_thread::types::{
1212
};
1313
use git_function_history::{types::Directions, Commit, FileFilterType, Filter, FunctionHistory};
1414
use itertools::Itertools;
15-
use types::HistoryFilterType;
15+
use types::{HistoryFilterType, PLFilter};
1616

1717
// TODO: stop cloning everyting and use references instead
1818
pub struct MyEguiApp {
@@ -398,37 +398,13 @@ impl eframe::App for MyEguiApp {
398398
HistoryFilterType::None,
399399
"none",
400400
);
401-
function_grep::filter::Filters::default()
402-
.into_iter()
403-
.sorted_by_cached_key(|(key, _)| {
404-
key.clone()
405-
})
406-
.for_each(|filter| {
407-
ui.selectable_value(
408-
&mut self.history_filter_type,
409-
HistoryFilterType::PL(
410-
if let function_grep::filter::FilterType::All(filter) =
411-
filter.1
412-
{
413-
filter
414-
.attributes()
415-
.into_iter()
416-
.map(|(attr, kind)| {
417-
(
418-
attr.to_string(
419-
),
420-
kind.to_string(
421-
),
422-
)
423-
})
424-
.collect()
425-
} else {
426-
HashMap::new()
427-
},
428-
filter.1,
429-
),
430-
filter.0,
431-
);
401+
function_grep::filter::Filters::default() .into_iter() .sorted_by_cached_key(|(key, _)| { key.clone() }) .for_each(|filter| { ui.selectable_value( &mut self.history_filter_type, match filter.1 { function_grep::filter::FilterType::All(allfilter) => { HistoryFilterType::PL( types::PLFilter::Single( allfilter .attributes() .into_iter() .map(|(attr, kind)| { ( attr.to_string(), kind.to_string(),) }) .collect(), filter.1)) } function_grep::filter::FilterType::Single(allfilter) => { HistoryFilterType::PL( types::PLFilter::Single( allfilter .attributes() .into_iter() .map(|(attr, kind)| { ( attr.to_string(), kind.to_string(),) }) .collect(), filter.1)) }
402+
403+
404+
function_grep::filter::SingleOrMany::Many(ref filters) => {
405+
let collect_vec = filters.filters.keys().cloned().collect_vec();
406+
HistoryFilterType::PL(types::PLFilter::Many( HashMap::new(), filter.1, collect_vec, None, String::new() ))
407+
} }, filter.0,);
432408
})
433409
});
434410
match &mut self.history_filter_type {
@@ -445,33 +421,52 @@ impl eframe::App for MyEguiApp {
445421
HistoryFilterType::None => {
446422
// do nothing
447423
}
448-
HistoryFilterType::PL(inputs, filters) => {
449-
inputs.iter_mut().for_each(|(desc, field)| {
424+
HistoryFilterType::PL(filter ) => {
425+
match filter {
426+
types::PLFilter::Single(inputs, _) => {
427+
inputs.iter_mut().for_each(|(desc, field )| {
450428
ui.horizontal(|ui| {
451429
ui.set_min_width(4.0);
452430
ui.set_max_width(max);
453431
ui.label(desc.to_string());
454432
ui.add(TextEdit::singleline(field));
455433
});
456-
if let function_grep::filter::FilterType::Many(_) = filters {
434+
});
435+
}
436+
types::PLFilter::Many(inputs,filters, languages, specific, next_field ) => {
437+
// TODO: cleanup
438+
inputs.iter_mut().for_each(|(desc, field )| {
439+
ui.horizontal(|ui| {
440+
ui.set_min_width(4.0);
441+
ui.set_max_width(max);
442+
ui.label(desc.to_string());
443+
ui.add(TextEdit::singleline(&mut field.1));
444+
// TODO: make - work
445+
field.0= ui.add(Button::new("-")).clicked();
446+
});
447+
});
457448

458-
// TODO: update history filter type
459-
// hashmap to keep track of if a field
460-
// is removed
461-
let resp = ui.add(Button::new("-"));
462-
if resp.clicked() {
463-
}
464-
}
465-
});
466-
if let function_grep::filter::FilterType::Many(_) = filters {
449+
ui.add(TextEdit::singleline(next_field));
467450
let resp = ui.add(Button::new("add field"));
468451
if resp.clicked() {
469-
let total = inputs.len()+ 1;
470-
inputs.insert(format!("field{total}"), String::new());
452+
inputs.insert(next_field.to_string(), (false, String::new()));
471453
}
472-
}
454+
455+
egui::ComboBox::from_id_source("filter_language_chooser")
456+
.selected_text("Language")
457+
.show_ui(ui, |ui| {
458+
ui.selectable_value(
459+
specific, None, "All");
460+
languages.iter().for_each(|name| { ui.selectable_value(specific, Some(name.to_string()), name); });
461+
}
462+
463+
);
464+
if let Some(language) = specific {
465+
*filter = PLFilter::Single(HashMap::new(), filters.specific(language).unwrap());
466+
}
467+
473468
}
474-
}
469+
}}}
475470
let resp = ui.add(Button::new("Go"));
476471
if resp.clicked() {
477472
self.status = Status::Loading;
@@ -503,14 +498,13 @@ impl eframe::App for MyEguiApp {
503498
self.status = Status::Ok(None);
504499
None
505500
}
506-
HistoryFilterType::PL(input, filter) => {
507-
let filter = filter.to_filter(
508-
&input
509-
.values()
510-
.cloned()
511-
.collect::<Vec<_>>()
512-
.join(" "),
513-
);
501+
HistoryFilterType::PL(filter) => {
502+
let filter = match filter {
503+
types::PLFilter::Single(hash_map, single_or_many) => single_or_many.to_filter(&hash_map.into_iter().map(|v| format!("{}: {}", v.0, v.1)).collect_vec().join(" ")),
504+
types::PLFilter::Many(input, filter, _, _, _) =>
505+
filter.to_filter(&input.into_iter().map(|v| format!("{}: {}", v.0, v.1.1)).collect_vec().join(" "))
506+
507+
};
514508
filter
515509
.inspect_err(|e| {
516510
self.status =

git-function-history-gui/src/types.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use function_grep::filter::FilterType;
1+
use function_grep::filter::{All, Filter, FilterType, Language};
22
use std::{collections::HashMap, fmt};
33

44
pub enum HistoryFilterType {
@@ -11,9 +11,30 @@ pub enum HistoryFilterType {
1111
// TODO: if filter type is a many and it has more than on filter
1212
// 1. if you can pick which language to use
1313
// 2. or you can add or remove a field to apply to the filter
14-
PL(HashMap<String, String>, FilterType<'static>),
14+
PL(PLFilter),
1515
None,
1616
}
17+
pub enum PLFilter {
18+
Single(HashMap<String, String>, FilterType<'static>),
19+
Many(
20+
// if the field should be deleted
21+
HashMap<String, (bool, String)>,
22+
FilterType<'static>,
23+
Vec<String>,
24+
// choose a sepcific language that supports this filter
25+
Option<String>,
26+
// next field
27+
String,
28+
),
29+
}
30+
impl PLFilter {
31+
fn filter_name(&self) -> String {
32+
match self {
33+
PLFilter::Single(_, single_or_many) => single_or_many.filter_name(),
34+
PLFilter::Many(_, filter, _, _, _) => filter.filter_name(),
35+
}
36+
}
37+
}
1738

1839
impl PartialEq for HistoryFilterType {
1940
fn eq(&self, other: &Self) -> bool {
@@ -24,7 +45,7 @@ impl PartialEq for HistoryFilterType {
2445
(Self::FileAbsolute(l0), Self::FileAbsolute(r0)) => l0 == r0,
2546
(Self::FileRelative(l0), Self::FileRelative(r0)) => l0 == r0,
2647
(Self::Directory(l0), Self::Directory(r0)) => l0 == r0,
27-
(Self::PL(_, l1), Self::PL(_, r1)) => l1.filter_name() == r1.filter_name(),
48+
(Self::PL(l0), Self::PL(r0)) => l0.filter_name() == r0.filter_name(),
2849
_ => core::mem::discriminant(self) == core::mem::discriminant(other),
2950
}
3051
}
@@ -43,11 +64,7 @@ impl fmt::Debug for HistoryFilterType {
4364
Self::FileAbsolute(arg0) => f.debug_tuple("FileAbsolute").field(arg0).finish(),
4465
Self::FileRelative(arg0) => f.debug_tuple("FileRelative").field(arg0).finish(),
4566
Self::Directory(arg0) => f.debug_tuple("Directory").field(arg0).finish(),
46-
Self::PL(arg0, arg1) => f
47-
.debug_tuple("PL")
48-
.field(arg0)
49-
.field(&arg1.filter_name())
50-
.finish(),
67+
Self::PL(filter) => f.debug_tuple("PL").field(&filter.filter_name()).finish(),
5168
Self::None => write!(f, "None"),
5269
}
5370
}
@@ -62,7 +79,7 @@ impl fmt::Display for HistoryFilterType {
6279
HistoryFilterType::FileAbsolute(_) => write!(f, "file absolute"),
6380
HistoryFilterType::FileRelative(_) => write!(f, "file relative"),
6481
HistoryFilterType::Directory(_) => write!(f, "directory"),
65-
HistoryFilterType::PL(_, pl) => write!(f, "{}", pl.filter_name()),
82+
HistoryFilterType::PL(pl) => write!(f, "{}", pl.filter_name()),
6683
HistoryFilterType::None => write!(f, "none"),
6784
}
6885
}

0 commit comments

Comments
 (0)