-
-
Notifications
You must be signed in to change notification settings - Fork 74
Make clicking on a match select it on close-on-click (Fixes #149) #250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
132eb02
632924c
872f8d0
973b555
26dfae2
d6db78a
d6de661
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ use relm4::prelude::*; | |
use wl_clipboard_rs::copy; | ||
|
||
use crate::{ | ||
config::{Action, Config, ConfigArgs, Keybind}, | ||
config::{Action, Config, ConfigArgs, Keybind, Mousebind}, | ||
plugin_box::{PluginBox, PluginBoxInput, PluginBoxOutput, PluginMatch}, | ||
}; | ||
|
||
|
@@ -106,6 +106,27 @@ impl App { | |
(i, plugin, plugin_match) | ||
}) | ||
} | ||
|
||
fn select_row(&self, plugin_ind: DynamicIndex, match_ind: DynamicIndex) { | ||
// Select match row | ||
for (i, plugin) in self.plugins.iter().enumerate() { | ||
if i == plugin_ind.current_index() { | ||
for (j, plugin_match) in plugin.matches.iter().enumerate() { | ||
if j == match_ind.current_index() { | ||
plugin | ||
.matches | ||
.widget() | ||
.select_row(Option::<>k::ListBoxRow>::Some(&plugin_match.row)); | ||
} | ||
} | ||
} else { | ||
plugin | ||
.matches | ||
.widget() | ||
.select_row(Option::<>k::ListBoxRow>::None); | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[relm4::component] | ||
|
@@ -377,6 +398,7 @@ impl Component for App { | |
} | ||
} | ||
AppMsg::Action(action) => match action { | ||
Action::Nop => {} | ||
Action::Close => { | ||
root.close(); | ||
relm4::main_application().quit(); | ||
|
@@ -472,6 +494,26 @@ impl Component for App { | |
} | ||
} | ||
} | ||
AppMsg::PluginOutput(PluginBoxOutput::MouseAction(button, match_ind, plugin_ind)) => { | ||
// Handle binding | ||
if let Some(Mousebind { action, .. }) = self | ||
.config | ||
.mousebinds | ||
.iter() | ||
.find(|mousebind| mousebind.button == button) | ||
{ | ||
// Potentially select row | ||
match action { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This kind of preprocessing of actions feels a bit ugly, I'd prefer if there was a general enum for mouse actions/events as a part of In practice the mouse action part of |
||
Action::Select | Action::Nop => self.select_row(plugin_ind, match_ind), | ||
_ => { | ||
// Don't select row for other actions | ||
} | ||
}; | ||
|
||
// Perform action | ||
sender.input(AppMsg::Action(*action)); | ||
} | ||
} | ||
} | ||
self.update_view(widgets, sender); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,26 +6,46 @@ use gtk::{glib, pango, prelude::*}; | |
use gtk4 as gtk; | ||
use relm4::prelude::*; | ||
|
||
use crate::Config; | ||
use crate::{config::MouseButton, Config}; | ||
|
||
pub struct PluginMatch { | ||
pub content: Match, | ||
pub row: gtk::ListBoxRow, | ||
config: Rc<Config>, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum MatchOutput { | ||
MouseAction(MouseButton, <PluginMatch as FactoryComponent>::Index), | ||
} | ||
|
||
#[relm4::factory(pub)] | ||
impl FactoryComponent for PluginMatch { | ||
type Init = (Match, Rc<Config>); | ||
type Input = (); | ||
type Output = (); | ||
type Output = MatchOutput; | ||
type CommandOutput = (); | ||
type ParentWidget = gtk::ListBox; | ||
view! { | ||
gtk::ListBoxRow { | ||
set_css_classes: &["match"], | ||
set_height_request: 32, | ||
gtk::Box { | ||
|
||
add_controller = gtk::GestureClick { | ||
set_button: 0, | ||
connect_pressed[sender, index] => move |gesture, _, _, _| { | ||
gesture.set_state(gtk::EventSequenceState::Claimed); | ||
let button: MouseButton = match gesture.current_button() { | ||
gtk::gdk::BUTTON_PRIMARY => MouseButton::Primary, | ||
gtk::gdk::BUTTON_SECONDARY => MouseButton::Secondary, | ||
gtk::gdk::BUTTON_MIDDLE => MouseButton::Middle, | ||
other => MouseButton::Unknown(other), | ||
}; | ||
sender.output(MatchOutput::MouseAction(button, index.clone())).unwrap(); | ||
} | ||
}, | ||
|
||
set_orientation: gtk::Orientation::Horizontal, | ||
set_spacing: 10, | ||
set_css_classes: &["match"], | ||
|
@@ -74,10 +94,10 @@ impl FactoryComponent for PluginMatch { | |
|
||
fn init_widgets( | ||
&mut self, | ||
_index: &Self::Index, | ||
index: &Self::Index, | ||
root: Self::Root, | ||
_returned_widget: &<Self::ParentWidget as relm4::factory::FactoryView>::ReturnedWidget, | ||
_sender: FactorySender<Self>, | ||
sender: FactorySender<Self>, | ||
) -> Self::Widgets { | ||
let widgets = view_output!(); | ||
|
||
|
@@ -140,6 +160,11 @@ pub enum PluginBoxInput { | |
pub enum PluginBoxOutput { | ||
MatchesLoaded, | ||
RowSelected(<PluginBox as FactoryComponent>::Index), | ||
MouseAction( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is complex enough where it could be structified in the enum, as in: MouseAction {
button: MouseButton,
...
} |
||
MouseButton, | ||
<PluginMatch as FactoryComponent>::Index, | ||
<PluginBox as FactoryComponent>::Index, | ||
), | ||
} | ||
|
||
#[relm4::factory(pub)] | ||
|
@@ -212,12 +237,17 @@ impl FactoryComponent for PluginBox { | |
|
||
fn init_model( | ||
(plugin, config): Self::Init, | ||
_index: &Self::Index, | ||
_sender: FactorySender<Self>, | ||
index: &Self::Index, | ||
sender: FactorySender<Self>, | ||
) -> Self { | ||
let matches = FactoryVecDeque::builder() | ||
let ind = index.clone(); | ||
let matches = FactoryVecDeque::<PluginMatch>::builder() | ||
.launch(gtk::ListBox::default()) | ||
.detach(); | ||
.forward(sender.output_sender(), move |output| match output { | ||
MatchOutput::MouseAction(button, row) => { | ||
PluginBoxOutput::MouseAction(button, row, ind.clone()) | ||
} | ||
}); | ||
|
||
Self { | ||
plugin, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of having a Nop action?