Skip to content

Commit

Permalink
fixes #4 : files will highlighed when opened in Explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
ish-u committed Oct 2, 2022
1 parent a63f241 commit 3e5276e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
18 changes: 18 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,26 @@
windows_subsystem = "windows"
)]

use std::process::Command;
use std::env;
#[tauri::command]
fn open_in_explorer(path: &str){
// FOR OTHER OS REFER - https://doc.rust-lang.org/std/env/consts/constant.OS.html
// REF - https://github.com/tauri-apps/tauri/issues/4062
// TARGET - WINDOWS
if env:: consts:: OS == "windows" {
Command::new("explorer")
.args(["/select,",path])
.spawn()
.unwrap();
}
}

fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![
open_in_explorer
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
7 changes: 3 additions & 4 deletions src/components/Content/Editor/TabMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import ContextMenu from "../../ContextMenu/ContextMenu.svelte";
import CopyFile from "carbon-icons-svelte/lib/CopyFile.svelte";
import Cut from "carbon-icons-svelte/lib/Cut.svelte";
import { clipboard, shell, path } from "@tauri-apps/api";
import { clipboard, path, invoke } from "@tauri-apps/api";
import { closeTab, setActive } from "./Tabs";
export let id: number;
export let target;
Expand Down Expand Up @@ -47,9 +47,8 @@
</ContextMenuOption>
<ContextMenuOption labelText="Show in Explorer" on:click={() => {
let dir = filepath.split(path.sep);
dir.pop();
dir = dir.join(path.sep);
shell.open(dir);
let explorerPath = dir.join(path.sep);
invoke("open_in_explorer",{ path:explorerPath})
}}></ContextMenuOption>
</ContextMenu>

Expand Down
7 changes: 3 additions & 4 deletions src/components/FileTree/LeafNodeMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import CopyFile from "carbon-icons-svelte/lib/CopyFile.svelte";
import Cut from "carbon-icons-svelte/lib/Cut.svelte";
import Script from "carbon-icons-svelte/lib/Script.svelte";
import { fs, clipboard, shell, path } from "@tauri-apps/api";
import { fs, clipboard, path, invoke } from "@tauri-apps/api";
export let target;
export let filename;
export let filepath;
Expand Down Expand Up @@ -40,9 +40,8 @@
</ContextMenuOption>
<ContextMenuOption labelText="Show in Explorer" on:click={() => {
let dir = filepath.split(path.sep);
dir.pop();
dir = dir.join(path.sep);
shell.open(dir);
let explorerPath = dir.join(path.sep);
invoke("open_in_explorer",{ path:explorerPath})
}}></ContextMenuOption>

<ContextMenuDivider></ContextMenuDivider>
Expand Down
6 changes: 4 additions & 2 deletions src/components/FileTree/ParentNodeMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import Paste from "carbon-icons-svelte/lib/Paste.svelte";
import Cut from "carbon-icons-svelte/lib/Cut.svelte";
import RenameModel from "../Modal/RenameModel.svelte";
import { fs, clipboard, shell, path } from "@tauri-apps/api";
import { fs, clipboard, invoke, path } from "@tauri-apps/api";
export let target;
export let filename;
export let filepath;
Expand Down Expand Up @@ -41,7 +41,9 @@
</ContextMenuOption>
</ContextMenuOption>
<ContextMenuOption labelText="Show in Explorer" on:click={() => {
shell.open(filepath);
let dir = filepath.split(path.sep);
let explorerPath = dir.join(path.sep);
invoke("open_in_explorer",{ path:explorerPath})
}}></ContextMenuOption>
<ContextMenuDivider></ContextMenuDivider>
<ContextMenuOption labelText="Delete..." on:click={ async() => {
Expand Down

0 comments on commit 3e5276e

Please sign in to comment.