From 2c55110776c3b3d28b0cf7d14170fac3d74fe770 Mon Sep 17 00:00:00 2001 From: Lea O'Anthony Date: Tue, 17 Sep 2024 21:19:00 +1000 Subject: [PATCH] Improved menus. Fixed warning on windows quit. --- mkdocs-website/docs/en/changelog.md | 1 + v3/pkg/application/application_windows.go | 2 + v3/pkg/application/linux_cgo.go | 27 ++++ v3/pkg/application/menuitem_roles.go | 7 +- v3/pkg/application/menuitem_windows.go | 122 ------------------- v3/pkg/application/webview_window.go | 43 +++++++ v3/pkg/application/webview_window_darwin.go | 21 ++++ v3/pkg/application/webview_window_linux.go | 2 +- v3/pkg/application/webview_window_windows.go | 29 +++++ v3/pkg/w32/actions.go | 2 + 10 files changed, 132 insertions(+), 124 deletions(-) diff --git a/mkdocs-website/docs/en/changelog.md b/mkdocs-website/docs/en/changelog.md index 55bb08afeb6..3e99e2acfdb 100644 --- a/mkdocs-website/docs/en/changelog.md +++ b/mkdocs-website/docs/en/changelog.md @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Do not bind internal service methods in [#3720](https://github.com/wailsapp/wails/pull/3720) by [leaanthony](https://github.com/leaanthony) - [windows] Fixed system tray startup panic in [#3693](https://github.com/wailsapp/wails/issues/3693) by [@DeltaLaboratory](https://github.com/DeltaLaboratory) - Major menu item refactor and event handling. Mainly improves macOS for now. By [leaanthony](https://github.com/leaanthony) +- [windows] Fixed `Failed to unregister class Chrome_WidgetWin_0` warning. By [leaanthony](https://github.com/leaanthony) ## v3.0.0-alpha.6 - 2024-07-30 diff --git a/v3/pkg/application/application_windows.go b/v3/pkg/application/application_windows.go index 59b2dd83d09..f2f486ffb31 100644 --- a/v3/pkg/application/application_windows.go +++ b/v3/pkg/application/application_windows.go @@ -192,6 +192,8 @@ func (m *windowsApp) destroy() { return } globalApplication.cleanup() + // Destroy the main thread window + w32.DestroyWindow(m.mainThreadWindowHWND) // Post a quit message to the main thread w32.PostQuitMessage(0) } diff --git a/v3/pkg/application/linux_cgo.go b/v3/pkg/application/linux_cgo.go index 29e3f75fdcf..ced5eb63481 100644 --- a/v3/pkg/application/linux_cgo.go +++ b/v3/pkg/application/linux_cgo.go @@ -1765,3 +1765,30 @@ func runSaveFileDialog(dialog *SaveFileDialogStruct) (chan string, error) { return results, err } + +func (w *linuxWebviewWindow) cut() { + C.webkit_web_view_execute_editing_command(w.webview, C.WEBKIT_EDITING_COMMAND_CUT) +} + +func (w *linuxWebviewWindow) paste() { + C.webkit_web_view_execute_editing_command(w.webview, C.WEBKIT_EDITING_COMMAND_PASTE) +} + +func (w *linuxWebviewWindow) copy() { + C.webkit_web_view_execute_editing_command(w.webview, C.WEBKIT_EDITING_COMMAND_COPY) +} + +func (w *linuxWebviewWindow) selectAll() { + C.webkit_web_view_execute_editing_command(w.webview, C.WEBKIT_EDITING_COMMAND_SELECT_ALL) +} + +func (w *linuxWebviewWindow) undo() { + C.webkit_web_view_execute_editing_command(w.webview, C.WEBKIT_EDITING_COMMAND_UNDO) +} + +func (w *linuxWebviewWindow) redo() { + C.webkit_web_view_execute_editing_command(w.webview, C.WEBKIT_EDITING_COMMAND_REDO) +} + +func (w *linuxWebviewWindow) delete() { +} diff --git a/v3/pkg/application/menuitem_roles.go b/v3/pkg/application/menuitem_roles.go index b1e8eb08648..6f7091f0b96 100644 --- a/v3/pkg/application/menuitem_roles.go +++ b/v3/pkg/application/menuitem_roles.go @@ -44,7 +44,12 @@ func NewRedoMenuItem() *MenuItem { func NewCutMenuItem() *MenuItem { return NewMenuItem("Cut"). - SetAccelerator("CmdOrCtrl+x") + SetAccelerator("CmdOrCtrl+x").OnClick(func(ctx *Context) { + currentWindow := globalApplication.CurrentWindow() + if currentWindow != nil { + currentWindow.cut() + } + }) } func NewCopyMenuItem() *MenuItem { diff --git a/v3/pkg/application/menuitem_windows.go b/v3/pkg/application/menuitem_windows.go index bb9a70a2dfc..b776c5e371d 100644 --- a/v3/pkg/application/menuitem_windows.go +++ b/v3/pkg/application/menuitem_windows.go @@ -134,128 +134,6 @@ func newMenuItemImpl(item *MenuItem, parentMenu w32.HMENU, ID int) *windowsMenuI return result } -//func newAboutMenuItem() *MenuItem { -// return NewMenuItem("About " + globalApplication.options.Name). -// OnClick(func(ctx *Context) { -// globalApplication.ShowAboutDialog() -// }) -//} -// -//func newCloseMenuItem() *MenuItem { -// return NewMenuItem("Close"). -// SetAccelerator("CmdOrCtrl+w"). -// OnClick(func(ctx *Context) { -// currentWindow := globalApplication.CurrentWindow() -// if currentWindow != nil { -// currentWindow.Close() -// } -// }) -//} -//func newReloadMenuItem() *MenuItem { -// return NewMenuItem("Reload"). -// SetAccelerator("CmdOrCtrl+r"). -// OnClick(func(ctx *Context) { -// currentWindow := globalApplication.CurrentWindow() -// if currentWindow != nil { -// currentWindow.Reload() -// } -// }) -//} -// -//func newForceReloadMenuItem() *MenuItem { -// return NewMenuItem("Force Reload"). -// SetAccelerator("CmdOrCtrl+Shift+r"). -// OnClick(func(ctx *Context) { -// currentWindow := globalApplication.CurrentWindow() -// if currentWindow != nil { -// currentWindow.ForceReload() -// } -// }) -//} -// -//func newToggleFullscreenMenuItem() *MenuItem { -// result := NewMenuItem("Toggle Full Screen"). -// OnClick(func(ctx *Context) { -// currentWindow := globalApplication.CurrentWindow() -// if currentWindow != nil { -// currentWindow.ToggleFullscreen() -// } -// }) -// if runtime.GOOS == "darwin" { -// result.SetAccelerator("Ctrl+Command+F") -// } else { -// result.SetAccelerator("F11") -// } -// return result -//} -// -//func newZoomResetMenuItem() *MenuItem { -// // reset zoom menu item -// return NewMenuItem("Actual Size"). -// SetAccelerator("CmdOrCtrl+0"). -// OnClick(func(ctx *Context) { -// currentWindow := globalApplication.CurrentWindow() -// if currentWindow != nil { -// currentWindow.ZoomReset() -// } -// }) -//} -// -//func newZoomInMenuItem() *MenuItem { -// return NewMenuItem("Zoom In"). -// SetAccelerator("CmdOrCtrl+plus"). -// OnClick(func(ctx *Context) { -// currentWindow := globalApplication.CurrentWindow() -// if currentWindow != nil { -// currentWindow.ZoomIn() -// } -// }) -//} -// -//func newZoomOutMenuItem() *MenuItem { -// return NewMenuItem("Zoom Out"). -// SetAccelerator("CmdOrCtrl+-"). -// OnClick(func(ctx *Context) { -// currentWindow := globalApplication.CurrentWindow() -// if currentWindow != nil { -// currentWindow.ZoomOut() -// } -// }) -//} -// -//func newFullScreenMenuItem() *MenuItem { -// return NewMenuItem("Fullscreen"). -// OnClick(func(ctx *Context) { -// currentWindow := globalApplication.CurrentWindow() -// if currentWindow != nil { -// currentWindow.Fullscreen() -// } -// }) -//} -// -//func newMinimizeMenuItem() *MenuItem { -// return NewMenuItem("Minimize"). -// SetAccelerator("CmdOrCtrl+M"). -// OnClick(func(ctx *Context) { -// currentWindow := globalApplication.CurrentWindow() -// if currentWindow != nil { -// currentWindow.Minimise() -// } -// }) -//} -// -//func newZoomMenuItem() *MenuItem { -// return NewMenuItem("Zoom"). -// OnClick(func(ctx *Context) { -// currentWindow := globalApplication.CurrentWindow() -// if currentWindow != nil { -// currentWindow.Zoom() -// } -// }) -//} - -// ---------- unsupported on windows ---------- - func (m *windowsMenuItem) setTooltip(_ string) { // Unsupported } diff --git a/v3/pkg/application/webview_window.go b/v3/pkg/application/webview_window.go index 851ca4d1668..2f71fd72371 100644 --- a/v3/pkg/application/webview_window.go +++ b/v3/pkg/application/webview_window.go @@ -92,6 +92,13 @@ type ( setCloseButtonState(state ButtonState) isIgnoreMouseEvents() bool setIgnoreMouseEvents(ignore bool) + cut() + copy() + paste() + undo() + delete() + selectAll() + redo() } ) @@ -1265,3 +1272,39 @@ func (w *WebviewWindow) SetIgnoreMouseEvents(ignore bool) Window { }) return w } + +func (w *WebviewWindow) cut() { + if w.impl == nil && !w.isDestroyed() { + w.impl.cut() + } +} + +func (w *WebviewWindow) copy() { + if w.impl == nil && !w.isDestroyed() { + w.impl.copy() + } +} + +func (w *WebviewWindow) paste() { + if w.impl == nil && !w.isDestroyed() { + w.impl.paste() + } +} + +func (w *WebviewWindow) selectAll() { + if w.impl == nil && !w.isDestroyed() { + w.impl.selectAll() + } +} + +func (w *WebviewWindow) undo() { + if w.impl == nil && !w.isDestroyed() { + w.impl.undo() + } +} + +func (w *WebviewWindow) delete() { + if w.impl == nil && !w.isDestroyed() { + w.impl.delete() + } +} diff --git a/v3/pkg/application/webview_window_darwin.go b/v3/pkg/application/webview_window_darwin.go index 3618645fdf4..dff8d4560b5 100644 --- a/v3/pkg/application/webview_window_darwin.go +++ b/v3/pkg/application/webview_window_darwin.go @@ -1348,3 +1348,24 @@ func (w *macosWebviewWindow) isIgnoreMouseEvents() bool { func (w *macosWebviewWindow) setIgnoreMouseEvents(ignore bool) { C.setIgnoreMouseEvents(w.nsWindow, C.bool(ignore)) } + +func (w *macosWebviewWindow) cut() { +} + +func (w *macosWebviewWindow) paste() { +} + +func (w *macosWebviewWindow) copy() { +} + +func (w *macosWebviewWindow) selectAll() { +} + +func (w *macosWebviewWindow) undo() { +} + +func (w *macosWebviewWindow) delete() { +} + +func (w *macosWebviewWindow) redo() { +} diff --git a/v3/pkg/application/webview_window_linux.go b/v3/pkg/application/webview_window_linux.go index aff492c359b..f1b2f7449bf 100644 --- a/v3/pkg/application/webview_window_linux.go +++ b/v3/pkg/application/webview_window_linux.go @@ -2,7 +2,7 @@ package application -import ( +import ( "fmt" "time" diff --git a/v3/pkg/application/webview_window_windows.go b/v3/pkg/application/webview_window_windows.go index 4de3a3e91da..ab7a1670e18 100644 --- a/v3/pkg/application/webview_window_windows.go +++ b/v3/pkg/application/webview_window_windows.go @@ -72,6 +72,33 @@ type windowsWebviewWindow struct { moveDebouncer func(func()) } +func (w *windowsWebviewWindow) cut() { + w32.Cut(w.hwnd) +} + +func (w *windowsWebviewWindow) paste() { + w32.Paste(w.hwnd) +} + +func (w *windowsWebviewWindow) copy() { + w32.Copy(w.hwnd) +} + +func (w *windowsWebviewWindow) selectAll() { + w32.SelectAll(w.hwnd) +} + +func (w *windowsWebviewWindow) undo() { + w32.Undo(w.hwnd) +} + +func (w *windowsWebviewWindow) delete() { + w32.Delete(w.hwnd) +} + +func (w *windowsWebviewWindow) redo() { +} + func (w *windowsWebviewWindow) handleKeyEvent(_ string) { // Unused on windows } @@ -444,6 +471,8 @@ func (w *windowsWebviewWindow) destroy() { if w.dropTarget != nil { w.dropTarget.Release() } + // Destroy the window + w32.DestroyWindow(w.hwnd) } func (w *windowsWebviewWindow) reload() { diff --git a/v3/pkg/w32/actions.go b/v3/pkg/w32/actions.go index 35a06e88f71..2d376c7f4bd 100644 --- a/v3/pkg/w32/actions.go +++ b/v3/pkg/w32/actions.go @@ -1,3 +1,5 @@ +//go:build windows + package w32 func Undo(hwnd HWND) {