-
Notifications
You must be signed in to change notification settings - Fork 679
Extract leetcode webview base class & add md settings listener #270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
d4c026f
4c34172
d0ccd53
82ec804
df68b0e
90c9480
9f0999e
85a7164
084e844
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) jdneo. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import { ConfigurationChangeEvent, Disposable, ExtensionContext, ViewColumn, WebviewPanel, window, workspace } from "vscode"; | ||
import { markdownEngine } from "./markdownEngine"; | ||
|
||
export abstract class LeetCodeWebview implements Disposable { | ||
|
||
protected panel: WebviewPanel | undefined; | ||
private context: ExtensionContext; | ||
private listener: Disposable; | ||
|
||
public initialize(context: ExtensionContext): void { | ||
const { onDidChangeConfiguration } = this.getWebviewOption(); | ||
this.context = context; | ||
if (onDidChangeConfiguration) { | ||
this.listener = workspace.onDidChangeConfiguration(onDidChangeConfiguration, this); | ||
} else { | ||
this.listener = workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => { | ||
if (event.affectsConfiguration("markdown") && this.panel) { | ||
this.panel.webview.html = this.getWebviewContent(); | ||
} | ||
}, this); | ||
} | ||
} | ||
|
||
public dispose(): void { | ||
this.listener.dispose(); | ||
if (this.panel) { | ||
this.panel.dispose(); | ||
} | ||
} | ||
|
||
protected showWebviewInternal(): this is { panel: WebviewPanel } { | ||
|
||
if (!this.panel) { | ||
const { viewType, title, viewColumn, onDidReceiveMessage } = this.getWebviewOption(); | ||
|
||
this.panel = window.createWebviewPanel(viewType, title, viewColumn || ViewColumn.One, { | ||
enableScripts: true, | ||
enableCommandUris: true, | ||
enableFindWidget: true, | ||
retainContextWhenHidden: true, | ||
localResourceRoots: markdownEngine.localResourceRoots, | ||
}); | ||
|
||
this.panel.onDidDispose(() => { | ||
this.panel = undefined; | ||
}, null, this.context.subscriptions); | ||
|
||
if (onDidReceiveMessage) { | ||
this.panel.webview.onDidReceiveMessage(onDidReceiveMessage, this, this.context.subscriptions); | ||
} | ||
} | ||
|
||
this.panel.webview.html = this.getWebviewContent(); | ||
return true; | ||
} | ||
|
||
protected abstract getWebviewOption(): ILeetCodeWebviewOption; | ||
|
||
protected abstract getWebviewContent(): string; | ||
} | ||
|
||
export interface ILeetCodeWebviewOption { | ||
viewType: string; | ||
title: string; | ||
viewColumn?: ViewColumn; | ||
onDidReceiveMessage?: (message: any) => Promise<void>; | ||
onDidChangeConfiguration?: (event: ConfigurationChangeEvent) => Promise<void>; | ||
} |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.