Skip to content

Commit

Permalink
Merge pull request #527 from GRFreire/work-without-trash
Browse files Browse the repository at this point in the history
Work without trash
  • Loading branch information
yorukot authored Dec 30, 2024
2 parents cbf1fc3 + bf31cb0 commit 98a019f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
32 changes: 20 additions & 12 deletions src/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,19 @@ func Run(content embed.FS) {

InitConfigFile()

err := InitTrash()
hasTrash := true
if err != nil {
hasTrash = false
}

variable.FixHotkeys = c.Bool("fix-hotkeys")
variable.FixConfigFile = c.Bool("fix-config-file")
variable.PrintLastDir = c.Bool("print-last-dir")

firstUse := checkFirstUse()

p := tea.NewProgram(internal.InitialModel(path, firstUse), tea.WithAltScreen(), tea.WithMouseCellMotion())
p := tea.NewProgram(internal.InitialModel(path, firstUse, hasTrash), tea.WithAltScreen(), tea.WithMouseCellMotion())
if _, err := p.Run(); err != nil {
log.Fatalf("Alas, there's been an error: %v", err)
}
Expand Down Expand Up @@ -115,17 +121,6 @@ func InitConfigFile() {
log.Fatalln("Error creating directories:", err)
}

// Create trash directories
if runtime.GOOS != "darwin" {
if err := createDirectories(
xdg.DataHome+variable.TrashDirectory,
xdg.DataHome+variable.TrashDirectoryFiles,
xdg.DataHome+variable.TrashDirectoryInfo,
); err != nil {
log.Fatalln("Error creating directories:", err)
}
}

// Create files
if err := createFiles(
variable.PinnedFile,
Expand All @@ -147,6 +142,19 @@ func InitConfigFile() {
}
}

func InitTrash() error {
// Create trash directories
if runtime.GOOS != "darwin" {
err := createDirectories(
xdg.DataHome+variable.TrashDirectory,
xdg.DataHome+variable.TrashDirectoryFiles,
xdg.DataHome+variable.TrashDirectoryInfo,
)
return err
}
return nil
}

// Helper functions
// Create all dirs that does not already exists
func createDirectories(dirs ...string) error {
Expand Down
2 changes: 1 addition & 1 deletion src/internal/handle_file_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (m *model) deleteItemWarn() {
messageType: sendWarnModal,
}

if isExternalDiskPath(panel.location) {
if !hasTrash || isExternalDiskPath(panel.location) {
message.warnModal = warnModal{
open: true,
title: "Are you sure you want to completely delete",
Expand Down
4 changes: 2 additions & 2 deletions src/internal/key_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (m *model) warnModalOpenKey(msg string) {
case confirmDeleteItem:
panel := m.fileModel.filePanels[m.filePanelFocusIndex]
if m.fileModel.filePanels[m.filePanelFocusIndex].panelMode == selectMode {
if isExternalDiskPath(panel.location) {
if !hasTrash || isExternalDiskPath(panel.location) {
go func() {
m.completelyDeleteMultipleItems()
m.fileModel.filePanels[m.filePanelFocusIndex].selected = m.fileModel.filePanels[m.filePanelFocusIndex].selected[:0]
Expand All @@ -226,7 +226,7 @@ func (m *model) warnModalOpenKey(msg string) {
}()
}
} else {
if isExternalDiskPath(panel.location) {
if !hasTrash || isExternalDiskPath(panel.location) {
go func() {
m.completelyDeleteSingleItem()
}()
Expand Down
4 changes: 3 additions & 1 deletion src/internal/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var LastTimeCursorMove = [2]int{int(time.Now().UnixMicro()), 0}
var ListeningMessage = true

var firstUse = false
var hasTrash = true

var theme ThemeType
var Config ConfigType
Expand All @@ -31,9 +32,10 @@ var channel = make(chan channelMessage, 1000)
var progressBarLastRenderTime time.Time = time.Now()

// Initialize and return model with default configs
func InitialModel(dir string, firstUseCheck bool) model {
func InitialModel(dir string, firstUseCheck bool, hasTrashCheck bool) model {
toggleDotFileBool, toggleFooter, firstFilePanelDir := initialConfig(dir)
firstUse = firstUseCheck
hasTrash = hasTrashCheck
return defaultModelConfig(toggleDotFileBool, toggleFooter, firstFilePanelDir)
}

Expand Down

0 comments on commit 98a019f

Please sign in to comment.