Skip to content

Commit a4232a8

Browse files
committed
update The external hard drive will be deleted directly (a confirmation message will be displayed)
1 parent 52ede94 commit a4232a8

11 files changed

+303
-74
lines changed

Diff for: changelog.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ All notable changes to this project will be documented in this file. Dates are d
1313
- The user can enter the path, which will be the path of the first file panel [`14620b3`](https://github.com/MHNightCat/superfile/commit/14620b33b09edfce80a95e1f52f7f66b3686a9d0)
1414
- Make user can open file with default browser text-editor etc [`f47d291`](https://github.com/MHNightCat/superfile/commit/f47d2915bf637da0cf99a4b15fa0bea8edc8d380)
1515
- Can open terminal in focused file panel path [`f47d291`](https://github.com/MHNightCat/superfile/commit/f47d2915bf637da0cf99a4b15fa0bea8edc8d380)
16-
16+
- The external hard drive will be deleted directly (a confirmation message will be displayed) [``]()
1717
#### Bug fix
1818

1919
- Fix processes bar cursor index display error [`f6eb9d8`](https://github.com/MHNightCat/superfile/commit/f6eb9d879f9f7ef31859e3f84c8792e2f0fc543a)

Diff for: release/release.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
projectName="superfile"
4+
version="v1.0.1"
5+
osList=("darwin" "freebsd" "linux" "openbsd" "netbsd")
6+
archList=("amd64" "arm" "arm64")
7+
mkdir dist
8+
9+
for os in "${osList[@]}"; do
10+
for arch in "${archList[@]}"; do
11+
echo $projectName-$os-$version-$arch
12+
mkdir ./dist/$projectName-$os-$version-$arch
13+
cd ../src
14+
go build -o ../release/dist/$projectName-$os-$version-$arch/spf main.go
15+
cd ../release
16+
tar czf ./dist/$projectName-$os-$version-$arch.tar.gz ./dist/$projectName-$os-$version-$arch
17+
done
18+
done

Diff for: src/components/function.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package components
33
import (
44
"encoding/json"
55
"fmt"
6+
"github.com/rkoesters/xdg/userdirs"
67
"io"
78
"log"
89
"math"
@@ -13,8 +14,6 @@ import (
1314
"sort"
1415
"strconv"
1516
"strings"
16-
17-
"github.com/rkoesters/xdg/userdirs"
1817
)
1918

2019
func getFolder() []folder {
@@ -43,10 +42,7 @@ func getFolder() []folder {
4342
OutPutLog("Read superfile data error", err)
4443
}
4544
var pinnedFolder []string
46-
err = json.Unmarshal(jsonData, &pinnedFolder)
47-
if err != nil {
48-
OutPutLog("Unmarshal superfile data error", err)
49-
}
45+
json.Unmarshal(jsonData, &pinnedFolder)
5046
folders := []folder{
5147
{location: HomeDir, name: "󰋜 Home"},
5248
{location: userdirs.Download, name: "󰏔 Downloads"},
@@ -296,8 +292,8 @@ func PasteDir(src, dst string, id string, m model) (model, error) {
296292
p.name = "󰆏 " + filepath.Base(path)
297293
}
298294

299-
if len(processBarChannel) < 5 {
300-
processBarChannel <- processBarMessage{
295+
if len(channel) < 5 {
296+
channel <- channelMessage{
301297
processId: id,
302298
processNewState: p,
303299
}
@@ -306,15 +302,15 @@ func PasteDir(src, dst string, id string, m model) (model, error) {
306302
err := PasteFile(path, newPath)
307303
if err != nil {
308304
p.state = failure
309-
processBarChannel <- processBarMessage{
305+
channel <- channelMessage{
310306
processId: id,
311307
processNewState: p,
312308
}
313309
return err
314310
}
315311
p.done++
316-
if len(processBarChannel) < 5 {
317-
processBarChannel <- processBarMessage{
312+
if len(channel) < 5 {
313+
channel <- channelMessage{
318314
processId: id,
319315
processNewState: p,
320316
}
@@ -431,3 +427,7 @@ func countFiles(dirPath string) (int, error) {
431427

432428
return count, err
433429
}
430+
431+
func IsExternalPath(path string) bool {
432+
return strings.HasPrefix(path, "/run/media")
433+
}

Diff for: src/components/globalController.go

+16-15
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ package components
22

33
import (
44
"encoding/json"
5-
"github.com/charmbracelet/bubbles/progress"
6-
"github.com/charmbracelet/bubbles/textinput"
7-
"github.com/lithammer/shortuuid"
8-
"github.com/rkoesters/xdg/trash"
95
"log"
106
"os"
117
"os/exec"
128
"path"
139
"path/filepath"
1410
"runtime"
1511
"time"
12+
13+
"github.com/charmbracelet/bubbles/progress"
14+
"github.com/charmbracelet/bubbles/textinput"
15+
"github.com/lithammer/shortuuid"
16+
"github.com/rkoesters/xdg/trash"
1617
)
1718

1819
/* CURSOR CONTROLLER START */
@@ -297,7 +298,7 @@ func PasteItem(m model) model {
297298

298299
m.processBarModel.process[id] = newProcess
299300

300-
processBarChannel <- processBarMessage{
301+
channel <- channelMessage{
301302
processId: id,
302303
processNewState: newProcess,
303304
}
@@ -315,7 +316,7 @@ func PasteItem(m model) model {
315316
p = m.processBarModel.process[id]
316317
if err != nil {
317318
p.state = failure
318-
processBarChannel <- processBarMessage{
319+
channel <- channelMessage{
319320
processId: id,
320321
processNewState: p,
321322
}
@@ -327,7 +328,7 @@ func PasteItem(m model) model {
327328
p.state = successful
328329
p.done = totalFiles
329330
p.doneTime = time.Now()
330-
processBarChannel <- processBarMessage{
331+
channel <- channelMessage{
331332
processId: id,
332333
processNewState: p,
333334
}
@@ -360,10 +361,10 @@ func PanelCreateNewFile(m model) model {
360361
ti.CharLimit = 156
361362
ti.Width = modalWidth - 10
362363

363-
m.createNewItem.location = panel.location
364-
m.createNewItem.itemType = newFile
365-
m.createNewItem.open = true
366-
m.createNewItem.textInput = ti
364+
m.typingModal.location = panel.location
365+
m.typingModal.itemType = newFile
366+
m.typingModal.open = true
367+
m.typingModal.textInput = ti
367368
m.firstTextInput = true
368369

369370
m.fileModel.filePanels[m.filePanelFocusIndex] = panel
@@ -379,10 +380,10 @@ func PanelCreateNewFolder(m model) model {
379380
ti.CharLimit = 156
380381
ti.Width = modalWidth - 10
381382

382-
m.createNewItem.location = panel.location
383-
m.createNewItem.itemType = newFolder
384-
m.createNewItem.open = true
385-
m.createNewItem.textInput = ti
383+
m.typingModal.location = panel.location
384+
m.typingModal.itemType = newFolder
385+
m.typingModal.open = true
386+
m.typingModal.textInput = ti
386387
m.firstTextInput = true
387388

388389
m.fileModel.filePanels[m.filePanelFocusIndex] = panel

Diff for: src/components/model.go

+40-14
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var Config ConfigType
3333
var logOutput *os.File
3434
var et *exiftool.Exiftool
3535

36-
var processBarChannel = make(chan processBarMessage, 1000)
36+
var channel = make(chan channelMessage, 1000)
3737

3838
func InitialModel(dir string) model {
3939
var err error
@@ -105,7 +105,7 @@ func InitialModel(dir string) model {
105105
}
106106
}
107107

108-
func listenForProcessBarMessage(msg chan processBarMessage) tea.Cmd {
108+
func listenForchannelMessage(msg chan channelMessage) tea.Cmd {
109109
return func() tea.Msg {
110110
select {
111111
case m := <-msg:
@@ -120,18 +120,22 @@ func (m model) Init() tea.Cmd {
120120
return tea.Batch(
121121
tea.SetWindowTitle("SuperFile"),
122122
textinput.Blink, // Assuming textinput.Blink is a valid command
123-
listenForProcessBarMessage(processBarChannel),
123+
listenForchannelMessage(channel),
124124
)
125125
}
126126

127127
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
128128
var cmd tea.Cmd
129129
switch msg := msg.(type) {
130-
case processBarMessage:
131-
if !contains(m.processBarModel.processList, msg.processId) {
132-
m.processBarModel.processList = append(m.processBarModel.processList, msg.processId)
130+
case channelMessage:
131+
if msg.returnWarnModal {
132+
m.warnModal = msg.warnModal
133+
} else {
134+
if !contains(m.processBarModel.processList, msg.processId) {
135+
m.processBarModel.processList = append(m.processBarModel.processList, msg.processId)
136+
}
137+
m.processBarModel.process[msg.processId] = msg.processNewState
133138
}
134-
m.processBarModel.process[msg.processId] = msg.processNewState
135139
case tea.WindowSizeMsg:
136140
m.mainPanelHeight = msg.Height - bottomBarHeight
137141
m.fileModel.width = (msg.Width - sideBarWidth - (4 + (len(m.fileModel.filePanels)-1)*2)) / len(m.fileModel.filePanels)
@@ -140,14 +144,32 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
140144
return m, nil
141145
case tea.KeyMsg:
142146
// if in the create item modal
143-
if m.createNewItem.open {
147+
if m.typingModal.open {
144148
switch msg.String() {
145149
case Config.Cancel[0], Config.Cancel[1]:
146-
m = CancelModal(m)
150+
m = CancelTypingModal(m)
147151
case Config.Confirm[0], Config.Confirm[1]:
148152
m = CreateItem(m)
149153
}
150154
// if in the renaming mode
155+
} else if m.warnModal.open {
156+
switch msg.String() {
157+
case Config.Cancel[0], Config.Cancel[1]:
158+
m = CancelWarnModal(m)
159+
case Config.Confirm[0], Config.Confirm[1]:
160+
m.warnModal.open = false
161+
if m.fileModel.filePanels[m.filePanelFocusIndex].panelMode == selectMode {
162+
go func() {
163+
m = CompletelyDeleteMultipleFile(m)
164+
m.fileModel.filePanels[m.filePanelFocusIndex].selected = m.fileModel.filePanels[m.filePanelFocusIndex].selected[:0]
165+
}()
166+
} else {
167+
go func() {
168+
m = CompletelyDeleteSingleFile(m)
169+
}()
170+
}
171+
}
172+
// if in the renaming mode
151173
} else if m.fileModel.renaming {
152174
switch msg.String() {
153175
case Config.Cancel[0], Config.Cancel[1]:
@@ -237,7 +259,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
237259
case Config.FilePanelSelectModeItemDelete[0], Config.FilePanelSelectModeItemDelete[1]:
238260
go func() {
239261
m = DeleteMultipleItem(m)
240-
m.fileModel.filePanels[m.filePanelFocusIndex].selected = m.fileModel.filePanels[m.filePanelFocusIndex].selected[:0]
262+
if !IsExternalPath(m.fileModel.filePanels[m.filePanelFocusIndex].location) {
263+
m.fileModel.filePanels[m.filePanelFocusIndex].selected = m.fileModel.filePanels[m.filePanelFocusIndex].selected[:0]
264+
}
241265
}()
242266
case Config.FilePanelSelectModeItemCopy[0], Config.FilePanelSelectModeItemCopy[1]:
243267
m = CopyMultipleItem(m)
@@ -280,14 +304,14 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
280304
} else if m.fileModel.renaming {
281305
m.fileModel.filePanels[m.filePanelFocusIndex].rename, cmd = m.fileModel.filePanels[m.filePanelFocusIndex].rename.Update(msg)
282306
} else {
283-
m.createNewItem.textInput, cmd = m.createNewItem.textInput.Update(msg)
307+
m.typingModal.textInput, cmd = m.typingModal.textInput.Update(msg)
284308
}
285309

286310
if m.fileModel.filePanels[m.filePanelFocusIndex].cursor < 0 {
287311
m.fileModel.filePanels[m.filePanelFocusIndex].cursor = 0
288312
}
289313

290-
cmd = tea.Batch(cmd, listenForProcessBarMessage(processBarChannel))
314+
cmd = tea.Batch(cmd, listenForchannelMessage(channel))
291315
m.sideBarModel.pinnedModel.folder = getFolder()
292316
return m, cmd
293317
}
@@ -296,8 +320,10 @@ func (m model) View() string {
296320
// check is the terminal size enough
297321
if m.fullHeight < minimumHeight || m.fullWidth < minimumWidth {
298322
return TerminalSizeWarnRender(m)
299-
} else if m.createNewItem.open {
300-
return ModalRender(m)
323+
} else if m.typingModal.open {
324+
return TypineModalRender(m)
325+
} else if m.warnModal.open {
326+
return WarnModalRender(m)
301327
} else {
302328
sideBar := SideBarRender(m)
303329

Diff for: src/components/modelRender.go

+15-6
Original file line numberDiff line numberDiff line change
@@ -302,18 +302,27 @@ func TerminalSizeWarnRender(m model) string {
302302
" Height = " + terminalMinimumSize.Render(minimumHeightString))
303303
}
304304

305-
func ModalRender(m model) string {
306-
if m.createNewItem.itemType == newFile {
307-
fileLocation := filePanelTopFolderIcon.Render("  ") + filePanelTopPath.Render(TruncateTextBeginning(m.createNewItem.location+"/"+m.createNewItem.textInput.Value(), modalWidth-4)) + "\n"
305+
func TypineModalRender(m model) string {
306+
if m.typingModal.itemType == newFile {
307+
fileLocation := filePanelTopFolderIcon.Render("  ") + filePanelTopPath.Render(TruncateTextBeginning(m.typingModal.location+"/"+m.typingModal.textInput.Value(), modalWidth-4)) + "\n"
308308
confirm := modalConfirm.Render(" (" + Config.Confirm[0] + ") New File ")
309309
cancel := modalCancel.Render(" (" + Config.Cancel[0] + ") Cancel ")
310310
tip := confirm + " " + cancel
311-
return FullScreenStyle(m.fullHeight, m.fullWidth).Render(FocusedModalStyle(modalHeight, modalWidth).Render(fileLocation + "\n" + m.createNewItem.textInput.View() + "\n\n" + tip))
311+
return FullScreenStyle(m.fullHeight, m.fullWidth).Render(FocusedModalStyle(modalHeight, modalWidth).Render(fileLocation + "\n" + m.typingModal.textInput.View() + "\n\n" + tip))
312312
} else {
313-
fileLocation := filePanelTopFolderIcon.Render("  ") + filePanelTopPath.Render(TruncateTextBeginning(m.createNewItem.location+"/"+m.createNewItem.textInput.Value(), modalWidth-4)) + "\n"
313+
fileLocation := filePanelTopFolderIcon.Render("  ") + filePanelTopPath.Render(TruncateTextBeginning(m.typingModal.location+"/"+m.typingModal.textInput.Value(), modalWidth-4)) + "\n"
314314
confirm := modalConfirm.Render(" (" + Config.Confirm[0] + ") New Folder ")
315315
cancel := modalCancel.Render(" (" + Config.Cancel[0] + ") Cancel ")
316316
tip := confirm + " " + cancel
317-
return FullScreenStyle(m.fullHeight, m.fullWidth).Render(FocusedModalStyle(modalHeight, modalWidth).Render(fileLocation + "\n" + m.createNewItem.textInput.View() + "\n\n" + tip))
317+
return FullScreenStyle(m.fullHeight, m.fullWidth).Render(FocusedModalStyle(modalHeight, modalWidth).Render(fileLocation + "\n" + m.typingModal.textInput.View() + "\n\n" + tip))
318318
}
319319
}
320+
321+
func WarnModalRender(m model) string {
322+
title := m.warnModal.title
323+
content := m.warnModal.content
324+
confirm := modalCancel.Render(" (" + Config.Confirm[0] + ") Cofnirm ")
325+
cancel := modalCancel.Render(" (" + Config.Cancel[0] + ") Cancel ")
326+
tip := confirm + " " + cancel
327+
return FullScreenStyle(m.fullHeight, m.fullWidth).Render(FocusedModalStyle(modalHeight, modalWidth).Render(title + "\n\n" + content + "\n\n" + tip))
328+
}

0 commit comments

Comments
 (0)