mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
[windows] Fix radio group menu items
This commit is contained in:
parent
459b5e1036
commit
7cbde83f38
6 changed files with 37 additions and 18 deletions
|
|
@ -57,6 +57,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Fixed `AlwaysOnTop` not working on Mac by [leaanthony](https://github.com/leaanthony) in [#3841](https://github.com/wailsapp/wails/pull/3841)
|
||||
- [darwin] Fixed `application.NewEditMenu` including a duplicate `PasteAndMatchStyle` role in the edit menu on Darwin by [johnmccabe](https://github.com/johnmccabe) in [#3839](https://github.com/wailsapp/wails/pull/3839)
|
||||
- [linux] Fixed aarch64 compilation [#3840](https://github.com/wailsapp/wails/issues/3840) in [#3854](https://github.com/wailsapp/wails/pull/3854) by [kodflow](https://github.com/kodflow)
|
||||
- [windows] Fixed radio group menu items by [@leaanthony](https://github.com/leaanthony)
|
||||
|
||||
## v3.0.0-alpha.7 - 2024-09-18
|
||||
|
||||
|
|
|
|||
|
|
@ -62,27 +62,29 @@ func (m *Menu) AddRole(role Role) *Menu {
|
|||
|
||||
func (m *Menu) processRadioGroups() {
|
||||
var radioGroup []*MenuItem
|
||||
|
||||
closeOutRadioGroups := func() {
|
||||
if len(radioGroup) > 0 {
|
||||
for _, item := range radioGroup {
|
||||
item.radioGroupMembers = radioGroup
|
||||
}
|
||||
radioGroup = []*MenuItem{}
|
||||
}
|
||||
}
|
||||
|
||||
for _, item := range m.items {
|
||||
if item.itemType != radio {
|
||||
closeOutRadioGroups()
|
||||
}
|
||||
if item.itemType == submenu {
|
||||
item.submenu.processRadioGroups()
|
||||
continue
|
||||
}
|
||||
if item.itemType == radio {
|
||||
radioGroup = append(radioGroup, item)
|
||||
} else {
|
||||
if len(radioGroup) > 0 {
|
||||
for _, item := range radioGroup {
|
||||
item.radioGroupMembers = radioGroup
|
||||
}
|
||||
radioGroup = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(radioGroup) > 0 {
|
||||
for _, item := range radioGroup {
|
||||
item.radioGroupMembers = radioGroup
|
||||
}
|
||||
}
|
||||
closeOutRadioGroups()
|
||||
}
|
||||
|
||||
func (m *Menu) SetLabel(label string) {
|
||||
|
|
|
|||
|
|
@ -60,6 +60,9 @@ func (w *windowsMenu) processMenu(parentMenu w32.HMENU, inputMenu *Menu) {
|
|||
if item.IsSeparator() {
|
||||
flags = flags | w32.MF_SEPARATOR
|
||||
}
|
||||
if item.itemType == radio {
|
||||
flags = flags | w32.MFT_RADIOCHECK
|
||||
}
|
||||
|
||||
if item.submenu != nil {
|
||||
flags = flags | w32.MF_POPUP
|
||||
|
|
|
|||
|
|
@ -69,6 +69,10 @@ func (m *windowsMenuItem) IsCheckbox() bool {
|
|||
return m.itemType == checkbox
|
||||
}
|
||||
|
||||
func (m *windowsMenuItem) IsRadio() bool {
|
||||
return m.itemType == radio
|
||||
}
|
||||
|
||||
func (m *windowsMenuItem) Enabled() bool {
|
||||
return !m.disabled
|
||||
}
|
||||
|
|
@ -146,6 +150,9 @@ func (m *windowsMenuItem) getMenuInfo() *w32.MENUITEMINFO {
|
|||
mii.FType = w32.MFT_SEPARATOR
|
||||
} else {
|
||||
mii.FType = w32.MFT_STRING
|
||||
if m.IsRadio() {
|
||||
mii.FType |= w32.MFT_RADIOCHECK
|
||||
}
|
||||
thisText := m.label
|
||||
if m.menuItem.accelerator != nil {
|
||||
thisText += "\t" + m.menuItem.accelerator.String()
|
||||
|
|
@ -160,7 +167,7 @@ func (m *windowsMenuItem) getMenuInfo() *w32.MENUITEMINFO {
|
|||
mii.FState |= w32.MFS_DISABLED
|
||||
}
|
||||
|
||||
if m.IsCheckbox() {
|
||||
if m.IsCheckbox() || m.IsRadio() {
|
||||
mii.FMask |= w32.MIIM_CHECKMARKS
|
||||
}
|
||||
if m.Checked() {
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ func (p *Win32Menu) newMenu() w32.HMENU {
|
|||
}
|
||||
|
||||
func (p *Win32Menu) buildMenu(parentMenu w32.HMENU, inputMenu *Menu) {
|
||||
var currentRadioGroup RadioGroup
|
||||
currentRadioGroup := RadioGroup{}
|
||||
for _, item := range inputMenu.items {
|
||||
if item.Hidden() {
|
||||
if item.accelerator != nil {
|
||||
|
|
@ -84,20 +84,22 @@ func (p *Win32Menu) buildMenu(parentMenu w32.HMENU, inputMenu *Menu) {
|
|||
if item.disabled {
|
||||
flags = flags | w32.MF_GRAYED
|
||||
}
|
||||
if item.checked && item.IsCheckbox() {
|
||||
if item.checked {
|
||||
flags = flags | w32.MF_CHECKED
|
||||
}
|
||||
if item.IsSeparator() {
|
||||
flags = flags | w32.MF_SEPARATOR
|
||||
}
|
||||
|
||||
if item.checked && item.IsRadio() {
|
||||
flags = flags | w32.MFT_RADIOCHECK
|
||||
}
|
||||
|
||||
if item.IsCheckbox() {
|
||||
p.checkboxItems[item] = append(p.checkboxItems[item], itemID)
|
||||
}
|
||||
if item.IsRadio() {
|
||||
if currentRadioGroup != nil {
|
||||
currentRadioGroup.Add(itemID, item)
|
||||
}
|
||||
currentRadioGroup.Add(itemID, item)
|
||||
} else {
|
||||
if len(currentRadioGroup) > 0 {
|
||||
for _, radioMember := range currentRadioGroup {
|
||||
|
|
@ -219,6 +221,9 @@ func (p *Win32Menu) ProcessCommand(cmdMsgID int) bool {
|
|||
return false
|
||||
}
|
||||
if item.IsRadio() {
|
||||
if item.checked {
|
||||
return true
|
||||
}
|
||||
item.checked = true
|
||||
p.updateRadioGroup(item)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -241,6 +241,7 @@ func (w *windowsWebviewWindow) run() {
|
|||
theMenu = w.parent.options.Windows.Menu
|
||||
}
|
||||
if theMenu != nil {
|
||||
theMenu.Update()
|
||||
w.menu = NewApplicationMenu(w, theMenu)
|
||||
w.menu.parentWindow = w
|
||||
appMenu = w.menu.menu
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue