Browse Source

Some more TypeScript Sketches

Josh Engebretson 10 years ago
parent
commit
107f4acd06

+ 20 - 49
Data/AtomicEditor/Resources/EditorData/AtomicEditor/typescript/ui/MainFrame.ts

@@ -1,8 +1,9 @@
 
 import strings = require("./EditorStrings");
 import menubar = require("./MainFrameMenu");
+import scriptwidget = require("./ScriptWidget");
 
-export class MainFrame extends Atomic.UIWidget {
+export class MainFrame extends scriptwidget.ScriptWidget {
 
 	constructor(view: Atomic.UIView, width: number, height: number) {
 
@@ -12,79 +13,49 @@ export class MainFrame extends Atomic.UIWidget {
 
 		this.setSize(width, height);
 
-		this.subscribeToEvent(this, "WidgetEvent", function(data) {
-			
-			// this no longer refers to this MainFrame, 
-			// instead it is the this of the function call 
-			// look into fixing this
-
-			if (data.handler.handleMenuBarEvent(data)) return true;
-
-			return false;
-
-		});
-
 	}
 
-	handlePopupMenu(data): boolean {
-
-		var target = data.target;
-
-		if (target && target.id == "menu atomic editor popup") {
-
-			if (data.refid == "quit") {
-
-				// todo, send a request for file saves, etc
-				Atomic.getEngine().exit();
-
-				return true;
-
-			}
-
-		}
+	onEventClick(target: Atomic.UIWidget, refid: string): void {
 
-		if (target && target.id == "menu edit popup") {
+		if (this.handlePopupMenu(target, refid))
+			return;
 
-			if (data.refid == "edit play") {
+		var src = menubar.getMenuItemSource(target.id);
 
-				new ToolCore.PlayCmd().run();
+		if (src) {
 
-				return true;
-
-			}
+			var menu = new Atomic.UIMenuWindow(target, target.id + " popup");
+			menu.show(src);
 
 		}
 
-
 	}
 
-	handleMenuBarEvent(data): boolean {
 
-		if (this.handlePopupMenu(data))
-			return true;
+	handlePopupMenu(target: Atomic.UIWidget, refid: string): boolean {
 
-		if (data.type == Atomic.UI.EVENT_TYPE_CLICK) {
+		if (target.id == "menu atomic editor popup") {
 
-			//if (mainframe.handleMenuAtomicEditor(data)) return true;
+			if (refid == "quit")
+				Atomic.getEngine().exit();
 
-			var target = data.target;
+		}
 
-			var src = menubar.getMenuItemSource(target.id);
+		if (target.id == "menu edit popup") {
 
-			if (src) {
+			if (refid == "edit play") {
 
-				var menu = new Atomic.UIMenuWindow(target, target.id + " popup");
-				menu.show(src);
+				new ToolCore.PlayCmd().run();
 				return true;
 
 			}
 
-		}
-
-		return false;
+			return false;
 
+		}
 	}
 
+	// override example	
 	setSize(width: number, height: number): void {
 
 		super.setSize(width, height);

+ 31 - 20
Data/AtomicEditor/Resources/EditorData/AtomicEditor/typescript/ui/MainFrameMenu.ts

@@ -6,40 +6,51 @@ var UIMenuItem = Atomic.UIMenuItem;
 
 var StringID = strings.StringID;
 
+var editorItems = {
+  "About Atomic Editor": "about atomic editor",
+  "-1": null,
+  "Manage License": "manage license",
+  "-2": null,
+  "Check for Updates": "check update",
+  "-3": null,
+  "Quit": "quit"
+};
+
 var editItems = {
 
-  "Undo" : ["edit undo", StringID.ShortcutUndo],
-  "Redo" : ["edit redo", StringID.ShortcutRedo],
-  "-1" : null,
-  "Cut" : ["edit cut", StringID.ShortcutCut],
-  "Copy" : ["edit copy", StringID.ShortcutCopy],
-  "Paste" : ["edit paste", StringID.ShortcutPaste],
-  "Select All" : ["edit select all", StringID.ShortcutSelectAll],
-  "-2" : null,
-  "Find" : ["edit find", StringID.ShortcutFind],
-  "Find Next" : ["edit find next", StringID.ShortcutFindNext],
-  "Find Prev" : ["edit find prev", StringID.ShortcutFindPrev],
-  "-3" : null,
-  "Format Code" : ["edit format code", StringID.ShortcutBeautify],
-  "-4" : null,
-  "Play" : ["edit play", StringID.ShortcutPlay]
-  
+  "Undo": ["edit undo", StringID.ShortcutUndo],
+  "Redo": ["edit redo", StringID.ShortcutRedo],
+  "-1": null,
+  "Cut": ["edit cut", StringID.ShortcutCut],
+  "Copy": ["edit copy", StringID.ShortcutCopy],
+  "Paste": ["edit paste", StringID.ShortcutPaste],
+  "Select All": ["edit select all", StringID.ShortcutSelectAll],
+  "-2": null,
+  "Find": ["edit find", StringID.ShortcutFind],
+  "Find Next": ["edit find next", StringID.ShortcutFindNext],
+  "Find Prev": ["edit find prev", StringID.ShortcutFindPrev],
+  "-3": null,
+  "Format Code": ["edit format code", StringID.ShortcutBeautify],
+  "-4": null,
+  "Play": ["edit play", StringID.ShortcutPlay]
+
 };
 
 var srcLookup = {};
 
+srcLookup["menu atomic editor"] = createMenuItemSource(editorItems);
 srcLookup["menu edit"] = createMenuItemSource(editItems);
 
-export function getMenuItemSource(id:string):Atomic.UIMenuItemSource {
-  return srcLookup[id];  
+export function getMenuItemSource(id: string): Atomic.UIMenuItemSource {
+  return srcLookup[id];
 }
 
-function createMenuItemSource(items:any):Atomic.UIMenuItemSource {
+function createMenuItemSource(items: any): Atomic.UIMenuItemSource {
 
   var src = new UIMenuItemSource();
 
   for (var key in items) {
-    
+
     if (items.hasOwnProperty(key)) {
 
       var value = items[key];

+ 36 - 0
Data/AtomicEditor/Resources/EditorData/AtomicEditor/typescript/ui/ScriptWidget.ts

@@ -0,0 +1,36 @@
+
+
+export class ScriptWidget extends Atomic.UIWidget {
+
+	constructor() {
+
+		super();
+		
+		// JS way of binding method
+		// this.subscribeToEvent(this, "WidgetEvent", this.handleWidgetEvent.bind(this));
+		
+		// TypeScript-ey
+		this.subscribeToEvent(this, "WidgetEvent", (data) => this.handleWidgetEvent(data));
+
+	}
+
+	onEventClick(target: Atomic.UIWidget, refid: string): void {
+
+	}
+
+
+	handleWidgetEvent(data): boolean {
+
+		if (data.type == Atomic.UI.EVENT_TYPE_CLICK) {
+
+			this.onEventClick(data.target, data.refid);
+
+			return true;
+
+		}
+
+		return false;
+
+	}
+
+}