Skip to content

Commit

Permalink
added SessionStateEditor context menu item for creating new objects
Browse files Browse the repository at this point in the history
Change-Id: I98f2e2bf8c2fa55403b0631c31df15b95b55a2d8
  • Loading branch information
adufilie committed Oct 16, 2015
1 parent 6119f30 commit 5a7f1bc
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 7 deletions.
3 changes: 2 additions & 1 deletion WeaveCore/src/weave/core/SessionManager.as
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,12 @@ package weave.core
if (!treeItem.data)
{
treeItem.data = root;
treeItem.label = objectName;
treeItem.children = getTreeItemChildren;
// dependency is used to determine when to recalculate children array
treeItem.dependency = root is ILinkableHashMap ? (root as ILinkableHashMap).childListCallbacks : root;
}
if (objectName)
treeItem.label = objectName;
return treeItem;
}

Expand Down
15 changes: 14 additions & 1 deletion WeaveUI/src/weave/ui/SessionNavigator.as
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,24 @@ package weave.ui
return WeaveAPI.getPath(getSelectedLinkableObject());
}

public function setSelectedLinkableObject(object:ILinkableObject):void
{
if (object)
{
var tree:WeaveTreeItem = (WeaveAPI.SessionManager as SessionManager).getSessionStateTree(object, null);
scrollToAndSelectMatchingItem(tree);
expandItem(tree, true);
setFocus();
}
else
selectedItem = null;
}

public function getSelectedLinkableObject():ILinkableObject
{
return selectedTreeItem ? selectedTreeItem.data as ILinkableObject : null;
}


[Bindable("change")]
[Bindable("valueCommit")]
override public function get selectedItem():Object
Expand Down
77 changes: 72 additions & 5 deletions WeaveUI/src/weave/ui/SessionStateEditor.mxml
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ A text editor to change the Session State on the fly.
</mx:VDividedBox>
<mx:Script>
<![CDATA[
import avmplus.getQualifiedClassName;
import flash.desktop.Clipboard;
import flash.desktop.ClipboardFormats;
import mx.binding.utils.BindingUtils;
import mx.collections.ArrayCollection;
import mx.containers.VBox;
import mx.controls.Alert;
import mx.controls.dataGridClasses.DataGridColumn;
import mx.core.INavigatorContent;
Expand All @@ -119,6 +120,7 @@ A text editor to change the Session State on the fly.
import weave.Weave;
import weave.api.core.DynamicState;
import weave.api.core.ILinkableCompositeObject;
import weave.api.core.ILinkableDynamicObject;
import weave.api.core.ILinkableHashMap;
import weave.api.core.ILinkableObject;
Expand All @@ -133,15 +135,17 @@ A text editor to change the Session State on the fly.
import weave.api.setSessionState;
import weave.compiler.Compiler;
import weave.core.ClassUtils;
import weave.core.LinkableCallbackScript;
import weave.core.LinkableDynamicObject;
import weave.core.LinkableHashMap;
import weave.core.LinkableString;
import weave.core.LinkableSynchronizer;
import weave.core.StageUtils;
import weave.core.WeaveXMLDecoder;
import weave.core.WeaveXMLEncoder;
import weave.data.AttributeColumns.DynamicColumn;
import weave.data.AttributeColumns.ExtendedDynamicColumn;
import weave.menus.WeaveContextMenu;
import weave.menus.WeaveMenuItem;
import weave.primitives.WeaveTreeItem;
import weave.utils.ColumnUtils;
import weave.utils.DebugUtils;
Expand Down Expand Up @@ -214,18 +218,81 @@ A text editor to change the Session State on the fly.
shown: isObjectSelected,
label: lang('Link session state with another object'),
click: linkStatePath
}, {
},
WeaveMenuItem.TYPE_SEPARATOR,
{
shown: isObjectSelected,
label: lang('Watch selected object'),
click: function():void { DebugUtils.watch(sessionNav.getSelectedLinkableObject()); }
enabled: function():Boolean {
return sessionNav.getSelectedLinkableObject() is ILinkableCompositeObject;
},
label: lang('New object...'),
click: function():void {
var parent:ILinkableObject = sessionNav.getSelectedLinkableObject();
AlertTextBox.show(
"Create new object",
"Enter the object type",
"",
function(className:String):Boolean {
try {
return Compiler.getDefinition(className) != null;
} catch (e:Error) { }
return false;
},
function(className:String):void {
callLater(newObject, [parent, Compiler.getDefinition(className)]);
}
);
}
}, {
shown: isObjectSelected,
label: lang('Delete selected object'),
click: deleteSelectedItem
},
WeaveMenuItem.TYPE_SEPARATOR,
{
shown: isObjectSelected,
label: lang('Watch selected object'),
click: function():void { DebugUtils.watch(sessionNav.getSelectedLinkableObject()); }
}
]);
}
private function newObject(parent:ILinkableObject, classDef:Class):void
{
var className:String = getQualifiedClassName(classDef).split('::').pop();
if (parent is ILinkableDynamicObject)
{
var newObject:ILinkableObject = (parent as ILinkableDynamicObject).requestLocalObject(classDef, false);
if (newObject)
sessionNav.setSelectedLinkableObject(newObject);
else
reportError("Unable to create new " + className);
return;
}
var ilh:ILinkableHashMap = parent as ILinkableHashMap;
if (!ilh)
{
reportError("Cannot create object under parent of type " + getQualifiedClassName(parent));
return;
}
AlertTextBox.show(
"Create new object",
"Enter the name of the new " + className,
ilh.generateUniqueName(className),
null,
function(name:String):void
{
var newObject:ILinkableObject = ilh.requestObject(name, classDef, false);
if (newObject)
sessionNav.setSelectedLinkableObject(newObject);
else
reportError("Unable to create new " + className);
}
);
}
private function isObjectSelected():Boolean
{
return sessionNav.getSelectedLinkableObject() != null;
Expand Down

0 comments on commit 5a7f1bc

Please sign in to comment.