diff --git a/routers/web/repo/blame.go b/routers/web/repo/blame.go index e304633f95238..7e104db9ed2fb 100644 --- a/routers/web/repo/blame.go +++ b/routers/web/repo/blame.go @@ -74,7 +74,7 @@ func RefBlame(ctx *context.Context) { tplName := tplRepoViewContent if !ctx.FormBool("only_content") { - prepareHomeTreeSideBarSwitch(ctx) + prepareTreeSideBarSwitch(ctx) tplName = tplRepoView } diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go index 2a5ac102824d9..47e560f06a4e6 100644 --- a/routers/web/repo/editor.go +++ b/routers/web/repo/editor.go @@ -280,6 +280,8 @@ func EditFile(ctx *context.Context) { return } + prepareTreeSideBarSwitch(ctx) + // on the "New File" page, we should add an empty path field to make end users could input a new name prepareTreePathFieldsAndPaths(ctx, util.Iif(isNewFile, ctx.Repo.TreePath+"/", ctx.Repo.TreePath)) @@ -320,6 +322,7 @@ func EditFile(ctx *context.Context) { } } + ctx.Data["PageIsEdit"] = true ctx.Data["EditorconfigJson"] = getContextRepoEditorConfig(ctx, ctx.Repo.TreePath) ctx.HTML(http.StatusOK, tplEditFile) } @@ -376,6 +379,8 @@ func EditFilePost(ctx *context.Context) { // DeleteFile render delete file page func DeleteFile(ctx *context.Context) { + prepareTreePathFieldsAndPaths(ctx, ctx.Repo.TreePath) + prepareTreeSideBarSwitch(ctx) prepareEditorCommitFormOptions(ctx, "_delete") if ctx.Written() { return diff --git a/routers/web/repo/editor_apply_patch.go b/routers/web/repo/editor_apply_patch.go index bd2811cc5f01d..98ef2e5327505 100644 --- a/routers/web/repo/editor_apply_patch.go +++ b/routers/web/repo/editor_apply_patch.go @@ -14,6 +14,7 @@ import ( ) func NewDiffPatch(ctx *context.Context) { + prepareTreeSideBarSwitch(ctx) prepareEditorCommitFormOptions(ctx, "_diffpatch") if ctx.Written() { return diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index e47bc56d081a6..7892cb0ed6d78 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -13,6 +13,7 @@ import ( "net/http" "net/url" "path" + "strconv" "strings" "time" @@ -257,6 +258,19 @@ func LastCommit(ctx *context.Context) { ctx.HTML(http.StatusOK, tplRepoViewList) } +func prepareTreeSideBarSwitch(ctx *context.Context) { + showFileTree := true + if ctx.Doer != nil { + v, err := user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyCodeViewShowFileTree, "true") + if err != nil { + log.Error("GetUserSetting: %v", err) + } else { + showFileTree, _ = strconv.ParseBool(v) + } + } + ctx.Data["UserSettingCodeViewShowFileTree"] = showFileTree +} + func prepareDirectoryFileIcons(ctx *context.Context, files []git.CommitInfo) { renderedIconPool := fileicon.NewRenderedIconPool() fileIcons := map[string]template.HTML{} diff --git a/routers/web/repo/view_home.go b/routers/web/repo/view_home.go index f475e93f60489..1b59d217fefe8 100644 --- a/routers/web/repo/view_home.go +++ b/routers/web/repo/view_home.go @@ -9,7 +9,6 @@ import ( "html/template" "net/http" "path" - "strconv" "strings" "time" @@ -17,7 +16,6 @@ import ( git_model "code.gitea.io/gitea/models/git" repo_model "code.gitea.io/gitea/models/repo" unit_model "code.gitea.io/gitea/models/unit" - user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/htmlutil" @@ -318,19 +316,6 @@ func handleRepoHomeFeed(ctx *context.Context) bool { return true } -func prepareHomeTreeSideBarSwitch(ctx *context.Context) { - showFileTree := true - if ctx.Doer != nil { - v, err := user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyCodeViewShowFileTree, "true") - if err != nil { - log.Error("GetUserSetting: %v", err) - } else { - showFileTree, _ = strconv.ParseBool(v) - } - } - ctx.Data["UserSettingCodeViewShowFileTree"] = showFileTree -} - func redirectSrcToRaw(ctx *context.Context) bool { // GitHub redirects a tree path with "?raw=1" to the raw path // It is useful to embed some raw contents into Markdown files, @@ -386,7 +371,7 @@ func Home(ctx *context.Context) { return } - prepareHomeTreeSideBarSwitch(ctx) + prepareTreeSideBarSwitch(ctx) // get the current git entry which doer user is currently looking at. entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath) diff --git a/templates/repo/editor/common_breadcrumb.tmpl b/templates/repo/editor/common_breadcrumb.tmpl index 8cfbe09d3eef5..ff4efd8ab513d 100644 --- a/templates/repo/editor/common_breadcrumb.tmpl +++ b/templates/repo/editor/common_breadcrumb.tmpl @@ -5,7 +5,9 @@ {{range $i, $v := .TreeNames}}
{{if eq $i $l}} - + {{svg "octicon-info"}} {{else}} {{$v}} diff --git a/templates/repo/editor/delete.tmpl b/templates/repo/editor/delete.tmpl index bf6143f1cb91a..bb260c6e5e4da 100644 --- a/templates/repo/editor/delete.tmpl +++ b/templates/repo/editor/delete.tmpl @@ -1,13 +1,28 @@ {{template "base/head" .}}