ronantakizawa/codereview-bench huggingface dataset:
Repository: fyne-io/fyne
File: widget/entry.go (Go)

Code before:

// SetPlaceHolder sets the text that will be displayed if the entry is otherwise empty
func (e *Entry) SetPlaceHolder(text string) {
	e.propertyLock.Lock()
	e.PlaceHolder = text
	e.propertyLock.Unlock()

	e.placeholderProvider().Segments[0].(*TextSegment).Text = text
	e.placeholder.updateRowBounds()
	e.placeholderProvider().Refresh()
}

// SetText manually sets the text of the Entry to the given text value.
// Calling SetText resets all undo history.
func (e *Entry) SetText(text string) {
	e.updateTextAndRefresh(text)

	e.updateCursorAndSelection()

	e.propertyLock.Lock()
	e.undoStack.Clear()
	e.propertyLock.Unlock()
}

// Undo un-does the last modifying user-action.
func (e *Entry) Undo() {
	var pos int
	e.propertyLock.Lock()
	newText, action := e.undoStack.Undo(e.Text)
	if insert, ok := action.(*entryInsertAction); ok {
		pos = insert.Position
		if insert.Delete {
			pos += len(insert.Text)
		}
	}
	e.propertyLock.Unlock()
	e.updateTextAndRefresh(newText)
	e.propertyLock.Lock()
	e.CursorRow, e.CursorColumn = e.rowColFromTextPos(pos)
	e.propertyLock.Unlock()
	e.Refresh()
}

