guanghuispark
3 年前
当前提交
cf9944aa
共有 13 个文件被更改,包括 1217 次插入 和 101 次删除
-
7com.unity.uiwidgets.devtools/Editor/v2/main.cs
-
21com.unity.uiwidgets.devtools/Editor/v2/src/inspector/diagnostics_node.cs
-
243com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_controller.cs
-
112com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_screen.cs
-
305com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_service.cs
-
141com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_tree.cs
-
197com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_tree_flutter.cs
-
1com.unity.uiwidgets.devtools/Editor/v2/src/theme.cs
-
13com.unity.uiwidgets/Runtime/widgets/ticker_provider.cs
-
10com.unity.uiwidgets.devtools/Editor/v2/src/ui/colors.cs
-
187com.unity.uiwidgets.devtools/Editor/v2/src/ui/icons.cs
-
81com.unity.uiwidgets.devtools/Editor/v2/src/ui/label.cs
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel; |
|||
using Unity.UIWidgets.async; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.widgets; |
|||
// public class ObjectGroup
|
|||
// {
|
|||
// public ObjectGroup(
|
|||
// string debugName,
|
|||
// InspectorService inspectorService
|
|||
// )
|
|||
// {
|
|||
// groupName = $"{debugName}_${InspectorService.nextGroupId}";
|
|||
// InspectorService.nextGroupId++;
|
|||
// }
|
|||
//
|
|||
// /// Object group all objects in this arena are allocated with.
|
|||
// public readonly string groupName;
|
|||
// public readonly InspectorService inspectorService;
|
|||
// bool disposed = false;
|
|||
// }
|
|||
|
|||
public enum FlutterTreeType { |
|||
widget, |
|||
renderObject |
|||
|
|||
} |
|||
|
|||
public class ObjectGroup |
|||
{ |
|||
public ObjectGroup( |
|||
string debugName, |
|||
InspectorService inspectorService |
|||
) |
|||
{ |
|||
groupName = $"{debugName}_${InspectorService.nextGroupId}"; |
|||
InspectorService.nextGroupId++; |
|||
|
|||
} |
|||
|
|||
/// Object group all objects in this arena are allocated with.
|
|||
public readonly string groupName; |
|||
public readonly InspectorService inspectorService; |
|||
public bool disposed = false; |
|||
|
|||
public Future dispose() { |
|||
// var disposeComplete = invokeVoidServiceMethod("disposeGroup", groupName);
|
|||
// disposed = true;
|
|||
// return disposeComplete;
|
|||
return new SynchronousFuture(null); |
|||
} |
|||
|
|||
|
|||
public Future<RemoteDiagnosticsNode> getRoot(FlutterTreeType type) { |
|||
// There is no excuse to call this method on a disposed group.
|
|||
D.assert(!disposed); |
|||
switch (type) { |
|||
case FlutterTreeType.widget: |
|||
return getRootWidget(); |
|||
case FlutterTreeType.renderObject: |
|||
return getRootRenderObject(); |
|||
} |
|||
throw new Exception("Unexpected FlutterTreeType"); |
|||
} |
|||
|
|||
public RemoteDiagnosticsNode _getRoot(FlutterTreeType type) { |
|||
// There is no excuse to call this method on a disposed group.
|
|||
D.assert(!disposed); |
|||
switch (type) { |
|||
case FlutterTreeType.widget: |
|||
return _getRootWidget(); |
|||
case FlutterTreeType.renderObject: |
|||
return null; |
|||
} |
|||
throw new Exception("Unexpected FlutterTreeType"); |
|||
} |
|||
|
|||
RemoteDiagnosticsNode _getRootWidget() { |
|||
// return invokeServiceMethodReturningNode('getRootWidgetSummaryTree');
|
|||
|
|||
Dictionary<string, object> widgetTree = new Dictionary<string, object>(); |
|||
widgetTree["hasChildren"] = true; |
|||
widgetTree["name"] = "inspector"; |
|||
widgetTree["children"] = new List<Widget>() |
|||
{ |
|||
new Text("text1"), |
|||
new Text("text2"), |
|||
new Text("text3"), |
|||
new Text("text4"), |
|||
new Text("text5"), |
|||
}; |
|||
widgetTree["properties"] = new List<object>() |
|||
{ |
|||
"properties_1", |
|||
"properties_2", |
|||
"properties_3", |
|||
"properties_4", |
|||
"properties_5", |
|||
}; |
|||
return new RemoteDiagnosticsNode(widgetTree, |
|||
inspectorService: FutureOr.value(inspectorService), |
|||
true, |
|||
null); |
|||
} |
|||
|
|||
|
|||
Future<RemoteDiagnosticsNode> getRootWidget() { |
|||
// return invokeServiceMethodReturningNode('getRootWidgetSummaryTree');
|
|||
|
|||
Dictionary<string, object> widgetTree = new Dictionary<string, object>(); |
|||
widgetTree["children"] = new List<Widget>() |
|||
{ |
|||
new Text("text1"), |
|||
new Text("text2"), |
|||
new Text("text3"), |
|||
new Text("text4"), |
|||
new Text("text5"), |
|||
}; |
|||
widgetTree["properties"] = new List<object>() |
|||
{ |
|||
"properties_1", |
|||
"properties_2", |
|||
"properties_3", |
|||
"properties_4", |
|||
"properties_5", |
|||
}; |
|||
return Future.value(FutureOr.value(new RemoteDiagnosticsNode(widgetTree, |
|||
inspectorService: FutureOr.value(inspectorService), |
|||
true, |
|||
null))).to<RemoteDiagnosticsNode>(); |
|||
} |
|||
|
|||
|
|||
Future<RemoteDiagnosticsNode> getRootRenderObject() |
|||
{ |
|||
return Future.value(FutureOr.value(null)).to<RemoteDiagnosticsNode>(); |
|||
} |
|||
|
|||
|
|||
public Future<RemoteDiagnosticsNode> getDetailsSubtree( |
|||
RemoteDiagnosticsNode node, |
|||
int subtreeDepth = 2 |
|||
) { |
|||
if (node == null) return null; |
|||
// var args = new Dictionary<string,object>(){
|
|||
// {"objectGroup", groupName},
|
|||
// {"arg", node.dartDiagnosticRef.id},
|
|||
// {"subtreeDepth", subtreeDepth.ToString()},
|
|||
// };
|
|||
// return parseDiagnosticsNodeDaemon(invokeServiceMethodDaemonParams(
|
|||
// "getDetailsSubtree",
|
|||
// args
|
|||
// ));
|
|||
return Future.value(FutureOr.value("enpty")).to<RemoteDiagnosticsNode>(); |
|||
} |
|||
|
|||
} |
|||
|
|||
class InspectorObjectGroupManager { |
|||
public InspectorObjectGroupManager( |
|||
InspectorService inspectorService, |
|||
string debugName) |
|||
{ |
|||
this.inspectorService = inspectorService; |
|||
this.debugName = debugName; |
|||
} |
|||
|
|||
public InspectorService inspectorService; |
|||
public string debugName; |
|||
ObjectGroup _current; |
|||
ObjectGroup _next; |
|||
|
|||
Completer _pendingNext; |
|||
|
|||
// Future<void> pendingUpdateDone {
|
|||
// if (_pendingNext != null) {
|
|||
// return _pendingNext.future;
|
|||
// }
|
|||
// if (_next == null) {
|
|||
// // There is no pending update.
|
|||
// return Future.value();
|
|||
// }
|
|||
//
|
|||
// _pendingNext = Completer();
|
|||
// return _pendingNext.future;
|
|||
// }
|
|||
//
|
|||
public ObjectGroup current { |
|||
get |
|||
{ |
|||
// _current ??= inspectorService.createObjectGroup(debugName);
|
|||
return _current; |
|||
} |
|||
|
|||
} |
|||
|
|||
public ObjectGroup next { |
|||
get |
|||
{ |
|||
// _next ??= inspectorService.createObjectGroup(debugName);
|
|||
return _next; |
|||
} |
|||
|
|||
} |
|||
//
|
|||
// void clear(bool isolateStopped) {
|
|||
// if (isolateStopped) {
|
|||
// // The Dart VM will handle GCing the underlying memory.
|
|||
// _current = null;
|
|||
// _setNextNull();
|
|||
// } else {
|
|||
// clearCurrent();
|
|||
// cancelNext();
|
|||
// }
|
|||
// }
|
|||
|
|||
public void promoteNext() { |
|||
clearCurrent(); |
|||
_current = _next; |
|||
_setNextNull(); |
|||
} |
|||
|
|||
void clearCurrent() { |
|||
if (_current != null) { |
|||
_current.dispose(); |
|||
_current = null; |
|||
} |
|||
} |
|||
|
|||
public void cancelNext() { |
|||
if (_next != null) { |
|||
_next.dispose(); |
|||
_setNextNull(); |
|||
} |
|||
} |
|||
|
|||
void _setNextNull() { |
|||
_next = null; |
|||
if (_pendingNext != null) { |
|||
_pendingNext.complete(); |
|||
_pendingNext = null; |
|||
} |
|||
} |
|||
} |
|||
|
|||
public class InspectorService |
|||
{ |
|||
|
|||
public static int nextGroupId = 0; |
|||
public Future<string> inferPubRootDirectoryIfNeeded() |
|||
{ |
|||
var group = createObjectGroup("temp"); |
|||
var root = group.getRoot(FlutterTreeType.widget); |
|||
return Future.value("aaa").to<string>(); |
|||
} |
|||
|
|||
ObjectGroup createObjectGroup(string debugName) { |
|||
return new ObjectGroup(debugName, this); |
|||
} |
|||
|
|||
// static Future<InspectorService> create(VmService vmService) async {
|
|||
// assert(_inspectorDependenciesLoaded);
|
|||
// assert(serviceManager.hasConnection);
|
|||
// assert(serviceManager.service != null);
|
|||
// final inspectorLibrary = EvalOnDartLibrary(
|
|||
// inspectorLibraryUriCandidates,
|
|||
// vmService,
|
|||
// );
|
|||
//
|
|||
// final libraryRef = await inspectorLibrary.libraryRef.catchError(
|
|||
// (_) => throw FlutterInspectorLibraryNotFound(),
|
|||
// test: (e) => e is LibraryNotFound,
|
|||
// );
|
|||
// final libraryFuture = inspectorLibrary.getLibrary(libraryRef, null);
|
|||
// final library = await libraryFuture;
|
|||
// Future<Set<String>> lookupFunctionNames() async {
|
|||
// for (ClassRef classRef in library.classes) {
|
|||
// if ('WidgetInspectorService' == classRef.name) {
|
|||
// final classObj = await inspectorLibrary.getClass(classRef, null);
|
|||
// final functionNames = <String>{};
|
|||
// for (FuncRef funcRef in classObj.functions) {
|
|||
// functionNames.add(funcRef.name);
|
|||
// }
|
|||
// return functionNames;
|
|||
// }
|
|||
// }
|
|||
// // WidgetInspectorService is not available. Either this is not a Flutter
|
|||
// // application or it is running in profile mode.
|
|||
// return null;
|
|||
// }
|
|||
//
|
|||
// final supportedServiceMethods = await lookupFunctionNames();
|
|||
// if (supportedServiceMethods == null) return null;
|
|||
// return InspectorService(
|
|||
// vmService,
|
|||
// inspectorLibrary,
|
|||
// supportedServiceMethods,
|
|||
// );
|
|||
// }
|
|||
//
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
} |
|
|||
using uiwidgets; |
|||
using Unity.UIWidgets.ui; |
|||
|
|||
namespace Unity.UIWidgets.DevTools.ui |
|||
{ |
|||
public static class ColorsUtils |
|||
{ |
|||
public static Color treeGuidelineColor => Color.fromARGB(255, 200, 200, 200); |
|||
} |
|||
} |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.DevTools.ui; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEditor; |
|||
using Image = Unity.UIWidgets.widgets.Image; |
|||
using TextStyle = Unity.UIWidgets.painting.TextStyle; |
|||
|
|||
namespace Unity.UIWidgets.DevTools.ui |
|||
{ |
|||
|
|||
public static class IconsUtils |
|||
{ |
|||
public static Image createImageIcon(string url, float size = ThemeUtils.defaultIconSize) { |
|||
return new Image( |
|||
image: new AssetImage(url), |
|||
height: size, |
|||
width: size |
|||
); |
|||
} |
|||
} |
|||
|
|||
|
|||
class CustomIcon : StatelessWidget { |
|||
public CustomIcon( |
|||
IconKind kind = null, |
|||
string text = null, |
|||
bool isAbstract = false |
|||
) |
|||
{ |
|||
this.kind = kind; |
|||
this.text = text; |
|||
this.isAbstract = isAbstract; |
|||
} |
|||
|
|||
public readonly IconKind kind; |
|||
public readonly string text; |
|||
public readonly bool isAbstract; |
|||
|
|||
Image baseIcon => kind.icon; |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new Container( |
|||
width: baseIcon.width, |
|||
height: baseIcon.height, |
|||
child: new Stack( |
|||
alignment: AlignmentDirectional.center, |
|||
children: new List<Widget>{ |
|||
baseIcon, |
|||
new Text( |
|||
text, |
|||
textAlign: TextAlign.center, |
|||
style: new TextStyle(fontSize: 9, color: new Color(0xFF231F20)) |
|||
), |
|||
} |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
|
|||
class CustomIconMaker { |
|||
Dictionary<string, CustomIcon> iconCache = new Dictionary<string, CustomIcon>(); |
|||
|
|||
CustomIcon getCustomIcon(string fromText, |
|||
IconKind kind = null, bool isAbstract = false) { |
|||
if (kind == null) |
|||
{ |
|||
kind = IconKind.classIcon; |
|||
} |
|||
if (fromText?.isEmpty() != false) { |
|||
return null; |
|||
} |
|||
|
|||
string text = toUpperCase(fromText[0].ToString()); |
|||
string mapKey = $"{text}_{kind.name}_{isAbstract}"; |
|||
|
|||
return iconCache.putIfAbsent(mapKey, () => { |
|||
return new CustomIcon(kind: kind, text: text, isAbstract: isAbstract); |
|||
}); |
|||
} |
|||
|
|||
string toUpperCase(string str) |
|||
{ |
|||
if (str != null) |
|||
{ |
|||
string retStr = string.Empty; |
|||
for (int i = 0; i < str.Length; i++) |
|||
{ |
|||
if (str[i]>='a'&&str[i]<='z') |
|||
{ |
|||
retStr += (char)(str[i] - 'a' + 'A'); |
|||
continue; |
|||
} |
|||
retStr += str[i]; |
|||
} |
|||
return retStr; |
|||
} |
|||
|
|||
return "str is null"; |
|||
} |
|||
|
|||
|
|||
public CustomIcon fromWidgetName(string name) { |
|||
if (name == null) { |
|||
return null; |
|||
} |
|||
|
|||
bool isPrivate = name.StartsWith("_"); |
|||
while (name.isNotEmpty() && !isAlphabetic(name[0])) { |
|||
name = name.Substring(1); |
|||
} |
|||
|
|||
if (name.isEmpty()) { |
|||
return null; |
|||
} |
|||
|
|||
return getCustomIcon( |
|||
name, |
|||
kind: isPrivate ? IconKind.method : IconKind.classIcon |
|||
); |
|||
} |
|||
|
|||
CustomIcon fromInfo(String name) { |
|||
if (name == null) { |
|||
return null; |
|||
} |
|||
|
|||
if (name.isEmpty()) { |
|||
return null; |
|||
} |
|||
|
|||
return getCustomIcon(name, kind: IconKind.info); |
|||
} |
|||
|
|||
bool isAlphabetic(int _char) { |
|||
return (_char < '0' || _char > '9') && |
|||
_char != '_' && |
|||
_char != '$'; |
|||
} |
|||
} |
|||
|
|||
|
|||
class IconKind { |
|||
public IconKind(string name, Image icon, Image abstractIcon = null) |
|||
{ |
|||
this.name = name; |
|||
this.icon = icon; |
|||
abstractIcon = abstractIcon ?? icon; |
|||
} |
|||
|
|||
public static IconKind classIcon = new IconKind( |
|||
"class", |
|||
IconsUtils.createImageIcon("icons/custom/class.png"), |
|||
IconsUtils.createImageIcon("icons/custom/class_abstract.png") |
|||
); |
|||
public static IconKind field = new IconKind( |
|||
"fields", |
|||
IconsUtils.createImageIcon("icons/custom/fields.png") |
|||
); |
|||
public static IconKind _interface = new IconKind( |
|||
"interface", |
|||
IconsUtils.createImageIcon("icons/custom/interface.png") |
|||
); |
|||
public static IconKind method = new IconKind( |
|||
"method", |
|||
IconsUtils.createImageIcon("icons/custom/method.png"), |
|||
IconsUtils.createImageIcon("icons/custom/method_abstract.png") |
|||
); |
|||
public static IconKind property = new IconKind( |
|||
"property", |
|||
IconsUtils.createImageIcon("icons/custom/property.png") |
|||
); |
|||
public static IconKind info = new IconKind( |
|||
"info", |
|||
IconsUtils.createImageIcon("icons/custom/info.png") |
|||
); |
|||
|
|||
public readonly string name; |
|||
public readonly Image icon; |
|||
public readonly Image abstractIcon; |
|||
} |
|||
|
|||
} |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace Unity.UIWidgets.DevTools.ui |
|||
{ |
|||
|
|||
public static class LabelUtils |
|||
{ |
|||
public static bool _showLabelText(BuildContext context, double includeTextWidth) { |
|||
return includeTextWidth == null || |
|||
MediaQuery.of(context).size.width > includeTextWidth; |
|||
} |
|||
} |
|||
|
|||
class ImageIconLabel : StatelessWidget { |
|||
public ImageIconLabel(Image icon, string text, float minIncludeTextWidth = 100) |
|||
{ |
|||
this.icon = icon; |
|||
this.text = text; |
|||
this.minIncludeTextWidth = minIncludeTextWidth; |
|||
} |
|||
|
|||
public readonly Image icon; |
|||
public readonly string text; |
|||
public readonly float minIncludeTextWidth; |
|||
|
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
List<Widget> temp = new List<Widget>(); |
|||
temp.Add(icon); |
|||
if (LabelUtils._showLabelText(context, minIncludeTextWidth)) |
|||
{ |
|||
temp.Add(new Padding( |
|||
padding: EdgeInsets.only(left: 8.0f), |
|||
child: new Text(text) |
|||
)); |
|||
} |
|||
return new Row( |
|||
children: temp |
|||
); |
|||
} |
|||
} |
|||
|
|||
class MaterialIconLabel : StatelessWidget { |
|||
public MaterialIconLabel(IconData iconData, string text, float includeTextWidth = 10) |
|||
{ |
|||
this.iconData = iconData; |
|||
this.text = text; |
|||
this.includeTextWidth = includeTextWidth; |
|||
} |
|||
|
|||
public readonly IconData iconData; |
|||
public readonly string text; |
|||
public readonly float includeTextWidth; |
|||
|
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
List<Widget> temp = new List<Widget>(); |
|||
temp.Add(new Icon(iconData, size: 18.0f)); |
|||
if (LabelUtils._showLabelText(context, includeTextWidth)) |
|||
{ |
|||
temp.Add( |
|||
new Padding( |
|||
padding: EdgeInsets.only(left: 8.0f), |
|||
child: new Text(text) |
|||
) |
|||
); |
|||
} |
|||
return new Row( |
|||
children: temp |
|||
); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue