Skip to content

Commit

Permalink
Improved menus.
Browse files Browse the repository at this point in the history
Fixed warning on windows quit.
  • Loading branch information
leaanthony committed Sep 17, 2024
1 parent 56494d8 commit 2c55110
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 124 deletions.
1 change: 1 addition & 0 deletions mkdocs-website/docs/en/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions v3/pkg/application/application_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
27 changes: 27 additions & 0 deletions v3/pkg/application/linux_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
7 changes: 6 additions & 1 deletion v3/pkg/application/menuitem_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
122 changes: 0 additions & 122 deletions v3/pkg/application/menuitem_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
43 changes: 43 additions & 0 deletions v3/pkg/application/webview_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ type (
setCloseButtonState(state ButtonState)
isIgnoreMouseEvents() bool
setIgnoreMouseEvents(ignore bool)
cut()
copy()
paste()
undo()
delete()
selectAll()
redo()
}
)

Expand Down Expand Up @@ -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()
}
}
21 changes: 21 additions & 0 deletions v3/pkg/application/webview_window_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
2 changes: 1 addition & 1 deletion v3/pkg/application/webview_window_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package application

import (
import (
"fmt"
"time"

Expand Down
29 changes: 29 additions & 0 deletions v3/pkg/application/webview_window_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions v3/pkg/w32/actions.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package w32

func Undo(hwnd HWND) {
Expand Down

0 comments on commit 2c55110

Please sign in to comment.