Skip to content

Commit

Permalink
Show regex error as tooltip for commit author filter
Browse files Browse the repository at this point in the history
  • Loading branch information
ArekPiekarz committed Jun 19, 2022
1 parent a9273ad commit 13249bd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
12 changes: 8 additions & 4 deletions src/commit_log_author_filter_entry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::event::{Event, handleUnknown, IEventHandler, Sender, Source};
use crate::gui_element_provider::GuiElementProvider;

use anyhow::Error;
use gtk::EditableSignals;
use gtk::prelude::IsA;
use gtk::traits::CssProviderExt;
Expand All @@ -15,6 +16,7 @@ const VALID_INPUT_CSS: &[u8] = "".as_bytes();

pub(crate) struct CommitLogAuthorFilterEntry
{
widget: gtk::Entry,
cssProvider: gtk::CssProvider
}

Expand All @@ -23,8 +25,8 @@ impl IEventHandler for CommitLogAuthorFilterEntry
fn handle(&mut self, source: Source, event: &Event)
{
match event {
Event::InvalidTextInputted => self.onInvalidRegexInputted(),
Event::ValidTextInputted => self.onValidRegexInputted(),
Event::InvalidTextInputted(error) => self.onInvalidRegexInputted(error),
Event::ValidTextInputted => self.onValidRegexInputted(),
_ => handleUnknown(source, event)
}
}
Expand All @@ -38,17 +40,19 @@ impl CommitLogAuthorFilterEntry
let cssProvider = setupCss(&widget);
connectWidget(&widget, sender.clone());
setupRegexButton(guiElementProvider, sender);
Self{cssProvider}
Self{widget, cssProvider}
}

fn onInvalidRegexInputted(&self)
fn onInvalidRegexInputted(&self, error: &Error)
{
self.cssProvider.load_from_data(INVALID_INPUT_CSS).unwrap();
self.widget.set_tooltip_text(Some(&error.to_string()));
}

fn onValidRegexInputted(&self)
{
self.cssProvider.load_from_data(VALID_INPUT_CSS).unwrap();
self.widget.set_tooltip_text(None);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/commit_log_model_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::event::{Event, handleUnknown, IEventHandler, Sender, Source};
use crate::gui_element_provider::GuiElementProvider;
use crate::text_filter::TextFilter;

use anyhow::Result;
use anyhow::{Error, Result};
use gtk::traits::TreeModelExt;
use gtk::traits::TreeModelFilterExt;
use std::cell::RefCell;
Expand Down Expand Up @@ -61,7 +61,7 @@ impl CommitLogModelFilter
{
match result {
Ok(()) => self.onChangeSucceeded(),
Err(_) => self.onChangeFailed()
Err(e) => self.onChangeFailed(e)
}
}

Expand All @@ -74,11 +74,11 @@ impl CommitLogModelFilter
self.requestRefilter();
}

fn onChangeFailed(&mut self)
fn onChangeFailed(&mut self, error: Error)
{
if self.state == State::Success {
self.state = State::Failure;
self.sendInvalidTextInputted();
self.sendInvalidTextInputted(error);
}
}

Expand All @@ -98,9 +98,9 @@ impl CommitLogModelFilter
self.sender.send((Source::CommitLogModelFilter, Event::ValidTextInputted)).unwrap();
}

fn sendInvalidTextInputted(&self)
fn sendInvalidTextInputted(&self, error: Error)
{
self.sender.send((Source::CommitLogModelFilter, Event::InvalidTextInputted)).unwrap();
self.sender.send((Source::CommitLogModelFilter, Event::InvalidTextInputted(error))).unwrap();
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/event.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::commit_message::CommitMessage;
use crate::file_change::{FileChange, FileChangeUpdate};

use anyhow::Error;
use gtk::{gdk, glib};


Expand Down Expand Up @@ -66,7 +67,7 @@ pub enum Event

// text entry
TextEntered(String),
InvalidTextInputted,
InvalidTextInputted(Error),
ValidTextInputted,
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn setupDispatching(gui: GuiObjects, mut repository: Rc<RefCell<Repository>>, re
(S::CommitLogAuthorFilterRegexButton, E::Toggled(_)) => commitLogModelFilter.handle(source, &event),
(S::CommitLogModelFilter, E::RefilterRequested) => (&mut commitLogView, &mut commitLogModelFilter).handle(source, &event),
(S::CommitLogModelFilter, E::RefilterEnded) => commitLogView.handle(source, &event),
(S::CommitLogModelFilter, E::InvalidTextInputted) => commitLogAuthorFilterEntry.handle(source, &event),
(S::CommitLogModelFilter, E::InvalidTextInputted(_)) => commitLogAuthorFilterEntry.handle(source, &event),
(S::CommitLogModelFilter, E::ValidTextInputted) => commitLogAuthorFilterEntry.handle(source, &event),
(S::CommitLogView, E::CommitSelected(_)) => commitDiffView.handle(source, &event),
(S::CommitLogView, E::CommitUnselected) => commitDiffView.handle(source, &event),
Expand Down

0 comments on commit 13249bd

Please sign in to comment.