// Redo un-does the last undo action.
func (e *Entry) Redo() {
	var pos int
	e.propertyLock.Lock()
	newText, action := e.undoStack.Redo(e.Text)
	if insert, ok := action.(*entryInsertAction); ok {
		pos = insert.Position
		if !insert.Delete {

Review comment (suggestion):
The new public methods must also include in the doc:
```
\\
\\ Since: 2.5
```

Code after:

	if !e.selecting {
		return ""
	}

	start, stop := e.selection()
	if start == stop {
		return ""
	}
	r := ([]rune)(e.textProvider().String())
	return string(r[start:stop])
}

// SetMinRowsVisible forces a multi-line entry to show `count` number of rows without scrolling.
// This is not a validation or requirement, it just impacts the minimum visible size.
// Use this carefully as Fyne apps can run on small screens so you may wish to add a scroll container if
// this number is high. Default is 3.
//
// Since: 2.2
func (e *Entry) SetMinRowsVisible(count int) {
	e.multiLineRows = count
}

// SetPlaceHolder sets the text that will be displayed if the entry is otherwise empty
func (e *Entry) SetPlaceHolder(text string) {
	e.propertyLock.Lock()
	e.PlaceHolder = text
	e.propertyLock.Unlock()

	e.placeholderProvider().Segments[0].(*TextSegment).Text = text
	e.placeholder.updateRowBounds()
	e.placeholderProvider().Refresh()
}

// SetText manually sets the text of the Entry to the given text value.
// Calling SetText resets all undo history.
func (e *Entry) SetText(text string) {
	e.updateTextAndRefresh(text)

	e.updateCursorAndSelection()

	e.propertyLock.Lock()
	e.undoStack.Clear()
	e.propertyLock.Unlock()
}

// Appends the text to the end of the entry
//
// Since: 2.4
func (e *Entry) Append(text string) {
	e.propertyLock.Lock()
Repository: fyne-io/fyne
File: shortcut.go (Go)

Code before:

var _ KeyboardShortcut = (*ShortcutSelectAll)(nil)

// Key returns the KeyName for this shortcut.
//
// Implements: KeyboardShortcut
func (se *ShortcutSelectAll) Key() KeyName {
	return KeyA
}

// Mod returns the KeyModifier for this shortcut.
//
// Implements: KeyboardShortcut
func (se *ShortcutSelectAll) Mod() KeyModifier {
	return KeyModifierShortcutDefault
}

// ShortcutName returns the shortcut name
func (se *ShortcutSelectAll) ShortcutName() string {
	return "SelectAll"
}

// ShortcutUndo describes a shortcut undo action.
type ShortcutUndo struct{}

var _ KeyboardShortcut = (*ShortcutUndo)(nil)

// Key returns the KeyName for this shortcut.
//
// Implements: KeyboardShortcut
func (se *ShortcutUndo) Key() KeyName {
	return KeyZ
}

// Mod returns the KeyModifier for this shortcut.
//
// Implements: KeyboardShortcut
func (se *ShortcutUndo) Mod() KeyModifier {
	return KeyModifierShortcutDefault
}

// ShortcutName returns the shortcut name
func (se *ShortcutUndo) ShortcutName() string {
	return "Undo"
}

// ShortcutRedo describes a shortcut redo action.
type ShortcutRedo struct{}

var _ KeyboardShortcut = (*ShortcutRedo)(nil)


Review comment (suggestion):
These new types need the extra:

```go
//
// Since: 2.5
```

Code after:

var _ KeyboardShortcut = (*ShortcutSelectAll)(nil)

// Key returns the KeyName for this shortcut.
//
// Implements: KeyboardShortcut
func (se *ShortcutSelectAll) Key() KeyName {
	return KeyA
}

// Mod returns the KeyModifier for this shortcut.
//
// Implements: KeyboardShortcut
func (se *ShortcutSelectAll) Mod() KeyModifier {
	return KeyModifierShortcutDefault
}

// ShortcutName returns the shortcut name
func (se *ShortcutSelectAll) ShortcutName() string {
	return "SelectAll"
}

// ShortcutUndo describes a shortcut undo action.
//
// Since: 2.5
type ShortcutUndo struct{}

var _ KeyboardShortcut = (*ShortcutUndo)(nil)

// Key returns the KeyName for this shortcut.
//
// Implements: KeyboardShortcut
func (se *ShortcutUndo) Key() KeyName {
	return KeyZ
}

// Mod returns the KeyModifier for this shortcut.
//
// Implements: KeyboardShortcut
func (se *ShortcutUndo) Mod() KeyModifier {
	return KeyModifierShortcutDefault
}

// ShortcutName returns the shortcut name
func (se *ShortcutUndo) ShortcutName() string {
	return "Undo"
}

// ShortcutRedo describes a shortcut redo action.
//
// Since: 2.5
Repository: fyne-io/fyne
File: dialog/file.go (Go)

Code before:
	loc     fyne.URI
}

type fileDialogPanel interface {
	fyne.Widget

	Unselect(int)
}

type fileDialog struct {
	file             *FileDialog
	fileName         textWidget
	dismiss          *widget.Button
	open             *widget.Button
	breadcrumb       *fyne.Container
	breadcrumbScroll *container.Scroll
	files            fileDialogPanel
	filesScroll      *container.Scroll
	favorites        []favoriteItem
	favoritesList    *widget.List
	showHidden       bool

	view viewLayout

	data     []fyne.URI
	dataLock *sync.RWMutex

	win        *widget.PopUp
	selected   fyne.URI
	selectedID int
	dir        fyne.ListableURI
	// this will be the initial filename in a FileDialog in save mode
	initialFileName string
}

// FileDialog is a dialog containing a file picker for use in opening or saving files.
type FileDialog struct {
	callback         interface{}
	onClosedCallback func(bool)
	parent           fyne.Window
	dialog           *fileDialog

	confirmText, dismissText string
	desiredSize              fyne.Size
	filter                   storage.FileFilter
	save                     bool
	// this will be applied to dialog.dir when it's loaded
	startingLocation fyne.ListableURI
	// this will be the initial filename in a FileDialog in save mode
	initialFileName string
}

Review comment (suggestion):
You can remove the pointer and just embed `sync.RWMutex` into the struct directly. It avoids having to manually create the mutex in all struct definitions below.

Code after:
	locName string
	locIcon fyne.Resource
	loc     fyne.URI
}

type fileDialogPanel interface {
	fyne.Widget

	Unselect(int)
}

type fileDialog struct {
	file             *FileDialog
	fileName         textWidget
	dismiss          *widget.Button
	open             *widget.Button
	breadcrumb       *fyne.Container
	breadcrumbScroll *container.Scroll
	files            fileDialogPanel
	filesScroll      *container.Scroll
	favorites        []favoriteItem
	favoritesList    *widget.List
	showHidden       bool

	view viewLayout

	data     []fyne.URI
	dataLock sync.RWMutex

	win        *widget.PopUp
	selected   fyne.URI
	selectedID int
	dir        fyne.ListableURI
	// this will be the initial filename in a FileDialog in save mode
	initialFileName string
}

// FileDialog is a dialog containing a file picker for use in opening or saving files.
type FileDialog struct {
	callback         interface{}
	onClosedCallback func(bool)
	parent           fyne.Window
	dialog           *fileDialog

	confirmText, dismissText string
	desiredSize              fyne.Size
	filter                   storage.FileFilter
	save                     bool
	// this will be applied to dialog.dir when it's loaded
	startingLocation fyne.ListableURI
	// this will be the initial filename in a FileDialog in save mode
Repository: fyne-io/fyne
File: dialog/file.go (Go)

Code before:
			f.open.Disable()
		}
	} else {
		f.fileName.SetText(file.Name())
		f.open.Enable()
	}
}

