Skip to content

Commit

Permalink
rework: deprecate select methods (#207)
Browse files Browse the repository at this point in the history
* Deprecate public methods

* Rename examples and fix deprecation warnings

* Rename labels

* Rename labels

* Update changelog
  • Loading branch information
fluxxcode authored Nov 24, 2024
1 parent 4be7bfe commit 99e69b0
Show file tree
Hide file tree
Showing 17 changed files with 205 additions and 101 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
- Added the ability to drag and drop files and folders to open their respective path [#192](https://github.com/fluxxcode/egui-file-dialog/pull/192) (thanks [@hacknus](https://github.com/hacknus)!)
- Support network drives on MacOS [#194](https://github.com/fluxxcode/egui-file-dialog/pull/194) (thanks [@hacknus](https://github.com/hacknus)!)

### ☢️ Deprecated
- Deprecated all `select_*` methods and added new equivalent `pick_*` methods [207](https://github.com/fluxxcode/egui-file-dialog/pull/207)

### 🐛 Bug Fixes
- Fixed heading `Places` not being able to be updated with `FileDialogLabels` [#180](https://github.com/fluxxcode/egui-file-dialog/pull/180)
- Fix display errors with path prefix on Windows [#182](https://github.com/fluxxcode/egui-file-dialog/pull/182)
Expand Down
24 changes: 12 additions & 12 deletions examples/custom-right-panel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@ use egui_file_dialog::{DialogMode, FileDialog};

struct MyApp {
file_dialog: FileDialog,
selected_items: Option<Vec<PathBuf>>,
picked_items: Option<Vec<PathBuf>>,
}

impl MyApp {
pub fn new(_cc: &eframe::CreationContext) -> Self {
Self {
file_dialog: FileDialog::new(),
selected_items: None,
picked_items: None,
}
}
}

impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
if ui.button("Select single").clicked() {
self.file_dialog.select_file();
if ui.button("Pick single").clicked() {
self.file_dialog.pick_file();
}
if ui.button("Select multiple").clicked() {
self.file_dialog.select_multiple();
if ui.button("Pick multiple").clicked() {
self.file_dialog.pick_multiple();
}

ui.label("Selected items:");
ui.label("Picked items:");

if let Some(items) = &self.selected_items {
if let Some(items) = &self.picked_items {
for item in items {
ui.label(format!("{:?}", item));
}
Expand Down Expand Up @@ -59,13 +59,13 @@ impl eframe::App for MyApp {

match self.file_dialog.mode() {
DialogMode::SelectMultiple => {
if let Some(items) = self.file_dialog.take_selected_multiple() {
self.selected_items = Some(items);
if let Some(items) = self.file_dialog.take_picked_multiple() {
self.picked_items = Some(items);
}
}
_ => {
if let Some(item) = self.file_dialog.take_selected() {
self.selected_items = Some(vec![item]);
if let Some(item) = self.file_dialog.take_picked() {
self.picked_items = Some(vec![item]);
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions examples/multi_selection/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@ use egui_file_dialog::FileDialog;

struct MyApp {
file_dialog: FileDialog,
selected_items: Option<Vec<PathBuf>>,
picked_items: Option<Vec<PathBuf>>,
}

impl MyApp {
pub fn new(_cc: &eframe::CreationContext) -> Self {
Self {
file_dialog: FileDialog::new(),
selected_items: None,
picked_items: None,
}
}
}

impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
if ui.button("Select multiple").clicked() {
self.file_dialog.select_multiple();
if ui.button("Pick multiple").clicked() {
self.file_dialog.pick_multiple();
}

ui.label("Selected items:");
ui.label("Picked items:");

if let Some(items) = &self.selected_items {
if let Some(items) = &self.picked_items {
for item in items {
ui.label(format!("{:?}", item));
}
Expand All @@ -36,8 +36,8 @@ impl eframe::App for MyApp {

self.file_dialog.update(ctx);

if let Some(items) = self.file_dialog.take_selected_multiple() {
self.selected_items = Some(items);
if let Some(items) = self.file_dialog.take_picked_multiple() {
self.picked_items = Some(items);
}
});
}
Expand Down
14 changes: 7 additions & 7 deletions examples/multilingual/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct MyApp {
file_dialog: FileDialog,
language: Language,

selected_file: Option<PathBuf>,
picked_file: Option<PathBuf>,
}

impl MyApp {
Expand All @@ -71,7 +71,7 @@ impl MyApp {
file_dialog: FileDialog::new().id("egui_file_dialog"),
language: Language::English,

selected_file: None,
picked_file: None,
}
}

Expand Down Expand Up @@ -99,15 +99,15 @@ impl eframe::App for MyApp {
self.update_labels();
}

if ui.button("Select file").clicked() {
self.file_dialog.select_file();
if ui.button("Picked file").clicked() {
self.file_dialog.pick_file();
}
ui.label(format!("Selected file: {:?}", self.selected_file));
ui.label(format!("Picked file: {:?}", self.picked_file));

self.file_dialog.update(ctx);

if let Some(path) = self.file_dialog.take_selected() {
self.selected_file = Some(path);
if let Some(path) = self.file_dialog.take_picked() {
self.picked_file = Some(path);
}
});
}
Expand Down
30 changes: 15 additions & 15 deletions examples/multiple_actions/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,48 @@ use egui_file_dialog::{DialogMode, FileDialog};
struct MyApp {
file_dialog: FileDialog,

selected_file_a: Option<PathBuf>,
selected_file_b: Option<PathBuf>,
picked_file_a: Option<PathBuf>,
picked_file_b: Option<PathBuf>,
}

impl MyApp {
pub fn new(_cc: &eframe::CreationContext) -> Self {
Self {
file_dialog: FileDialog::new().id("egui_file_dialog"),

selected_file_a: None,
selected_file_b: None,
picked_file_a: None,
picked_file_b: None,
}
}
}

impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
if ui.button("Select file a").clicked() {
if ui.button("Pick file a").clicked() {
let _ = self
.file_dialog
.open(DialogMode::SelectFile, true, Some("select_a"));
.open(DialogMode::SelectFile, true, Some("pick_a"));
}

if ui.button("Select file b").clicked() {
if ui.button("Pick file b").clicked() {
let _ = self
.file_dialog
.open(DialogMode::SelectFile, true, Some("select_b"));
.open(DialogMode::SelectFile, true, Some("pick_b"));
}

ui.label(format!("Selected file a: {:?}", self.selected_file_a));
ui.label(format!("Selected file b: {:?}", self.selected_file_b));
ui.label(format!("Pick file a: {:?}", self.picked_file_a));
ui.label(format!("Pick file b: {:?}", self.picked_file_b));

self.file_dialog.update(ctx);

if let Some(path) = self.file_dialog.selected() {
if self.file_dialog.operation_id() == Some("select_a") {
self.selected_file_a = Some(path.to_path_buf());
if let Some(path) = self.file_dialog.picked() {
if self.file_dialog.operation_id() == Some("pick_a") {
self.picked_file_a = Some(path.to_path_buf());
}

if self.file_dialog.operation_id() == Some("select_b") {
self.selected_file_b = Some(path.to_path_buf());
if self.file_dialog.operation_id() == Some("pick_b") {
self.picked_file_b = Some(path.to_path_buf());
}
}
});
Expand Down
14 changes: 7 additions & 7 deletions examples/persistence/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use egui_file_dialog::FileDialog;

struct MyApp {
file_dialog: FileDialog,
selected_file: Option<PathBuf>,
picked_file: Option<PathBuf>,
}

impl MyApp {
Expand All @@ -21,7 +21,7 @@ impl MyApp {

Self {
file_dialog,
selected_file: None,
picked_file: None,
}
}
}
Expand All @@ -38,16 +38,16 @@ impl eframe::App for MyApp {

fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
if ui.button("Select file").clicked() {
self.file_dialog.select_file();
if ui.button("Pick file").clicked() {
self.file_dialog.pick_file();
}

ui.label(format!("Selected file: {:?}", self.selected_file));
ui.label(format!("Picked file: {:?}", self.picked_file));

self.file_dialog.update(ctx);

if let Some(path) = self.file_dialog.take_selected() {
self.selected_file = Some(path);
if let Some(path) = self.file_dialog.take_picked() {
self.picked_file = Some(path);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "select_directory"
name = "pick_directory"
version = "0.1.0"
edition = "2021"

Expand Down
File renamed without changes.
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ use egui_file_dialog::FileDialog;

struct MyApp {
file_dialog: FileDialog,
selected_directory: Option<PathBuf>,
picked_directory: Option<PathBuf>,
}

impl MyApp {
pub fn new(_cc: &eframe::CreationContext) -> Self {
Self {
file_dialog: FileDialog::new(),
selected_directory: None,
picked_directory: None,
}
}
}

impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
if ui.button("Select directory").clicked() {
self.file_dialog.select_directory();
if ui.button("Pick directory").clicked() {
self.file_dialog.pick_directory();
}

ui.label(format!("Selected directory: {:?}", self.selected_directory));
ui.label(format!("Picked directory: {:?}", self.picked_directory));

if let Some(path) = self.file_dialog.update(ctx).selected() {
self.selected_directory = Some(path.to_path_buf());
if let Some(path) = self.file_dialog.update(ctx).picked() {
self.picked_directory = Some(path.to_path_buf());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "select_file"
name = "pick_file"
version = "0.1.0"
edition = "2021"

Expand Down
File renamed without changes.
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ use egui_file_dialog::FileDialog;

struct MyApp {
file_dialog: FileDialog,
selected_file: Option<PathBuf>,
picked_file: Option<PathBuf>,
}

impl MyApp {
pub fn new(_cc: &eframe::CreationContext) -> Self {
Self {
file_dialog: FileDialog::new(),
selected_file: None,
picked_file: None,
}
}
}

impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
if ui.button("Select file").clicked() {
self.file_dialog.select_file();
if ui.button("Picked file").clicked() {
self.file_dialog.pick_file();
}

ui.label(format!("Selected file: {:?}", self.selected_file));
ui.label(format!("Picked file: {:?}", self.picked_file));

if let Some(path) = self.file_dialog.update(ctx).selected() {
self.selected_file = Some(path.to_path_buf());
if let Some(path) = self.file_dialog.update(ctx).picked() {
self.picked_file = Some(path.to_path_buf());
}
});
}
Expand Down
Loading

0 comments on commit 99e69b0

Please sign in to comment.