Skip to content

Commit

Permalink
Complete Compiler Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarTawfik committed Dec 3, 2018
1 parent d44f37e commit f479e14
Show file tree
Hide file tree
Showing 169 changed files with 9,939 additions and 2,303 deletions.
1 change: 0 additions & 1 deletion .gitignore
@@ -1,6 +1,5 @@
# VS files
.vs/
.vscode/
*.csproj.user

# Binary files
Expand Down
8 changes: 8 additions & 0 deletions .vscode/launch.json
@@ -0,0 +1,8 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
@@ -0,0 +1,3 @@
{
"dotnet-test-explorer.testProjectPath": "./Source/Tests"
}
5 changes: 5 additions & 0 deletions .vscode/tasks.json
@@ -0,0 +1,5 @@
{
"version": "2.0.0",
"tasks": [
]
}
File renamed without changes.
File renamed without changes.
74 changes: 74 additions & 0 deletions Source/Client/Interop/CSInteropTypes.Generated.ts
@@ -0,0 +1,74 @@
/*!
* Copyright (c) 2018 Omar Tawfik. All rights reserved. Licensed under the MIT License. See LICENSE file in the project root for license information.
*/

/// <summary>
/// This file is auto-generated by a build task. It shouldn't be edited by hand.
/// </summary>

// Definition of this file is not published yet to somewhere we can consume. Declare for now:
// https://github.com/aspnet/Blazor/issues/1452
// https://github.com/aspnet/Blazor/blob/0.5.1/src/Microsoft.JSInterop/JavaScriptRuntime/src/Microsoft.JSInterop.ts
export declare module DotNet {
function invokeMethodAsync<T>(assemblyName: string, methodIdentifier: string, ...args: any[]): Promise<T>;
}

export module CSIntrop {
export module Graphics {
export function notifyButtonClicked(buttonName: string): Promise<void> {
return DotNet.invokeMethodAsync<boolean>("SuperBasic.Editor", "CSIntrop.Graphics.NotifyButtonClicked", buttonName).then(() => {
Promise.resolve();
});
}

export function notifyTextBoxControlEntry(textBoxName: string): Promise<void> {
return DotNet.invokeMethodAsync<boolean>("SuperBasic.Editor", "CSIntrop.Graphics.NotifyTextBoxControlEntry", textBoxName).then(() => {
Promise.resolve();
});
}

export function notifyGraphicsWindowTextEntry(keyCode: number): Promise<void> {
return DotNet.invokeMethodAsync<boolean>("SuperBasic.Editor", "CSIntrop.Graphics.NotifyGraphicsWindowTextEntry", keyCode).then(() => {
Promise.resolve();
});
}

export function notifyKeyDown(keyCode: number): Promise<void> {
return DotNet.invokeMethodAsync<boolean>("SuperBasic.Editor", "CSIntrop.Graphics.NotifyKeyDown", keyCode).then(() => {
Promise.resolve();
});
}

export function notifyKeyUp(keyCode: number): Promise<void> {
return DotNet.invokeMethodAsync<boolean>("SuperBasic.Editor", "CSIntrop.Graphics.NotifyKeyUp", keyCode).then(() => {
Promise.resolve();
});
}

export function notifyMouseDown(x: number, y: number): Promise<void> {
return DotNet.invokeMethodAsync<boolean>("SuperBasic.Editor", "CSIntrop.Graphics.NotifyMouseDown", x, y).then(() => {
Promise.resolve();
});
}

export function notifyMouseMove(x: number, y: number): Promise<void> {
return DotNet.invokeMethodAsync<boolean>("SuperBasic.Editor", "CSIntrop.Graphics.NotifyMouseMove", x, y).then(() => {
Promise.resolve();
});
}

export function notifyMouseUp(x: number, y: number): Promise<void> {
return DotNet.invokeMethodAsync<boolean>("SuperBasic.Editor", "CSIntrop.Graphics.NotifyMouseUp", x, y).then(() => {
Promise.resolve();
});
}
}

export module File {
export function reportFileError(error: string): Promise<void> {
return DotNet.invokeMethodAsync<boolean>("SuperBasic.Editor", "CSIntrop.File.ReportFileError", error).then(() => {
Promise.resolve();
});
}
}
}
229 changes: 229 additions & 0 deletions Source/Client/Interop/ControlsInterop.ts
@@ -0,0 +1,229 @@

/*!
* Copyright (c) 2018 Omar Tawfik. All rights reserved. Licensed under the MIT License. See LICENSE file in the project root for license information.
*/

import { IControlsInterop } from "./JSInteropTypes.Generated";
import { CSIntrop } from "./CSInteropTypes.Generated";