func (f *fileDialog) setView(view viewLayout) {
	f.view = view
	count := func() int {
		f.dataLock.RLock()
		defer f.dataLock.RUnlock()

		return len(f.data)
	}
	template := func() fyne.CanvasObject {
		return f.newFileItem(storage.NewFileURI("./tempfile"), true, false)
	}
	update := func(id widget.GridWrapItemID, o fyne.CanvasObject) {
		f.dataLock.RLock()

		if id >= len(f.data) {
			f.dataLock.RUnlock()
			return
		}

		dir := f.data[id]
		f.dataLock.RUnlock()

		parent := id == 0 && len(dir.Path()) < len(f.dir.Path())
		_, isDir := dir.(fyne.ListableURI)
		o.(*fileDialogItem).setLocation(dir, isDir || parent, parent)
	}
	choose := func(id int) {
		f.dataLock.RLock()

		if id >= len(f.data) {
			f.dataLock.RUnlock()
			return
		}

		file := f.data[id]
		f.dataLock.RUnlock()

		f.selectedID = id
		f.setSelected(file, id)
	}
	if f.view == gridView {
		grid := widget.NewGridWrap(count, template, update)
		grid.OnSelected = choose

Review comment (suggestion):
**One more thought here (I'm not necessarily right):**
Can this case ever happen if we lock and unlock the data both before writing and reading?
I'm thinking that if we change the length of the backing data, we have to wait until after the read is done anyway.

Code after:
		)
	}

	f.breadcrumbScroll.Refresh()
	f.breadcrumbScroll.Offset.X = f.breadcrumbScroll.Content.Size().Width - f.breadcrumbScroll.Size().Width
	f.breadcrumbScroll.Refresh()

	if f.file.isDirectory() {
		f.fileName.SetText(dir.Name())
		f.open.Enable()
	}
	f.refreshDir(list)

	return nil
}

func (f *fileDialog) setSelected(file fyne.URI, id int) {
	if file != nil {
		if listable, err := storage.CanList(file); err == nil && listable {
			f.setLocation(file)
			return
		}
	}
	f.selected = file
	f.selectedID = id

	if file == nil || file.String()[len(file.Scheme())+3:] == "" {
		// keep user input while navigating
		// in a FileSave dialog
		if !f.file.save {
			f.fileName.SetText("")
			f.open.Disable()
		}
	} else {
		f.fileName.SetText(file.Name())
		f.open.Enable()
	}
}

