Skip to content

Commit

Permalink
Central pane-renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
OfekShilon committed Aug 17, 2024
1 parent 4f57931 commit 7c96e66
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions static/event-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export type EventMap = {
ppViewClosed: (compilerId: number) => void;
ppViewOpened: (compilerId: number) => void;
ppViewOptionsUpdated: (compilerId: number, options: PPOptions, recompile: boolean) => void;
renamePane: () => void;
requestCompilation: (editorId: number | boolean, treeId: boolean | number) => void;
requestMotd: () => void;
requestSettings: () => void;
Expand Down
2 changes: 1 addition & 1 deletion static/panes/ast-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class Ast extends MonacoPane<monaco.editor.IStandaloneCodeEditor, AstStat
this.editor.onMouseMove(e => mouseMoveThrottledFunction(e));

this.fontScale.on('change', this.updateState.bind(this));
this.paneRenaming.on('renamePane', this.updateState.bind(this));
this.eventHub.on('renamePane', this.updateState.bind(this));

this.container.on('destroy', this.close, this);

Expand Down
4 changes: 2 additions & 2 deletions static/panes/conformance-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class Conformance extends Pane<ConformanceViewState> {

this.stateByLang = {};

this.paneRenaming = new PaneRenaming(this, state);
this.paneRenaming = new PaneRenaming(this, state, hub);

this.initButtons();
this.initCallbacks();
Expand Down Expand Up @@ -174,7 +174,7 @@ export class Conformance extends Pane<ConformanceViewState> {
if (this.compilerInfo.editorId) this.eventHub.emit('conformanceViewClose', this.compilerInfo.editorId);
});

this.paneRenaming.on('renamePane', this.saveState.bind(this));
this.eventHub.on('renamePane', this.saveState.bind(this));

this.container.on('destroy', this.close, this);
this.container.on('open', () => {
Expand Down
4 changes: 2 additions & 2 deletions static/panes/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class Executor extends Pane<ExecutorState> {
this.options = state.options || options.compileOptions[this.currentLangId];
this.executionArguments = state.execArgs || '';
this.executionStdin = state.execStdin || '';
this.paneRenaming = new PaneRenaming(this, state);
this.paneRenaming = new PaneRenaming(this, state, this.hub);
}

override getInitialHTML(): string {
Expand Down Expand Up @@ -909,7 +909,7 @@ export class Executor extends Pane<ExecutorState> {
initListeners(): void {
// this.filters.on('change', this.onFilterChange.bind(this));
this.fontScale.on('change', this.onFontScale.bind(this));
this.paneRenaming.on('renamePane', this.updateState.bind(this));
this.eventHub.on('renamePane', this.updateState.bind(this));
this.toggleWrapButton.on('change', this.onToggleWrapChange.bind(this));

this.container.on('destroy', this.close, this);
Expand Down
2 changes: 1 addition & 1 deletion static/panes/ir-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export class Ir extends MonacoPane<monaco.editor.IStandaloneCodeEditor, IrState>
const onMouseMove = _.throttle(this.onMouseMove.bind(this), 50);
const onDidChangeCursorSelection = _.throttle(this.onDidChangeCursorSelection.bind(this), 500);

this.paneRenaming.on('renamePane', this.updateState.bind(this));
this.eventHub.on('renamePane', this.updateState.bind(this));

this.eventHub.on('compileResult', this.onCompileResult.bind(this));
this.eventHub.on('colours', this.onColours.bind(this));
Expand Down
4 changes: 2 additions & 2 deletions static/panes/pane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export abstract class Pane<S> {
this.initializeCompilerInfo(state);
this.topBar = this.domRoot.find('.top-bar');

this.paneRenaming = new PaneRenaming(this, state);
this.paneRenaming = new PaneRenaming(this, state, hub);

this.initializeDefaults();
this.initializeGlobalDependentProperties();
Expand Down Expand Up @@ -200,7 +200,7 @@ export abstract class Pane<S> {

/** Initialize standard lifecycle hooks */
protected registerStandardCallbacks(): void {
this.paneRenaming.on('renamePane', this.updateState.bind(this));
this.eventHub.on('renamePane', this.updateState.bind(this));
this.container.on('destroy', this.close.bind(this));
this.container.on('resize', this.resize.bind(this));
this.eventHub.on('compileResult', this.onCompileResult.bind(this));
Expand Down
11 changes: 6 additions & 5 deletions static/widgets/pane-renaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@

import $ from 'jquery';
import {Tab} from 'golden-layout';
import {EventEmitter} from 'events';
import {Alert} from './alert.js';
import {Hub} from '../hub.js';

export class PaneRenaming extends EventEmitter.EventEmitter {
export class PaneRenaming {
private pane: any;
private alertSystem: any;
private state: any;
private hub: Hub;

constructor(pane: any, state: any) {
super();
constructor(pane: any, state: any, hub: Hub) {
this.pane = pane;
this.alertSystem = this.pane.alertSystem ?? new Alert();
this.state = state;
this.hub = hub;

this.loadSavedPaneName();
this.registerCallbacks();
Expand Down Expand Up @@ -69,7 +70,7 @@ export class PaneRenaming extends EventEmitter.EventEmitter {
// Update title and emit event to save it into the state
this.pane.paneName = value;
this.pane.updateTitle();
this.emit('renamePane');
this.hub.layout.eventHub.emit('renamePane');
},
yesClass: 'btn btn-primary',
yesHtml: 'Rename',
Expand Down

0 comments on commit 7c96e66

Please sign in to comment.