mirror of
https://github.com/servo/servo.git
synced 2025-08-11 16:35:33 +01:00
servoshell: Port Permission dialog code to use egui instead of tinyfiledialogs (#35577)
Signed-off-by: L Ashwin B <lashwinib@gmail.com>
This commit is contained in:
parent
a433b20259
commit
f6e2e3d418
2 changed files with 49 additions and 30 deletions
|
@ -9,7 +9,7 @@ use egui::Modal;
|
|||
use egui_file_dialog::{DialogState, FileDialog as EguiFileDialog};
|
||||
use log::warn;
|
||||
use servo::ipc_channel::ipc::IpcSender;
|
||||
use servo::{AuthenticationRequest, FilterPattern, PromptResult};
|
||||
use servo::{AuthenticationRequest, FilterPattern, PermissionRequest, PromptResult};
|
||||
|
||||
pub enum Dialog {
|
||||
File {
|
||||
|
@ -35,6 +35,10 @@ pub enum Dialog {
|
|||
password: String,
|
||||
request: Option<AuthenticationRequest>,
|
||||
},
|
||||
Permission {
|
||||
message: String,
|
||||
request: Option<PermissionRequest>,
|
||||
},
|
||||
}
|
||||
|
||||
impl Dialog {
|
||||
|
@ -95,6 +99,17 @@ impl Dialog {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn new_permission_request_dialog(permission_request: PermissionRequest) -> Self {
|
||||
let message = format!(
|
||||
"Do you want to grant permission for {:?}?",
|
||||
permission_request.feature()
|
||||
);
|
||||
Dialog::Permission {
|
||||
message,
|
||||
request: Some(permission_request),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, ctx: &egui::Context) -> bool {
|
||||
match self {
|
||||
Dialog::File {
|
||||
|
@ -261,6 +276,32 @@ impl Dialog {
|
|||
});
|
||||
is_open
|
||||
},
|
||||
Dialog::Permission { message, request } => {
|
||||
let mut is_open = true;
|
||||
let modal = Modal::new("permission".into());
|
||||
modal.show(ctx, |ui| {
|
||||
make_dialog_label(message, ui, None);
|
||||
egui::Sides::new().show(
|
||||
ui,
|
||||
|_ui| {},
|
||||
|ui| {
|
||||
if ui.button("Allow").clicked() {
|
||||
let request =
|
||||
request.take().expect("non-None until dialog is closed");
|
||||
request.allow();
|
||||
is_open = false;
|
||||
}
|
||||
if ui.button("Deny").clicked() {
|
||||
let request =
|
||||
request.take().expect("non-None until dialog is closed");
|
||||
request.deny();
|
||||
is_open = false;
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
is_open
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue