Skip to content

Commit

Permalink
feat: openfolder
Browse files Browse the repository at this point in the history
Signed-off-by: seven <[email protected]>
  • Loading branch information
Blankll committed Oct 21, 2024
1 parent 73b25fb commit ba02cbb
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 5 deletions.
79 changes: 79 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2021"
tauri-build = { version = "1.5", features = [] }

[dependencies]
tauri = { version = "1.7", features = [ "fs-create-dir", "global-shortcut-all", "http-all", "fs-exists", "fs-read-file", "fs-write-file", "shell-open"] }
tauri = { version = "1.7", features = [ "dialog-open", "fs-create-dir", "global-shortcut-all", "http-all", "fs-exists", "fs-read-file", "fs-write-file", "shell-open"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1"
tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
Expand Down
3 changes: 3 additions & 0 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
},
"globalShortcut": {
"all": true
},
"dialog": {
"open": true
}
},
"windows": [
Expand Down
34 changes: 30 additions & 4 deletions src/views/file/components/tool-bar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="tool-bar-container">
<n-tooltip trigger="hover" v-for="toolBar in toolBarList">
<template #trigger>
<n-icon size="26" class="tool-bar-item">
<n-icon size="26" class="tool-bar-item" @click="handleToolBarAction(toolBar.id)">
<component :is="toolBar.icon" />
</n-icon>
</template>
Expand All @@ -12,25 +12,51 @@
</template>

<script setup lang="ts">
import { open } from '@tauri-apps/api/dialog';
import { DocumentAdd, FolderAdd, FolderOpen } from '@vicons/carbon';
enum ToolBarAction {
ADD_DOCUMENT = 'ADD_DOCUMENT',
ADD_FOLDER = 'ADD_FOLDER',
OPEN_FOLDER = 'OPEN_FOLDER',
}
const toolBarList = [
{
id: 'add-document',
id: ToolBarAction.ADD_DOCUMENT,
icon: DocumentAdd,
title: 'Add Document',
},
{
id: 'add-folder',
id: ToolBarAction.ADD_FOLDER,
icon: FolderAdd,
title: 'Add Folder',
},
{
id: 'open-folder',
id: ToolBarAction.OPEN_FOLDER,
icon: FolderOpen,
title: 'Open Folder',
},
];
const handleToolBarAction = async (id: ToolBarAction) => {
if (id === ToolBarAction.ADD_DOCUMENT) {
console.log('Add Document');
} else if (id === ToolBarAction.ADD_FOLDER) {
console.log('Add Folder');
} else if (id === ToolBarAction.OPEN_FOLDER) {
try {
const selectedFiles = await open({
multiple: false,
directory: true,
});
console.log('Selected files:', selectedFiles);
} catch (error) {
console.error('Failed to open file dialog:', error);
}
console.log(id);
}
};
</script>

<style lang="scss" scoped>
Expand Down

0 comments on commit ba02cbb

Please sign in to comment.