feat: button to show and copy profile uuid in debug view menu

This commit is contained in:
Gabriele Musco 2024-07-28 11:19:06 +02:00
commit 1b41029a30
2 changed files with 59 additions and 9 deletions

View file

@ -653,6 +653,9 @@ impl SimpleComponent for App {
self.main_view self.main_view
.sender() .sender()
.emit(MainViewMsg::UpdateSelectedProfile(profile.clone())); .emit(MainViewMsg::UpdateSelectedProfile(profile.clone()));
self.debug_view
.sender()
.emit(DebugViewMsg::UpdateSelectedProfile(profile.clone()));
} }
Msg::OpenLibsurviveSetup => { Msg::OpenLibsurviveSetup => {
self.libsurvive_setup_window self.libsurvive_setup_window
@ -871,6 +874,7 @@ impl SimpleComponent for App {
ret.set_enabled(false); ret.set_enabled(false);
ret ret
}; };
let selected_profile = config.get_selected_profile(&profiles);
let mut model = App { let mut model = App {
tracker: 0, tracker: 0,
@ -880,7 +884,7 @@ impl SimpleComponent for App {
main_view: MainView::builder() main_view: MainView::builder()
.launch(MainViewInit { .launch(MainViewInit {
config: config.clone(), config: config.clone(),
selected_profile: config.get_selected_profile(&profiles), selected_profile: selected_profile.clone(),
root_win: root.clone().into(), root_win: root.clone().into(),
}) })
.forward(sender.input_sender(), |message| match message { .forward(sender.input_sender(), |message| match message {
@ -891,12 +895,13 @@ impl SimpleComponent for App {
MainViewOutMsg::SaveProfile(p) => Msg::SaveProfile(p), MainViewOutMsg::SaveProfile(p) => Msg::SaveProfile(p),
MainViewOutMsg::OpenLibsurviveSetup => Msg::OpenLibsurviveSetup, MainViewOutMsg::OpenLibsurviveSetup => Msg::OpenLibsurviveSetup,
}), }),
debug_view: DebugView::builder().launch(DebugViewInit {}).forward( debug_view: DebugView::builder()
sender.input_sender(), .launch(DebugViewInit {
|message| match message { profile: selected_profile,
})
.forward(sender.input_sender(), |message| match message {
DebugViewOutMsg::StartWithDebug => Msg::StartWithDebug, DebugViewOutMsg::StartWithDebug => Msg::StartWithDebug,
}, }),
),
about_dialog: AboutDialog::builder() about_dialog: AboutDialog::builder()
.transient_for(&root) .transient_for(&root)
.launch(()) .launch(())

View file

@ -1,6 +1,8 @@
use super::term_widget::TermWidget; use super::term_widget::TermWidget;
use super::util::copy_text;
use crate::log_level::LogLevel; use crate::log_level::LogLevel;
use crate::log_parser::MonadoLog; use crate::log_parser::MonadoLog;
use crate::profile::Profile;
use crate::ui::app::{DebugCopyEnvVarsAction, DebugOpenDataAction, DebugOpenPrefixAction}; use crate::ui::app::{DebugCopyEnvVarsAction, DebugOpenDataAction, DebugOpenPrefixAction};
use gtk::glib::clone; use gtk::glib::clone;
use gtk::prelude::*; use gtk::prelude::*;
@ -13,6 +15,7 @@ pub enum SearchDirection {
Backward, Backward,
} }
#[allow(clippy::large_enum_variant)]
#[derive(Debug)] #[derive(Debug)]
pub enum DebugViewMsg { pub enum DebugViewMsg {
LogUpdated(Vec<String>), LogUpdated(Vec<String>),
@ -21,6 +24,8 @@ pub enum DebugViewMsg {
SearchFindMatch(SearchDirection), SearchFindMatch(SearchDirection),
LogLevelChanged(LogLevel), LogLevelChanged(LogLevel),
XRServiceActiveChanged(bool), XRServiceActiveChanged(bool),
UpdateSelectedProfile(Profile),
CopyProfileId,
SetColorScheme, SetColorScheme,
} }
@ -42,9 +47,15 @@ pub struct DebugView {
log_level: LogLevel, log_level: LogLevel,
#[tracker::do_not_track] #[tracker::do_not_track]
term: TermWidget, term: TermWidget,
#[tracker::do_not_track]
profile_id_widget: gtk::Button,
#[no_eq]
profile: Profile,
} }
pub struct DebugViewInit {} pub struct DebugViewInit {
pub profile: Profile,
}
#[relm4::component(pub)] #[relm4::component(pub)]
impl SimpleComponent for DebugView { impl SimpleComponent for DebugView {
@ -54,6 +65,9 @@ impl SimpleComponent for DebugView {
menu! { menu! {
debug_menu: { debug_menu: {
section! {
custom: "profile_id_widget",
},
section! { section! {
"Open _Data Folder" => DebugOpenDataAction, "Open _Data Folder" => DebugOpenDataAction,
"Open _Prefix Folder" => DebugOpenPrefixAction, "Open _Prefix Folder" => DebugOpenPrefixAction,
@ -72,7 +86,7 @@ impl SimpleComponent for DebugView {
add_css_class: "flat", add_css_class: "flat",
pack_end: debug_menu_btn = &gtk::MenuButton { pack_end: debug_menu_btn = &gtk::MenuButton {
set_icon_name: "view-more-symbolic", set_icon_name: "view-more-symbolic",
set_tooltip_text: Some("Debug Actions..."), set_tooltip_text: Some("Debug Actions"),
set_menu_model: Some(&debug_menu), set_menu_model: Some(&debug_menu),
}, },
pack_end: search_toggle = &gtk::ToggleButton { pack_end: search_toggle = &gtk::ToggleButton {
@ -189,11 +203,19 @@ impl SimpleComponent for DebugView {
Self::Input::SetColorScheme => { Self::Input::SetColorScheme => {
self.term.set_color_scheme(); self.term.set_color_scheme();
} }
Self::Input::UpdateSelectedProfile(prof) => {
self.set_profile(prof);
self.profile_id_widget
.set_label(&format!("Profile id: {}", self.profile.uuid))
}
Self::Input::CopyProfileId => {
copy_text(&self.profile.uuid);
}
} }
} }
fn init( fn init(
_init: Self::Init, init: Self::Init,
root: Self::Root, root: Self::Root,
sender: ComponentSender<Self>, sender: ComponentSender<Self>,
) -> ComponentParts<Self> { ) -> ComponentParts<Self> {
@ -238,14 +260,37 @@ impl SimpleComponent for DebugView {
dropdown: None, dropdown: None,
log_level: LogLevel::Trace, log_level: LogLevel::Trace,
term: TermWidget::new(), term: TermWidget::new(),
profile_id_widget: gtk::Button::builder()
.css_classes(["flat", "dim-label", "caption"])
.label(format!("Profile id: {}", init.profile.uuid))
.tooltip_text("Copy")
.build(),
profile: init.profile,
}; };
model.term.set_color_scheme(); model.term.set_color_scheme();
model.profile_id_widget.connect_clicked(clone!(
#[strong]
sender,
move |_| {
sender.input(Self::Input::CopyProfileId);
}
));
let widgets = view_output!(); let widgets = view_output!();
model.searchbar = Some(widgets.searchbar.clone()); model.searchbar = Some(widgets.searchbar.clone());
model.search_entry = Some(widgets.search_entry.clone()); model.search_entry = Some(widgets.search_entry.clone());
model.dropdown = Some(log_level_dropdown.clone()); model.dropdown = Some(log_level_dropdown.clone());
widgets
.debug_menu_btn
.popover()
.clone()
.unwrap()
.downcast::<gtk::PopoverMenu>()
.unwrap()
.add_child(&model.profile_id_widget, "profile_id_widget");
ComponentParts { model, widgets } ComponentParts { model, widgets }
} }
} }