export class ControlsInterop implements IControlsInterop {
private container: HTMLElement | null = null;

private buttonCounter: number = 0;
private buttons: { [key: string]: HTMLButtonElement } = {};

private textBoxCounter: number = 0;
private textBoxes: { [key: string]: HTMLInputElement | HTMLTextAreaElement } = {};

public initialize(containerId: string): Promise<void> {
this.container = document.getElementById(containerId);

if (!this.container) {
throw new Error(`Container element with id '${containerId} not found`);
}

this.buttonCounter = 0;
this.buttons = {};

this.textBoxCounter = 0;
this.textBoxes = {};

return Promise.resolve();
}

public dispose(): Promise<void> {
this.clear();

this.container = null;
this.buttonCounter = 0;
this.textBoxCounter = 0;

return Promise.resolve();
}

public addButton(caption: string, left: number, top: number): Promise<string> {
if (!this.container) {
throw new Error("ControlsInterop not initialized.");
}

const name = "Button" + (++this.buttonCounter);
const containerRect = this.container.getBoundingClientRect();

const button = document.createElement("button");
button.textContent = caption;

button.style.position = "absolute";
button.style.top = (top + containerRect.top) + "px";
button.style.left = (left + containerRect.left) + "px";

this.buttons[name] = button;
this.container.appendChild(button);

button.addEventListener("click", () => {
CSIntrop.Graphics.notifyButtonClicked(name);
});

button.addEventListener("mouseenter", () => {
if (!this.container) {
throw new Error("ControlsInterop not initialized.");
}

this.container.style.cursor = "pointer";
});

button.addEventListener("mouseleave", () => {
if (!this.container) {
throw new Error("ControlsInterop not initialized.");
}

this.container.style.cursor = "default";
});

return Promise.resolve(name);
}

public addTextBox(isMultiLine: boolean, left: number, top: number): Promise<string> {
if (!this.container) {
throw new Error("ControlsInterop not initialized.");
}

const name = "TextBox" + (++this.textBoxCounter);
const boundingRect = this.container.getBoundingClientRect();

let inputElement: HTMLInputElement | HTMLTextAreaElement;
if (isMultiLine) {
inputElement = <any>document.createElement("textarea");
} else {
inputElement = document.createElement("input");
inputElement.type = "text";
}

inputElement.value = "";

inputElement.style.position = "absolute";
inputElement.style.top = (top + boundingRect.top) + "px";
inputElement.style.left = (left + boundingRect.left) + "px";
inputElement.style.width = "160px";

this.textBoxes[name] = inputElement;
this.container.appendChild(inputElement);

inputElement.addEventListener("keydown", () => {
CSIntrop.Graphics.notifyTextBoxControlEntry(name);
});

return Promise.resolve(name);
}

public getButtonCaption(buttonName: string): Promise<string> {
const button = this.buttons[buttonName];
return Promise.resolve(button ? (button.textContent || "") : "");
}

public getTextBoxText(textBoxName: string): Promise<string> {
const textBox = this.textBoxes[textBoxName];
return Promise.resolve(textBox ? textBox.value : "");
}

public hideControl(controlName: string): Promise<void> {
const control = this.buttons[controlName] || this.textBoxes[controlName];
if (control) {
control.style.visibility = "hidden";
}

return Promise.resolve();
}

public moveControl(controlName: string, x: number, y: number): Promise<void> {
if (!this.container) {
throw new Error("ControlsInterop not initialized.");
}

const control = this.buttons[controlName] || this.textBoxes[controlName];
if (control) {
const containerRect = this.container.getBoundingClientRect();

control.style.left = (x + containerRect.left) + "px";
control.style.top = (y + containerRect.top) + "px";
}

return Promise.resolve();
}

public removeControl(controlName: string): Promise<void> {
if (!this.container) {
throw new Error("ControlsInterop not initialized.");
}

const control = this.buttons[controlName] || this.textBoxes[controlName];
if (control) {
if (control.parentElement) {
control.parentElement.removeChild(control);
}

delete this.buttons[controlName];
delete this.textBoxes[controlName];
}

return Promise.resolve();
}

public setButtonCaption(buttonName: string, caption: string): Promise<void> {
const button = this.buttons[buttonName];
if (button) {
button.textContent = caption;
}

return Promise.resolve();
}

public setTextBoxText(textBoxName: string, text: string): Promise<void> {
const textBox = this.textBoxes[textBoxName];
if (textBox) {
textBox.value = text;
}

return Promise.resolve();
}

public setSize(controlName: string, width: number, height: number): Promise<void> {
const control = this.buttons[controlName] || this.textBoxes[controlName];
if (control) {
control.style.height = height + "px";
control.style.width = width + "px";
}

return Promise.resolve();
}

public showControl(controlName: string): Promise<void> {
const control = this.buttons[controlName] || this.textBoxes[controlName];
if (control) {
control.style.visibility = "visible";
}

return Promise.resolve();
}

public getHeight(): Promise<number> {
if (!this.container) {
throw new Error("GraphicsInterop not initialized");
}

return Promise.resolve(this.container.getBoundingClientRect().height);
}

public getWidth(): Promise<number> {
if (!this.container) {
throw new Error("GraphicsInterop not initialized");
}

return Promise.resolve(this.container.getBoundingClientRect().width);
}

public clear(): Promise<void> {
Object.keys(this.buttons).forEach(this.removeControl);
Object.keys(this.textBoxes).forEach(this.removeControl);
return Promise.resolve();
}
}
26 changes: 26 additions & 0 deletions Source/Client/Interop/DesktopInterop.ts
@@ -0,0 +1,26 @@
/*!
* Copyright (c) 2018 Omar Tawfik. All rights reserved. Licensed under the MIT License. See LICENSE file in the project root for license information.
*/

import { IDesktopInterop } from "./JSInteropTypes.Generated";
import { INativeApis } from "../Native/NativeApis.Interfaces";

const NativeApis: INativeApis = require("NativeApis");

export class DesktopInterop implements IDesktopInterop {
public getHeight(): Promise<number> {
return NativeApis.desktop.getHeight();
}

public getWidth(): Promise<number> {
return NativeApis.desktop.getWidth();
}

public setWallPaperFromFile(filePath: string): Promise<void> {
return NativeApis.desktop.setWallPaperFromFile(filePath);
}

public setWallPaperFromUrl(url: string): Promise<void> {
return NativeApis.desktop.setWallPaperFromUrl(url);
}
}

0 comments on commit f479e14

Please sign in to comment.