示例#1
0
	public static FGCodeWindow OpenNewWindow(Object target, FGCodeWindow nextTo, bool reuseExisting)
	{
		FGTextEditor.nextF12GoesBack = false;
		
		if (focusedWindow && IsMaximized(focusedWindow))
			ToggleMaximized(focusedWindow);
		
		UnhideSi3Tabs();
		
		if (reuseExisting || target == null)
		{
			if (target == null)
				target = Selection.activeObject as MonoScript;
			if (target == null)
				target = Selection.activeObject as TextAsset;
			if (target == null)
				target = Selection.activeObject as Shader;
			if (target == null)
				return null;
			
			var assetPath = AssetDatabase.GetAssetPath(target);
			if (assetPath.EndsWith(".dll", System.StringComparison.OrdinalIgnoreCase) ||
				assetPath.EndsWith(".exe", System.StringComparison.OrdinalIgnoreCase))
			{
				return null;
			}
			
			string guid = AssetDatabase.AssetPathToGUID(assetPath);
			
			foreach (FGCodeWindow codeWindow in codeWindows)
			{
				if (codeWindow && codeWindow.targetAssetGuid == guid)
				{
					codeWindow.Focus();
					return codeWindow;
				}
			}
		}

		useTargetAsset = target;
		FGCodeWindow window = ScriptableObject.CreateInstance<FGCodeWindow>();
		useTargetAsset = null;

		if (!window.TryDockNextToSimilarTab(nextTo))
		{
			var rc = defaultPosition;
			rc.y -= 5f;
			window.position = rc;
			window.Show();
			window.position = rc;
		}

		window.Focus();
		return window;
	}
示例#2
0
	public void CloseOtherTabs()
	{
		var allWindows = new FGCodeWindow[codeWindows.Count];
		codeWindows.CopyTo(allWindows);
		foreach (var window in allWindows)
			if (window && window != this)
				window.Close();
	}
示例#3
0
	private bool TryDockNextToSimilarTab(FGCodeWindow nextTo)
	{
		if (API.windowsField == null || API.mainViewField == null || API.panesField == null || API.addTabMethod == null)
			return false;
		
		System.Array windows = API.windowsField.GetValue(null, null) as System.Array;
		if (windows == null)
			return false;

		foreach (var window in windows)
		{
			var mainView = API.mainViewField.GetValue(window, null);
			var allChildren = API.allChildrenField.GetValue(mainView, null) as System.Array;
			if (allChildren == null)
				continue;

		    foreach (var view in allChildren)
		    {
				if (view.GetType() != API.dockAreaType)
					continue;

			    var panes = API.panesField.GetValue(view) as List<EditorWindow>;
				if (panes == null)
					continue;

			    if (nextTo != null ? panes.Contains(nextTo) : panes.Find(pane =>
				    defaultDockNextTo != null ? pane.GetType().ToString() == defaultDockNextTo : pane is FGCodeWindow))
				{
					API.addTabMethod.Invoke(view, new object[] { this });
					return true;
				}
		    }
		}
		return false;
	}
示例#4
0
	public void AddItemsToMenu(GenericMenu menu)
	{
		if (!string.IsNullOrEmpty(textEditor.targetPath))
		{
			var fileName = System.IO.Path.GetFileName(textEditor.targetPath);
#if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2
			fileName = fileName.Replace('_', '\xFF3F');
#endif
			menu.AddItem(new GUIContent("Ping " + fileName), false, () => {
				EditorApplication.ExecuteMenuItem("Window/Project");
				EditorGUIUtility.PingObject(targetAsset);
			});
#if UNITY_EDITOR_OSX
			menu.AddItem(new GUIContent("Reveal in Finder"), false, () => {
				Selection.activeObject = targetAsset;
				EditorApplication.ExecuteMenuItem("Assets/Reveal in Finder");
			});
#else
			menu.AddItem(new GUIContent("Show in Explorer"), false, () => {
				Selection.activeObject = targetAsset;
				EditorApplication.ExecuteMenuItem("Assets/Show in Explorer");
			});
#endif
			menu.AddSeparator("");
			var isMaximized = IsMaximized();
			
			menu.AddItem("Maximize", "&\n", "Maximize", "&enter", isMaximized, () => ToggleMaximized(this));
			if (isMaximized)
			{
				menu.AddDisabledItem(new GUIContent("Close Tab"));
				menu.AddDisabledItem(new GUIContent("Close All SI Tabs"));
				menu.AddItem("Close Other SI Tabs", "#%w", "Close Other SI Tabs", "#%w", false, null);
			}
			else
			{
				menu.AddItem("Close Tab", "#%w", "Close Tab", "%w", false, () => {
					Close();
				});
				menu.AddItem(new GUIContent("Close All SI Tabs"), false, () => {
					var allWindows = new FGCodeWindow[codeWindows.Count];
					codeWindows.CopyTo(allWindows);
					foreach (var window in allWindows)
						if (window)
							window.Close();
				});
				menu.AddItem("Close Other SI Tabs", "", "Close Other SI Tabs", "#%w", false, CloseOtherTabs);
			}
			
			menu.ShowAsContext();
			GUIUtility.ExitGUI();
		}
	}
示例#5
0
	public void AddItemsToMenu(GenericMenu menu)
	{
		if (!string.IsNullOrEmpty(textEditor.targetPath))
		{
			var fileName = System.IO.Path.GetFileName(textEditor.targetPath);
			menu.AddItem(new GUIContent("Ping " + fileName), false, () => {
				EditorApplication.ExecuteMenuItem("Window/Project");
				EditorGUIUtility.PingObject(targetAsset);
			});
#if UNITY_EDITOR_OSX
			menu.AddItem(new GUIContent("Reveal in Finder"), false, () => {
				Selection.activeObject = targetAsset;
				EditorApplication.ExecuteMenuItem("Assets/Reveal in Finder");
			});
#else
			menu.AddItem(new GUIContent("Show in Explorer"), false, () => {
				Selection.activeObject = targetAsset;
				EditorApplication.ExecuteMenuItem("Assets/Show in Explorer");
			});
#endif
			menu.AddSeparator("");
			var isMaximized = IsMaximized();
			
			if (Application.platform == RuntimePlatform.OSXEditor)
				menu.AddItem(new GUIContent("Maximize _&\n"), isMaximized, () => ToggleMaximized(this));
			else
				menu.AddItem(new GUIContent("Maximize _&enter"), isMaximized, () => ToggleMaximized(this));
			if (isMaximized)
			{
				menu.AddDisabledItem(new GUIContent("Close Tab"));
				menu.AddDisabledItem(new GUIContent("Close All SI Tabs"));
				menu.AddDisabledItem(new GUIContent("Close Other SI Tabs _#%w"));
			}
			else
			{
				menu.AddItem(new GUIContent("Close Tab _%w"), false, () => {
					Close();
				});
				menu.AddItem(new GUIContent("Close All SI Tabs"), false, () => {
					var allWindows = new FGCodeWindow[codeWindows.Count];
					codeWindows.CopyTo(allWindows);
					foreach (var window in allWindows)
						if (window)
							window.Close();
				});
				menu.AddItem(new GUIContent("Close Other SI Tabs _#%w"), false, () => {
					var allWindows = new FGCodeWindow[codeWindows.Count];
					codeWindows.CopyTo(allWindows);
					foreach (var window in allWindows)
						if (window && window != this)
							window.Close();
				});
			}
			
			menu.ShowAsContext();
			GUIUtility.ExitGUI();
		}
	}