func (f *fileDialog) setView(view viewLayout) {
	f.view = view
	fyne.CurrentApp().Preferences().SetInt(viewLayoutKey, int(view))

	count := func() int {
		f.dataLock.RLock()
		defer f.dataLock.RUnlock()

		return len(f.data)
	}
	template := func() fyne.CanvasObject {
		return f.newFileItem(storage.NewFileURI("./tempfile"), true, false)
Repository: fyne-io/fyne
File: dialog/file.go (Go)

Code before:
	count := func() int {
		f.dataLock.RLock()
		defer f.dataLock.RUnlock()

		return len(f.data)
	}
	template := func() fyne.CanvasObject {
		return f.newFileItem(storage.NewFileURI("./tempfile"), true, false)
	}
	update := func(id widget.GridWrapItemID, o fyne.CanvasObject) {
		f.dataLock.RLock()

		if id >= len(f.data) {
			f.dataLock.RUnlock()
			return
		}

		dir := f.data[id]
		f.dataLock.RUnlock()

		parent := id == 0 && len(dir.Path()) < len(f.dir.Path())
		_, isDir := dir.(fyne.ListableURI)
		o.(*fileDialogItem).setLocation(dir, isDir || parent, parent)
	}
	choose := func(id int) {
		f.dataLock.RLock()

		if id >= len(f.data) {
			f.dataLock.RUnlock()
			return
		}

		file := f.data[id]
		f.dataLock.RUnlock()

		f.selectedID = id
		f.setSelected(file, id)
	}
	if f.view == gridView {
		grid := widget.NewGridWrap(count, template, update)
		grid.OnSelected = choose
		f.files = grid
	} else {
		list := widget.NewList(count, template, update)
		list.OnSelected = choose
		f.files = list
	}
	if f.dir != nil {
		f.refreshDir(f.dir)
	}
	f.filesScroll.Content = container.NewPadded(f.files)

Review comment (refactor):
Perhaps this block of code that is repeated in the update and choose funcs could be extracted as its own helper:

```go
func (f *fileDialog) getDataItem(id int) (fyne.URI, bool) {
    f.dataLock.RLock()
    defer f.dataLock.RUnlock()
    if id >= len(f.data) {
        return nil, false
    }
    return f.data[id], true
}

Code after:
	}
	f.refreshDir(list)

	return nil
}

func (f *fileDialog) setSelected(file fyne.URI, id int) {
	if file != nil {
		if listable, err := storage.CanList(file); err == nil && listable {
			f.setLocation(file)
			return
		}
	}
	f.selected = file
	f.selectedID = id

	if file == nil || file.String()[len(file.Scheme())+3:] == "" {
		// keep user input while navigating
		// in a FileSave dialog
		if !f.file.save {
			f.fileName.SetText("")
			f.open.Disable()
		}
	} else {
		f.fileName.SetText(file.Name())
		f.open.Enable()
	}
}

func (f *fileDialog) setView(view viewLayout) {
	f.view = view
	fyne.CurrentApp().Preferences().SetInt(viewLayoutKey, int(view))

	count := func() int {
		f.dataLock.RLock()
		defer f.dataLock.RUnlock()

		return len(f.data)
	}
	template := func() fyne.CanvasObject {
		return f.newFileItem(storage.NewFileURI("./tempfile"), true, false)
	}
	update := func(id widget.GridWrapItemID, o fyne.CanvasObject) {
		if dir, ok := f.getDataItem(id); ok {
			parent := id == 0 && len(dir.Path()) < len(f.dir.Path())
			_, isDir := dir.(fyne.ListableURI)
			o.(*fileDialogItem).setLocation(dir, isDir || parent, parent)
		}
	}
	choose := func(id int) {
		if file, ok := f.getDataItem(id); ok {
Repository: fyne-io/fyne
File: widget/toolbar.go (Go)

Code before:
package widget

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/canvas"
	"fyne.io/fyne/v2/internal/widget"
	"fyne.io/fyne/v2/layout"
	"fyne.io/fyne/v2/theme"
)

// ToolbarItem represents any interface element that can be added to a toolbar
type ToolbarItem interface {
	ToolbarObject() fyne.CanvasObject
}

// ToolbarAction is push button style of ToolbarItem
type ToolbarAction struct {
	Icon        fyne.Resource
	OnActivated func() `json:"-"`
	button      *Button
}

// ToolbarObject gets a button to render this ToolbarAction
func (t *ToolbarAction) ToolbarObject() fyne.CanvasObject {
	t.button.OnTapped = t.OnActivated
	return t.button
}

// SetIcon updates the icon on a ToolbarItem
//
// Since: 2.2
func (t *ToolbarAction) SetIcon(icon fyne.Resource) {
	t.Icon = icon
	t.button.SetIcon(t.Icon)
	t.button.Refresh()
}

// Enable this ToolbarAction, updating any style or features appropriately.
//
// Since: 2.5
func (t *ToolbarAction) Enable() {
	t.button.Enable()
}

// Disable this ToolbarAction so that it cannot be interacted with, updating any style appropriately.

Review comment (suggestion):
I'm not sure how I feel about embedding button directly here. What I might prefer is adding a `Disabled  bool` here, and creating a private `toolbarActionButton` type here that extends `widget.Button`, holds a reference to the parent `ToolbarAction`, and in its overridden `Refresh` function, syncs the state from the `ToolbarAction` to the button, and then call `BaseWidget.Refresh()`.

Then, in `ToolbarObject()`, create and return a new `toolbarActionButton` that has the reference to `t`.

Code after:
package widget

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/canvas"
	"fyne.io/fyne/v2/internal/widget"
	"fyne.io/fyne/v2/layout"
	"fyne.io/fyne/v2/theme"
)

// ToolbarItem represents any interface element that can be added to a toolbar
type ToolbarItem interface {
	ToolbarObject() fyne.CanvasObject
}

// ToolbarAction is push button style of ToolbarItem
type ToolbarAction struct {
	Icon        fyne.Resource
	OnActivated func() `json:"-"`
	button      Button
}

// ToolbarObject gets a button to render this ToolbarAction
func (t *ToolbarAction) ToolbarObject() fyne.CanvasObject {
	// synchronize properties
	t.button.Icon = t.Icon
	t.button.OnTapped = t.OnActivated

	return &t.button
}

// SetIcon updates the icon on a ToolbarItem
//
// Since: 2.2
func (t *ToolbarAction) SetIcon(icon fyne.Resource) {
	t.Icon = icon
	t.button.SetIcon(t.Icon)
}

// Enable this ToolbarAction, updating any style or features appropriately.
//
// Since: 2.5
func (t *ToolbarAction) Enable() {
	t.button.Enable()
}
Repository: fyne-io/fyne
File: widget/toolbar.go (Go)

Code before:
package widget

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/canvas"
	"fyne.io/fyne/v2/internal/widget"
	"fyne.io/fyne/v2/layout"
	"fyne.io/fyne/v2/theme"
)

// ToolbarItem represents any interface element that can be added to a toolbar
type ToolbarItem interface {
	ToolbarObject() fyne.CanvasObject
}

type toolbarActionButton struct {
	Button

	t *ToolbarAction
}

func (b *toolbarActionButton) Refresh() {
	b.Icon = b.t.Icon
	b.OnTapped = b.t.OnActivated

	if b.t.Disabled {
		b.Button.Disable()
	} else {
		b.Button.Enable()
	}
}

// ToolbarAction is push button style of ToolbarItem
type ToolbarAction struct {
	Icon        fyne.Resource
	OnActivated func() `json:"-"`
	// Since: 2.5
	Disabled bool
}

// ToolbarObject gets a button to render this ToolbarAction

Review comment (suggestion):
I think you may need to create a constructor for this and call `ExtendBaseWidget` in the constructor

Code after:
package widget

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/canvas"
	"fyne.io/fyne/v2/internal/widget"
	"fyne.io/fyne/v2/layout"
	"fyne.io/fyne/v2/theme"
)

// ToolbarItem represents any interface element that can be added to a toolbar
type ToolbarItem interface {
	ToolbarObject() fyne.CanvasObject
}

// ToolbarAction is push button style of ToolbarItem
type ToolbarAction struct {
	Icon        fyne.Resource
	OnActivated func() `json:"-"`
	button      Button
}

// ToolbarObject gets a button to render this ToolbarAction
func (t *ToolbarAction) ToolbarObject() fyne.CanvasObject {
	// synchronize properties
	t.button.Icon = t.Icon
	t.button.OnTapped = t.OnActivated

	return &t.button
}

// SetIcon updates the icon on a ToolbarItem
//
// Since: 2.2
func (t *ToolbarAction) SetIcon(icon fyne.Resource) {
	t.Icon = icon
	t.button.SetIcon(t.Icon)
}

// Enable this ToolbarAction, updating any style or features appropriately.
//
Repository: fyne-io/fyne
File: widget/toolbar.go (Go)

Code before:
	"fyne.io/fyne/v2/theme"
)

// ToolbarItem represents any interface element that can be added to a toolbar
type ToolbarItem interface {
	ToolbarObject() fyne.CanvasObject
}

// ToolbarAction is push button style of ToolbarItem
type ToolbarAction struct {
	Icon        fyne.Resource
	OnActivated func() `json:"-"`
	button      *Button
}

// ToolbarObject gets a button to render this ToolbarAction
func (t *ToolbarAction) ToolbarObject() fyne.CanvasObject {
	if t.button == nil {
		// lazy initialization of the button, when the ToolbarAction 
		// has not been created via the constructor
		t.button = createToolbarActionButton(t.Icon, t.OnActivated)
	} else {
		// synchronize properties
		t.button.Icon = t.Icon
		t.button.OnTapped = t.OnActivated
	}

	return t.button
}

// SetIcon updates the icon on a ToolbarItem
//
// Since: 2.2
func (t *ToolbarAction) SetIcon(icon fyne.Resource) {
	t.Icon = icon
	t.button.SetIcon(t.Icon)
}

// Enable this ToolbarAction, updating any style or features appropriately.
//
// Since: 2.5
func (t *ToolbarAction) Enable() {
	t.button.Enable()
}

// Disable this ToolbarAction so that it cannot be interacted with, updating any style appropriately.
//
// Since: 2.5
func (t *ToolbarAction) Disable() {
	t.button.Disable()
}

Review comment (refactor):
I was unsure about this, as it violates the happy-path-left pattern. But I also did not want to duplicate the `return t.button` line. Let me know what you think/prefer.

Code after:
	"fyne.io/fyne/v2/theme"
)

// ToolbarItem represents any interface element that can be added to a toolbar
type ToolbarItem interface {
	ToolbarObject() fyne.CanvasObject
}

// ToolbarAction is push button style of ToolbarItem
type ToolbarAction struct {
	Icon        fyne.Resource
	OnActivated func() `json:"-"`
	button      Button
}

// ToolbarObject gets a button to render this ToolbarAction
func (t *ToolbarAction) ToolbarObject() fyne.CanvasObject {
	// synchronize properties
	t.button.Icon = t.Icon
	t.button.OnTapped = t.OnActivated

	return &t.button
}

// SetIcon updates the icon on a ToolbarItem
//
// Since: 2.2
func (t *ToolbarAction) SetIcon(icon fyne.Resource) {
	t.Icon = icon
	t.button.SetIcon(t.Icon)
}

// Enable this ToolbarAction, updating any style or features appropriately.
//
// Since: 2.5
func (t *ToolbarAction) Enable() {
	t.button.Enable()
}

// Disable this ToolbarAction so that it cannot be interacted with, updating any style appropriately.
//
// Since: 2.5
func (t *ToolbarAction) Disable() {
	t.button.Disable()
}

// Disabled returns true if this ToolbarAction is currently disabled or false if it can currently be interacted with.
//
// Since: 2.5
func (t *ToolbarAction) Disabled() bool {
	return t.button.Disabled()
Repository: fyne-io/fyne
File: widget/toolbar.go (Go)

Code before:
package widget

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/canvas"
	"fyne.io/fyne/v2/internal/widget"
	"fyne.io/fyne/v2/layout"
	"fyne.io/fyne/v2/theme"
)

// ToolbarItem represents any interface element that can be added to a toolbar
type ToolbarItem interface {
	ToolbarObject() fyne.CanvasObject
}

// ToolbarAction is push button style of ToolbarItem
type ToolbarAction struct {
	Icon        fyne.Resource
	OnActivated func() `json:"-"`
	button      *Button
}

// ToolbarObject gets a button to render this ToolbarAction
func (t *ToolbarAction) ToolbarObject() fyne.CanvasObject {
	if t.button == nil {
		// lazy initialization of the button, when the ToolbarAction 
		// has not been created via the constructor
		t.button = createToolbarActionButton(t.Icon, t.OnActivated)
	} else {
		// synchronize properties
		t.button.Icon = t.Icon
		t.button.OnTapped = t.OnActivated
	}

	return t.button
}

// SetIcon updates the icon on a ToolbarItem
//
// Since: 2.2
func (t *ToolbarAction) SetIcon(icon fyne.Resource) {
	t.Icon = icon
	t.button.SetIcon(t.Icon)
}


Review comment (suggestion):
You can change this field to not be a pointer. Saves you having to do a nil check. It also avoid needing to construct it manually. Just set the fields you want. Just return a reference to the field in places where it wants it to be a pointer.

Code after:
package widget

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/canvas"
	"fyne.io/fyne/v2/internal/widget"
	"fyne.io/fyne/v2/layout"
	"fyne.io/fyne/v2/theme"
)

// ToolbarItem represents any interface element that can be added to a toolbar
type ToolbarItem interface {
	ToolbarObject() fyne.CanvasObject
}

// ToolbarAction is push button style of ToolbarItem
type ToolbarAction struct {
	Icon        fyne.Resource
	OnActivated func() `json:"-"`
	button      Button
}

// ToolbarObject gets a button to render this ToolbarAction
func (t *ToolbarAction) ToolbarObject() fyne.CanvasObject {
	// synchronize properties
	t.button.Icon = t.Icon
	t.button.OnTapped = t.OnActivated

	return &t.button
}

// SetIcon updates the icon on a ToolbarItem
//
// Since: 2.2
func (t *ToolbarAction) SetIcon(icon fyne.Resource) {
	t.Icon = icon
	t.button.SetIcon(t.Icon)
}

// Enable this ToolbarAction, updating any style or features appropriately.
//
// Since: 2.5
func (t *ToolbarAction) Enable() {
	t.button.Enable()
}