wails/v3/pkg/application/context_window_event.go
Atterpac 10447e6fcd
[V3] Drag-n-Drop Zones and improvements (#4318)
* new events

* macOS dnd improvements

* wailsio adds for dropzone

* update example

* sorta working

the top 300px of the window are not dropabble for some reason i suspect it has to do with the drag enter/drag leave xy as the performOperation needed to use the ContentView for appropriate X/Y

* implement attribute detection for data-wails-dropzone

* docs

* pass x/y dnd linux

* cleanup exmample

* changelog

* pass all attributes to golang on dragdrop

* filetree example

* fix dnd build windows

* Fix windows dnd

* update docs

* remove debug log

* appease the security bot

* Fix changelog

* Fix changelog

* Revert "Fix event generation issues."

This reverts commit ae4ed4fe

* Fix events

* Fix merge conflicts. Fix events generation formatting

* Update docs

* Fix duplicate bundledassets import causing build failures

Remove duplicate import of bundledassets package that was causing
compilation errors in PR #4318. The import was declared twice in
the same import block, causing "bundledassets redeclared" errors.

Fixes build issues in GitHub Actions for drag-and-drop zones feature.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Replace fmt.Printf debug statements with globalApplication.debug

Replace all fmt.Printf debug logging statements in drag-and-drop
functionality with proper globalApplication.debug calls. This provides:

- Consistent logging with the rest of the application
- Proper key-value structured logging
- Better integration with the application's logging system
- Cleaner debug output format

Changes:
- application_darwin.go: Replace 2 fmt.Printf calls
- webview_window.go: Replace 6 fmt.Printf calls
- webview_window_windows.go: Replace 13 fmt.Printf calls
- Remove unused fmt import from application_darwin.go

All debug messages maintain the same information but now use
structured logging with key-value pairs instead of printf formatting.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Add nil checks to WindowEventContext methods

Ensure all WindowEventContext methods properly handle nil c.data
by initializing the map when it's nil. This prevents panics when
methods are called on contexts that haven't been properly initialized.

Changes:
- DroppedFiles(): Add nil check and map initialization
- setCoordinates(): Add nil check and map initialization
- setDropZoneDetails(): Add nil check and map initialization
- DropZoneDetails(): Add nil check and map initialization

All methods now follow the same pattern as setDroppedFiles()
where a nil data map is automatically initialized to prevent
runtime panics during drag-and-drop operations.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Update v3/pkg/application/webview_window_darwin.m

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* reinstate events docs.

---------

Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-08-04 20:40:19 +10:00

81 lines
1.7 KiB
Go

package application
var blankWindowEventContext = &WindowEventContext{}
const (
droppedFiles = "droppedFiles"
dropZoneDetailsKey = "dropZoneDetails"
)
type WindowEventContext struct {
// contains filtered or unexported fields
data map[string]any
}
func (c WindowEventContext) DroppedFiles() []string {
if c.data == nil {
c.data = make(map[string]any)
}
files, ok := c.data[droppedFiles]
if !ok {
return nil
}
result, ok := files.([]string)
if !ok {
return nil
}
return result
}
func (c WindowEventContext) setDroppedFiles(files []string) {
if c.data == nil {
c.data = make(map[string]any)
}
c.data[droppedFiles] = files
}
func (c WindowEventContext) setCoordinates(x, y int) {
if c.data == nil {
c.data = make(map[string]any)
}
c.data["x"] = x
c.data["y"] = y
}
func (c WindowEventContext) setDropZoneDetails(details *DropZoneDetails) {
if c.data == nil {
c.data = make(map[string]any)
}
if details == nil {
c.data[dropZoneDetailsKey] = nil
return
}
c.data[dropZoneDetailsKey] = details
}
// DropZoneDetails retrieves the detailed drop zone information, if available.
func (c WindowEventContext) DropZoneDetails() *DropZoneDetails {
if c.data == nil {
c.data = make(map[string]any)
}
details, ok := c.data[dropZoneDetailsKey]
if !ok {
return nil
}
// Explicitly type assert, handle if it's nil (though setDropZoneDetails should handle it)
if details == nil {
return nil
}
result, ok := details.(*DropZoneDetails)
if !ok {
// This case indicates a programming error if data was set incorrectly
return nil
}
return result
}
func newWindowEventContext() *WindowEventContext {
return &WindowEventContext{
data: make(map[string]any),
}
}