Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
sedwards2009 committed Feb 13, 2017
2 parents 979c5aa + c50f616 commit 9caee46
Show file tree
Hide file tree
Showing 30 changed files with 1,652 additions and 571 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ src/config.js
src/configuredialog.js
src/domutils.js
src/gui/checkboxmenuitem.js
src/gui/commandpalette.js
src/gui/contextmenu.js
src/gui/dropdown.js
src/gui/markdownviewer.js
Expand Down Expand Up @@ -80,3 +79,11 @@ src/BulkDOMOperation.js
src/codemirroroperation.ts
src/BulkDOMOperationTest.js
src/SupportsClipboardPaste.js
src/PluginManager.js
src/PluginApi.js
src/InternalExtratermApi.js
src/codemirroroperation.js
src/gui/PopDownDialog.js
src/gui/PopDownListPicker.js
src/gui/PopDownNumberDialog.js
src/plugins/TextViewer/TextViewerPlugin.js
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"shelljs": "0.6.0",
"tsd": "0.6.0-beta.5",
"typedoc": "0.3.12",
"typescript": "2.0.3",
"typescript": "2.1.5",
"webfont": "^4.0.0"
},
"jshintConfig": {
Expand Down
7 changes: 7 additions & 0 deletions src/InternalExtratermApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import PluginApi = require('./PluginApi');

export interface InternalExtratermApi extends PluginApi.ExtratermApi {
setTopLevel(el: HTMLElement): void;
addTab(el: HTMLElement): void;
removeTab(el: HTMLElement): void;
}
28 changes: 28 additions & 0 deletions src/PluginApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2017 Simon Edwards <[email protected]>
*
* This source code is licensed under the MIT license which is detailed in the LICENSE.txt file.
*/

export interface PluginMetaData {
name: string;
factory: string;
}

export interface ElementListener {
(element: HTMLElement): void;
}

export interface ExtratermApi {
addNewTopLevelEventListener(callback: ElementListener): void;
addNewTabEventListener(callback: ElementListener): void;
// registerViewer(): void;
}

export interface ExtratermPluginFactory {
(api: ExtratermApi): ExtratermPlugin;
}

export interface ExtratermPlugin {

}
93 changes: 93 additions & 0 deletions src/PluginManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright 2017 Simon Edwards <[email protected]>
*
* This source code is licensed under the MIT license which is detailed in the LICENSE.txt file.
*/

import fs = require('fs');
import path = require('path');
import Logger = require('./logger');
import PluginApi = require('./PluginApi');

const PLUGIN_METADATA = "metadata.json";

// Partial because people forget to fill in json files correctly.
type PartialPluginMetaData = {
[P in keyof PluginApi.PluginMetaData]?: PluginApi.PluginMetaData[P];
}

interface PluginInfo {
path: string;
name: string;
factoryName: string;
instance: PluginApi.ExtratermPlugin;
}

export class PluginManager {

private _log: Logger = null;

private _pluginDir: string = null;

private _pluginData: PluginInfo[] = [];

constructor(pluginDir: string) {
this._log = new Logger("PluginManager", this);
this._pluginDir = pluginDir;
}

/**
* Load all of the plugins and create instances.
*
* @param api the API instance to pass to the plugins at creation time.
*/
load(api: PluginApi.ExtratermApi): void {
this._pluginData = this._scan(this._pluginDir);

for (const pluginData of this._pluginData) {
const factory = this._loadPlugin(pluginData);
pluginData.instance = factory(api);
}
}

private _loadPlugin(pluginData: PluginInfo): PluginApi.ExtratermPluginFactory {
const factoryPath = path.join(pluginData.path, pluginData.factoryName);
return <PluginApi.ExtratermPluginFactory> require(factoryPath);
}

/**
* Scan a directory for available plugins.
*
* @param pluginDir the directory to scan.
* @return list of plugin info describing what was found.
*/
private _scan(pluginDir: string): PluginInfo[] {
const result: PluginInfo[] = [];

if (fs.existsSync(pluginDir)) {
const contents = fs.readdirSync(pluginDir);
for (const item of contents) {
const metadataPath = path.join(pluginDir, item, PLUGIN_METADATA);

if (fs.existsSync(metadataPath)) {
const metadataString = fs.readFileSync(metadataPath, "UTF8");
try {
const metadata = <PartialPluginMetaData> JSON.parse(metadataString);
if (metadata.name == null || metadata.factory == null) {
this._log.warn(`An error occurred while reading the metadata from ${metadataPath}. It is missing 'name' or 'factory' fields.`);
} else {
result.push( { path: path.join(pluginDir, item), name: metadata.name, factoryName: metadata.factory, instance: null } );
}

} catch(ex) {
this._log.warn(`An error occurred while processing ${metadataPath}.`, ex);
}
} else {
this._log.warn(`Couldn't find a ${PLUGIN_METADATA} file in ${item}. Ignoring.`);
}
}
}
return result;
}
}

4 changes: 2 additions & 2 deletions src/codemirror_extra.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license which is detailed in the LICENSE.txt file.
*/

declare module CodeMirror {
declare namespace CodeMirror {
interface Editor {
on(eventName: 'keyHandled', handler: (instance: CodeMirror.Editor, name: string, event: KeyboardEvent) => void ): void;
off(eventName: 'keyHandled', handler: (instance: CodeMirror.Editor, name: string, event: KeyboardEvent) => void ): void;
Expand All @@ -30,7 +30,7 @@ declare module CodeMirror {
interface Doc {
getSelection(linesep?: string): string;
getSelections(linesep?: string): string[];
setSelections(ranges: {anchor: CodeMirror.Position, head: CodeMirror.Position}[], primary?: number, options?: Object);
setSelections(ranges: {anchor: Position, head: Position}[], primary?: number, options?: Object);
replaceSelections(replacements: string[], select?: 'around' | 'start');
}

Expand Down
4 changes: 2 additions & 2 deletions src/domutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,12 @@ export function getEventDeepPath(ev: Event): Node[] {
export function focusWithoutScroll(el: HTMLElement): void {
const preScrollTops: {element: Element, top: number}[] = [];

let p = el;
let p: Element = el;
do {
preScrollTops.push( { element: p, top: p.scrollTop } );


let parent = p.parentElement;
let parent: Element = p.parentElement;
if (parent == null) {
const nodeParent = p.parentNode;
if (nodeParent != null && nodeParent.nodeName === "#document-fragment") {
Expand Down
18 changes: 4 additions & 14 deletions src/extra_lib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,10 @@ interface CaretPosition {
}

interface DocumentOrShadowRoot {
getSelection(): Selection | null;
elementFromPoint(x: number, y: number): Element | null;
elementsFromPoint(x: number, y: number): NodeListOf<Element>;
caretPositionFromPoint(x: number, y: number): CaretPosition | null;
activeElement: Element | null;
styleSheets: StyleSheetList;
}

interface ShadowRoot extends DocumentFragment, DocumentOrShadowRoot {
host: HTMLElement;
mode: ShadowRootMode;
}

Expand All @@ -44,13 +38,6 @@ interface HTMLSlotElement extends HTMLElement {
assignedNodes(options?: AssignedNodesOptions): NodeList;
}

interface Element {
attachShadow(shadowRootInitDict: ShadowRootInit): ShadowRoot;
assignedSlot: HTMLSlotElement | null;
slot: string;
shadowRoot: ShadowRoot | null;
}

interface Event {
composedPath(): Node[];
}
Expand Down Expand Up @@ -121,10 +108,13 @@ interface KeyboardEventInit {

interface Event {
path: Node[]; // <- obsolete. Removed from later the Shadow DOM spec.
deepPath: Node[];
encapsulated: boolean;
}

interface EventInit {
composed?: boolean;
}

interface Console {
timeStamp(label: string): void;
}
Expand Down
Loading

0 comments on commit 9caee46

Please sign in to comment.