Skip to content

Commit

Permalink
feat: drag and drop files
Browse files Browse the repository at this point in the history
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
  • Loading branch information
Ryex committed Oct 4, 2024
1 parent 99994a3 commit 4ab454f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
42 changes: 37 additions & 5 deletions internal/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,34 @@ func (a *App) Main() {
a.window.SetIcon(assets.Icon)
a.window.Resize(fyne.NewSize(1200, 800))

a.window.SetOnDropped(func(_ fyne.Position, u []fyne.URI) {
if len(u) > 1 {
dialog.ShowInformation(
lang.X("tooManyDrops.title", "Too Many Dropped Items"),
lang.X("tooManyDrop.message", "DungeonDraft GoPackager does not support dropping multiple items"),
a.window,
)
} else if len(u) == 1 {
path := filepath.Clean(u[0].Path())
dlg := dialog.NewConfirm(
lang.X("dropOpenDialog.title", "Confirm Open Pack"),
lang.X(
"dropOpenDialog.message",
"Do you want to open '{{.Path}}' ?",
map[string]string{
"Path": path,
},
),
func(confirmed bool) {
if confirmed {
a.operatingPath.Set(path)
}
},
a.window,
)
dlg.Show()
}
})
a.buildMainUI()
a.setupPathHandler()

Expand Down Expand Up @@ -251,13 +279,17 @@ func (a *App) buildMainUI() {
folderBtn,
)

defaultMainText := canvas.NewText(
lang.X("main.defaultText", "Enter a path to get started."),
defaultMainText := multilineCanvasText(
lang.X(
"main.defaultText",
"Enter a path to get started.\n"+
"You can also drag and drop a resource pack file or unpacked folder.",
),
28,
fyne.TextStyle{Italic: true},
fyne.TextAlignCenter,
theme.Color(theme.ColorNameForeground),
)
defaultMainText.Alignment = fyne.TextAlignCenter
defaultMainText.TextSize = 28
defaultMainText.TextStyle = fyne.TextStyle{Italic: true}

a.defaultMainContent = container.NewBorder(
nil, nil, nil, nil,
Expand Down
6 changes: 5 additions & 1 deletion internal/gui/translation/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
"pathInput.placeholder": "Path to .dungeondraft_pack or folder",
"packBtn.text": "Open pack",
"folderBtn.text": "Open folder",
"main.defaultText": "Enter a path to get started.",
"main.defaultText": "Enter a path to get started.\nYou can also drag and drop a resource pack file or unpacked folder.",
"err.badPath": "Can not open \"{{.Path}}\"",
"err.badPack": "Failed to load {{.Path}}",
"err.badResources": "Failed to load unpacked resources from {{.Path}}",
"err.fileList": "Failed to build file list from {{.Path}}",
"tree.label": "Resources",
"tooManyDrops.title": "Too Many Dropped Items",
"tooManyDrop.message": "DungeonDraft GoPackager does not support dropping multiple items",
"dropOpenDialog.title": "Confirm Open Pack",
"dropOpenDialog.message": "Do you want to open '{{.Path}}' ?",
"tree.filter.placeholder.resource": "Filter with glob (ie. */objects/**)",
"tree.filter.placeholder.tags": "Filter by tag name",
"tree.displayBy.label": "Display By",
Expand Down

0 comments on commit 4ab454f

Please sign in to comment.