Skip to content

Commit

Permalink
update trash can function
Browse files Browse the repository at this point in the history
  • Loading branch information
yorukot committed Apr 16, 2024
1 parent df53f0c commit a7e0455
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/components/global_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"strings"
"time"

"github.com/Bios-Marcel/wastebasket"
"github.com/charmbracelet/bubbles/progress"
"github.com/charmbracelet/bubbles/textinput"
"github.com/lithammer/shortuuid"
"github.com/rkoesters/xdg/trash"
)

/* CURSOR CONTROLLER START */
Expand Down Expand Up @@ -347,7 +347,7 @@ func pasteItem(m model) model {
if m.copyItems.cut {
for _, item := range m.copyItems.items {

err := trash.Trash(item)
err := wastebasket.Trash(item)
if err != nil {
outPutLog("Paste item function move file to trash can error", err)
}
Expand Down
10 changes: 4 additions & 6 deletions src/components/normal_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ package components

import (
"os"
"os/exec"
"path"
"runtime"
"time"

"os/exec"

"github.com/Bios-Marcel/wastebasket"
"github.com/atotto/clipboard"
"github.com/charmbracelet/bubbles/progress"
"github.com/charmbracelet/bubbles/textinput"
"github.com/lithammer/shortuuid"
"github.com/rkoesters/xdg/trash"
)

func enterPanel(m model) model {
Expand Down Expand Up @@ -127,7 +125,7 @@ func deleteSingleItem(m model) model {
return m
}

if isExternalDiskPath(panel.location) || runtime.GOOS == "darwin" {
if isExternalDiskPath(panel.location) {
channel <- channelMessage{
messageId: id,
returnWarnModal: true,
Expand Down Expand Up @@ -158,7 +156,7 @@ func deleteSingleItem(m model) model {
processNewState: newProcess,
}

err := trash.Trash(panel.element[panel.cursor].location)
err := wastebasket.Trash(panel.element[panel.cursor].location)
if err != nil {
outPutLog("Delete single item function move file to trash can error", err)
}
Expand Down
7 changes: 3 additions & 4 deletions src/components/select_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package components
import (
"os"
"path/filepath"
"runtime"

"github.com/Bios-Marcel/wastebasket"
"github.com/atotto/clipboard"
"github.com/charmbracelet/bubbles/progress"
"github.com/lithammer/shortuuid"
"github.com/rkoesters/xdg/trash"
)

func singleItemSelect(m model) model {
Expand Down Expand Up @@ -144,7 +143,7 @@ func deleteMultipleItem(m model) model {
panel := m.fileModel.filePanels[m.filePanelFocusIndex]
if len(panel.selected) != 0 {
id := shortuuid.New()
if isExternalDiskPath(panel.location) || runtime.GOOS == "darwin" {
if isExternalDiskPath(panel.location) {
channel <- channelMessage{
messageId: id,
returnWarnModal: true,
Expand Down Expand Up @@ -187,7 +186,7 @@ func deleteMultipleItem(m model) model {
processNewState: p,
}
}
err := trash.Trash(filePath)
err := wastebasket.Trash(filePath)
if err != nil {
outPutLog("Delete single item function move file to trash can error", err)
}
Expand Down
5 changes: 4 additions & 1 deletion src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ require (
github.com/urfave/cli/v2 v2.27.1
)

require github.com/deckarep/golang-set v1.8.0 // indirect
require (
github.com/Bios-Marcel/wastebasket v0.0.3 // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
)

require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions src/go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/Bios-Marcel/wastebasket v0.0.3 h1:gyuMcoDav6n+sdynn9TDl1NN7GOAnoy227JErVSW3RM=
github.com/Bios-Marcel/wastebasket v0.0.3/go.mod h1:FChzXi1izqzdPb6BiNZmcZLGyTYiT61iGx9Rxx9GNeI=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
Expand Down
16 changes: 13 additions & 3 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -106,17 +107,26 @@ func InitConfigFile() {
ThemeFolder: themeFolder,
ThemeZipName: themeZipName,
}

// Create directories
if err := createDirectories(
config.MainDir, config.DataDir,
config.CacheDir,
basedir.DataHome+trashDirectory,
basedir.DataHome+trashDirectoryFiles,
basedir.DataHome+trashDirectoryInfo,
); err != nil {
log.Fatalln("Error creating directories:", err)
}

// Create trash directories
if runtime.GOOS != "darwin" {
if err := createDirectories(
basedir.DataHome+trashDirectory,
basedir.DataHome+trashDirectoryFiles,
basedir.DataHome+trashDirectoryInfo,
); err != nil {
log.Fatalln("Error creating directories:", err)
}
}

// Create files
if err := createFiles(
config.DataDir+config.PinnedFile,
Expand Down

0 comments on commit a7e0455

Please sign in to comment.