Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions crates/desktop/src/app/chrome/certificates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,12 @@ impl ProbeApp {
.flex()
.items_center()
.child(
components::icon_button(
components::icon_button_with_disabled(
theme,
format!("certificate-up-{index}"),
CERTIFICATE_MOVE_UP,
components::reorder_icon(theme, true),
busy || index == 0,
move |_, _, cx| {
let _ = up.update(cx, |view, cx| {
view.apply_environment_manager_draft(cx, |dialog| {
Expand All @@ -233,15 +234,15 @@ impl ProbeApp {
});
},
)
.flex_none()
.disabled(busy || index == 0),
.flex_none(),
)
.child(
components::icon_button(
components::icon_button_with_disabled(
theme,
format!("certificate-down-{index}"),
CERTIFICATE_MOVE_DOWN,
components::reorder_icon(theme, false),
busy || index + 1 == dialog.draft().client_certificates.len(),
move |_, _, cx| {
let _ = down.update(cx, |view, cx| {
view.apply_environment_manager_draft(cx, |dialog| {
Expand All @@ -250,31 +251,29 @@ impl ProbeApp {
});
},
)
.flex_none()
.disabled(
busy || index + 1 == dialog.draft().client_certificates.len(),
),
.flex_none(),
)
.child(
components::icon_button(
components::icon_button_with_disabled(
theme,
format!("certificate-edit-{index}"),
format!("Edit certificate for {domain}"),
components::edit_icon(theme),
busy,
move |_, window, cx| {
let _ = edit.update(cx, |view, cx| {
view.open_certificate_editor(Some(index), window, cx)
});
},
)
.flex_none()
.disabled(busy),
.flex_none(),
)
.child(
components::remove_row_button(
components::remove_row_button_with_disabled(
theme,
format!("certificate-delete-{index}"),
format!("Remove certificate for {domain}"),
busy,
move |_, _, cx| {
let _ = delete.update(cx, |view, cx| {
view.apply_environment_manager_draft(cx, |dialog| {
Expand All @@ -283,8 +282,7 @@ impl ProbeApp {
});
},
)
.flex_none()
.disabled(busy),
.flex_none(),
),
),
);
Expand Down
32 changes: 15 additions & 17 deletions crates/desktop/src/app/chrome/environments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl ProbeApp {
.child(
Popover::new("environment-manager-add-menu")
.trigger(
components::icon_button(
components::icon_button_with_disabled(
theme,
"environment-manager-add",
add_label,
Expand All @@ -154,10 +154,10 @@ impl ProbeApp {
} else {
theme.colors.text.secondary
}),
add_disabled,
|_, _, _| {},
)
.flex_none()
.disabled(add_disabled),
.flex_none(),
)
.content(move |_, _, cx| {
let create_menu = cx.weak_entity();
Expand Down Expand Up @@ -524,21 +524,19 @@ impl ProbeApp {
}),
);
row_element = if let Some(index) = direct_index {
row_element.child(
components::remove_row_button(
theme,
format!("environment-variable-delete-{row_id}"),
format!("Remove {name} from this environment"),
move |_, _, cx| {
let _ = remove_view.update(cx, |view, cx| {
view.apply_environment_manager_draft(cx, |dialog| {
dialog.remove_variable(index);
});
row_element.child(components::remove_row_button_with_disabled(
theme,
format!("environment-variable-delete-{row_id}"),
format!("Remove {name} from this environment"),
busy,
move |_, _, cx| {
let _ = remove_view.update(cx, |view, cx| {
view.apply_environment_manager_draft(cx, |dialog| {
dialog.remove_variable(index);
});
},
)
.disabled(busy),
)
});
},
))
} else {
row_element.child(div().w(px(32.0)))
};
Expand Down
3 changes: 2 additions & 1 deletion crates/desktop/src/components/controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ mod input;

pub(crate) use buttons::{
browse_file_button, compact_icon_button, editor_action_button, editor_add_button,
editor_button, editor_key_value_row, editor_subtab, icon_button, remove_row_button, text_tab,
editor_button, editor_key_value_row, editor_subtab, icon_button, icon_button_with_disabled,
remove_row_button, remove_row_button_with_disabled, text_tab,
};
pub(crate) use dropdown::{dropdown, dropdown_with_option_colors};
pub(super) use input::{
Expand Down
35 changes: 32 additions & 3 deletions crates/desktop/src/components/controls/buttons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,22 @@ pub(crate) fn remove_row_button(
aria_label: impl Into<SharedString>,
on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
) -> Button {
icon_button(
remove_row_button_with_disabled(theme, id, aria_label, false, on_click)
}

pub(crate) fn remove_row_button_with_disabled(
theme: Theme,
id: impl Into<ElementId>,
aria_label: impl Into<SharedString>,
disabled: bool,
on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
) -> Button {
icon_button_with_disabled(
theme,
id,
aria_label,
trash_icon(theme.colors.text.secondary),
disabled,
on_click,
)
}
Expand All @@ -207,6 +218,19 @@ pub(crate) fn icon_button(
aria_label: impl Into<SharedString>,
icon: impl IntoElement,
on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
) -> Button {
icon_button_with_disabled(theme, id, aria_label, icon, false, on_click)
}

// Choose hover styling here: Button's disabled semantic styles cannot remove
// GPUI hover styles after they have been attached.
pub(crate) fn icon_button_with_disabled(
theme: Theme,
id: impl Into<ElementId>,
aria_label: impl Into<SharedString>,
icon: impl IntoElement,
disabled: bool,
on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
) -> Button {
let id = id.into();
let debug_id = id.to_string();
Expand All @@ -224,8 +248,13 @@ pub(crate) fn icon_button(
.bg(transparent_black())
.border_1()
.border_color(transparent_black())
.cursor_pointer()
.hover(move |button| button.bg(theme.colors.selection.inactive_background))
.disabled(disabled)
.when(disabled, |button| button.cursor_default())
.when(!disabled, |button| {
button
.cursor_pointer()
.hover(move |button| button.bg(theme.colors.selection.inactive_background))
})
.focus_visible(move |button| button.border_color(theme.colors.borders.focused))
.on_click(on_click)
.child(icon)
Expand Down
5 changes: 3 additions & 2 deletions crates/desktop/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ pub(crate) use controls::{
FieldInput, ListScroll, ListScrollState, ResponseBodyInputOptions, browse_file_button,
compact_icon_button, dialog_text_input, dropdown, dropdown_with_option_colors,
editor_action_button, editor_add_button, editor_button, editor_key_value_row, editor_subtab,
icon_button, list_scroll_region, remove_row_button, sidebar_search_input, text_tab,
url_text_input, variable_text_input,
icon_button, icon_button_with_disabled, list_scroll_region, remove_row_button,
remove_row_button_with_disabled, sidebar_search_input, text_tab, url_text_input,
variable_text_input,
};

mod icons;
Expand Down
Loading