Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to various core changes #336

Merged
merged 8 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion canvas/sprites.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func SetSpritePos(sp *core.Sprite, pos image.Point) {
// InactivateSprites inactivates sprites of given type
func InactivateSprites(ctx core.Widget, typ Sprites) {
sprites := &ctx.AsWidget().Scene.Stage.Sprites
for _, spkv := range sprites.Names.Order {
for _, spkv := range sprites.Order {
sp := spkv.Value
st, _, _ := SpriteProperties(sp)
if st == typ {
Expand Down
16 changes: 8 additions & 8 deletions code/cmdstd.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,56 +347,56 @@ var StandardCommands = Commands{
Dir: "{FileDirPath}",
Wait: CmdNoWait, Focus: CmdNoFocus, Confirm: CmdNoConfirm},

// SVN
{Cat: "SVN", Name: "Add",
// Svn
{Cat: "Svn", Name: "Add",
Desc: "svn add file",
Lang: fileinfo.Any,
Cmds: []CmdAndArgs{{Cmd: "svn",
Args: []string{"add", "{FilePath}"}}},
Dir: "{FileDirPath}",
Wait: CmdNoWait, Focus: CmdNoFocus, Confirm: CmdNoConfirm},

{Cat: "SVN", Name: "Status",
{Cat: "Svn", Name: "Status",
Desc: "svn status",
Lang: fileinfo.Any,
Cmds: []CmdAndArgs{{Cmd: "svn",
Args: []string{"status"}}},
Dir: "{FileDirPath}",
Wait: CmdNoWait, Focus: CmdNoFocus, Confirm: CmdNoConfirm},

{Cat: "SVN", Name: "Info",
{Cat: "Svn", Name: "Info",
Desc: "svn info",
Lang: fileinfo.Any,
Cmds: []CmdAndArgs{{Cmd: "svn",
Args: []string{"info"}}},
Dir: "{FileDirPath}",
Wait: CmdNoWait, Focus: CmdNoFocus, Confirm: CmdNoConfirm},

{Cat: "SVN", Name: "Log",
{Cat: "Svn", Name: "Log",
Desc: "svn log",
Lang: fileinfo.Any,
Cmds: []CmdAndArgs{{Cmd: "svn",
Args: []string{"log", "-v"}}},
Dir: "{FileDirPath}",
Wait: CmdNoWait, Focus: CmdNoFocus, Confirm: CmdNoConfirm},

{Cat: "SVN", Name: "Commit Project",
{Cat: "Svn", Name: "Commit Project",
Desc: "svn commit for entire project directory",
Lang: fileinfo.Any,
Cmds: []CmdAndArgs{{Cmd: "svn",
Args: []string{"commit", "-m", "{PromptString1}"}, PromptIsString: true}},
Dir: "{ProjectPath}",
Wait: CmdWait, Focus: CmdNoFocus, Confirm: CmdNoConfirm}, // promptstring1 provided during normal commit process

{Cat: "SVN", Name: "Commit Dir",
{Cat: "Svn", Name: "Commit Dir",
Desc: "svn commit in directory of current file",
Lang: fileinfo.Any,
Cmds: []CmdAndArgs{{Cmd: "svn",
Args: []string{"commit", "-m", "{PromptString1}"}, PromptIsString: true}},
Dir: "{FileDirPath}",
Wait: CmdWait, Focus: CmdNoFocus, Confirm: CmdNoConfirm}, // promptstring1 provided during normal commit process

{Cat: "SVN", Name: "Update",
{Cat: "Svn", Name: "Update",
Desc: "svn update",
Lang: fileinfo.Any,
Cmds: []CmdAndArgs{{Cmd: "svn",
Expand Down
32 changes: 15 additions & 17 deletions code/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,10 @@ func (cv *Code) SelectedFileNode() *filetree.Node {
return filetree.AsNode(cv.Files.SelectedNodes[n-1])
}

// VersionControl returns the version control system in effect, using the file tree detected
// version or whatever is set in project settings
func (cv *Code) VersionControl() filetree.VersionControlName {
vc := cv.Settings.VersionControl
return vc
// VersionControl returns the version control system in effect,
// using the file tree detected version or whatever is set in project settings.
func (cv *Code) VersionControl() vcs.Types {
return cv.Settings.VersionControl
}

func (cv *Code) FocusOnTabs() bool {
Expand Down Expand Up @@ -387,10 +386,10 @@ func (cv *Code) OpenPath(path core.Filename) *Code { //types:add
cv.Settings.ProjectFilename = core.Filename(filepath.Join(root, pnm+".code"))
cv.ProjectFilename = cv.Settings.ProjectFilename
cv.Settings.ProjectRoot = cv.ProjectRoot
cv.GuessMainLang()
cv.LangDefaults()
cv.SetWindowNameTitle()
cv.UpdateFiles()
cv.GuessMainLang()
cv.LangDefaults()
cv.SplitsSetView(SplitName(AvailableSplitNames[0]))
if fnm != "" {
cv.NextViewFile(core.Filename(fnm))
Expand All @@ -399,8 +398,8 @@ func (cv *Code) OpenPath(path core.Filename) *Code { //types:add
return cv
}

// OpenProject opens .code project file and its settings from given filename, in a standard
// toml-formatted file
// OpenProject opens .code project file and its settings from given filename,
// in a standard toml-formatted file.
func (cv *Code) OpenProject(filename core.Filename) *Code { //types:add
if !cv.IsEmpty() {
return OpenCodeProject(string(filename))
Expand All @@ -411,9 +410,6 @@ func (cv *Code) OpenProject(filename core.Filename) *Code { //types:add
}
root, pnm, _, ok := ProjectPathParse(string(filename))
cv.Settings.ProjectRoot = core.Filename(root)
if cv.Settings.MainLang == fileinfo.Unknown {
cv.GuessMainLang()
}
cv.Settings.ProjectFilename = filename // should already be set but..
if ok {
SetGoMod(cv.Settings.GoMod)
Expand All @@ -425,6 +421,10 @@ func (cv *Code) OpenProject(filename core.Filename) *Code { //types:add
cv.Scene.SetName(pnm)
cv.ApplySettings()
cv.UpdateFiles()
if cv.Settings.MainLang == fileinfo.Unknown {
cv.GuessMainLang()
cv.LangDefaults()
}
cv.SetWindowNameTitle()
}
return cv
Expand All @@ -433,8 +433,8 @@ func (cv *Code) OpenProject(filename core.Filename) *Code { //types:add
// NewProject creates a new project at given path, making a new folder in that
// path -- all Code projects are essentially defined by a path to a folder
// containing files. If the folder already exists, then use OpenPath.
// Can also specify main language and version control type
func (cv *Code) NewProject(path core.Filename, folder string, mainLang fileinfo.Known, VersionControl filetree.VersionControlName) *Code { //types:add
// Can also specify main language and version control type.
func (cv *Code) NewProject(path core.Filename, folder string, mainLang fileinfo.Known, versionControl vcs.Types) *Code { //types:add
np := filepath.Join(string(path), folder)
err := os.MkdirAll(np, 0775)
if err != nil {
Expand All @@ -443,9 +443,7 @@ func (cv *Code) NewProject(path core.Filename, folder string, mainLang fileinfo.
}
nge := cv.OpenPath(core.Filename(np))
nge.Settings.MainLang = mainLang
if VersionControl != "" {
nge.Settings.VersionControl = VersionControl
}
nge.Settings.VersionControl = versionControl
return nge
}

Expand Down
6 changes: 4 additions & 2 deletions code/commandbufs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"cogentcore.org/core/base/fileinfo"
"cogentcore.org/core/base/vcs"
"cogentcore.org/core/core"
"cogentcore.org/core/events"
"cogentcore.org/core/filetree"
Expand Down Expand Up @@ -197,7 +198,7 @@ func (cv *Code) Run() { //types:add
// Checks for VCS setting and for unsaved files.
func (cv *Code) Commit() { //types:add
vc := cv.VersionControl()
if vc == "" {
if vc == vcs.NoVCS {
core.MessageDialog(cv, "No version control system detected in file system, or defined in project prefs -- define in project prefs if viewing a sub-directory within a larger repository", "No Version Control System Found")
return
}
Expand All @@ -215,7 +216,8 @@ func (cv *Code) CommitNoChecks() {
if len(ct) < 2 {
continue
}
if !filetree.IsVersionControlSystem(ct[0]) {
var vcstype vcs.Types
if vcstype.SetString(ct[0]) != nil {
continue
}
for _, cm := range ct {
Expand Down
13 changes: 6 additions & 7 deletions code/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,16 +679,15 @@ var CustomCommands = Commands{}

// FilterCmdNames returns a slice of commands organized by category
// that are compatible with given language and version control system.
func (cm *Commands) FilterCmdNames(lang fileinfo.Known, vcnm filetree.VersionControlName) [][]string {
vnm := strings.ToLower(string(vcnm))
func (cm *Commands) FilterCmdNames(lang fileinfo.Known, vcstype vcs.Types) [][]string {
var cmds [][]string
cat := ""
var csub []string
for _, cmd := range *cm {
if cmd.LangMatch(lang) {
if cmd.Cat != cat {
lcat := strings.ToLower(cmd.Cat)
if filetree.IsVersionControlSystem(lcat) && lcat != vnm {
var vct vcs.Types
if vct.SetString(cmd.Cat) == nil && vcstype != vct {
continue
}
cat = cmd.Cat
Expand Down Expand Up @@ -803,11 +802,11 @@ func CommandMenu(fn *filetree.Node) func(mm *core.Scene) {
return nil
}
lang := fn.Info.Known
vcnm := cv.VersionControl()
vcstype := cv.VersionControl()
if repo, _ := fn.Repo(); repo != nil {
vcnm = filetree.VersionControlName(repo.Vcs())
vcstype = repo.Type()
}
cmds := AvailableCommands.FilterCmdNames(lang, vcnm)
cmds := AvailableCommands.FilterCmdNames(lang, vcstype)
lastCmd := ""
hsz := len(cv.CmdHistory)
if hsz > 0 {
Expand Down
8 changes: 4 additions & 4 deletions code/keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ var StandardKeyMaps = keymap.Maps{
"Control+X Control+J": KeyJump,
"Control+X v": KeySetSplit,
"Control+X Control+V": KeySetSplit,
"Control+M m": KeyBuildProject,
"Control+M Control+M": KeyBuildProject,
"Control+M r": KeyRunProject,
"Control+M Control+R": KeyRunProject,
"Control+X m": KeyBuildProject,
"Control+X Control+M": KeyBuildProject,
"Control+X r": KeyRunProject,
"Control+X Control+R": KeyRunProject,
}},
{"LinuxStandard", "Standard Linux key map", keymap.Map{
"Control+Tab": KeyNextPanel,
Expand Down
27 changes: 8 additions & 19 deletions code/settings.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
// Copyright (c) 2018, Cogent Core. All rights reserved.
// Copyright (c) 2024, Cogent Core. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package code

import (
"fmt"
"os"
"path/filepath"
"slices"
"strings"

"cogentcore.org/cogent/code/cdebug"
"cogentcore.org/core/base/errors"
"cogentcore.org/core/base/fileinfo"
"cogentcore.org/core/base/iox/tomlx"
"cogentcore.org/core/base/vcs"
"cogentcore.org/core/core"
"cogentcore.org/core/events"
"cogentcore.org/core/filetree"
Expand Down Expand Up @@ -75,15 +74,6 @@ type FileSettings struct { //types:add
// Defaults are the defaults for Settings
func (se *SettingsData) Defaults() {
se.Files.Defaults()
home := core.SystemSettings.User.HomeDir
texPath := ".:" + home + "/texmf/tex/latex:/Library/TeX/Root/texmf-dist/tex/latex:"
se.EnvVars = map[string]string{
"TEXINPUTS": texPath,
"BIBINPUTS": texPath,
"BSTINPUTS": texPath,
"PATH": home + "/bin:" + home + "/go/bin:/usr/local/bin:/opt/homebrew/bin:/opt/homebrew/shbin:/Library/TeX/texbin:/usr/bin:/bin:/usr/sbin:/sbin",
"PKG_CONFIG_PATH": "/usr/local/lib/pkgconfig:/opt/homebrew/lib",
}
}

// Defaults are the defaults for FileSettings
Expand Down Expand Up @@ -215,7 +205,7 @@ type ProjectSettings struct { //types:add

// the type of version control system used in this project (git, svn, etc).
// filters commands available
VersionControl filetree.VersionControlName
VersionControl vcs.Types

// current project filename for saving / loading specific Code
// configuration information in a .code file (optional)
Expand Down Expand Up @@ -280,7 +270,6 @@ func (se *ProjectSettings) Update() {
// Open open from file
func (se *ProjectSettings) Open(filename core.Filename) error { //types:add
err := errors.Log(tomlx.Open(se, string(filename)))
se.VersionControl = filetree.VersionControlName(strings.ToLower(string(se.VersionControl))) // official names are lowercase now
return err
}

Expand Down Expand Up @@ -328,7 +317,7 @@ func OpenPaths() {

// Defaults sets new project defaults based on overall settings
func (cv *Code) Defaults() {
cv.Settings.VersionControl = "git"
cv.Settings.VersionControl = vcs.NoVCS
cv.Settings.Files = Settings.Files
cv.Settings.Editor = core.SystemSettings.Editor
cv.Settings.Splits = [4]float32{.1, .5, .5, .3}
Expand Down Expand Up @@ -453,19 +442,19 @@ func (cv *Code) LangDefaults() {
if len(cv.Settings.BuildCmds) == 0 {
switch cv.Settings.MainLang {
case fileinfo.Go:
cv.Settings.BuildCmds = CmdNames{"Go: Build Project"}
cv.Settings.BuildCmds = CmdNames{"Go: Build Dir"}
cv.Settings.RunCmds = CmdNames{"Core: Run"}
case fileinfo.TeX:
cv.Settings.BuildCmds = CmdNames{"LaTeX: LaTeX PDF"}
cv.Settings.RunCmds = CmdNames{"File: Open Target"}
default:
cv.Settings.BuildCmds = CmdNames{"Build: Make"}
}
}
if cv.Settings.VersionControl == "" {
fmt.Printf("firstvcs")
if cv.Settings.VersionControl == vcs.NoVCS {
repo, _ := cv.Files.FirstVCS()
if repo != nil {
cv.Settings.VersionControl = filetree.VersionControlName(repo.Vcs())
cv.Settings.VersionControl = repo.Type()
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions craft/craft.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ func main() {
se.Styler(func(s *styles.Style) {
sc.Background = colors.Scheme.Select.Container
})
xyz.NewAmbientLight(sc, "ambient", 0.3, xyz.DirectSun)
xyz.NewAmbient(sc, "ambient", 0.3, xyz.DirectSun)

dir := xyz.NewDirLight(sc, "dir", 1, xyz.DirectSun)
dir := xyz.NewDirectional(sc, "dir", 1, xyz.DirectSun)
dir.Pos.Set(0, 2, 1) // default: 0,1,1 = above and behind us (we are at 0,0,X)

// point := xyz.NewPointLight(sc, "point", 1, xyz.DirectSun)
Expand All @@ -53,8 +53,8 @@ func main() {
w.SetFunc(func(file core.Filename) {
currentFile = string(file)
objgp.DeleteChildren()
sc.DeleteMeshes()
sc.DeleteTextures()
sc.ResetMeshes()
// sc.ResetTextures() // TODO: ResetTextures missing
errors.Log1(sc.OpenNewObj(string(file), objgp))
sc.SetCamera("default")
sc.SetNeedsUpdate()
Expand All @@ -64,7 +64,5 @@ func main() {
w.SetText("Open").SetIcon(icons.Open).SetTooltip("Open a 3D object file for viewing")
})
})

sc.SetNeedsConfig()
b.RunMainWindow()
}
Loading
Loading