mirror of https://github.com/go-gitea/gitea.git
Web editor: improve edit file tooltip
This commit is contained in:
parent
f0b5c3b90a
commit
6e171c5225
|
@ -436,17 +436,17 @@ commit_changes = Commit Changes
|
||||||
default_commit_message = Add an optional extended description...
|
default_commit_message = Add an optional extended description...
|
||||||
last_commit_info = %s edited this file %s
|
last_commit_info = %s edited this file %s
|
||||||
delete_this_file = Delete this file
|
delete_this_file = Delete this file
|
||||||
edit_this_file = Edit this file
|
|
||||||
edit_file = Edit file
|
edit_file = Edit file
|
||||||
delete_confirm_message = Are you sure you want to delete this file?
|
delete_confirm_message = Are you sure you want to delete this file?
|
||||||
delete_commit_message = Write a note about this delete (optional)
|
delete_commit_message = Write a note about this delete (optional)
|
||||||
unable_to_update_file = Unable to update this file, error occurred
|
unable_to_update_file = Unable to update this file, error occurred
|
||||||
must_be_on_branch = You must be on a branch to make or propose changes to this file
|
|
||||||
must_be_writer = You must have write access to make or propose changes to this file
|
must_be_writer = You must have write access to make or propose changes to this file
|
||||||
cannot_edit_binary_files = Cannot edit binary files
|
|
||||||
filename_help = To add directory, just type it and press /. To remove a directory, go to the beginning of the field and press backspace.
|
filename_help = To add directory, just type it and press /. To remove a directory, go to the beginning of the field and press backspace.
|
||||||
fork_before_edit = You must fork this before editing
|
|
||||||
new_branch = new branch
|
new_branch = new branch
|
||||||
|
editor.cannot_edit_non_text_files = Cannot edit non-text files
|
||||||
|
editor.edit_this_file = Edit this file
|
||||||
|
editor.must_be_on_a_branch = You must be on a branch to make or propose changes to this file
|
||||||
|
editor.fork_before_edit = You must fork this repository before editing the file
|
||||||
editor.file_delete_success = File '%s' has been deleted successfully!
|
editor.file_delete_success = File '%s' has been deleted successfully!
|
||||||
editor.commit_directly_to_this_branch = Commit directly to the <strong class="branch-name">%s</strong> branch.
|
editor.commit_directly_to_this_branch = Commit directly to the <strong class="branch-name">%s</strong> branch.
|
||||||
editor.create_new_branch = Create a <strong>new branch</strong> for this commit and start a pull request.
|
editor.create_new_branch = Create a <strong>new branch</strong> for this commit and start a pull request.
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -24,7 +24,6 @@ import (
|
||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
"github.com/gogits/gogs/modules/template"
|
"github.com/gogits/gogs/modules/template"
|
||||||
"github.com/gogits/gogs/modules/template/highlight"
|
"github.com/gogits/gogs/modules/template/highlight"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -46,33 +45,18 @@ func Home(ctx *context.Context) {
|
||||||
userName := ctx.Repo.Owner.Name
|
userName := ctx.Repo.Owner.Name
|
||||||
repoName := ctx.Repo.Repository.Name
|
repoName := ctx.Repo.Repository.Name
|
||||||
|
|
||||||
repoLink := ctx.Repo.RepoLink
|
|
||||||
branchLink := ctx.Repo.RepoLink + "/src/" + branchName
|
branchLink := ctx.Repo.RepoLink + "/src/" + branchName
|
||||||
treeLink := branchLink
|
treeLink := branchLink
|
||||||
rawLink := ctx.Repo.RepoLink + "/raw/" + branchName
|
rawLink := ctx.Repo.RepoLink + "/raw/" + branchName
|
||||||
editLink := ctx.Repo.RepoLink + "/_edit/" + branchName
|
// newFileLink := ctx.Repo.RepoLink + "/_new/" + branchName
|
||||||
newFileLink := ctx.Repo.RepoLink + "/_new/" + branchName
|
// uploadFileLink := ctx.Repo.RepoLink + "/upload/" + branchName
|
||||||
forkLink := setting.AppSubUrl + "/repo/fork/" + strconv.FormatInt(ctx.Repo.Repository.ID, 10)
|
|
||||||
uploadFileLink := ctx.Repo.RepoLink + "/upload/" + branchName
|
|
||||||
|
|
||||||
// Get tree path
|
treePath := ctx.Repo.TreePath
|
||||||
treename := ctx.Repo.TreePath
|
if len(treePath) > 0 {
|
||||||
|
treeLink += "/" + treePath
|
||||||
if len(treename) > 0 {
|
|
||||||
if treename[len(treename)-1] == '/' {
|
|
||||||
ctx.Redirect(repoLink + "/src/" + branchName + "/" + treename[:len(treename)-1])
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
treeLink += "/" + treename
|
|
||||||
}
|
}
|
||||||
|
|
||||||
treePath := treename
|
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(treePath)
|
||||||
if len(treePath) != 0 {
|
|
||||||
treePath = treePath + "/"
|
|
||||||
}
|
|
||||||
|
|
||||||
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(treename)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if git.IsErrNotExist(err) {
|
if git.IsErrNotExist(err) {
|
||||||
ctx.Handle(404, "GetTreeEntryByPath", err)
|
ctx.Handle(404, "GetTreeEntryByPath", err)
|
||||||
|
@ -94,7 +78,7 @@ func Home(ctx *context.Context) {
|
||||||
ctx.Data["IsFile"] = true
|
ctx.Data["IsFile"] = true
|
||||||
ctx.Data["FileName"] = blob.Name()
|
ctx.Data["FileName"] = blob.Name()
|
||||||
ctx.Data["HighlightClass"] = highlight.FileNameToHighlightClass(blob.Name())
|
ctx.Data["HighlightClass"] = highlight.FileNameToHighlightClass(blob.Name())
|
||||||
ctx.Data["FileLink"] = rawLink + "/" + treename
|
ctx.Data["FileLink"] = rawLink + "/" + treePath
|
||||||
|
|
||||||
buf := make([]byte, 1024)
|
buf := make([]byte, 1024)
|
||||||
n, _ := dataRc.Read(buf)
|
n, _ := dataRc.Read(buf)
|
||||||
|
@ -107,25 +91,30 @@ func Home(ctx *context.Context) {
|
||||||
_, isPDFFile := base.IsPDFFile(buf)
|
_, isPDFFile := base.IsPDFFile(buf)
|
||||||
ctx.Data["IsFileText"] = isTextFile
|
ctx.Data["IsFileText"] = isTextFile
|
||||||
|
|
||||||
|
// Assume file is not editable first.
|
||||||
|
if !isTextFile {
|
||||||
|
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.cannot_edit_non_text_files")
|
||||||
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case isPDFFile:
|
case isPDFFile:
|
||||||
ctx.Data["IsPDFFile"] = true
|
ctx.Data["IsPDFFile"] = true
|
||||||
ctx.Data["FileEditLinkTooltip"] = ctx.Tr("repo.cannot_edit_binary_files")
|
|
||||||
case isImageFile:
|
case isImageFile:
|
||||||
ctx.Data["IsImageFile"] = true
|
ctx.Data["IsImageFile"] = true
|
||||||
ctx.Data["FileEditLinkTooltip"] = ctx.Tr("repo.cannot_edit_binary_files")
|
|
||||||
case isTextFile:
|
case isTextFile:
|
||||||
if blob.Size() >= setting.UI.MaxDisplayFileSize {
|
if blob.Size() >= setting.UI.MaxDisplayFileSize {
|
||||||
ctx.Data["IsFileTooLarge"] = true
|
ctx.Data["IsFileTooLarge"] = true
|
||||||
} else {
|
} else {
|
||||||
ctx.Data["IsFileTooLarge"] = false
|
|
||||||
d, _ := ioutil.ReadAll(dataRc)
|
d, _ := ioutil.ReadAll(dataRc)
|
||||||
buf = append(buf, d...)
|
buf = append(buf, d...)
|
||||||
readmeExist := markdown.IsMarkdownFile(blob.Name()) || markdown.IsReadmeFile(blob.Name())
|
|
||||||
isMarkdown := readmeExist || markdown.IsMarkdownFile(blob.Name())
|
isMarkdown := markdown.IsMarkdownFile(blob.Name())
|
||||||
ctx.Data["ReadmeExist"] = readmeExist
|
|
||||||
ctx.Data["IsMarkdown"] = isMarkdown
|
ctx.Data["IsMarkdown"] = isMarkdown
|
||||||
if isMarkdown {
|
|
||||||
|
readmeExist := isMarkdown || markdown.IsReadmeFile(blob.Name())
|
||||||
|
ctx.Data["ReadmeExist"] = readmeExist
|
||||||
|
if readmeExist {
|
||||||
|
// TODO: don't need to render if it's a README but not Markdown file.
|
||||||
ctx.Data["FileContent"] = string(markdown.Render(buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))
|
ctx.Data["FileContent"] = string(markdown.Render(buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))
|
||||||
} else {
|
} else {
|
||||||
// Building code view blocks with line number on server side.
|
// Building code view blocks with line number on server side.
|
||||||
|
@ -153,22 +142,19 @@ func Home(ctx *context.Context) {
|
||||||
ctx.Data["LineNums"] = gotemplate.HTML(output.String())
|
ctx.Data["LineNums"] = gotemplate.HTML(output.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Repo.IsWriter() && ctx.Repo.IsViewBranch {
|
if ctx.Repo.IsWriter() && ctx.Repo.IsViewBranch {
|
||||||
ctx.Data["FileEditLink"] = editLink + "/" + treename
|
ctx.Data["CanEditFile"] = true
|
||||||
ctx.Data["FileEditLinkTooltip"] = ctx.Tr("repo.edit_this_file")
|
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.edit_this_file")
|
||||||
} else {
|
} else if !ctx.Repo.IsViewBranch {
|
||||||
if !ctx.Repo.IsViewBranch {
|
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
|
||||||
ctx.Data["FileEditLinkTooltip"] = ctx.Tr("repo.must_be_on_branch")
|
} else if !ctx.Repo.IsWriter() {
|
||||||
} else if !ctx.Repo.IsWriter() {
|
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.fork_before_edit")
|
||||||
ctx.Data["FileEditLink"] = forkLink
|
|
||||||
ctx.Data["FileEditLinkTooltip"] = ctx.Tr("repo.fork_before_edit")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
ctx.Data["FileEditLinkTooltip"] = ctx.Tr("repo.cannot_edit_binary_files")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Repo.IsWriter() && ctx.Repo.IsViewBranch {
|
if ctx.Repo.IsWriter() && ctx.Repo.IsViewBranch {
|
||||||
|
ctx.Data["CanDeleteFile"] = true
|
||||||
ctx.Data["FileDeleteLinkTooltip"] = ctx.Tr("repo.delete_this_file")
|
ctx.Data["FileDeleteLinkTooltip"] = ctx.Tr("repo.delete_this_file")
|
||||||
} else {
|
} else {
|
||||||
if !ctx.Repo.IsViewBranch {
|
if !ctx.Repo.IsViewBranch {
|
||||||
|
@ -180,7 +166,7 @@ func Home(ctx *context.Context) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Directory and file list.
|
// Directory and file list.
|
||||||
tree, err := ctx.Repo.Commit.SubTree(treename)
|
tree, err := ctx.Repo.Commit.SubTree(treePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(404, "SubTree", err)
|
ctx.Handle(404, "SubTree", err)
|
||||||
return
|
return
|
||||||
|
@ -224,7 +210,7 @@ func Home(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["FileSize"] = readmeFile.Size()
|
ctx.Data["FileSize"] = readmeFile.Size()
|
||||||
ctx.Data["FileLink"] = rawLink + "/" + treename
|
ctx.Data["FileLink"] = rawLink + "/" + treePath
|
||||||
_, isTextFile := base.IsTextFile(buf)
|
_, isTextFile := base.IsTextFile(buf)
|
||||||
ctx.Data["FileIsText"] = isTextFile
|
ctx.Data["FileIsText"] = isTextFile
|
||||||
ctx.Data["FileName"] = readmeFile.Name()
|
ctx.Data["FileName"] = readmeFile.Name()
|
||||||
|
@ -254,12 +240,12 @@ func Home(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
ctx.Data["LastCommit"] = lastCommit
|
ctx.Data["LastCommit"] = lastCommit
|
||||||
ctx.Data["LastCommitUser"] = models.ValidateCommitWithEmail(lastCommit)
|
ctx.Data["LastCommitUser"] = models.ValidateCommitWithEmail(lastCommit)
|
||||||
if ctx.Repo.IsWriter() && ctx.Repo.IsViewBranch {
|
// if ctx.Repo.IsWriter() && ctx.Repo.IsViewBranch {
|
||||||
ctx.Data["NewFileLink"] = newFileLink + "/" + treename
|
// ctx.Data["NewFileLink"] = newFileLink + "/" + treePath
|
||||||
if setting.Repository.Upload.Enabled {
|
// if setting.Repository.Upload.Enabled {
|
||||||
ctx.Data["UploadFileLink"] = uploadFileLink + "/" + treename
|
// ctx.Data["UploadFileLink"] = uploadFileLink + "/" + treePath
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["Username"] = userName
|
ctx.Data["Username"] = userName
|
||||||
|
@ -274,8 +260,8 @@ func Home(ctx *context.Context) {
|
||||||
var treenames []string
|
var treenames []string
|
||||||
paths := make([]string, 0)
|
paths := make([]string, 0)
|
||||||
|
|
||||||
if len(treename) > 0 {
|
if len(treePath) > 0 {
|
||||||
treenames = strings.Split(treename, "/")
|
treenames = strings.Split(treePath, "/")
|
||||||
for i := range treenames {
|
for i := range treenames {
|
||||||
paths = append(paths, strings.Join(treenames[0:i+1], "/"))
|
paths = append(paths, strings.Join(treenames[0:i+1], "/"))
|
||||||
}
|
}
|
||||||
|
@ -287,9 +273,9 @@ func Home(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["Paths"] = paths
|
ctx.Data["Paths"] = paths
|
||||||
ctx.Data["TreeName"] = treename
|
|
||||||
ctx.Data["Treenames"] = treenames
|
|
||||||
ctx.Data["TreePath"] = treePath
|
ctx.Data["TreePath"] = treePath
|
||||||
|
ctx.Data["TreeLink"] = treeLink
|
||||||
|
ctx.Data["Treenames"] = treenames
|
||||||
ctx.Data["BranchLink"] = branchLink
|
ctx.Data["BranchLink"] = branchLink
|
||||||
ctx.HTML(200, HOME)
|
ctx.HTML(200, HOME)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,18 +15,18 @@
|
||||||
<div class="ui right file-actions">
|
<div class="ui right file-actions">
|
||||||
<div class="ui buttons">
|
<div class="ui buttons">
|
||||||
{{if not .IsViewCommit}}
|
{{if not .IsViewCommit}}
|
||||||
<a class="ui button" href="{{.RepoLink}}/src/{{.CommitID}}/{{EscapePound .TreeName}}">{{.i18n.Tr "repo.file_permalink"}}</a>
|
<a class="ui button" href="{{.RepoLink}}/src/{{.CommitID}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.file_permalink"}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
<a class="ui button" href="{{.RepoLink}}/commits/{{EscapePound .BranchName}}/{{EscapePound .TreeName}}">{{.i18n.Tr "repo.file_history"}}</a>
|
<a class="ui button" href="{{.RepoLink}}/commits/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.file_history"}}</a>
|
||||||
<a class="ui button" href="{{EscapePound .FileLink}}">{{.i18n.Tr "repo.file_raw"}}</a>
|
<a class="ui button" href="{{EscapePound .FileLink}}">{{.i18n.Tr "repo.file_raw"}}</a>
|
||||||
</div>
|
</div>
|
||||||
{{if .FileEditLink}}
|
{{if .CanEditFile}}
|
||||||
<a href="{{EscapePound $.FileEditLink}}"><i class="poping up octicon octicon-pencil btn-octicon" data-content="{{.FileEditLinkTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i></a>
|
<a href="{{.RepoLink}}/_edit/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}"><i class="poping up octicon octicon-pencil btn-octicon" data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i></a>
|
||||||
{{else}}
|
{{else}}
|
||||||
<i class="octicon btn-octicon octicon-pencil poping up disabled" data-content="{{.FileEditLinkTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
|
<i class="octicon btn-octicon octicon-pencil poping up disabled" data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if and .IsViewBranch .IsRepositoryWriter}}
|
{{if .CanDeleteFile}}
|
||||||
<form id="delete-file-form" class="ui form inline-form" action="{{.RepoLink}}/_delete/{{EscapePound .BranchName}}/{{.TreeName}}" method="post">
|
<form id="delete-file-form" class="ui form inline-form" action="{{.RepoLink}}/_delete/{{EscapePound .BranchName}}/{{.TreePath}}" method="post">
|
||||||
{{.CsrfTokenHtml}}
|
{{.CsrfTokenHtml}}
|
||||||
<button onclick="submitDeleteForm()" class="octicon octicon-trashcan btn-octicon btn-octicon-danger poping up" type="button" data-content="{{.FileDeleteLinkTooltip}}" data-position="bottom center" data-variation="tiny inverted"></button>
|
<button onclick="submitDeleteForm()" class="octicon octicon-trashcan btn-octicon btn-octicon-danger poping up" type="button" data-content="{{.FileDeleteLinkTooltip}}" data-position="bottom center" data-variation="tiny inverted"></button>
|
||||||
<input type="hidden" id="delete-message" name="commit_message" value="">
|
<input type="hidden" id="delete-message" name="commit_message" value="">
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
{{else}}
|
{{else}}
|
||||||
<td class="name">
|
<td class="name">
|
||||||
<span class="octicon octicon-file-{{if or $entry.IsDir}}directory{{else}}text{{end}}"></span>
|
<span class="octicon octicon-file-{{if or $entry.IsDir}}directory{{else}}text{{end}}"></span>
|
||||||
<a href="{{EscapePound $.BranchLink}}/{{EscapePound $.TreePath}}{{EscapePound $entry.Name}}">{{$entry.Name}}</a>
|
<a href="{{EscapePound $.TreeLink}}/{{EscapePound $entry.Name}}">{{$entry.Name}}</a>
|
||||||
</td>
|
</td>
|
||||||
{{end}}
|
{{end}}
|
||||||
<td class="message collapsing has-emoji">
|
<td class="message collapsing has-emoji">
|
||||||
|
|
Loading…
Reference in New Issue