Wiring tabs to update editor and handle closing of file view
This commit is contained in:
parent
04e3bbcc77
commit
0d1fdfa031
@ -10,7 +10,10 @@ import { ServiceMessage } from '../../types/service-message.type';
|
|||||||
})
|
})
|
||||||
export class EditorsService {
|
export class EditorsService {
|
||||||
private messageSubject: ReplaySubject<ServiceMessage> = new ReplaySubject<ServiceMessage>(1);
|
private messageSubject: ReplaySubject<ServiceMessage> = new ReplaySubject<ServiceMessage>(1);
|
||||||
private activationSubject: ReplaySubject<string> = new ReplaySubject<string>(1);
|
private activationSubject: ReplaySubject<string> = new ReplaySubject<string>(1);
|
||||||
|
private switchSessionSubject: ReplaySubject<string> = new ReplaySubject<string>(1);
|
||||||
|
private closeTabSubject: ReplaySubject<string> = new ReplaySubject<string>(1);
|
||||||
|
|
||||||
|
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
@ -30,4 +33,19 @@ export class EditorsService {
|
|||||||
return this.activationSubject.asObservable();
|
return this.activationSubject.asObservable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setTabToEditor(data: string): void {
|
||||||
|
this.switchSessionSubject.next(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
loadTabToEditor$(): Observable<string> {
|
||||||
|
return this.switchSessionSubject.asObservable();
|
||||||
|
}
|
||||||
|
|
||||||
|
closeTab(data: string): void {
|
||||||
|
this.closeTabSubject.next(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
closeTabRequested$(): Observable<string> {
|
||||||
|
return this.closeTabSubject.asObservable();
|
||||||
|
}
|
||||||
}
|
}
|
@ -2,4 +2,5 @@ export class ServiceMessage {
|
|||||||
action: string = "none";
|
action: string = "none";
|
||||||
message: string = "";
|
message: string = "";
|
||||||
uuid!: string;
|
uuid!: string;
|
||||||
|
data: any;
|
||||||
}
|
}
|
@ -144,4 +144,11 @@ export class AceEditorComponent extends AceEditorBase {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public newBuffer() {
|
||||||
|
let buffer = ace.createEditSession([""]);
|
||||||
|
this.editor.setSession(buffer);
|
||||||
|
this.activeFile = null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -64,6 +64,34 @@ export class EditorsComponent {
|
|||||||
).subscribe((uuid: string) => {
|
).subscribe((uuid: string) => {
|
||||||
this.activeEditor = uuid;
|
this.activeEditor = uuid;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.editorsService.loadTabToEditor$().pipe(
|
||||||
|
takeUntil(this.unsubscribe)
|
||||||
|
).subscribe((path: string) => {
|
||||||
|
let file = this.files.get(path);
|
||||||
|
let editorComponent = this.getActiveEditorComponent();
|
||||||
|
let editor = editorComponent.editor;
|
||||||
|
|
||||||
|
editorComponent.activeFile = file;
|
||||||
|
editor.setSession(file.session);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.editorsService.closeTabRequested$().pipe(
|
||||||
|
takeUntil(this.unsubscribe)
|
||||||
|
).subscribe((path: string) => {
|
||||||
|
let file = this.files.get(path);
|
||||||
|
let editors = [...this.editors.values()];
|
||||||
|
|
||||||
|
for (let i = 0; i < editors.length; i++) {
|
||||||
|
let editorComponent = editors[i].instance;
|
||||||
|
if (editorComponent.editor.session == file.session) {
|
||||||
|
editorComponent.newBuffer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
file.session.destroy();
|
||||||
|
this.files.delete(path);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
loadMainSubscribers() {
|
loadMainSubscribers() {
|
||||||
@ -205,6 +233,7 @@ export class EditorsComponent {
|
|||||||
message.action = "create-tab";
|
message.action = "create-tab";
|
||||||
message.message = file.fname;
|
message.message = file.fname;
|
||||||
message.uuid = file.hash;
|
message.uuid = file.hash;
|
||||||
|
message.data = file.path;
|
||||||
|
|
||||||
this.tabsService.setData(message);
|
this.tabsService.setData(message);
|
||||||
}
|
}
|
||||||
|
@ -5,18 +5,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
.tab {
|
|
||||||
float: left;
|
|
||||||
clear: left;
|
|
||||||
display: flow;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
margin-left: 2em;
|
margin-left: 2em;
|
||||||
margin-right: 2em;
|
margin-right: 2em;
|
||||||
|
font-size: 4em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.title:hover {
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.close-button {
|
.close-button {
|
||||||
@ -24,7 +20,6 @@
|
|||||||
border-style: solid;
|
border-style: solid;
|
||||||
border-color: rgba(0, 0, 0, 0.64);
|
border-color: rgba(0, 0, 0, 0.64);
|
||||||
border-width: 1px;
|
border-width: 1px;
|
||||||
border-radius: 0em 1em 0em 0em;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.close-button:hover {
|
.close-button:hover {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<span class="tab">
|
<span class="tab" title="{{path}}">
|
||||||
<span class="title">{{title}}</span>
|
<span class="title" (mouseup)="setTabToEditor()">{{title}}</span>
|
||||||
<button class="close-button">X</button>
|
<button class="close-button" (mouseup)="closeTab()">X</button>
|
||||||
</span>
|
</span>
|
@ -1,5 +1,7 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
|
import { EditorsService } from '../../../common/services/editor/editors.service';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -10,21 +12,31 @@ import { Component } from '@angular/core';
|
|||||||
templateUrl: './tab.component.html',
|
templateUrl: './tab.component.html',
|
||||||
styleUrl: './tab.component.css',
|
styleUrl: './tab.component.css',
|
||||||
host: {
|
host: {
|
||||||
'class': 'col'
|
'class': ''
|
||||||
// 'class': 'col tab'
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
export class TabComponent {
|
export class TabComponent {
|
||||||
|
|
||||||
title: string;
|
title: string;
|
||||||
|
path: string;
|
||||||
|
ref: any;
|
||||||
|
|
||||||
|
|
||||||
constructor() {
|
constructor(
|
||||||
|
private editorsService: EditorsService,
|
||||||
|
) {
|
||||||
this.title = "[NO TITLE]";
|
this.title = "[NO TITLE]";
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setTabToEditor() {
|
||||||
|
this.editorsService.setTabToEditor(this.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
closeTab() {
|
||||||
|
this.editorsService.closeTab(this.path);
|
||||||
|
this.ref.destroy();
|
||||||
|
}
|
||||||
}
|
}
|
@ -37,7 +37,7 @@ export class TabsComponent {
|
|||||||
takeUntil(this.unsubscribe)
|
takeUntil(this.unsubscribe)
|
||||||
).subscribe((data: ServiceMessage) => {
|
).subscribe((data: ServiceMessage) => {
|
||||||
if (data.action === "create-tab")
|
if (data.action === "create-tab")
|
||||||
this.createTab(data.message, data.uuid);
|
this.createTab(data.message, data.uuid, data.data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,9 +46,12 @@ export class TabsComponent {
|
|||||||
this.unsubscribe.complete();
|
this.unsubscribe.complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
private createTab(title: string, uuid: string) {
|
private createTab(title: string, uuid: string, path: string) {
|
||||||
const component = this.containerRef.createComponent(TabComponent);
|
const component = this.containerRef.createComponent(TabComponent);
|
||||||
component.instance.title = title;
|
component.instance.title = title;
|
||||||
|
component.instance.path = path;
|
||||||
|
component.instance.ref = component;
|
||||||
|
|
||||||
this.tabs.set(uuid, component)
|
this.tabs.set(uuid, component)
|
||||||
|
|
||||||
return component;
|
return component;
|
||||||
|
@ -40,9 +40,8 @@ body {
|
|||||||
display: flex;
|
display: flex;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
float: left;
|
float: left;
|
||||||
margin-right: 0.5em;
|
margin-right: 2em;
|
||||||
|
font-size: 0.2em;
|
||||||
border-radius: 1em 1em 0em 0em;
|
|
||||||
|
|
||||||
border-top-style: solid;
|
border-top-style: solid;
|
||||||
border-top-color: #ffffff64;
|
border-top-color: #ffffff64;
|
||||||
|
Loading…
Reference in New Issue
Block a user