mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 17:52:29 +08:00
Add "DragAndDropEnabled" option for window
Add "FileDraggingExited" event
This commit is contained in:
parent
260fd061f6
commit
045a830fbc
@ -43,8 +43,8 @@ When emitting an event in JS, it now sends the event to the application. This wi
|
||||
|
||||
## Window
|
||||
|
||||
The Window API has largely remained the same, however there are a few changes to note.
|
||||
|
||||
The Window API has largely remained the same, however the methods are now on an instance of a window rather than the runtime.
|
||||
Some notable differences are:
|
||||
- Windows now have a Name that identifies them. This is used to identify the window when emitting events.
|
||||
|
||||
## ClipBoard
|
||||
@ -61,11 +61,11 @@ Dialogs are now available in JavaScript!
|
||||
|
||||
## Drag and Drop
|
||||
|
||||
TBD
|
||||
Native drag and drop can be enabled per-window. Simply set the `EnableDragAndDrop` window config option to `true` and the window will allow files to be dragged onto it. When this happens, the `events.FilesDropped` event will be emitted. The filenames can then be retrieved from the WindowEventContext using the `DroppedFiles()` method. This returns a slice of strings containing the filenames.
|
||||
|
||||
## Context Menus
|
||||
|
||||
Context menus are contextual menus that are shown when the user right clicks on an element. Creating a context menu is the same as creating a standard menu , by using `app.NewMenu()`. To make the context menu available to a window, call `window.RegisterContextMenu(name, menu)`. The name will be the id of the context menu and used by the frontend.
|
||||
Context menus are contextual menus that are shown when the user right-clicks on an element. Creating a context menu is the same as creating a standard menu , by using `app.NewMenu()`. To make the context menu available to a window, call `window.RegisterContextMenu(name, menu)`. The name will be the id of the context menu and used by the frontend.
|
||||
|
||||
To indicate that an element has a context menu, add the `data-contextmenu` attribute to the element. The value of this attribute should be the name of a context menu previously registered with the window.
|
||||
|
||||
|
@ -32,6 +32,7 @@ func main() {
|
||||
TitleBar: application.MacTitleBarHiddenInsetUnified,
|
||||
InvisibleTitleBarHeight: 50,
|
||||
},
|
||||
EnableDragAndDrop: true,
|
||||
})
|
||||
|
||||
window.On(events.FilesDropped, func(ctx *application.WindowEventContext) {
|
||||
|
@ -39,6 +39,7 @@ type WebviewWindowOptions struct {
|
||||
Hidden bool
|
||||
EnableFraudulentWebsiteWarnings bool
|
||||
Zoom float64
|
||||
EnableDragAndDrop bool
|
||||
}
|
||||
|
||||
var WebviewWindowDefaults = &WebviewWindowOptions{
|
||||
|
@ -22,7 +22,7 @@ extern void processDragItems(unsigned int windowId, char** arr, int length);
|
||||
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
|
||||
NSPasteboard *pasteboard = [sender draggingPasteboard];
|
||||
if ([[pasteboard types] containsObject:NSFilenamesPboardType]) {
|
||||
processWindowEvent(self.windowId, EventWebViewDraggingEntered);
|
||||
processWindowEvent(self.windowId, EventWindowFileDraggingEntered);
|
||||
return NSDragOperationCopy;
|
||||
}
|
||||
return NSDragOperationNone;
|
||||
@ -30,7 +30,7 @@ extern void processDragItems(unsigned int windowId, char** arr, int length);
|
||||
|
||||
|
||||
- (void)draggingExited:(id<NSDraggingInfo>)sender {
|
||||
NSLog(@"I am here!!!!");
|
||||
processWindowEvent(self.windowId, EventWindowFileDraggingExited);
|
||||
}
|
||||
|
||||
- (BOOL)prepareForDragOperation:(id<NSDraggingInfo>)sender {
|
||||
@ -39,6 +39,7 @@ extern void processDragItems(unsigned int windowId, char** arr, int length);
|
||||
|
||||
- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
|
||||
NSPasteboard *pasteboard = [sender draggingPasteboard];
|
||||
processWindowEvent(self.windowId, EventWindowFileDraggingPerformed);
|
||||
if ([[pasteboard types] containsObject:NSFilenamesPboardType]) {
|
||||
NSArray *files = [pasteboard propertyListForType:NSFilenamesPboardType];
|
||||
NSUInteger count = [files count];
|
||||
|
@ -657,8 +657,6 @@ func (w *WebviewWindow) error(message string, args ...any) {
|
||||
}
|
||||
|
||||
func (w *WebviewWindow) handleDragAndDropMessage(event *dragAndDropMessage) {
|
||||
println("Drag and drop message received for " + w.Name())
|
||||
// Print filenames
|
||||
ctx := newWindowEventContext()
|
||||
ctx.setDroppedFiles(event.filenames)
|
||||
for _, listener := range w.eventListeners[uint(events.FilesDropped)] {
|
||||
|
@ -525,6 +525,24 @@ extern bool hasListeners(unsigned int);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)windowFileDraggingEntered:(NSNotification *)notification {
|
||||
if( hasListeners(EventWindowFileDraggingEntered) ) {
|
||||
processWindowEvent(self.windowId, EventWindowFileDraggingEntered);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)windowFileDraggingPerformed:(NSNotification *)notification {
|
||||
if( hasListeners(EventWindowFileDraggingPerformed) ) {
|
||||
processWindowEvent(self.windowId, EventWindowFileDraggingPerformed);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)windowFileDraggingExited:(NSNotification *)notification {
|
||||
if( hasListeners(EventWindowFileDraggingExited) ) {
|
||||
processWindowEvent(self.windowId, EventWindowFileDraggingExited);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)webView:(WKWebView *)webview didStartProvisionalNavigation:(WKNavigation *)navigation {
|
||||
if( hasListeners(EventWebViewDidStartProvisionalNavigation) ) {
|
||||
processWindowEvent(self.windowId, EventWebViewDidStartProvisionalNavigation);
|
||||
@ -549,17 +567,5 @@ extern bool hasListeners(unsigned int);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)webView:(WKWebView *)webview draggingEntered:(WKNavigation *)navigation {
|
||||
if( hasListeners(EventWebViewDraggingEntered) ) {
|
||||
processWindowEvent(self.windowId, EventWebViewDraggingEntered);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)webView:(WKWebView *)webview draggingPerformed:(WKNavigation *)navigation {
|
||||
if( hasListeners(EventWebViewDraggingPerformed) ) {
|
||||
processWindowEvent(self.windowId, EventWebViewDraggingPerformed);
|
||||
}
|
||||
}
|
||||
|
||||
// GENERATED EVENTS END
|
||||
@end
|
||||
|
@ -18,7 +18,7 @@ package application
|
||||
extern void registerListener(unsigned int event);
|
||||
|
||||
// Create a new Window
|
||||
void* windowNew(unsigned int id, int width, int height, bool fraudulentWebsiteWarningEnabled, bool frameless) {
|
||||
void* windowNew(unsigned int id, int width, int height, bool fraudulentWebsiteWarningEnabled, bool frameless, bool enableDragAndDrop) {
|
||||
|
||||
NSWindowStyleMask styleMask = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable;
|
||||
if (frameless) {
|
||||
@ -72,10 +72,12 @@ void* windowNew(unsigned int id, int width, int height, bool fraudulentWebsiteWa
|
||||
delegate.webView = webView;
|
||||
delegate.hideOnClose = false;
|
||||
|
||||
if( enableDragAndDrop ) {
|
||||
WebviewDrag* dragView = [[WebviewDrag alloc] initWithFrame:NSMakeRect(0, 0, width-1, height-1)];
|
||||
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
||||
[view addSubview:dragView];
|
||||
dragView.windowId = id;
|
||||
}
|
||||
|
||||
return window;
|
||||
}
|
||||
@ -1064,6 +1066,7 @@ func (w *macosWebviewWindow) run() {
|
||||
C.int(w.parent.options.Height),
|
||||
C.bool(w.parent.options.EnableFraudulentWebsiteWarnings),
|
||||
C.bool(w.parent.options.Frameless),
|
||||
C.bool(w.parent.options.EnableDragAndDrop),
|
||||
)
|
||||
w.setTitle(w.parent.options.Title)
|
||||
w.setAlwaysOnTop(w.parent.options.AlwaysOnTop)
|
||||
|
@ -130,8 +130,9 @@ type macEvents struct {
|
||||
WebViewDidReceiveServerRedirectForProvisionalNavigation WindowEventType
|
||||
WebViewDidFinishNavigation WindowEventType
|
||||
WebViewDidCommitNavigation WindowEventType
|
||||
WebViewDraggingEntered WindowEventType
|
||||
WebViewDraggingPerformed WindowEventType
|
||||
WindowFileDraggingEntered WindowEventType
|
||||
WindowFileDraggingPerformed WindowEventType
|
||||
WindowFileDraggingExited WindowEventType
|
||||
}
|
||||
|
||||
func newMacEvents() macEvents {
|
||||
@ -256,7 +257,8 @@ func newMacEvents() macEvents {
|
||||
WebViewDidReceiveServerRedirectForProvisionalNavigation: 1141,
|
||||
WebViewDidFinishNavigation: 1142,
|
||||
WebViewDidCommitNavigation: 1143,
|
||||
WebViewDraggingEntered: 1144,
|
||||
WebViewDraggingPerformed: 1145,
|
||||
WindowFileDraggingEntered: 1144,
|
||||
WindowFileDraggingPerformed: 1145,
|
||||
WindowFileDraggingExited: 1146,
|
||||
}
|
||||
}
|
||||
|
@ -126,10 +126,11 @@ extern void processWindowEvent(unsigned int, unsigned int);
|
||||
#define EventWebViewDidReceiveServerRedirectForProvisionalNavigation 1141
|
||||
#define EventWebViewDidFinishNavigation 1142
|
||||
#define EventWebViewDidCommitNavigation 1143
|
||||
#define EventWebViewDraggingEntered 1144
|
||||
#define EventWebViewDraggingPerformed 1145
|
||||
#define EventWindowFileDraggingEntered 1144
|
||||
#define EventWindowFileDraggingPerformed 1145
|
||||
#define EventWindowFileDraggingExited 1146
|
||||
|
||||
#define MAX_EVENTS 1146
|
||||
#define MAX_EVENTS 1147
|
||||
|
||||
|
||||
#endif
|
@ -118,7 +118,7 @@ mac:WebViewDidStartProvisionalNavigation
|
||||
mac:WebViewDidReceiveServerRedirectForProvisionalNavigation
|
||||
mac:WebViewDidFinishNavigation
|
||||
mac:WebViewDidCommitNavigation
|
||||
mac:WebViewDraggingEntered
|
||||
mac:WebViewDraggingPerformed
|
||||
|
||||
mac:WindowFileDraggingEntered
|
||||
mac:WindowFileDraggingPerformed
|
||||
mac:WindowFileDraggingExited
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user