Skip to content

Commit 332a24c

Browse files
committed
feat(repo): add tree view context menu actions
1 parent 0721763 commit 332a24c

File tree

6 files changed

+76
-0
lines changed

6 files changed

+76
-0
lines changed

options/locale/locale_en-US.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,7 @@ ambiguous_character = `%[1]c [U+%04[1]X] can be confused with %[2]c [U+%04[2]X]`
13171317
escape_control_characters = Escape
13181318
unescape_control_characters = Unescape
13191319
file_copy_permalink = Copy Permalink
1320+
center_content = Center content
13201321
view_git_blame = View Git Blame
13211322
video_not_supported_in_browser = Your browser does not support the HTML5 'video' tag.
13221323
audio_not_supported_in_browser = Your browser does not support the HTML5 'audio' tag.
@@ -1354,6 +1355,7 @@ editor.this_file_locked = File is locked
13541355
editor.must_be_on_a_branch = You must be on a branch to make or propose changes to this file.
13551356
editor.fork_before_edit = You must fork this repository to make or propose changes to this file.
13561357
editor.delete_this_file = Delete File
1358+
editor.delete_this_directory = Delete Directory
13571359
editor.must_have_write_access = You must have write access to make or propose changes to this file.
13581360
editor.file_delete_success = File "%s" has been deleted.
13591361
editor.name_your_file = Name your file…

templates/repo/view_content.tmpl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,30 @@
8484
</a>
8585
</div>
8686
</button>
87+
<button class="ui dropdown basic compact jump button icon repo-file-actions-dropdown" data-tooltip-content="{{ctx.Locale.Tr "more_operations"}}">
88+
{{svg "octicon-kebab-horizontal"}}
89+
<div class="menu">
90+
<a class="item" data-clipboard-text="{{.TreePath}}">
91+
{{svg "octicon-copy" 16 "tw-mr-2"}}{{ctx.Locale.Tr "copy_path"}}
92+
</a>
93+
<a class="item" data-clipboard-text="{{AppUrl}}{{StringUtils.TrimPrefix .Repository.Link "/"}}/src/commit/{{.CommitID}}/{{PathEscapeSegments .TreePath}}">
94+
{{svg "octicon-link" 16 "tw-mr-2"}}{{ctx.Locale.Tr "repo.file_copy_permalink"}}
95+
</a>
96+
{{if and (.Permission.CanWrite ctx.Consts.RepoUnitTypeCode) (not .Repository.IsArchived)}}
97+
<div class="divider"></div>
98+
<a class="item" href="{{.RepoLink}}/_delete/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
99+
{{svg "octicon-trash" 16 "tw-mr-2"}}{{ctx.Locale.Tr "repo.editor.delete_this_directory"}}
100+
</a>
101+
{{end}}
102+
<div class="divider"></div>
103+
<div class="item">
104+
<div class="ui checkbox" id="center-content-toggle">
105+
<input type="checkbox" id="center-content-checkbox">
106+
<label for="center-content-checkbox">{{ctx.Locale.Tr "repo.center_content"}}</label>
107+
</div>
108+
</div>
109+
</div>
110+
</button>
87111
{{end}}
88112
<!-- Only show clone panel in repository home page -->
89113
{{if $isTreePathRoot}}

web_src/css/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
@import "./repo/issue-list.css";
6464
@import "./repo/list-header.css";
6565
@import "./repo/file-view.css";
66+
@import "./repo/file-actions.css";
6667
@import "./repo/wiki.css";
6768
@import "./repo/header.css";
6869
@import "./repo/home.css";

web_src/css/repo/file-actions.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* Repository file actions dropdown and centered content */
2+
.repo-file-actions-dropdown .menu {
3+
min-width: 200px;
4+
}
5+
6+
.repo-file-actions-dropdown .menu .item {
7+
cursor: pointer;
8+
}
9+
10+
.repo-file-actions-dropdown .menu .divider {
11+
margin: 0.5rem 0;
12+
}
13+
14+
/* Center content option */
15+
.repo-content-centered {
16+
max-width: 980px;
17+
margin-left: auto !important;
18+
margin-right: auto !important;
19+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Handle repository file/directory actions dropdown
2+
export function initRepoFileActions() {
3+
const centerContentCheckbox = document.querySelector<HTMLInputElement>('#center-content-checkbox');
4+
if (!centerContentCheckbox) return;
5+
6+
// Load saved preference
7+
const isCentered = localStorage.getItem('repo-content-centered') === 'true';
8+
centerContentCheckbox.checked = isCentered;
9+
applyCenterContent(isCentered);
10+
11+
// Handle checkbox change
12+
centerContentCheckbox.addEventListener('change', () => {
13+
const centered = centerContentCheckbox.checked;
14+
localStorage.setItem('repo-content-centered', String(centered));
15+
applyCenterContent(centered);
16+
});
17+
}
18+
19+
function applyCenterContent(centered: boolean) {
20+
const container = document.querySelector('.ui.container');
21+
if (!container) return;
22+
23+
if (centered) {
24+
container.classList.add('repo-content-centered');
25+
} else {
26+
container.classList.remove('repo-content-centered');
27+
}
28+
}

web_src/js/index-domready.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import {initGlobalButtonClickOnEnter, initGlobalButtons, initGlobalDeleteButton}
6565
import {initGlobalComboMarkdownEditor, initGlobalEnterQuickSubmit, initGlobalFormDirtyLeaveConfirm} from './features/common-form.ts';
6666
import {callInitFunctions} from './modules/init.ts';
6767
import {initRepoViewFileTree} from './features/repo-view-file-tree.ts';
68+
import {initRepoFileActions} from './features/repo-file-actions.ts';
6869

6970
const initStartTime = performance.now();
7071
const initPerformanceTracer = callInitFunctions([
@@ -138,6 +139,7 @@ const initPerformanceTracer = callInitFunctions([
138139
initRepoReleaseNew,
139140
initRepoTopicBar,
140141
initRepoViewFileTree,
142+
initRepoFileActions,
141143
initRepoWikiForm,
142144
initRepository,
143145
initRepositoryActionView,

0 commit comments

Comments
 (0)