feat(gui): folder select dialogue for directory block (#2315)

This commit is contained in:
Ellie Huxtable 2024-07-26 12:51:15 +01:00 committed by GitHub
parent c32bbcc7ed
commit a34efd6c6b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 142 additions and 23 deletions

74
ui/backend/Cargo.lock generated
View File

@ -167,6 +167,23 @@ version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
[[package]]
name = "ashpd"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd884d7c72877a94102c3715f3b1cd09ff4fac28221add3e57cfbe25c236d093"
dependencies = [
"enumflags2",
"futures-channel",
"futures-util",
"rand 0.8.5",
"serde",
"serde_repr",
"tokio",
"url",
"zbus",
]
[[package]]
name = "async-broadcast"
version = "0.7.1"
@ -3348,6 +3365,17 @@ dependencies = [
"objc_exception",
]
[[package]]
name = "objc-foundation"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9"
dependencies = [
"block",
"objc",
"objc_id",
]
[[package]]
name = "objc-sys"
version = "0.3.5"
@ -4411,6 +4439,30 @@ dependencies = [
"winreg 0.52.0",
]
[[package]]
name = "rfd"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25a73a7337fc24366edfca76ec521f51877b114e42dab584008209cca6719251"
dependencies = [
"ashpd",
"block",
"dispatch",
"glib-sys",
"gobject-sys",
"gtk-sys",
"js-sys",
"log",
"objc",
"objc-foundation",
"objc_id",
"raw-window-handle 0.6.2",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"windows-sys 0.48.0",
]
[[package]]
name = "ring"
version = "0.17.8"
@ -5812,6 +5864,24 @@ dependencies = [
"walkdir",
]
[[package]]
name = "tauri-plugin-dialog"
version = "2.0.0-beta.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8860dd73c96969eb14813f9f04d8665f2853342670456fb6619d637137ef0d09"
dependencies = [
"dunce",
"log",
"raw-window-handle 0.6.2",
"rfd",
"serde",
"serde_json",
"tauri",
"tauri-plugin",
"tauri-plugin-fs",
"thiserror",
]
[[package]]
name = "tauri-plugin-fs"
version = "2.0.0-beta.11"
@ -6174,6 +6244,7 @@ dependencies = [
"signal-hook-registry",
"socket2",
"tokio-macros",
"tracing",
"windows-sys 0.52.0",
]
@ -6487,6 +6558,7 @@ dependencies = [
"syntect",
"tauri",
"tauri-build",
"tauri-plugin-dialog",
"tauri-plugin-http",
"tauri-plugin-os",
"tauri-plugin-shell",
@ -7457,6 +7529,7 @@ dependencies = [
"serde_repr",
"sha1",
"static_assertions",
"tokio",
"tracing",
"uds_windows",
"windows-sys 0.52.0",
@ -7541,6 +7614,7 @@ dependencies = [
"enumflags2",
"serde",
"static_assertions",
"url",
"zvariant_derive",
]

View File

@ -37,6 +37,7 @@ tauri-plugin-http = "2.0.0-beta"
tauri-plugin-single-instance = "2.0.0-beta"
tauri-plugin-os = "2.0.0-beta.8"
tauri-plugin-shell = "2.0.0-beta.7"
tauri-plugin-dialog = "2.0.0-beta.11"
[target."cfg(target_os = \"macos\")".dependencies]
cocoa = "0.25"

View File

@ -2,7 +2,9 @@
"identifier": "migrated",
"description": "permissions that were migrated from v1",
"context": "local",
"windows": ["main"],
"windows": [
"main"
],
"permissions": [
"path:default",
"event:default",
@ -19,9 +21,16 @@
"window:allow-start-dragging",
{
"identifier": "http:default",
"allow": ["https://api.atuin.sh/*"]
"allow": [
"https://api.atuin.sh/*"
]
},
"os:default"
"os:default",
"dialog:default"
],
"platforms": ["linux", "macOS", "windows"]
}
"platforms": [
"linux",
"macOS",
"windows"
]
}

View File

@ -282,6 +282,7 @@ fn show_window(app: &AppHandle) {
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_shell::init())
.invoke_handler(tauri::generate_handler![

View File

@ -3,7 +3,7 @@ use std::io::BufRead;
use std::path::PathBuf;
use crate::state::AtuinState;
use tauri::{Manager, State, Emitter};
use tauri::{Emitter, Manager, State};
use atuin_client::{database::Sqlite, record::sqlite_store::SqliteStore, settings::Settings};
@ -15,7 +15,7 @@ pub async fn pty_open<'a>(
) -> Result<uuid::Uuid, String> {
let id = uuid::Uuid::new_v4();
let cwd = cwd.map(|c|shellexpand::tilde(c.as_str()).to_string());
let cwd = cwd.map(|c| shellexpand::tilde(c.as_str()).to_string());
let pty = crate::pty::Pty::open(24, 80, cwd).await.unwrap();
let reader = pty.reader.clone();

View File

@ -31,6 +31,7 @@
"@tanstack/react-table": "^8.19.3",
"@tanstack/react-virtual": "^3.8.3",
"@tauri-apps/api": "2.0.0-beta.15",
"@tauri-apps/plugin-dialog": "2.0.0-beta.7",
"@tauri-apps/plugin-http": "2.0.0-beta.8",
"@tauri-apps/plugin-os": "2.0.0-beta.7",
"@tauri-apps/plugin-shell": "2.0.0-beta.8",

View File

@ -68,6 +68,9 @@ dependencies:
'@tauri-apps/api':
specifier: 2.0.0-beta.15
version: 2.0.0-beta.15
'@tauri-apps/plugin-dialog':
specifier: 2.0.0-beta.7
version: 2.0.0-beta.7
'@tauri-apps/plugin-http':
specifier: 2.0.0-beta.8
version: 2.0.0-beta.8
@ -5145,6 +5148,12 @@ packages:
'@tauri-apps/cli-win32-x64-msvc': 2.0.0-beta.22
dev: true
/@tauri-apps/plugin-dialog@2.0.0-beta.7:
resolution: {integrity: sha512-myywwpsKbquDDzl5zaOmmLLv5O8EJ/GgHDAoVSPwO97R4iWzkDvj3HFF91tNh7i25Tu/bP6jYPAdZA1NCRxxtg==}
dependencies:
'@tauri-apps/api': 2.0.0-beta.15
dev: false
/@tauri-apps/plugin-http@2.0.0-beta.8:
resolution: {integrity: sha512-FhZP4WtS1o69Mn7z2RpNIdVS+2nPqmXyz6LhqweuP1FTjgTVraVxIfGLQCOMLpEUwo8zWY2uChllolV6WGYZ/A==}
dependencies:

View File

@ -1,10 +1,12 @@
import { useState } from "react";
import { Input, Tooltip } from "@nextui-org/react";
import { Input, Tooltip, Button } from "@nextui-org/react";
import { FolderInputIcon, HelpCircleIcon } from "lucide-react";
// @ts-ignore
import { createReactBlockSpec } from "@blocknote/react";
import { open } from "@tauri-apps/plugin-dialog";
interface DirectoryProps {
path: string;
onInputChange: (string) => void;
@ -13,27 +15,49 @@ interface DirectoryProps {
const Directory = ({ path, onInputChange }: DirectoryProps) => {
const [value, setValue] = useState(path);
const selectFolder = async () => {
const path = await open({
multiple: false,
directory: true,
});
setValue(path);
onInputChange(path);
};
return (
<div className="w-full !max-w-full !outline-none overflow-none">
<Tooltip
content="Change working directory for all subsequent code blocks"
delay={1000}
>
<Input
label="Directory"
placeholder="~"
labelPlacement="outside"
value={value}
autoComplete="off"
autoCapitalize="off"
autoCorrect="off"
spellCheck="false"
onValueChange={(val) => {
setValue(val);
onInputChange(val);
}}
startContent={<FolderInputIcon />}
/>
<div className="flex flex-row">
<div className="mr-2">
<Button
isIconOnly
variant="flat"
aria-label="Select folder"
onPress={selectFolder}
>
<FolderInputIcon />
</Button>
</div>
<div className="w-full">
<Input
placeholder="~"
value={value}
autoComplete="off"
autoCapitalize="off"
autoCorrect="off"
spellCheck="false"
onValueChange={(val) => {
setValue(val);
onInputChange(val);
}}
/>
</div>
</div>
</Tooltip>
</div>
);