Skip to content

Commit

Permalink
fix and add drag and drop support
Browse files Browse the repository at this point in the history
  • Loading branch information
arnavbhatt288 committed Nov 5, 2023
1 parent ef78c59 commit f5b124c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
4 changes: 2 additions & 2 deletions FyneApp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Icon = "assets/images/Icon.png"
Name = "Utkirna"
ID = "com.ghativega.Utkirna"
Version = "1.0.0"
Build = 1
Version = "1.0.1"
Build = 2

[LinuxAndBSD]
GenericName = "Disk Imager"
Expand Down
4 changes: 0 additions & 4 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ const (
START_VERIFY
)

func GetTrueImagePath(path string) string {
return path[7:]
}

func determineOptimalSize(numSectors int64, sector int64) int64 {
if numSectors-sector >= int64(1024) {
return int64(1024)
Expand Down
46 changes: 28 additions & 18 deletions gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type MainData struct {
type GUI struct {
cancelButton, readButton, writeButton, exitButton, openButton, reloadButton, verifyButton, saveButton *widget.Button
selectDrive *widget.Select
inputPath *widget.Entry
openPath, savePath *widget.Entry
statusLabel, elapsedLabel, speedLabel *widget.Label
rwProgressBar *widget.ProgressBar
window fyne.Window
Expand All @@ -39,7 +39,8 @@ func DisableCancelButton(widgets GUI, data MainData) {

widgets.selectDrive.Enable()
widgets.reloadButton.Enable()
widgets.inputPath.Enable()
widgets.openPath.Enable()
widgets.savePath.Enable()
widgets.openButton.Enable()
widgets.exitButton.Enable()
widgets.readButton.Enable()
Expand All @@ -64,7 +65,8 @@ func enableCancelButton(widgets GUI, data MainData) {

widgets.selectDrive.Disable()
widgets.reloadButton.Disable()
widgets.inputPath.Disable()
widgets.openPath.Disable()
widgets.savePath.Disable()
widgets.openButton.Disable()
widgets.exitButton.Disable()
widgets.readButton.Disable()
Expand All @@ -76,7 +78,7 @@ func enableCancelButton(widgets GUI, data MainData) {
widgets.cancelButton.Enable()
}

func FileOpenDialog(myApp fyne.App, gui GUI, data *MainData) {
func FileOpenDialog(myApp fyne.App, gui GUI) {
window := myApp.NewWindow("Utkirna")
window.CenterOnScreen()
window.SetFixedSize(true)
Expand All @@ -87,8 +89,7 @@ func FileOpenDialog(myApp fyne.App, gui GUI, data *MainData) {
window.Close()
}
if reader != nil {
data.imagePath = GetTrueImagePath(reader.URI().String())
gui.inputPath.SetText(data.imagePath)
gui.openPath.SetText(reader.URI().Path())
}
}, window)
fd.Show()
Expand All @@ -103,7 +104,7 @@ func FileOpenDialog(myApp fyne.App, gui GUI, data *MainData) {
window.Show()
}

func FileSaveDialog(myApp fyne.App, gui GUI, data *MainData) {
func FileSaveDialog(myApp fyne.App, gui GUI) {
window := myApp.NewWindow("Utkirna")
window.CenterOnScreen()
window.SetFixedSize(true)
Expand All @@ -114,8 +115,7 @@ func FileSaveDialog(myApp fyne.App, gui GUI, data *MainData) {
window.Close()
}
if writer != nil {
data.imagePath = GetTrueImagePath(writer.URI().String())
gui.inputPath.SetText(data.imagePath)
gui.savePath.SetText(writer.URI().Path())
}
}, window)
fd.SetFilter(storage.NewExtensionFileFilter([]string{".img"}))
Expand Down Expand Up @@ -189,22 +189,24 @@ func StartGui() {
selectImageLabel := widget.NewLabel("Select Image:")
saveImageLabel := widget.NewLabel("Save Image:")

gui.inputPath = widget.NewEntry()
gui.inputPath.SetPlaceHolder("Location of the image")
gui.openPath = widget.NewEntry()
gui.openPath.SetPlaceHolder("Location of the image to open")
gui.savePath = widget.NewEntry()
gui.savePath.SetPlaceHolder("Location of the image to save")

gui.openButton = widget.NewButton("Open Image", func() {
FileOpenDialog(myApp, gui, &data)
FileOpenDialog(myApp, gui)
})
gui.saveButton = widget.NewButton("Save Image", func() {
FileSaveDialog(myApp, gui, &data)
FileSaveDialog(myApp, gui)
})

openImage := container.NewGridWithColumns(2,
gui.inputPath,
gui.openPath,
gui.openButton,
)
saveImage := container.NewGridWithColumns(2,
gui.inputPath,
gui.savePath,
gui.saveButton,
)

Expand Down Expand Up @@ -247,12 +249,13 @@ func StartGui() {
"Select a drive to read from!",
gui.window,
)
} else if len(data.imagePath) < 1 {
} else if len(gui.openPath.Text) < 1 {
dialog.ShowInformation("Insufficient fields", "Select an image to write to!", gui.window)
} else {
dialog.ShowConfirm("Reading", "Are you sure to continue?", func(b bool) {
if b {
gui.statusLabel.SetText("Reading...")
data.imagePath = gui.savePath.Text
data.taskType = START_READ
enableCancelButton(gui, data)
StartMainTask(&data, gui)
Expand All @@ -263,12 +266,13 @@ func StartGui() {
gui.writeButton = widget.NewButton("Write", func() {
if len(data.selectedDrive) < 1 {
dialog.ShowInformation("Insufficient fields", "Select a drive to write to!", gui.window)
} else if len(data.imagePath) < 1 {
} else if len(gui.openPath.Text) < 1 {
dialog.ShowInformation("Insufficient fields", "Select an image to write from!", gui.window)
} else {
dialog.ShowConfirm("Writing", "Are you sure to continue?", func(b bool) {
if b {
gui.statusLabel.SetText("Writing...")
data.imagePath = gui.openPath.Text
data.taskType = START_WRITE
enableCancelButton(gui, data)
StartMainTask(&data, gui)
Expand All @@ -279,12 +283,13 @@ func StartGui() {
gui.verifyButton = widget.NewButton("Verify Only", func() {
if len(data.selectedDrive) < 1 {
dialog.ShowInformation("Insufficient fields", "Select a drive to verify!", gui.window)
} else if len(data.imagePath) < 1 {
} else if len(gui.openPath.Text) < 1 {
dialog.ShowInformation("Insufficient fields", "Select an image to verify from!", gui.window)
} else {
dialog.ShowConfirm("Verifying", "Are you sure to continue?", func(b bool) {
if b {
gui.statusLabel.SetText("Verifying...")
data.imagePath = gui.openPath.Text
data.taskType = START_VERIFY
enableCancelButton(gui, data)
StartMainTask(&data, gui)
Expand Down Expand Up @@ -335,6 +340,11 @@ func StartGui() {
gui.guiTabs.SetTabLocation(container.TabLocationTop)

gui.window.SetContent(gui.guiTabs)
gui.window.SetOnDropped(func(pos fyne.Position, dropped []fyne.URI) {
if gui.guiTabs.SelectedIndex() == 0 {
gui.openPath.SetText(dropped[0].Path())
}
})
gui.window.Show()

myApp.Run()
Expand Down

0 comments on commit f5b124c

Please sign in to comment.