Skip to content

Commit

Permalink
code sets read only for generated files; uses 'goal build' instead of…
Browse files Browse the repository at this point in the history
… 'go build' if it finds a 'goal' exe on path.
  • Loading branch information
rcoreilly committed Oct 8, 2024
1 parent 3478e75 commit 65cef3a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
14 changes: 12 additions & 2 deletions author/book/book.goal
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@ package book

import (
"fmt"

"cogentcore.org/core/base/logx"
"io/fs"
"log/slog"
"os"
"path"
"path/filepath"
"sort"

"cogentcore.org/cogent/author"
"cogentcore.org/cogent/author/refs"
"cogentcore.org/core/base/errors"
"cogentcore.org/core/base/iox/imagex"
"cogentcore.org/core/base/iox/yamlx"
"cogentcore.org/core/base/logx"
goalp "cogentcore.org/core/goal"
"cogentcore.org/core/goal/goalib"
)

var (
Expand Down
7 changes: 6 additions & 1 deletion code/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,12 @@ func (cv *Code) makeTextEditor(p *tree.Plan, i int) {
})
tree.AddChildAt(w, "texteditor-"+txnm, func(w *TextEditor) {
w.Code = cv
ConfigEditorTextEditor(&w.Editor)
w.Styler(func(s *styles.Style) {
s.Grow.Set(1, 1)
s.Min.X.Ch(20)
s.Min.Y.Em(5)
w.SetReadOnly(w.Buffer.Info.Generated)
})
w.OnFocus(func(e events.Event) {
cv.ActiveTextEditorIndex = i
})
Expand Down
10 changes: 10 additions & 0 deletions code/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,16 @@ func (cm *Commands) CopyFrom(cp Commands) {
// MergeAvailableCmds updates the AvailCmds list from CustomCmds and StdCmds
func MergeAvailableCmds() {
AvailableCommands.CopyFrom(StandardCommands)
hasGoal := false
if _, err := exec.LookPath("goal"); err == nil {
hasGoal = true
}
if hasGoal { // replace go build commands with goal build
gob, _, _ := AvailableCommands.CmdByName(CmdName(CommandName("Go", "Build Dir")), false)
gob.Cmds[0].Cmd = "goal"
gob, _, _ = AvailableCommands.CmdByName(CmdName(CommandName("Go", "Build Proj")), false)
gob.Cmds[0].Cmd = "goal"
}
for _, cmd := range CustomCommands {
_, idx, has := AvailableCommands.CmdByName(CmdName(cmd.Label()), false)
if has {
Expand Down
9 changes: 0 additions & 9 deletions code/texteditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,6 @@ func ConfigOutputTextEditor(ed *texteditor.Editor) {
})
}

// ConfigEditorTextEditor configures an editor texteditor
func ConfigEditorTextEditor(ed *texteditor.Editor) {
ed.Styler(func(s *styles.Style) {
s.Grow.Set(1, 1)
s.Min.X.Ch(20)
s.Min.Y.Em(5)
})
}

// ContextMenu builds the text editor context menu
func (ed *TextEditor) ContextMenu(m *core.Scene) {
core.NewButton(m).SetText("Copy").SetIcon(icons.ContentCopy).
Expand Down

0 comments on commit 65cef3a

Please sign in to comment.