Skip to content

Commit

Permalink
Reformat imports
Browse files Browse the repository at this point in the history
  • Loading branch information
cassaundra committed Jan 7, 2025
1 parent bba989a commit 9707d69
Show file tree
Hide file tree
Showing 25 changed files with 127 additions and 133 deletions.
5 changes: 3 additions & 2 deletions src/backend.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::message_dialog::MessageDialogResult;
use crate::FileHandle;
use std::future::Future;
use std::path::PathBuf;
use std::pin::Pin;

use crate::message_dialog::MessageDialogResult;
use crate::FileHandle;

#[cfg(all(
any(
target_os = "linux",
Expand Down
20 changes: 9 additions & 11 deletions src/backend/gtk3/file_dialog.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
pub mod dialog_ffi;
use std::path::PathBuf;

pub mod dialog_ffi;
use dialog_ffi::GtkFileDialog;

use std::path::PathBuf;

use super::gtk_future::GtkDialogFuture;
use super::utils::GtkGlobalThread;
use crate::backend::DialogFutureType;
use crate::{FileDialog, FileHandle};

use super::gtk_future::GtkDialogFuture;

//
// File Picker
//

use crate::backend::FilePickerDialogImpl;
use crate::backend::{AsyncFilePickerDialogImpl, FilePickerDialogImpl};

impl FilePickerDialogImpl for FileDialog {
fn pick_file(self) -> Option<PathBuf> {
GtkGlobalThread::instance().run_blocking(move || {
Expand All @@ -41,7 +40,6 @@ impl FilePickerDialogImpl for FileDialog {
}
}

use crate::backend::AsyncFilePickerDialogImpl;
impl AsyncFilePickerDialogImpl for FileDialog {
fn pick_file_async(self) -> DialogFutureType<Option<FileHandle>> {
let builder = move || GtkFileDialog::build_pick_file(&self);
Expand Down Expand Up @@ -82,7 +80,8 @@ impl AsyncFilePickerDialogImpl for FileDialog {
// Folder Picker
//

use crate::backend::FolderPickerDialogImpl;
use crate::backend::{AsyncFolderPickerDialogImpl, FolderPickerDialogImpl};

impl FolderPickerDialogImpl for FileDialog {
fn pick_folder(self) -> Option<PathBuf> {
GtkGlobalThread::instance().run_blocking(move || {
Expand All @@ -109,7 +108,6 @@ impl FolderPickerDialogImpl for FileDialog {
}
}

use crate::backend::AsyncFolderPickerDialogImpl;
impl AsyncFolderPickerDialogImpl for FileDialog {
fn pick_folder_async(self) -> DialogFutureType<Option<FileHandle>> {
let builder = move || GtkFileDialog::build_pick_folder(&self);
Expand Down Expand Up @@ -150,7 +148,8 @@ impl AsyncFolderPickerDialogImpl for FileDialog {
// File Save
//

use crate::backend::FileSaveDialogImpl;
use crate::backend::{AsyncFileSaveDialogImpl, FileSaveDialogImpl};

impl FileSaveDialogImpl for FileDialog {
fn save_file(self) -> Option<PathBuf> {
GtkGlobalThread::instance().run_blocking(move || {
Expand All @@ -165,7 +164,6 @@ impl FileSaveDialogImpl for FileDialog {
}
}

use crate::backend::AsyncFileSaveDialogImpl;
impl AsyncFileSaveDialogImpl for FileDialog {
fn save_file_async(self) -> DialogFutureType<Option<FileHandle>> {
let builder = move || GtkFileDialog::build_save_file(&self);
Expand Down
9 changes: 5 additions & 4 deletions src/backend/gtk3/file_dialog/dialog_ffi.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use super::super::AsGtkDialog;
use crate::FileDialog;
use gtk_sys::GtkFileChooserNative;

use std::ffi::{CStr, CString};
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::ptr;

use gtk_sys::GtkFileChooserNative;

use super::super::AsGtkDialog;
use crate::FileDialog;

#[repr(i32)]
pub enum GtkFileChooserAction {
Open = 0,
Expand Down
9 changes: 4 additions & 5 deletions src/backend/gtk3/gtk_future.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use super::utils::GtkGlobalThread;

use std::pin::Pin;
use std::sync::{Arc, Mutex};

use std::task::{Context, Poll, Waker};

use super::utils::GtkGlobalThread;
use super::AsGtkDialog;

struct FutureState<R, D> {
Expand Down Expand Up @@ -84,11 +82,12 @@ impl<R, D> std::future::Future for GtkDialogFuture<R, D> {
}
}

use gobject_sys::GCallback;
use gtk_sys::{GtkDialog, GtkResponseType};
use std::ffi::c_void;
use std::os::raw::c_char;

use gobject_sys::GCallback;
use gtk_sys::{GtkDialog, GtkResponseType};

unsafe fn connect_raw<F>(
receiver: *mut gobject_sys::GObject,
signal_name: *const c_char,
Expand Down
6 changes: 2 additions & 4 deletions src/backend/gtk3/message_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::ptr;
use super::gtk_future::GtkDialogFuture;
use super::utils::GtkGlobalThread;
use super::AsGtkDialog;

use crate::backend::DialogFutureType;
use crate::message_dialog::{MessageButtons, MessageDialog, MessageLevel};
use crate::MessageDialogResult;

Expand Down Expand Up @@ -187,7 +187,7 @@ impl AsGtkDialog for GtkMessageDialog {
}
}

use crate::backend::MessageDialogImpl;
use crate::backend::{AsyncMessageDialogImpl, MessageDialogImpl};

impl MessageDialogImpl for MessageDialog {
fn show(self) -> MessageDialogResult {
Expand All @@ -198,8 +198,6 @@ impl MessageDialogImpl for MessageDialog {
}
}

use crate::backend::{AsyncMessageDialogImpl, DialogFutureType};

impl AsyncMessageDialogImpl for MessageDialog {
fn show_async(self) -> DialogFutureType<MessageDialogResult> {
let builder = move || GtkMessageDialog::new(self);
Expand Down
15 changes: 8 additions & 7 deletions src/backend/macos/file_dialog.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::PathBuf;

use objc2::rc::autoreleasepool;
use objc2_app_kit::NSModalResponseOK;
use std::path::PathBuf;

mod panel_ffi;

Expand All @@ -14,7 +15,8 @@ use crate::{FileDialog, FileHandle};
// File Picker
//

use crate::backend::FilePickerDialogImpl;
use crate::backend::{AsyncFilePickerDialogImpl, FilePickerDialogImpl};

impl FilePickerDialogImpl for FileDialog {
fn pick_file(self) -> Option<PathBuf> {
autoreleasepool(move |_| {
Expand Down Expand Up @@ -45,7 +47,6 @@ impl FilePickerDialogImpl for FileDialog {
}
}

use crate::backend::AsyncFilePickerDialogImpl;
impl AsyncFilePickerDialogImpl for FileDialog {
fn pick_file_async(self) -> DialogFutureType<Option<FileHandle>> {
let win = self.parent.as_ref().map(window_from_raw_window_handle);
Expand Down Expand Up @@ -94,7 +95,8 @@ impl AsyncFilePickerDialogImpl for FileDialog {
// Folder Picker
//

use crate::backend::FolderPickerDialogImpl;
use crate::backend::{AsyncFolderPickerDialogImpl, FolderPickerDialogImpl};

impl FolderPickerDialogImpl for FileDialog {
fn pick_folder(self) -> Option<PathBuf> {
autoreleasepool(move |_| {
Expand Down Expand Up @@ -123,7 +125,6 @@ impl FolderPickerDialogImpl for FileDialog {
}
}

use crate::backend::AsyncFolderPickerDialogImpl;
impl AsyncFolderPickerDialogImpl for FileDialog {
fn pick_folder_async(self) -> DialogFutureType<Option<FileHandle>> {
let win = self.parent.as_ref().map(window_from_raw_window_handle);
Expand Down Expand Up @@ -172,7 +173,8 @@ impl AsyncFolderPickerDialogImpl for FileDialog {
// File Save
//

use crate::backend::FileSaveDialogImpl;
use crate::backend::{AsyncFileSaveDialogImpl, FileSaveDialogImpl};

impl FileSaveDialogImpl for FileDialog {
fn save_file(self) -> Option<PathBuf> {
autoreleasepool(move |_| {
Expand All @@ -188,7 +190,6 @@ impl FileSaveDialogImpl for FileDialog {
}
}

use crate::backend::AsyncFileSaveDialogImpl;
impl AsyncFileSaveDialogImpl for FileDialog {
fn save_file_async(self) -> DialogFutureType<Option<FileHandle>> {
let win = self.parent.as_ref().map(window_from_raw_window_handle);
Expand Down
1 change: 0 additions & 1 deletion src/backend/macos/file_dialog/panel_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::path::{Path, PathBuf};

use block2::Block;
use objc2::rc::Id;

use objc2_app_kit::{NSModalResponse, NSOpenPanel, NSSavePanel, NSWindow, NSWindowLevel};
use objc2_foundation::{MainThreadMarker, NSArray, NSObjectProtocol, NSString, NSURL};
use raw_window_handle::RawWindowHandle;
Expand Down
18 changes: 7 additions & 11 deletions src/backend/macos/message_dialog.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
use crate::backend::DialogFutureType;
use crate::message_dialog::{MessageButtons, MessageDialog, MessageDialogResult, MessageLevel};

use super::modal_future::{AsModal, InnerModal, ModalFuture};
use super::utils::{self, run_on_main, FocusManager, PolicyManager};

use super::utils::window_from_raw_window_handle;
use block2::Block;
use objc2::rc::{autoreleasepool, Id};
use objc2_app_kit::{
NSAlert, NSAlertFirstButtonReturn, NSAlertSecondButtonReturn, NSAlertStyle,
NSAlertThirdButtonReturn, NSApplication, NSModalResponse, NSWindow,
};
use objc2_foundation::{MainThreadMarker, NSString};

use objc2::rc::{autoreleasepool, Id};
use super::modal_future::{AsModal, InnerModal, ModalFuture};
use super::utils::{self, run_on_main, window_from_raw_window_handle, FocusManager, PolicyManager};
use crate::backend::DialogFutureType;
use crate::message_dialog::{MessageButtons, MessageDialog, MessageDialogResult, MessageLevel};

pub struct Alert {
buttons: MessageButtons,
Expand Down Expand Up @@ -149,7 +146,8 @@ impl InnerModal for NSAlert {
}
}

use crate::backend::MessageDialogImpl;
use crate::backend::{AsyncMessageDialogImpl, MessageDialogImpl};

impl MessageDialogImpl for MessageDialog {
fn show(self) -> MessageDialogResult {
autoreleasepool(move |_| {
Expand All @@ -164,8 +162,6 @@ impl MessageDialogImpl for MessageDialog {
}
}

use crate::backend::AsyncMessageDialogImpl;

impl AsyncMessageDialogImpl for MessageDialog {
fn show_async(self) -> DialogFutureType<MessageDialogResult> {
if self.parent.is_none() {
Expand Down
9 changes: 4 additions & 5 deletions src/backend/macos/modal_future.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use std::pin::Pin;
use std::sync::{Arc, Mutex};
use std::task::{Context, Poll, Waker};

use block2::Block;
use objc2::mutability::MainThreadOnly;
use objc2::rc::Id;
use objc2::ClassType;
use objc2_app_kit::{NSApplication, NSModalResponse, NSWindow};
use objc2_foundation::{run_on_main, MainThreadMarker};

use std::pin::Pin;
use std::sync::{Arc, Mutex};

use std::task::{Context, Poll, Waker};

use super::utils::activate_cocoa_multithreading;

pub(super) trait AsModal {
Expand Down
7 changes: 4 additions & 3 deletions src/backend/macos/utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
mod focus_manager;
mod policy_manager;
mod user_alert;

pub use focus_manager::FocusManager;

mod policy_manager;
pub use policy_manager::PolicyManager;

mod user_alert;
pub use user_alert::{async_pop_dialog, sync_pop_dialog};

use objc2::rc::Id;
Expand Down
1 change: 0 additions & 1 deletion src/backend/macos/utils/focus_manager.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use objc2::rc::Id;

use objc2_app_kit::{NSApplication, NSWindow};
use objc2_foundation::MainThreadMarker;

Expand Down
10 changes: 5 additions & 5 deletions src/backend/macos/utils/user_alert.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::backend::macos::utils::{FocusManager, PolicyManager};
use crate::backend::DialogFutureType;
use crate::message_dialog::{MessageButtons, MessageDialog, MessageDialogResult, MessageLevel};
use std::mem::MaybeUninit;
use std::{ptr, thread};

use core_foundation::base::TCFType;
use core_foundation::string::CFString;
Expand All @@ -15,8 +14,9 @@ use core_foundation_sys::user_notification::{
};
use objc2_foundation::MainThreadMarker;

use std::mem::MaybeUninit;
use std::{ptr, thread};
use crate::backend::macos::utils::{FocusManager, PolicyManager};
use crate::backend::DialogFutureType;
use crate::message_dialog::{MessageButtons, MessageDialog, MessageDialogResult, MessageLevel};

struct UserAlert {
timeout: CFTimeInterval,
Expand Down
14 changes: 8 additions & 6 deletions src/backend/wasm.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use web_sys::{Element, HtmlAnchorElement, HtmlButtonElement, HtmlElement, HtmlInputElement};

mod file_dialog;

use crate::backend::DialogFutureType;
use crate::file_dialog::FileDialog;
use crate::file_handle::WasmFileHandleKind;
use crate::{FileHandle, MessageDialogResult};
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use web_sys::{Element, HtmlAnchorElement, HtmlButtonElement, HtmlElement, HtmlInputElement};

#[derive(Clone, Debug)]
pub enum FileKind<'a> {
Expand Down Expand Up @@ -267,7 +269,7 @@ impl<'a> Drop for WasmDialog<'a> {
}
}

use super::{AsyncFilePickerDialogImpl, DialogFutureType};
use crate::backend::AsyncFilePickerDialogImpl;

impl AsyncFilePickerDialogImpl for FileDialog {
fn pick_file_async(self) -> DialogFutureType<Option<FileHandle>> {
Expand All @@ -287,7 +289,7 @@ extern "C" {
fn confirm(s: &str) -> bool;
}

use crate::backend::MessageDialogImpl;
use crate::backend::{AsyncMessageDialogImpl, MessageDialogImpl};
use crate::message_dialog::{MessageButtons, MessageDialog};

impl MessageDialogImpl for MessageDialog {
Expand All @@ -313,7 +315,7 @@ impl MessageDialogImpl for MessageDialog {
}
}

impl crate::backend::AsyncMessageDialogImpl for MessageDialog {
impl AsyncMessageDialogImpl for MessageDialog {
fn show_async(self) -> DialogFutureType<MessageDialogResult> {
let val = MessageDialogImpl::show(self);
Box::pin(std::future::ready(val))
Expand Down
12 changes: 8 additions & 4 deletions src/backend/wasm/file_dialog.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use std::future::ready;

use crate::backend::DialogFutureType;
use crate::file_dialog::FileDialog;
use crate::FileHandle;

//
// File Save
//

use crate::backend::{AsyncFileSaveDialogImpl, DialogFutureType};
use crate::file_dialog::FileDialog;
use crate::FileHandle;
use std::future::ready;
use crate::backend::AsyncFileSaveDialogImpl;

impl AsyncFileSaveDialogImpl for FileDialog {
fn save_file_async(self) -> DialogFutureType<Option<FileHandle>> {
let file = FileHandle::writable(self);
Expand Down
Loading

0 comments on commit 9707d69

Please sign in to comment.