mirror of
https://github.com/encounter/objdiff.git
synced 2025-12-08 21:17:59 +00:00
Use let chains (a.k.a. cargo clippy --fix)
This commit is contained in:
@@ -526,14 +526,12 @@ impl App {
|
||||
mod_check = true;
|
||||
}
|
||||
|
||||
if mod_check {
|
||||
if let Some(info) = &state.project_config_info {
|
||||
if let Some(last_ts) = info.timestamp {
|
||||
if file_modified(&info.path, last_ts) {
|
||||
state.config_change = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if mod_check
|
||||
&& let Some(info) = &state.project_config_info
|
||||
&& let Some(last_ts) = info.timestamp
|
||||
&& file_modified(&info.path, last_ts)
|
||||
{
|
||||
state.config_change = true;
|
||||
}
|
||||
|
||||
if state.config_change {
|
||||
@@ -581,22 +579,20 @@ impl App {
|
||||
state.queue_build = true;
|
||||
}
|
||||
|
||||
if let Some(result) = &diff_state.build {
|
||||
if mod_check {
|
||||
if let Some((obj, _)) = &result.first_obj {
|
||||
if let (Some(path), Some(timestamp)) = (&obj.path, obj.timestamp) {
|
||||
if file_modified(path, timestamp) {
|
||||
state.queue_reload = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some((obj, _)) = &result.second_obj {
|
||||
if let (Some(path), Some(timestamp)) = (&obj.path, obj.timestamp) {
|
||||
if file_modified(path, timestamp) {
|
||||
state.queue_reload = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(result) = &diff_state.build
|
||||
&& mod_check
|
||||
{
|
||||
if let Some((obj, _)) = &result.first_obj
|
||||
&& let (Some(path), Some(timestamp)) = (&obj.path, obj.timestamp)
|
||||
&& file_modified(path, timestamp)
|
||||
{
|
||||
state.queue_reload = true;
|
||||
}
|
||||
if let Some((obj, _)) = &result.second_obj
|
||||
&& let (Some(path), Some(timestamp)) = (&obj.path, obj.timestamp)
|
||||
&& file_modified(path, timestamp)
|
||||
{
|
||||
state.queue_reload = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -618,13 +614,12 @@ impl App {
|
||||
state.queue_reload = false;
|
||||
}
|
||||
|
||||
if graphics_state.should_relaunch {
|
||||
if let Some(app_path) = &self.app_path {
|
||||
if let Ok(mut guard) = self.relaunch_path.lock() {
|
||||
*guard = Some(app_path.clone());
|
||||
self.should_relaunch = true;
|
||||
}
|
||||
}
|
||||
if graphics_state.should_relaunch
|
||||
&& let Some(app_path) = &self.app_path
|
||||
&& let Ok(mut guard) = self.relaunch_path.lock()
|
||||
{
|
||||
*guard = Some(app_path.clone());
|
||||
self.should_relaunch = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,23 +173,23 @@ fn main() -> ExitCode {
|
||||
}
|
||||
|
||||
// Attempt to relaunch application from the updated path
|
||||
if let Ok(mut guard) = exec_path.lock() {
|
||||
if let Some(path) = guard.take() {
|
||||
cfg_if! {
|
||||
if #[cfg(unix)] {
|
||||
let e = exec::Command::new(path)
|
||||
.args(&std::env::args().collect::<Vec<String>>())
|
||||
.exec();
|
||||
if let Ok(mut guard) = exec_path.lock()
|
||||
&& let Some(path) = guard.take()
|
||||
{
|
||||
cfg_if! {
|
||||
if #[cfg(unix)] {
|
||||
let e = exec::Command::new(path)
|
||||
.args(&std::env::args().collect::<Vec<String>>())
|
||||
.exec();
|
||||
log::error!("Failed to relaunch: {e:?}");
|
||||
return ExitCode::FAILURE;
|
||||
} else {
|
||||
let result = std::process::Command::new(path)
|
||||
.args(std::env::args())
|
||||
.spawn();
|
||||
if let Err(e) = result {
|
||||
log::error!("Failed to relaunch: {e:?}");
|
||||
return ExitCode::FAILURE;
|
||||
} else {
|
||||
let result = std::process::Command::new(path)
|
||||
.args(std::env::args())
|
||||
.spawn();
|
||||
if let Err(e) = result {
|
||||
log::error!("Failed to relaunch: {e:?}");
|
||||
return ExitCode::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,16 +185,15 @@ pub fn config_ui(
|
||||
if result.update_available {
|
||||
ui.colored_label(appearance.insert_color, "Update available");
|
||||
ui.horizontal(|ui| {
|
||||
if let Some(bin_name) = &result.found_binary {
|
||||
if ui
|
||||
if let Some(bin_name) = &result.found_binary
|
||||
&& ui
|
||||
.add_enabled(!config_state.update_running, egui::Button::new("Automatic"))
|
||||
.on_hover_text_at_pointer(
|
||||
"Automatically download and replace the current build",
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
config_state.queue_update = Some(bin_name.clone());
|
||||
}
|
||||
{
|
||||
config_state.queue_update = Some(bin_name.clone());
|
||||
}
|
||||
if ui
|
||||
.button("Manual")
|
||||
@@ -329,12 +328,12 @@ pub fn config_ui(
|
||||
});
|
||||
});
|
||||
}
|
||||
if new_selected_index != selected_index {
|
||||
if let Some(idx) = new_selected_index {
|
||||
// Will set obj_changed, which will trigger a rebuild
|
||||
let config = objects[idx].clone();
|
||||
state_guard.set_selected_obj(config);
|
||||
}
|
||||
if new_selected_index != selected_index
|
||||
&& let Some(idx) = new_selected_index
|
||||
{
|
||||
// Will set obj_changed, which will trigger a rebuild
|
||||
let config = objects[idx].clone();
|
||||
state_guard.set_selected_obj(config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,18 +373,17 @@ fn display_unit(
|
||||
}
|
||||
|
||||
fn object_context_ui(ui: &mut egui::Ui, object: &ObjectConfig) {
|
||||
if let Some(source_path) = &object.source_path {
|
||||
if ui
|
||||
if let Some(source_path) = &object.source_path
|
||||
&& ui
|
||||
.button("Open source file")
|
||||
.on_hover_text("Open the source file in the default editor")
|
||||
.clicked()
|
||||
{
|
||||
log::info!("Opening file {source_path}");
|
||||
if let Err(e) = open::that_detached(source_path.as_str()) {
|
||||
log::error!("Failed to open source file: {e}");
|
||||
}
|
||||
ui.close();
|
||||
{
|
||||
log::info!("Opening file {source_path}");
|
||||
if let Err(e) = open::that_detached(source_path.as_str()) {
|
||||
log::error!("Failed to open source file: {e}");
|
||||
}
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -835,12 +833,11 @@ fn split_obj_config_ui(
|
||||
.add_enabled(state.project_config_info.is_none(), egui::Button::new("+").small())
|
||||
.on_disabled_hover_text(CONFIG_DISABLED_TEXT)
|
||||
.clicked()
|
||||
&& let Ok(glob) = Glob::new(&config_state.watch_pattern_text)
|
||||
{
|
||||
if let Ok(glob) = Glob::new(&config_state.watch_pattern_text) {
|
||||
state.config.watch_patterns.push(glob);
|
||||
state.watcher_change = true;
|
||||
config_state.watch_pattern_text.clear();
|
||||
}
|
||||
state.config.watch_patterns.push(glob);
|
||||
state.watcher_change = true;
|
||||
config_state.watch_pattern_text.clear();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ pub(crate) fn data_row_ui(
|
||||
write_text(byte_text.as_str(), byte_color, &mut job, appearance.code_font.clone());
|
||||
cur_addr += 1;
|
||||
cur_addr_actual += 1;
|
||||
if cur_addr % 8 == 0 {
|
||||
if cur_addr.is_multiple_of(8) {
|
||||
write_text(" ", base_color, &mut job, appearance.code_font.clone());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,10 +128,10 @@ pub fn diff_view_ui(
|
||||
let mut navigation = current_navigation.clone();
|
||||
if let Some((_symbol, symbol_diff, _symbol_idx)) = left_ctx.symbol {
|
||||
// If a matching symbol appears, select it
|
||||
if !right_ctx.has_symbol() {
|
||||
if let Some(target_symbol_ref) = symbol_diff.target_symbol {
|
||||
navigation.right_symbol = Some(target_symbol_ref);
|
||||
}
|
||||
if !right_ctx.has_symbol()
|
||||
&& let Some(target_symbol_ref) = symbol_diff.target_symbol
|
||||
{
|
||||
navigation.right_symbol = Some(target_symbol_ref);
|
||||
}
|
||||
} else if navigation.left_symbol.is_some()
|
||||
&& left_ctx.obj.is_some()
|
||||
@@ -142,10 +142,10 @@ pub fn diff_view_ui(
|
||||
}
|
||||
if let Some((_symbol, symbol_diff, _symbol_idx)) = right_ctx.symbol {
|
||||
// If a matching symbol appears, select it
|
||||
if !left_ctx.has_symbol() {
|
||||
if let Some(target_symbol_ref) = symbol_diff.target_symbol {
|
||||
navigation.left_symbol = Some(target_symbol_ref);
|
||||
}
|
||||
if !left_ctx.has_symbol()
|
||||
&& let Some(target_symbol_ref) = symbol_diff.target_symbol
|
||||
{
|
||||
navigation.left_symbol = Some(target_symbol_ref);
|
||||
}
|
||||
} else if navigation.right_symbol.is_some()
|
||||
&& right_ctx.obj.is_some()
|
||||
@@ -247,16 +247,15 @@ pub fn diff_view_ui(
|
||||
|
||||
// Third row
|
||||
if left_ctx.has_symbol() && right_ctx.has_symbol() {
|
||||
if state.current_view == View::FunctionDiff
|
||||
if (state.current_view == View::FunctionDiff
|
||||
&& ui
|
||||
.button("Change target")
|
||||
.on_hover_text_at_pointer("Choose a different symbol to use as the target")
|
||||
.clicked()
|
||||
|| hotkeys::consume_change_target_shortcut(ui.ctx())
|
||||
|| hotkeys::consume_change_target_shortcut(ui.ctx()))
|
||||
&& let Some(symbol_ref) = state.symbol_state.right_symbol.as_ref()
|
||||
{
|
||||
if let Some(symbol_ref) = state.symbol_state.right_symbol.as_ref() {
|
||||
ret = Some(DiffViewAction::SelectingLeft(symbol_ref.clone()));
|
||||
}
|
||||
ret = Some(DiffViewAction::SelectingLeft(symbol_ref.clone()));
|
||||
}
|
||||
} else if left_ctx.status.success && !left_ctx.has_symbol() {
|
||||
ui.horizontal(|ui| {
|
||||
@@ -409,17 +408,16 @@ pub fn diff_view_ui(
|
||||
if needs_separator {
|
||||
ui.separator();
|
||||
}
|
||||
if ui
|
||||
if (ui
|
||||
.button("Change base")
|
||||
.on_hover_text_at_pointer(
|
||||
"Choose a different symbol to use as the base",
|
||||
)
|
||||
.clicked()
|
||||
|| hotkeys::consume_change_base_shortcut(ui.ctx())
|
||||
|| hotkeys::consume_change_base_shortcut(ui.ctx()))
|
||||
&& let Some(symbol_ref) = state.symbol_state.left_symbol.as_ref()
|
||||
{
|
||||
if let Some(symbol_ref) = state.symbol_state.left_symbol.as_ref() {
|
||||
ret = Some(DiffViewAction::SelectingRight(symbol_ref.clone()));
|
||||
}
|
||||
ret = Some(DiffViewAction::SelectingRight(symbol_ref.clone()));
|
||||
}
|
||||
}
|
||||
} else if right_ctx.status.success && !right_ctx.has_symbol() {
|
||||
@@ -583,8 +581,8 @@ pub fn diff_view_ui(
|
||||
) {
|
||||
ret = Some(action);
|
||||
}
|
||||
} else if column == 1 {
|
||||
if let Some(action) = diff_col_ui(
|
||||
} else if column == 1
|
||||
&& let Some(action) = diff_col_ui(
|
||||
ui,
|
||||
state,
|
||||
appearance,
|
||||
@@ -594,9 +592,9 @@ pub fn diff_view_ui(
|
||||
available_width,
|
||||
open_sections.1,
|
||||
diff_config,
|
||||
) {
|
||||
ret = Some(action);
|
||||
}
|
||||
)
|
||||
{
|
||||
ret = Some(action);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -211,19 +211,19 @@ impl DiffViewState {
|
||||
|
||||
let mut resolved_left = self.resolve_symbol(nav.left_symbol, 0);
|
||||
let mut resolved_right = self.resolve_symbol(nav.right_symbol, 1);
|
||||
if let Some(resolved_right) = &resolved_right {
|
||||
if resolved_left.is_none() {
|
||||
resolved_left = resolved_right
|
||||
.target_symbol
|
||||
.and_then(|idx| self.resolve_symbol(Some(idx), 0));
|
||||
}
|
||||
if let Some(resolved_right) = &resolved_right
|
||||
&& resolved_left.is_none()
|
||||
{
|
||||
resolved_left = resolved_right
|
||||
.target_symbol
|
||||
.and_then(|idx| self.resolve_symbol(Some(idx), 0));
|
||||
}
|
||||
if let Some(resolved_left) = &resolved_left {
|
||||
if resolved_right.is_none() {
|
||||
resolved_right = resolved_left
|
||||
.target_symbol
|
||||
.and_then(|idx| self.resolve_symbol(Some(idx), 1));
|
||||
}
|
||||
if let Some(resolved_left) = &resolved_left
|
||||
&& resolved_right.is_none()
|
||||
{
|
||||
resolved_right = resolved_left
|
||||
.target_symbol
|
||||
.and_then(|idx| self.resolve_symbol(Some(idx), 1));
|
||||
}
|
||||
let resolved_nav = resolve_navigation(nav.kind, resolved_left, resolved_right);
|
||||
if (resolved_nav.left_symbol.is_some() && resolved_nav.right_symbol.is_some())
|
||||
@@ -500,16 +500,16 @@ pub fn symbol_context_menu_ui(
|
||||
ret = Some(action);
|
||||
}
|
||||
|
||||
if let Some(section) = section {
|
||||
if ui.button("Map symbol").clicked() {
|
||||
let symbol_ref = SymbolRefByName::new(symbol, Some(section));
|
||||
if column == 0 {
|
||||
ret = Some(DiffViewAction::SelectingRight(symbol_ref));
|
||||
} else {
|
||||
ret = Some(DiffViewAction::SelectingLeft(symbol_ref));
|
||||
}
|
||||
ui.close();
|
||||
if let Some(section) = section
|
||||
&& ui.button("Map symbol").clicked()
|
||||
{
|
||||
let symbol_ref = SymbolRefByName::new(symbol, Some(section));
|
||||
if column == 0 {
|
||||
ret = Some(DiffViewAction::SelectingRight(symbol_ref));
|
||||
} else {
|
||||
ret = Some(DiffViewAction::SelectingLeft(symbol_ref));
|
||||
}
|
||||
ui.close();
|
||||
}
|
||||
});
|
||||
ret
|
||||
@@ -664,10 +664,10 @@ pub fn symbol_list_ui(
|
||||
let mut ret = None;
|
||||
ScrollArea::both().auto_shrink([false, false]).show(ui, |ui| {
|
||||
let mut show_mapped_symbols = state.show_mapped_symbols;
|
||||
if let SymbolFilter::Mapping(_, _) = filter {
|
||||
if ui.checkbox(&mut show_mapped_symbols, "Show mapped symbols").changed() {
|
||||
ret = Some(DiffViewAction::SetShowMappedSymbols(show_mapped_symbols));
|
||||
}
|
||||
if let SymbolFilter::Mapping(_, _) = filter
|
||||
&& ui.checkbox(&mut show_mapped_symbols, "Show mapped symbols").changed()
|
||||
{
|
||||
ret = Some(DiffViewAction::SetShowMappedSymbols(show_mapped_symbols));
|
||||
}
|
||||
let section_display = display_sections(
|
||||
ctx.obj,
|
||||
|
||||
Reference in New Issue
Block a user