You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.2 KiB

  1. package repo
  2. import (
  3. "fmt"
  4. "code.gitea.io/git"
  5. "code.gitea.io/gitea/models"
  6. "code.gitea.io/gitea/modules/context"
  7. )
  8. // SetEditorconfigIfExists set editor config as render variable
  9. func SetEditorconfigIfExists(ctx *context.Context) {
  10. ec, err := ctx.Repo.GetEditorconfig()
  11. if err != nil && !git.IsErrNotExist(err) {
  12. description := fmt.Sprintf("Error while getting .editorconfig file: %v", err)
  13. if err := models.CreateRepositoryNotice(description); err != nil {
  14. ctx.ServerError("ErrCreatingReporitoryNotice", err)
  15. }
  16. return
  17. }
  18. ctx.Data["Editorconfig"] = ec
  19. }
  20. // SetDiffViewStyle set diff style as render variable
  21. func SetDiffViewStyle(ctx *context.Context) {
  22. queryStyle := ctx.Query("style")
  23. if !ctx.IsSigned {
  24. ctx.Data["IsSplitStyle"] = queryStyle == "split"
  25. return
  26. }
  27. var (
  28. userStyle = ctx.User.DiffViewStyle
  29. style string
  30. )
  31. if queryStyle == "unified" || queryStyle == "split" {
  32. style = queryStyle
  33. } else if userStyle == "unified" || userStyle == "split" {
  34. style = userStyle
  35. } else {
  36. style = "unified"
  37. }
  38. ctx.Data["IsSplitStyle"] = style == "split"
  39. if err := ctx.User.UpdateDiffViewStyle(style); err != nil {
  40. ctx.ServerError("ErrUpdateDiffViewStyle", err)
  41. }
  42. }