Skip to content

Commit

Permalink
Merge pull request #826 from marhkb/refactor/new-clone-macro
Browse files Browse the repository at this point in the history
refactor: Use new glib::clone macro syntax
  • Loading branch information
marhkb authored Oct 1, 2024
2 parents f524919 + 1515a92 commit 4c57005
Show file tree
Hide file tree
Showing 81 changed files with 3,748 additions and 2,445 deletions.
22 changes: 16 additions & 6 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@ mod imp {

glib::timeout_add_seconds_local(
10,
clone!(@weak obj => @default-return glib::ControlFlow::Break, move || {
obj.tick();
glib::ControlFlow::Continue
}),
clone!(
#[weak]
obj,
#[upgrade_or]
glib::ControlFlow::Break,
move || {
obj.tick();
glib::ControlFlow::Continue
}
),
);
}
}
Expand Down Expand Up @@ -207,8 +213,12 @@ impl Application {

let controller = gtk::EventControllerKey::new();
controller.connect_key_pressed(clone!(
@weak dialog => @default-return glib::Propagation::Stop, move |_, key, _, modifier| {
if key == gdk::Key::w && modifier == gdk::ModifierType::CONTROL_MASK{
#[weak]
dialog,
#[upgrade_or]
glib::Propagation::Stop,
move |_, key, _, modifier| {
if key == gdk::Key::w && modifier == gdk::ModifierType::CONTROL_MASK {
dialog.close();
}
glib::Propagation::Proceed
Expand Down
36 changes: 22 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,30 @@ fn main() {

multi_log::MultiLogger::init(loggers, log_level).unwrap();

glib::log_set_writer_func(clone!(@strong log_level => move |glib_log_level, fields| {
if (glib_log_level == glib::LogLevel::Debug && log_level >= log::Level::Debug )
|| (glib_log_level == glib::LogLevel::Info && log_level >= log::Level::Info)
|| (glib_log_level == glib::LogLevel::Message && log_level >= log::Level::Info)
|| (glib_log_level == glib::LogLevel::Warning && log_level >= log::Level::Warn)
|| (glib_log_level == glib::LogLevel::Error && log_level >= log::Level::Error)
|| (glib_log_level == glib::LogLevel::Critical && log_level >= log::Level::Error)
{
glib::log_writer_standard_streams(glib_log_level, fields);
glib::log_writer_journald(glib_log_level, fields);
glib::log_set_writer_func(clone!(
#[strong]
log_level,
move |glib_log_level, fields| {
if (glib_log_level == glib::LogLevel::Debug && log_level >= log::Level::Debug)
|| (glib_log_level == glib::LogLevel::Info && log_level >= log::Level::Info)
|| (glib_log_level == glib::LogLevel::Message
&& log_level >= log::Level::Info)
|| (glib_log_level == glib::LogLevel::Warning
&& log_level >= log::Level::Warn)
|| (glib_log_level == glib::LogLevel::Error
&& log_level >= log::Level::Error)
|| (glib_log_level == glib::LogLevel::Critical
&& log_level >= log::Level::Error)
{
glib::log_writer_standard_streams(glib_log_level, fields);
glib::log_writer_journald(glib_log_level, fields);

glib::LogWriterOutput::Handled
} else {
glib::LogWriterOutput::Unhandled
glib::LogWriterOutput::Handled
} else {
glib::LogWriterOutput::Unhandled
}
}
}));
));

adw::init().expect("Failed to init GTK/libadwaita");
sourceview5::init();
Expand Down
16 changes: 12 additions & 4 deletions src/model/abstract_container_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,22 @@ impl AbstractContainerList {

container.connect_notify_local(
Some("status"),
clone!(@weak list => move |_, _| Self::notify_num_containers(&list)),
clone!(
#[weak]
list,
move |_, _| Self::notify_num_containers(&list)
),
);

container.connect_notify_local(
Some("name"),
clone!(@weak list => move |container, _| {
list.container_name_changed(container);
}),
clone!(
#[weak]
list,
move |container, _| {
list.container_name_changed(container);
}
),
);
});

Expand Down
Loading

0 comments on commit 4c57005

Please sign in to comment.