Skip to content

Commit 98a019f

Browse files
authored
Merge pull request #527 from GRFreire/work-without-trash
Work without trash
2 parents cbf1fc3 + bf31cb0 commit 98a019f

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

src/cmd/main.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,19 @@ func Run(content embed.FS) {
7676

7777
InitConfigFile()
7878

79+
err := InitTrash()
80+
hasTrash := true
81+
if err != nil {
82+
hasTrash = false
83+
}
84+
7985
variable.FixHotkeys = c.Bool("fix-hotkeys")
8086
variable.FixConfigFile = c.Bool("fix-config-file")
8187
variable.PrintLastDir = c.Bool("print-last-dir")
8288

8389
firstUse := checkFirstUse()
8490

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

118-
// Create trash directories
119-
if runtime.GOOS != "darwin" {
120-
if err := createDirectories(
121-
xdg.DataHome+variable.TrashDirectory,
122-
xdg.DataHome+variable.TrashDirectoryFiles,
123-
xdg.DataHome+variable.TrashDirectoryInfo,
124-
); err != nil {
125-
log.Fatalln("Error creating directories:", err)
126-
}
127-
}
128-
129124
// Create files
130125
if err := createFiles(
131126
variable.PinnedFile,
@@ -147,6 +142,19 @@ func InitConfigFile() {
147142
}
148143
}
149144

145+
func InitTrash() error {
146+
// Create trash directories
147+
if runtime.GOOS != "darwin" {
148+
err := createDirectories(
149+
xdg.DataHome+variable.TrashDirectory,
150+
xdg.DataHome+variable.TrashDirectoryFiles,
151+
xdg.DataHome+variable.TrashDirectoryInfo,
152+
)
153+
return err
154+
}
155+
return nil
156+
}
157+
150158
// Helper functions
151159
// Create all dirs that does not already exists
152160
func createDirectories(dirs ...string) error {

src/internal/handle_file_operations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (m *model) deleteItemWarn() {
109109
messageType: sendWarnModal,
110110
}
111111

112-
if isExternalDiskPath(panel.location) {
112+
if !hasTrash || isExternalDiskPath(panel.location) {
113113
message.warnModal = warnModal{
114114
open: true,
115115
title: "Are you sure you want to completely delete",

src/internal/key_function.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func (m *model) warnModalOpenKey(msg string) {
214214
case confirmDeleteItem:
215215
panel := m.fileModel.filePanels[m.filePanelFocusIndex]
216216
if m.fileModel.filePanels[m.filePanelFocusIndex].panelMode == selectMode {
217-
if isExternalDiskPath(panel.location) {
217+
if !hasTrash || isExternalDiskPath(panel.location) {
218218
go func() {
219219
m.completelyDeleteMultipleItems()
220220
m.fileModel.filePanels[m.filePanelFocusIndex].selected = m.fileModel.filePanels[m.filePanelFocusIndex].selected[:0]
@@ -226,7 +226,7 @@ func (m *model) warnModalOpenKey(msg string) {
226226
}()
227227
}
228228
} else {
229-
if isExternalDiskPath(panel.location) {
229+
if !hasTrash || isExternalDiskPath(panel.location) {
230230
go func() {
231231
m.completelyDeleteSingleItem()
232232
}()

src/internal/model.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var LastTimeCursorMove = [2]int{int(time.Now().UnixMicro()), 0}
1919
var ListeningMessage = true
2020

2121
var firstUse = false
22+
var hasTrash = true
2223

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

3334
// Initialize and return model with default configs
34-
func InitialModel(dir string, firstUseCheck bool) model {
35+
func InitialModel(dir string, firstUseCheck bool, hasTrashCheck bool) model {
3536
toggleDotFileBool, toggleFooter, firstFilePanelDir := initialConfig(dir)
3637
firstUse = firstUseCheck
38+
hasTrash = hasTrashCheck
3739
return defaultModelConfig(toggleDotFileBool, toggleFooter, firstFilePanelDir)
3840
}
3941

0 commit comments

Comments
 (0)