This repository has been archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2249ef2
commit 083b352
Showing
16 changed files
with
455 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
**EXTENSION** | ||
|
||
# `GTUIWindow` | ||
|
||
## Methods | ||
### `setParentWindow(_:)` | ||
|
||
Set the window's parent window. | ||
- Parameter parent: The parent window. |
48 changes: 48 additions & 0 deletions
48
Documentation/Reference/extensions/Libadwaita.FileDialog.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
**EXTENSION** | ||
|
||
# `Libadwaita.FileDialog` | ||
|
||
## Properties | ||
### `importer` | ||
|
||
An ID for the importer field. | ||
|
||
### `folder` | ||
|
||
An ID for the folder field. | ||
|
||
### `result` | ||
|
||
An ID for the result field. | ||
|
||
### `cancel` | ||
|
||
An ID for the cancel field. | ||
|
||
### `isImporter` | ||
|
||
Whether the file dialog is an importer. | ||
|
||
### `folder` | ||
|
||
The selected folder in the file dialog. | ||
|
||
### `onResult` | ||
|
||
A closure triggered on selecting a file in the dialog. | ||
|
||
### `onCancel` | ||
|
||
A closure triggered when the dialog is canceled. | ||
|
||
## Methods | ||
### `setParentWindow(_:)` | ||
|
||
Set the window's parent window. | ||
- Parameter parent: The parent window. | ||
|
||
Currently not implemented. | ||
|
||
### `show()` | ||
|
||
Display the file dialog. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
**PROTOCOL** | ||
|
||
# `WindowType` | ||
|
||
A window type. | ||
|
||
## Properties | ||
### `fields` | ||
|
||
A dictionary for custom data. | ||
|
||
## Methods | ||
### `setParentWindow(_:)` | ||
|
||
Set a parent window. | ||
- Parameter parent: The parent window. | ||
|
||
### `show()` | ||
|
||
Show the window. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
**STRUCT** | ||
|
||
# `FileDialog` | ||
|
||
A structure representing a file dialog window. | ||
|
||
## Properties | ||
### `id` | ||
|
||
The window's identifier. | ||
|
||
### `importer` | ||
|
||
Whether the window is an importer. | ||
|
||
### `open` | ||
|
||
Whether an instance of the window type should be opened when the app is starting up. | ||
|
||
### `parentID` | ||
|
||
The identifier of the window's parent. | ||
|
||
### `appShortcuts` | ||
|
||
The keyboard shortcuts on the app level. | ||
|
||
### `initialFolder` | ||
|
||
The initial folder. | ||
|
||
### `initialName` | ||
|
||
The initial file name for the file exporter. | ||
|
||
### `extensions` | ||
|
||
The accepted extensions for the file importer. | ||
|
||
### `folders` | ||
|
||
Whether folders are accepted in the file importer. | ||
|
||
### `result` | ||
|
||
The closure to run when the import or export is successful. | ||
|
||
### `cancel` | ||
|
||
The closure to run when the import or export is not successful. | ||
|
||
## Methods | ||
### `init(importer:initialFolder:extensions:folders:onOpen:onClose:)` | ||
|
||
Create an importer file dialog window. | ||
- Parameters: | ||
- importer: The window's identifier. | ||
- initialFolder: The URL to the folder open when being opened. | ||
- extensions: The accepted file extensions. | ||
- folders: Whether folders are accepted. | ||
- onOpen: Run this when a file for importing has been chosen. | ||
- onClose: Run this when the user cancelled the action. | ||
|
||
### `init(exporter:initialFolder:initialName:onSave:onClose:)` | ||
|
||
Create an exporter file dialog window. | ||
- Parameters: | ||
- exporter: The window's identifier. | ||
- initialFolder: The URL to the folder open when being opened. | ||
- initialName: The default file name. | ||
- onSave: Run this when a path for exporting has been chosen. | ||
- onClose: Run this when the user cancelled the action. | ||
|
||
### `createWindow(app:)` | ||
|
||
Get the storage for the window. | ||
- Parameter app: The application. | ||
- Returns: The storage. | ||
|
||
### `update(_:app:)` | ||
|
||
Update a window. | ||
- Parameters: | ||
- storage: The storage to update. | ||
- app: The application. | ||
|
||
### `update(window:)` | ||
|
||
Update the window. | ||
- Parameter window: The window. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
Sources/Adwaita/Model/Extensions/Libadwaita.FileDialog.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// | ||
// Libadwaita.FileDialog.swift | ||
// Adwaita | ||
// | ||
// Created by david-swift on 09.12.23. | ||
// | ||
|
||
import Foundation | ||
import Libadwaita | ||
|
||
extension Libadwaita.FileDialog: WindowType { | ||
|
||
/// An ID for the importer field. | ||
static var importer: String { "importer" } | ||
/// An ID for the folder field. | ||
static var folder: String { "folder" } | ||
/// An ID for the result field. | ||
static var result: String { "result" } | ||
/// An ID for the cancel field. | ||
static var cancel: String { "cancel" } | ||
|
||
/// Whether the file dialog is an importer. | ||
var isImporter: Bool { | ||
get { | ||
fields[Self.importer] as? Bool ?? true | ||
} | ||
set { | ||
fields[Self.importer] = newValue | ||
} | ||
} | ||
/// The selected folder in the file dialog. | ||
var folder: URL? { | ||
get { | ||
fields[Self.folder] as? URL | ||
} | ||
set { | ||
fields[Self.folder] = newValue | ||
} | ||
} | ||
/// A closure triggered on selecting a file in the dialog. | ||
var onResult: ((URL) -> Void) { | ||
get { | ||
fields[Self.result] as? (URL) -> Void ?? { _ in } | ||
} | ||
set { | ||
fields[Self.result] = newValue | ||
} | ||
} | ||
/// A closure triggered when the dialog is canceled. | ||
var onCancel: (() -> Void) { | ||
get { | ||
fields[Self.cancel] as? () -> Void ?? { } | ||
} | ||
set { | ||
fields[Self.cancel] = newValue | ||
} | ||
} | ||
|
||
/// Set the window's parent window. | ||
/// - Parameter parent: The parent window. | ||
/// | ||
/// Currently not implemented. | ||
public func setParentWindow(_ parent: WindowType) { } | ||
|
||
/// Display the file dialog. | ||
public func show() { | ||
if isImporter { | ||
self.open(folder: folder, onResult, onClose: onCancel) | ||
} else { | ||
self.save(folder: folder, onResult, onClose: onCancel) | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.