mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-21 18:54:39 +02:00
Enable path editing of non text files
This commit is contained in:
parent
cbb2e52911
commit
c6598c27d3
@ -1331,7 +1331,6 @@ editor.upload_file = Upload File
|
|||||||
editor.edit_file = Edit File
|
editor.edit_file = Edit File
|
||||||
editor.preview_changes = Preview Changes
|
editor.preview_changes = Preview Changes
|
||||||
editor.cannot_edit_lfs_files = LFS files cannot be edited in the web interface.
|
editor.cannot_edit_lfs_files = LFS files cannot be edited in the web interface.
|
||||||
editor.cannot_edit_non_text_files = Binary files cannot be edited in the web interface.
|
|
||||||
editor.edit_this_file = Edit File
|
editor.edit_this_file = Edit File
|
||||||
editor.this_file_locked = File is locked
|
editor.this_file_locked = File is locked
|
||||||
editor.must_be_on_a_branch = You must be on a branch to make or propose changes to this file.
|
editor.must_be_on_a_branch = You must be on a branch to make or propose changes to this file.
|
||||||
@ -1395,6 +1394,9 @@ editor.user_no_push_to_branch = User cannot push to branch
|
|||||||
editor.require_signed_commit = Branch requires a signed commit
|
editor.require_signed_commit = Branch requires a signed commit
|
||||||
editor.cherry_pick = Cherry-pick %s onto:
|
editor.cherry_pick = Cherry-pick %s onto:
|
||||||
editor.revert = Revert %s onto:
|
editor.revert = Revert %s onto:
|
||||||
|
editor.file_too_large_not_editable = The file is too large to be edited.
|
||||||
|
editor.binary_file_not_editable = Binary file content is not editable.
|
||||||
|
editor.file_not_editable_hint = But you can still rename or move it.
|
||||||
|
|
||||||
commits.desc = Browse source code change history.
|
commits.desc = Browse source code change history.
|
||||||
commits.commits = Commits
|
commits.commits = Commits
|
||||||
|
@ -146,11 +146,6 @@ func editFile(ctx *context.Context, isNewFile bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
blob := entry.Blob()
|
blob := entry.Blob()
|
||||||
if blob.Size() >= setting.UI.MaxDisplayFileSize {
|
|
||||||
ctx.NotFound(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
dataRc, err := blob.DataAsync()
|
dataRc, err := blob.DataAsync()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.NotFound(err)
|
ctx.NotFound(err)
|
||||||
@ -159,6 +154,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
|
|||||||
|
|
||||||
defer dataRc.Close()
|
defer dataRc.Close()
|
||||||
|
|
||||||
|
ctx.Data["IsFileTooLarge"] = blob.Size() >= setting.UI.MaxDisplayFileSize
|
||||||
ctx.Data["FileSize"] = blob.Size()
|
ctx.Data["FileSize"] = blob.Size()
|
||||||
|
|
||||||
buf := make([]byte, 1024)
|
buf := make([]byte, 1024)
|
||||||
@ -166,10 +162,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
|
|||||||
buf = buf[:n]
|
buf = buf[:n]
|
||||||
|
|
||||||
// Only some file types are editable online as text.
|
// Only some file types are editable online as text.
|
||||||
if !typesniffer.DetectContentType(buf).IsRepresentableAsText() {
|
ctx.Data["IsFileText"] = typesniffer.DetectContentType(buf).IsRepresentableAsText()
|
||||||
ctx.NotFound(nil)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
d, _ := io.ReadAll(dataRc)
|
d, _ := io.ReadAll(dataRc)
|
||||||
|
|
||||||
|
@ -143,8 +143,6 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
|
|||||||
// Assume file is not editable first.
|
// Assume file is not editable first.
|
||||||
if fInfo.isLFSFile {
|
if fInfo.isLFSFile {
|
||||||
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.cannot_edit_lfs_files")
|
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.cannot_edit_lfs_files")
|
||||||
} else if !isRepresentableAsText {
|
|
||||||
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.cannot_edit_non_text_files")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// read all needed attributes which will be used later
|
// read all needed attributes which will be used later
|
||||||
@ -243,21 +241,6 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
|
|||||||
ctx.Data["FileContent"] = fileContent
|
ctx.Data["FileContent"] = fileContent
|
||||||
ctx.Data["LineEscapeStatus"] = statuses
|
ctx.Data["LineEscapeStatus"] = statuses
|
||||||
}
|
}
|
||||||
if !fInfo.isLFSFile {
|
|
||||||
if ctx.Repo.CanEnableEditor(ctx, ctx.Doer) {
|
|
||||||
if lfsLock != nil && lfsLock.OwnerID != ctx.Doer.ID {
|
|
||||||
ctx.Data["CanEditFile"] = false
|
|
||||||
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.this_file_locked")
|
|
||||||
} else {
|
|
||||||
ctx.Data["CanEditFile"] = true
|
|
||||||
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.edit_this_file")
|
|
||||||
}
|
|
||||||
} else if !ctx.Repo.RefFullName.IsBranch() {
|
|
||||||
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
|
|
||||||
} else if !ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, ctx.Repo.BranchName) {
|
|
||||||
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.fork_before_edit")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
case fInfo.st.IsPDF():
|
case fInfo.st.IsPDF():
|
||||||
ctx.Data["IsPDFFile"] = true
|
ctx.Data["IsPDFFile"] = true
|
||||||
@ -307,6 +290,22 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !fInfo.isLFSFile {
|
||||||
|
if ctx.Repo.CanEnableEditor(ctx, ctx.Doer) {
|
||||||
|
if lfsLock != nil && lfsLock.OwnerID != ctx.Doer.ID {
|
||||||
|
ctx.Data["CanEditFile"] = false
|
||||||
|
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.this_file_locked")
|
||||||
|
} else {
|
||||||
|
ctx.Data["CanEditFile"] = true
|
||||||
|
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.edit_this_file")
|
||||||
|
}
|
||||||
|
} else if !ctx.Repo.RefFullName.IsBranch() {
|
||||||
|
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
|
||||||
|
} else if !ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, ctx.Repo.BranchName) {
|
||||||
|
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.fork_before_edit")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ctx.Repo.CanEnableEditor(ctx, ctx.Doer) {
|
if ctx.Repo.CanEnableEditor(ctx, ctx.Doer) {
|
||||||
if lfsLock != nil && lfsLock.OwnerID != ctx.Doer.ID {
|
if lfsLock != nil && lfsLock.OwnerID != ctx.Doer.ID {
|
||||||
ctx.Data["CanDeleteFile"] = false
|
ctx.Data["CanDeleteFile"] = false
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
<input type="hidden" id="tree_path" name="tree_path" value="{{.TreePath}}" required>
|
<input type="hidden" id="tree_path" name="tree_path" value="{{.TreePath}}" required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{if .IsFileText}}
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<div class="ui top attached header">
|
<div class="ui top attached header">
|
||||||
<div class="ui compact small menu small-menu-items repo-editor-menu">
|
<div class="ui compact small menu small-menu-items repo-editor-menu">
|
||||||
@ -53,6 +54,21 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{else if .IsFileTooLarge}}
|
||||||
|
<div class="field">
|
||||||
|
<div class="ui segment tw-text-center">
|
||||||
|
<h4 class="tw-font-semibold tw-mb-2">{{ctx.Locale.Tr "repo.editor.file_too_large_not_editable"}}</h4>
|
||||||
|
<p>{{ctx.Locale.Tr "repo.editor.file_not_editable_hint"}}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{else}}
|
||||||
|
<div class="field">
|
||||||
|
<div class="ui segment tw-text-center">
|
||||||
|
<h4 class="tw-font-semibold tw-mb-2">{{ctx.Locale.Tr "repo.editor.binary_file_not_editable"}}</h4>
|
||||||
|
<p>{{ctx.Locale.Tr "repo.editor.file_not_editable_hint"}}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
{{template "repo/editor/commit_form" .}}
|
{{template "repo/editor/commit_form" .}}
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user