Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
active: true,
webviewAttributes: {
nodeintegration: true,
webPreferences: 'contextIsolation=false'
webPreferences: 'contextIsolation=false',
allowpopups: true,
},
ready: (tab) => {
tab.webview.addEventListener('ipc-message', (event) => {
Expand Down
8 changes: 8 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ app.on('activate', () => {
}
});

// allow open external links in webview (electron-tabs) context
app.on('web-contents-created', (_, webContents) => {
webContents.setWindowOpenHandler(({url}) => {
shell.openExternal(url);
return {action : "deny"};
});
});

ipcMain.on('SETTINGS_CHANGED', (event, electronSettings) => {
const unsafeRequestsEnabled = store.get('enableUnsafeRequests');
if (electronSettings && electronSettings.enableUnsafeRequests !== unsafeRequestsEnabled) {
Expand Down
16 changes: 16 additions & 0 deletions src/app/core/services/gitlab-api/gitlab-www.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Injectable } from '@angular/core';
import { Project } from './models/project';

@Injectable({
providedIn: 'root'
})
export class GitlabWwwService {

public openFileUrl(project: Project, file_with_path: string, line?: number): string {
let url = `${project.web_url}/-/blob/${project.default_branch}/${file_with_path}`;
if (line !== undefined) {
url += `#L${line+1}`;
}
return url;
}
}
1 change: 1 addition & 0 deletions src/app/core/services/gitlab-api/models/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export interface Project {
name: string;
name_with_namespace: string;
path_with_namespace: string;
web_url: string;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<clr-modal [clrModalOpen]="modalOpen" (clrModalOpenChange)="close()" [clrModalSize]="'xl'" [clrModalStaticBackdrop]="false">
<h3 class="modal-title">
<app-path-text [path]="filename"></app-path-text>
<div class="file-viewer-menu">
<div class="btn-group btn-outline-primary btn-icon btn-sm">
<a target="_blank" rel="noopener noreferrer" [href]="openGitLabUrl()" class="btn">
GitLab
<clr-icon shape="pop-out"></clr-icon>
</a>
</div>
</div>
<div class="jump-lines-icons" *ngIf="highlightedRanges.length > 0">
<span class="jump-counter">{{jumpedToLineIndex + 1}} of {{highlightedRanges.length}}</span>
<div class="btn-group btn-outline-primary btn-icon btn-sm">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ app-path-text {
margin-bottom: 4px;
}

.file-viewer-menu {
position: absolute;
line-height: 0;
}

.jump-lines-icons {
position: absolute;
line-height: 0;
Expand Down
15 changes: 14 additions & 1 deletion src/app/shared/components/file-viewer/file-viewer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AceComponent, AceConfigInterface } from 'ngx-ace-wrapper';
import { Project } from 'src/app/core/services/gitlab-api/models/project';
import { SettingsService } from 'src/app/settings/settings.service';
import { Range } from 'brace';
import { GitlabWwwService } from 'src/app/core/services/gitlab-api/gitlab-www.service';

import 'brace';
import 'brace/mode/javascript';
Expand Down Expand Up @@ -50,6 +51,7 @@ export class FileViewerComponent extends Modal<FileViewerInitData> implements On
@ViewChild('ace', { static: true })
ace: AceComponent;
aceConfig: AceConfigInterface;
aceInitialized = false;

project: Project;
filename: string;
Expand All @@ -62,7 +64,8 @@ export class FileViewerComponent extends Modal<FileViewerInitData> implements On
highlightedRanges: Range[] = [];
jumpedToLineIndex = -1;

constructor(private filesApiService: FilesApiService, private settingsService: SettingsService) {
constructor(private filesApiService: FilesApiService, private settingsService: SettingsService,
private gitlabWwwService: GitlabWwwService) {
super();
}

Expand Down Expand Up @@ -107,6 +110,11 @@ export class FileViewerComponent extends Modal<FileViewerInitData> implements On
this.goToHighlight(this.jumpedToLineIndex);
}

openGitLabUrl(): string {
const {row} = this.provideCursorPosition();
return this.gitlabWwwService.openFileUrl(this.project, this.filename, row);
}

private goToHighlight(index: number): void {
const range = this.highlightedRanges[index];
const ace = this.ace.directiveRef.ace();
Expand All @@ -131,6 +139,7 @@ export class FileViewerComponent extends Modal<FileViewerInitData> implements On
if (this.highlightedRanges.length > 0) {
this.goToNextHighlight();
}
this.aceInitialized = true;
});
}

Expand All @@ -142,4 +151,8 @@ export class FileViewerComponent extends Modal<FileViewerInitData> implements On
private decodeContent(content: string): string {
return decodeURIComponent(escape(atob(content)));
}

private provideCursorPosition(): {row?: number; column?: number} {
return this.aceInitialized ? this.ace.directiveRef.ace().getCursorPosition() : {};
}
}