ProjectWindow.cs 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using BansheeEngine;
  5. namespace BansheeEditor
  6. {
  7. internal enum ProjectViewType
  8. {
  9. Grid64, Grid48, Grid32, List16
  10. }
  11. internal sealed class ProjectWindow : EditorWindow
  12. {
  13. private class ContentInfo
  14. {
  15. public ContentInfo(ProjectWindow window, ProjectViewType viewType, int numEntries)
  16. {
  17. GUIPanel parentPanel = window.scrollAreaPanel;
  18. GUIPanel contentPanel = parentPanel.AddPanel(1);
  19. overlay = parentPanel.AddPanel(0);
  20. underlay = parentPanel.AddPanel(2);
  21. main = contentPanel.AddLayoutY();
  22. if (viewType == ProjectViewType.List16)
  23. {
  24. tileSize = 16;
  25. gridLayout = false;
  26. elementsPerRow = 1;
  27. }
  28. else
  29. {
  30. switch (viewType)
  31. {
  32. case ProjectViewType.Grid64:
  33. tileSize = 64;
  34. break;
  35. case ProjectViewType.Grid48:
  36. tileSize = 48;
  37. break;
  38. case ProjectViewType.Grid32:
  39. tileSize = 32;
  40. break;
  41. }
  42. gridLayout = true;
  43. Rect2I scrollBounds = window.contentScrollArea.Bounds;
  44. int availableWidth = scrollBounds.width;
  45. int elemSize = tileSize + GRID_ENTRY_SPACING;
  46. elementsPerRow = (availableWidth - GRID_ENTRY_SPACING * 2) / elemSize;
  47. int numRows = MathEx.CeilToInt(numEntries / (float)elementsPerRow);
  48. int neededHeight = numRows * (elemSize);
  49. bool requiresScrollbar = neededHeight > scrollBounds.height;
  50. if (requiresScrollbar)
  51. {
  52. availableWidth -= window.contentScrollArea.ScrollBarWidth;
  53. elementsPerRow = (availableWidth - GRID_ENTRY_SPACING * 2) / elemSize;
  54. }
  55. labelWidth = availableWidth / elementsPerRow;
  56. labelWidth -= (elementsPerRow + 1)*MIN_HORZ_SPACING;
  57. }
  58. this.window = window;
  59. }
  60. public GUILayout main;
  61. public GUIPanel overlay;
  62. public GUIPanel underlay;
  63. public ProjectWindow window;
  64. public int tileSize;
  65. public bool gridLayout;
  66. public int elementsPerRow;
  67. public int labelWidth;
  68. }
  69. private class ElementEntry
  70. {
  71. // Note: Order of these is relevant
  72. enum UnderlayState
  73. {
  74. None, Hovered, Selected, Pinged
  75. }
  76. public int index;
  77. public string path;
  78. public GUITexture icon;
  79. public GUILabel label;
  80. public Rect2I bounds;
  81. private GUITexture underlay;
  82. private ContentInfo info;
  83. private UnderlayState underlayState;
  84. public ElementEntry(ContentInfo info, GUILayout parent, LibraryEntry entry, int index)
  85. {
  86. GUILayout entryLayout;
  87. if (info.gridLayout)
  88. entryLayout = parent.AddLayoutY();
  89. else
  90. entryLayout = parent.AddLayoutX();
  91. SpriteTexture iconTexture = GetIcon(entry);
  92. icon = new GUITexture(iconTexture, GUIImageScaleMode.ScaleToFit,
  93. true, GUIOption.FixedHeight(info.tileSize), GUIOption.FixedWidth(info.tileSize));
  94. label = null;
  95. if (info.gridLayout)
  96. {
  97. label = new GUILabel(entry.Name, EditorStyles.MultiLineLabel,
  98. GUIOption.FixedWidth(info.labelWidth), GUIOption.FlexibleHeight(0, MAX_LABEL_HEIGHT));
  99. }
  100. else
  101. {
  102. label = new GUILabel(entry.Name);
  103. }
  104. entryLayout.AddElement(icon);
  105. entryLayout.AddElement(label);
  106. this.info = info;
  107. this.index = index;
  108. this.path = entry.Path;
  109. this.bounds = new Rect2I();
  110. this.underlay = null;
  111. }
  112. public void Initialize()
  113. {
  114. bounds = icon.Bounds;
  115. Rect2I labelBounds = label.Bounds;
  116. bounds.x = MathEx.Min(bounds.x, labelBounds.x);
  117. bounds.y = MathEx.Min(bounds.y, labelBounds.y) - 5; // 5 - Just padding for better look
  118. bounds.width = MathEx.Max(bounds.x + bounds.width,
  119. labelBounds.x + labelBounds.width) - bounds.x;
  120. bounds.height = MathEx.Max(bounds.y + bounds.height,
  121. labelBounds.y + labelBounds.height) - bounds.y;
  122. ProjectWindow hoistedWindow = info.window;
  123. string hoistedPath = path;
  124. GUIButton overlayBtn = new GUIButton("", EditorStyles.Blank);
  125. overlayBtn.Bounds = bounds;
  126. overlayBtn.OnClick += () => hoistedWindow.OnEntryClicked(hoistedPath);
  127. overlayBtn.OnDoubleClick += () => hoistedWindow.OnEntryDoubleClicked(hoistedPath);
  128. overlayBtn.SetContextMenu(info.window.entryContextMenu);
  129. info.overlay.AddElement(overlayBtn);
  130. }
  131. public Rect2I Bounds
  132. {
  133. get { return bounds; }
  134. }
  135. public void MarkAsCut(bool enable)
  136. {
  137. if (enable)
  138. icon.SetTint(CUT_COLOR);
  139. else
  140. icon.SetTint(Color.White);
  141. }
  142. public void MarkAsSelected(bool enable)
  143. {
  144. if ((int)underlayState > (int) UnderlayState.Selected)
  145. return;
  146. if (enable)
  147. {
  148. CreateUnderlay();
  149. underlay.SetTint(SELECTION_COLOR);
  150. }
  151. else
  152. ClearUnderlay();
  153. underlayState = UnderlayState.Selected;
  154. }
  155. public void MarkAsPinged(bool enable)
  156. {
  157. if ((int)underlayState > (int)UnderlayState.Pinged)
  158. return;
  159. if (enable)
  160. {
  161. CreateUnderlay();
  162. underlay.SetTint(PING_COLOR);
  163. }
  164. else
  165. ClearUnderlay();
  166. underlayState = UnderlayState.Pinged;
  167. }
  168. public void MarkAsHovered(bool enable)
  169. {
  170. if ((int)underlayState > (int)UnderlayState.Hovered)
  171. return;
  172. if (enable)
  173. {
  174. CreateUnderlay();
  175. underlay.SetTint(HOVER_COLOR);
  176. }
  177. else
  178. ClearUnderlay();
  179. underlayState = UnderlayState.Hovered;
  180. }
  181. private void ClearUnderlay()
  182. {
  183. if (underlay != null)
  184. {
  185. underlay.Destroy();
  186. underlay = null;
  187. }
  188. underlayState = UnderlayState.None;
  189. }
  190. private void CreateUnderlay()
  191. {
  192. if (underlay == null)
  193. {
  194. underlay = new GUITexture(Builtin.WhiteTexture);
  195. underlay.Bounds = Bounds;
  196. info.underlay.AddElement(underlay);
  197. }
  198. }
  199. private static SpriteTexture GetIcon(LibraryEntry entry)
  200. {
  201. if (entry.Type == LibraryEntryType.Directory)
  202. {
  203. return EditorBuiltin.FolderIcon;
  204. }
  205. else
  206. {
  207. FileEntry fileEntry = (FileEntry)entry;
  208. switch (fileEntry.ResType)
  209. {
  210. case ResourceType.Font:
  211. return EditorBuiltin.FontIcon;
  212. case ResourceType.Mesh:
  213. return EditorBuiltin.MeshIcon;
  214. case ResourceType.Texture:
  215. return EditorBuiltin.TextureIcon;
  216. case ResourceType.PlainText:
  217. return EditorBuiltin.PlainTextIcon;
  218. case ResourceType.ScriptCode:
  219. return EditorBuiltin.ScriptCodeIcon;
  220. case ResourceType.SpriteTexture:
  221. return EditorBuiltin.SpriteTextureIcon;
  222. case ResourceType.Shader:
  223. return EditorBuiltin.ShaderIcon;
  224. case ResourceType.Material:
  225. return EditorBuiltin.MaterialIcon;
  226. }
  227. }
  228. return null;
  229. }
  230. }
  231. enum MoveDirection
  232. {
  233. Up, Down, Left, Right
  234. }
  235. private const int GRID_ENTRY_SPACING = 15;
  236. private const int LIST_ENTRY_SPACING = 7;
  237. private const int MAX_LABEL_HEIGHT = 50;
  238. private const int MIN_HORZ_SPACING = 5;
  239. private const int DRAG_SCROLL_HEIGHT = 20;
  240. private const int DRAG_SCROLL_AMOUNT_PER_SECOND = 100;
  241. private const int FOLDER_BUTTON_WIDTH = 20;
  242. private const int FOLDER_SEPARATOR_WIDTH = 7;
  243. private static readonly Color PING_COLOR = Color.BansheeOrange;
  244. private static readonly Color SELECTION_COLOR = Color.DarkCyan;
  245. private static readonly Color HOVER_COLOR = new Color(Color.DarkCyan.r, Color.DarkCyan.g, Color.DarkCyan.b, 0.5f);
  246. private static readonly Color CUT_COLOR = new Color(1.0f, 1.0f, 1.0f, 0.5f);
  247. private bool hasContentFocus = false;
  248. private bool HasContentFocus { get { return HasFocus && hasContentFocus; } }
  249. private string searchQuery;
  250. private bool IsSearchActive { get { return !string.IsNullOrEmpty(searchQuery); } }
  251. private ProjectViewType viewType = ProjectViewType.Grid32;
  252. private bool requiresRefresh;
  253. private string currentDirectory = "";
  254. private List<string> selectionPaths = new List<string>();
  255. private int selectionAnchorStart = -1;
  256. private int selectionAnchorEnd = -1;
  257. private string pingPath = "";
  258. private string hoverHighlightPath = "";
  259. private ContentInfo contentInfo;
  260. private GUIScrollArea contentScrollArea;
  261. private GUIPanel scrollAreaPanel;
  262. private GUILayoutX searchBarLayout;
  263. private GUIButton optionsButton;
  264. private GUILayout folderBarLayout;
  265. private GUILayout folderListLayout;
  266. private GUITextField searchField;
  267. private GUITexture dragSelection;
  268. private ContextMenu entryContextMenu;
  269. private ProjectDropTarget dropTarget;
  270. private List<ElementEntry> entries = new List<ElementEntry>();
  271. private Dictionary<string, ElementEntry> entryLookup = new Dictionary<string, ElementEntry>();
  272. private int autoScrollAmount;
  273. private bool isDraggingSelection;
  274. private Vector2I dragSelectionStart;
  275. private Vector2I dragSelectionEnd;
  276. // Cut/Copy/Paste
  277. private List<string> copyPaths = new List<string>();
  278. private List<string> cutPaths = new List<string>();
  279. internal ProjectViewType ViewType
  280. {
  281. get { return viewType; }
  282. set { viewType = value; Refresh(); }
  283. }
  284. [MenuItem("Windows/Project", ButtonModifier.Ctrl, ButtonCode.P)]
  285. private static void OpenProjectWindow()
  286. {
  287. OpenWindow<ProjectWindow>();
  288. }
  289. private void OnInitialize()
  290. {
  291. ProjectLibrary.OnEntryAdded += OnEntryChanged;
  292. ProjectLibrary.OnEntryRemoved += OnEntryChanged;
  293. GUILayoutY contentLayout = GUI.AddLayoutY();
  294. searchBarLayout = contentLayout.AddLayoutX();
  295. searchField = new GUITextField();
  296. searchField.OnChanged += OnSearchChanged;
  297. GUIButton clearSearchBtn = new GUIButton("C");
  298. clearSearchBtn.OnClick += ClearSearch;
  299. clearSearchBtn.SetWidth(40);
  300. optionsButton = new GUIButton("O");
  301. optionsButton.OnClick += OpenOptionsWindow;
  302. optionsButton.SetWidth(40);
  303. searchBarLayout.AddElement(searchField);
  304. searchBarLayout.AddElement(clearSearchBtn);
  305. searchBarLayout.AddElement(optionsButton);
  306. folderBarLayout = contentLayout.AddLayoutX();
  307. GUIButton homeButton = new GUIButton("H", GUIOption.FixedWidth(FOLDER_BUTTON_WIDTH));
  308. homeButton.OnClick += OnHomeClicked;
  309. GUIButton upButton = new GUIButton("U", GUIOption.FixedWidth(FOLDER_BUTTON_WIDTH));
  310. upButton.OnClick += OnUpClicked;
  311. folderBarLayout.AddElement(homeButton);
  312. folderBarLayout.AddElement(upButton);
  313. folderBarLayout.AddSpace(10);
  314. contentScrollArea = new GUIScrollArea(GUIOption.FlexibleWidth(), GUIOption.FlexibleHeight());
  315. contentLayout.AddElement(contentScrollArea);
  316. contentLayout.AddFlexibleSpace();
  317. entryContextMenu = new ContextMenu();
  318. entryContextMenu.AddItem("Cut", CutSelection, new ShortcutKey(ButtonModifier.Ctrl, ButtonCode.X));
  319. entryContextMenu.AddItem("Copy", CopySelection, new ShortcutKey(ButtonModifier.Ctrl, ButtonCode.C));
  320. entryContextMenu.AddItem("Duplicate", DuplicateSelection, new ShortcutKey(ButtonModifier.Ctrl, ButtonCode.D));
  321. entryContextMenu.AddItem("Paste", PasteToSelection, new ShortcutKey(ButtonModifier.Ctrl, ButtonCode.V));
  322. Reset();
  323. dropTarget = new ProjectDropTarget(this);
  324. dropTarget.Bounds = contentScrollArea.Bounds;
  325. dropTarget.OnStart += DoOnDragStart;
  326. dropTarget.OnDrag += DoOnDragMove;
  327. dropTarget.OnLeave += DoOnDragLeave;
  328. dropTarget.OnDrop += DoOnDragDropped;
  329. dropTarget.OnEnd += DoOnDragEnd;
  330. }
  331. private ElementEntry FindElementAt(Vector2I windowPos)
  332. {
  333. Vector2I scrollPos = WindowToScrollAreaCoords(windowPos);
  334. foreach (var element in entries)
  335. {
  336. if (element.bounds.Contains(scrollPos))
  337. return element;
  338. }
  339. return null;
  340. }
  341. private ElementEntry[] FindElementsOverlapping(Rect2I scrollBounds)
  342. {
  343. List<ElementEntry> elements = new List<ElementEntry>();
  344. foreach (var element in entries)
  345. {
  346. if(element.Bounds.Overlaps(scrollBounds))
  347. elements.Add(element);
  348. }
  349. return elements.ToArray();
  350. }
  351. private void DoOnDragStart(Vector2I windowPos)
  352. {
  353. ElementEntry underCursorElem = FindElementAt(windowPos);
  354. if (underCursorElem == null || !selectionPaths.Contains(underCursorElem.path))
  355. {
  356. StartDragSelection(windowPos);
  357. return;
  358. }
  359. ResourceDragDropData dragDropData = new ResourceDragDropData(selectionPaths.ToArray());
  360. DragDrop.StartDrag(dragDropData);
  361. }
  362. private void DoOnDragMove(Vector2I windowPos)
  363. {
  364. // Auto-scroll
  365. Rect2I scrollAreaBounds = contentScrollArea.Bounds;
  366. int scrollAreaTop = scrollAreaBounds.y;
  367. int scrollAreaBottom = scrollAreaBounds.y + scrollAreaBounds.height;
  368. if (windowPos.y > scrollAreaTop && windowPos.y <= (scrollAreaTop + DRAG_SCROLL_HEIGHT))
  369. autoScrollAmount = -DRAG_SCROLL_AMOUNT_PER_SECOND;
  370. else if (windowPos.y >= (scrollAreaBottom - DRAG_SCROLL_HEIGHT) && windowPos.y < scrollAreaBottom)
  371. autoScrollAmount = DRAG_SCROLL_AMOUNT_PER_SECOND;
  372. else
  373. autoScrollAmount = 0;
  374. // Selection box
  375. if (UpdateDragSelection(windowPos))
  376. return;
  377. // Drag and drop (hover element under cursor)
  378. ElementEntry underCursorElem = FindElementAt(windowPos);
  379. if (underCursorElem == null)
  380. {
  381. ClearHoverHighlight();
  382. }
  383. else
  384. {
  385. if (underCursorElem.path != hoverHighlightPath)
  386. {
  387. ClearHoverHighlight();
  388. hoverHighlightPath = underCursorElem.path;
  389. underCursorElem.MarkAsHovered(true);
  390. }
  391. }
  392. }
  393. private void DoOnDragLeave()
  394. {
  395. ClearHoverHighlight();
  396. autoScrollAmount = 0;
  397. }
  398. private void DoOnDragDropped(Vector2I windowPos, string[] paths)
  399. {
  400. ClearHoverHighlight();
  401. autoScrollAmount = 0;
  402. if (EndDragSelection())
  403. return;
  404. string resourceDir = ProjectLibrary.ResourceFolder;
  405. string destinationFolder = Path.Combine(resourceDir, currentDirectory);
  406. ElementEntry underCursorElement = FindElementAt(windowPos);
  407. if (underCursorElement != null)
  408. {
  409. LibraryEntry entry = ProjectLibrary.GetEntry(underCursorElement.path);
  410. if (entry != null && entry.Type == LibraryEntryType.Directory)
  411. destinationFolder = Path.Combine(resourceDir, entry.Path);
  412. }
  413. if (paths != null)
  414. {
  415. foreach (var path in paths)
  416. {
  417. if (path == null)
  418. continue;
  419. string absolutePath = path;
  420. if (!Path.IsPathRooted(absolutePath))
  421. absolutePath = Path.Combine(resourceDir, path);
  422. if (string.IsNullOrEmpty(absolutePath))
  423. continue;
  424. if (PathEx.IsPartOf(destinationFolder, absolutePath) || PathEx.Compare(absolutePath, destinationFolder))
  425. continue;
  426. string destination = Path.Combine(destinationFolder, Path.GetFileName(absolutePath));
  427. if (ProjectLibrary.Exists(path))
  428. ProjectLibrary.Move(path, destination, true);
  429. else
  430. ProjectLibrary.Copy(path, destination, true);
  431. }
  432. }
  433. }
  434. private void DoOnDragEnd(Vector2I windowPos)
  435. {
  436. EndDragSelection();
  437. }
  438. private void ClearHoverHighlight()
  439. {
  440. if (!string.IsNullOrEmpty(hoverHighlightPath))
  441. {
  442. ElementEntry previousUnderCursorElem;
  443. if (entryLookup.TryGetValue(hoverHighlightPath, out previousUnderCursorElem))
  444. previousUnderCursorElem.MarkAsHovered(false);
  445. }
  446. hoverHighlightPath = "";
  447. }
  448. public void Ping(Resource resource)
  449. {
  450. if (!string.IsNullOrEmpty(pingPath))
  451. {
  452. ElementEntry entry;
  453. if (entryLookup.TryGetValue(pingPath, out entry))
  454. entry.MarkAsPinged(false);
  455. }
  456. if (resource != null)
  457. pingPath = ProjectLibrary.GetPath(resource);
  458. else
  459. pingPath = "";
  460. if (!string.IsNullOrEmpty(pingPath))
  461. {
  462. ElementEntry entry;
  463. if (entryLookup.TryGetValue(pingPath, out entry))
  464. entry.MarkAsPinged(true);
  465. ScrollToEntry(pingPath);
  466. }
  467. }
  468. private void DeselectAll()
  469. {
  470. SetSelection(new List<string>());
  471. selectionAnchorStart = -1;
  472. selectionAnchorEnd = -1;
  473. }
  474. private void Select(string path)
  475. {
  476. ElementEntry entry;
  477. if (!entryLookup.TryGetValue(path, out entry))
  478. return;
  479. bool ctrlDown = Input.IsButtonHeld(ButtonCode.LeftControl) || Input.IsButtonHeld(ButtonCode.RightControl);
  480. bool shiftDown = Input.IsButtonHeld(ButtonCode.LeftShift) || Input.IsButtonHeld(ButtonCode.RightShift);
  481. if (shiftDown)
  482. {
  483. if (selectionAnchorStart != -1 && selectionAnchorStart < entries.Count)
  484. {
  485. int start = Math.Min(entry.index, selectionAnchorStart);
  486. int end = Math.Max(entry.index, selectionAnchorStart);
  487. List<string> newSelection = new List<string>();
  488. for(int i = start; i <= end; i++)
  489. newSelection.Add(entries[i].path);
  490. SetSelection(newSelection);
  491. selectionAnchorEnd = entry.index;
  492. }
  493. else
  494. {
  495. SetSelection(new List<string>() {path});
  496. selectionAnchorStart = entry.index;
  497. selectionAnchorEnd = entry.index;
  498. }
  499. }
  500. else if (ctrlDown)
  501. {
  502. List<string> newSelection = new List<string>(selectionPaths);
  503. if (selectionPaths.Contains(path))
  504. {
  505. newSelection.Remove(path);
  506. if (newSelection.Count == 0)
  507. DeselectAll();
  508. else
  509. {
  510. if (selectionAnchorStart == entry.index)
  511. {
  512. ElementEntry newAnchorEntry;
  513. if (!entryLookup.TryGetValue(newSelection[0], out newAnchorEntry))
  514. selectionAnchorStart = -1;
  515. else
  516. selectionAnchorStart = newAnchorEntry.index;
  517. }
  518. if (selectionAnchorEnd == entry.index)
  519. {
  520. ElementEntry newAnchorEntry;
  521. if (!entryLookup.TryGetValue(newSelection[newSelection.Count - 1], out newAnchorEntry))
  522. selectionAnchorEnd = -1;
  523. else
  524. selectionAnchorEnd = newAnchorEntry.index;
  525. }
  526. SetSelection(newSelection);
  527. }
  528. }
  529. else
  530. {
  531. newSelection.Add(path);
  532. SetSelection(newSelection);
  533. selectionAnchorEnd = entry.index;
  534. }
  535. }
  536. else
  537. {
  538. SetSelection(new List<string>() { path });
  539. selectionAnchorStart = entry.index;
  540. selectionAnchorEnd = entry.index;
  541. }
  542. }
  543. private void MoveSelection(MoveDirection dir)
  544. {
  545. string newPath = "";
  546. if (selectionPaths.Count == 0 || selectionAnchorEnd == -1)
  547. {
  548. // Nothing is selected so we arbitrarily select first or last element
  549. if (entries.Count > 0)
  550. {
  551. switch (dir)
  552. {
  553. case MoveDirection.Left:
  554. case MoveDirection.Up:
  555. newPath = entries[entries.Count - 1].path;
  556. break;
  557. case MoveDirection.Right:
  558. case MoveDirection.Down:
  559. newPath = entries[0].path;
  560. break;
  561. }
  562. }
  563. }
  564. else
  565. {
  566. switch (dir)
  567. {
  568. case MoveDirection.Left:
  569. if (selectionAnchorEnd - 1 >= 0)
  570. newPath = entries[selectionAnchorEnd - 1].path;
  571. break;
  572. case MoveDirection.Up:
  573. if (selectionAnchorEnd - contentInfo.elementsPerRow >= 0)
  574. newPath = entries[selectionAnchorEnd - contentInfo.elementsPerRow].path;
  575. break;
  576. case MoveDirection.Right:
  577. if (selectionAnchorEnd + 1 < entries.Count)
  578. newPath = entries[selectionAnchorEnd + 1].path;
  579. break;
  580. case MoveDirection.Down:
  581. if (selectionAnchorEnd + contentInfo.elementsPerRow < entries.Count)
  582. newPath = entries[selectionAnchorEnd + contentInfo.elementsPerRow].path;
  583. break;
  584. }
  585. }
  586. if (!string.IsNullOrEmpty(newPath))
  587. {
  588. Select(newPath);
  589. ScrollToEntry(newPath);
  590. }
  591. }
  592. private void SetSelection(List<string> paths)
  593. {
  594. if (selectionPaths != null)
  595. {
  596. foreach (var path in selectionPaths)
  597. {
  598. ElementEntry entry;
  599. if (entryLookup.TryGetValue(path, out entry))
  600. entry.MarkAsSelected(false);
  601. }
  602. }
  603. selectionPaths = paths;
  604. if (selectionPaths != null)
  605. {
  606. foreach (var path in selectionPaths)
  607. {
  608. ElementEntry entry;
  609. if (entryLookup.TryGetValue(path, out entry))
  610. entry.MarkAsSelected(true);
  611. }
  612. }
  613. Ping(null);
  614. if (selectionPaths != null)
  615. Selection.resourcePaths = selectionPaths.ToArray();
  616. else
  617. Selection.resourcePaths = new string[0];
  618. }
  619. private void EnterDirectory(string directory)
  620. {
  621. currentDirectory = directory;
  622. DeselectAll();
  623. Refresh();
  624. }
  625. private void Cut(IEnumerable<string> sourcePaths)
  626. {
  627. foreach (var path in cutPaths)
  628. {
  629. ElementEntry entry;
  630. if (entryLookup.TryGetValue(path, out entry))
  631. entry.MarkAsCut(false);
  632. }
  633. cutPaths.Clear();
  634. cutPaths.AddRange(sourcePaths);
  635. foreach (var path in cutPaths)
  636. {
  637. ElementEntry entry;
  638. if (entryLookup.TryGetValue(path, out entry))
  639. entry.MarkAsCut(true);
  640. }
  641. copyPaths.Clear();
  642. }
  643. private void Copy(IEnumerable<string> sourcePaths)
  644. {
  645. copyPaths.Clear();
  646. copyPaths.AddRange(sourcePaths);
  647. foreach (var path in cutPaths)
  648. {
  649. ElementEntry entry;
  650. if (entryLookup.TryGetValue(path, out entry))
  651. entry.MarkAsCut(false);
  652. }
  653. cutPaths.Clear();
  654. }
  655. private void Duplicate(IEnumerable<string> sourcePaths)
  656. {
  657. foreach (var source in sourcePaths)
  658. {
  659. int idx = 0;
  660. string destination;
  661. do
  662. {
  663. destination = source + "_" + idx;
  664. idx++;
  665. } while (!ProjectLibrary.Exists(destination));
  666. ProjectLibrary.Copy(source, destination);
  667. }
  668. }
  669. private void Paste(string destinationFolder)
  670. {
  671. if (copyPaths.Count > 0)
  672. {
  673. for (int i = 0; i < copyPaths.Count; i++)
  674. {
  675. string cleanPath = copyPaths[i].TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
  676. string destination = Path.Combine(destinationFolder, Path.GetFileName(cleanPath));
  677. ProjectLibrary.Copy(copyPaths[i], destination, true);
  678. }
  679. Refresh();
  680. }
  681. else if (cutPaths.Count > 0)
  682. {
  683. for (int i = 0; i < cutPaths.Count; i++)
  684. {
  685. string cleanPath = cutPaths[i].TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
  686. string destination = Path.Combine(destinationFolder, Path.GetFileName(cleanPath));
  687. ProjectLibrary.Move(cutPaths[i], destination, true);
  688. }
  689. cutPaths.Clear();
  690. Refresh();
  691. }
  692. }
  693. private void EditorUpdate()
  694. {
  695. if (HasContentFocus)
  696. {
  697. if (Input.IsButtonHeld(ButtonCode.LeftControl) || Input.IsButtonHeld(ButtonCode.RightControl))
  698. {
  699. if (Input.IsButtonUp(ButtonCode.C))
  700. {
  701. CopySelection();
  702. }
  703. else if (Input.IsButtonUp(ButtonCode.X))
  704. {
  705. CutSelection();
  706. }
  707. else if (Input.IsButtonUp(ButtonCode.D))
  708. {
  709. DuplicateSelection();
  710. }
  711. else if (Input.IsButtonUp(ButtonCode.V))
  712. {
  713. PasteToSelection();
  714. }
  715. }
  716. if (Input.IsButtonDown(ButtonCode.Return))
  717. {
  718. if (selectionPaths.Count == 1)
  719. {
  720. LibraryEntry entry = ProjectLibrary.GetEntry(selectionPaths[0]);
  721. if (entry != null && entry.Type == LibraryEntryType.Directory)
  722. {
  723. EnterDirectory(entry.Path);
  724. }
  725. }
  726. }
  727. else if (Input.IsButtonDown(ButtonCode.Back))
  728. {
  729. LibraryEntry entry = ProjectLibrary.GetEntry(currentDirectory);
  730. if (entry != null && entry.Parent != null)
  731. {
  732. EnterDirectory(entry.Parent.Path);
  733. }
  734. }
  735. else if (Input.IsButtonDown(ButtonCode.Up))
  736. {
  737. MoveSelection(MoveDirection.Up);
  738. }
  739. else if (Input.IsButtonDown(ButtonCode.Down))
  740. {
  741. MoveSelection(MoveDirection.Down);
  742. }
  743. else if (Input.IsButtonDown(ButtonCode.Left))
  744. {
  745. MoveSelection(MoveDirection.Left);
  746. }
  747. else if (Input.IsButtonDown(ButtonCode.Right))
  748. {
  749. MoveSelection(MoveDirection.Right);
  750. }
  751. }
  752. if (autoScrollAmount != 0)
  753. {
  754. Rect2I contentBounds = contentScrollArea.ContentBounds;
  755. float scrollPct = autoScrollAmount / (float)contentBounds.height;
  756. contentScrollArea.VerticalScroll += scrollPct * Time.FrameDelta;
  757. }
  758. if (requiresRefresh)
  759. Refresh();
  760. dropTarget.Update();
  761. }
  762. private void OnEntryChanged(string entry)
  763. {
  764. requiresRefresh = true;
  765. }
  766. private void ScrollToEntry(string path)
  767. {
  768. ElementEntry entryGUI;
  769. if (!entryLookup.TryGetValue(path, out entryGUI))
  770. return;
  771. Rect2I entryBounds = entryGUI.Bounds;
  772. Rect2I contentBounds = contentScrollArea.Layout.Bounds;
  773. Rect2I windowEntryBounds = entryBounds;
  774. windowEntryBounds.x += contentBounds.x;
  775. windowEntryBounds.y += contentBounds.y;
  776. Rect2I scrollAreaBounds = contentScrollArea.Bounds;
  777. bool requiresScroll = windowEntryBounds.y < scrollAreaBounds.y ||
  778. (windowEntryBounds.y + windowEntryBounds.height) > (scrollAreaBounds.y + scrollAreaBounds.height);
  779. if (!requiresScroll)
  780. return;
  781. int scrollableSize = contentBounds.height - scrollAreaBounds.height;
  782. float percent = (((entryBounds.y + entryBounds.height * 0.5f) - scrollAreaBounds.height * 0.5f) / (float)scrollableSize);
  783. percent = MathEx.Clamp01(percent);
  784. contentScrollArea.VerticalScroll = percent;
  785. }
  786. private void Refresh()
  787. {
  788. requiresRefresh = false;
  789. LibraryEntry[] entriesToDisplay = new LibraryEntry[0];
  790. if (IsSearchActive)
  791. {
  792. entriesToDisplay = ProjectLibrary.Search("*" + searchQuery + "*");
  793. }
  794. else
  795. {
  796. DirectoryEntry entry = ProjectLibrary.GetEntry(currentDirectory) as DirectoryEntry;
  797. if (entry == null)
  798. {
  799. currentDirectory = ProjectLibrary.Root.Path;
  800. entry = ProjectLibrary.GetEntry(currentDirectory) as DirectoryEntry;
  801. }
  802. if(entry != null)
  803. entriesToDisplay = entry.Children;
  804. }
  805. if (scrollAreaPanel != null)
  806. scrollAreaPanel.Destroy();
  807. entries.Clear();
  808. entryLookup.Clear();
  809. scrollAreaPanel = contentScrollArea.Layout.AddPanel();
  810. RefreshDirectoryBar();
  811. SortEntries(entriesToDisplay);
  812. if (entriesToDisplay.Length == 0)
  813. return;
  814. contentInfo = new ContentInfo(this, viewType, entriesToDisplay.Length);
  815. if (viewType == ProjectViewType.List16)
  816. {
  817. for (int i = 0; i < entriesToDisplay.Length; i++)
  818. {
  819. ElementEntry guiEntry = new ElementEntry(contentInfo, contentInfo.main, entriesToDisplay[i], i);
  820. entries.Add(guiEntry);
  821. entryLookup[guiEntry.path] = guiEntry;
  822. if (i != entriesToDisplay.Length - 1)
  823. contentInfo.main.AddSpace(LIST_ENTRY_SPACING);
  824. }
  825. contentInfo.main.AddFlexibleSpace();
  826. }
  827. else
  828. {
  829. int tileSize = 64;
  830. switch (viewType)
  831. {
  832. case ProjectViewType.Grid64: tileSize = 64; break;
  833. case ProjectViewType.Grid48: tileSize = 48; break;
  834. case ProjectViewType.Grid32: tileSize = 32; break;
  835. }
  836. contentInfo.main.AddSpace(GRID_ENTRY_SPACING / 2);
  837. GUILayoutX rowLayout = contentInfo.main.AddLayoutX();
  838. contentInfo.main.AddSpace(GRID_ENTRY_SPACING);
  839. rowLayout.AddFlexibleSpace();
  840. int elemsInRow = 0;
  841. for (int i = 0; i < entriesToDisplay.Length; i++)
  842. {
  843. if (elemsInRow == contentInfo.elementsPerRow && elemsInRow > 0)
  844. {
  845. rowLayout = contentInfo.main.AddLayoutX();
  846. contentInfo.main.AddSpace(GRID_ENTRY_SPACING);
  847. rowLayout.AddFlexibleSpace();
  848. elemsInRow = 0;
  849. }
  850. ElementEntry guiEntry = new ElementEntry(contentInfo, rowLayout, entriesToDisplay[i], i);
  851. entries.Add(guiEntry);
  852. entryLookup[guiEntry.path] = guiEntry;
  853. rowLayout.AddFlexibleSpace();
  854. elemsInRow++;
  855. }
  856. int extraElements = contentInfo.elementsPerRow - elemsInRow;
  857. for (int i = 0; i < extraElements; i++)
  858. {
  859. rowLayout.AddSpace(contentInfo.labelWidth);
  860. rowLayout.AddFlexibleSpace();
  861. }
  862. contentInfo.main.AddFlexibleSpace();
  863. }
  864. for (int i = 0; i < entries.Count; i++)
  865. {
  866. ElementEntry guiEntry = entries[i];
  867. guiEntry.Initialize();
  868. if (cutPaths.Contains(guiEntry.path))
  869. guiEntry.MarkAsCut(true);
  870. if (selectionPaths.Contains(guiEntry.path))
  871. guiEntry.MarkAsSelected(true);
  872. else if (pingPath == guiEntry.path)
  873. guiEntry.MarkAsPinged(true);
  874. }
  875. Rect2I contentBounds = contentInfo.main.Bounds;
  876. Rect2I minimalBounds = GetScrollAreaBounds();
  877. contentBounds.height = Math.Max(contentBounds.height, minimalBounds.height);
  878. GUIButton catchAll = new GUIButton("", EditorStyles.Blank);
  879. catchAll.Bounds = contentBounds;
  880. catchAll.OnClick += OnCatchAllClicked;
  881. catchAll.SetContextMenu(entryContextMenu);
  882. contentInfo.underlay.AddElement(catchAll);
  883. Rect2I focusBounds = contentBounds; // Contents + Folder bar
  884. Rect2I scrollBounds = contentScrollArea.Bounds;
  885. focusBounds.x += scrollBounds.x;
  886. focusBounds.y += scrollBounds.y;
  887. Rect2I folderBarBounds = folderListLayout.Bounds;
  888. focusBounds.y -= folderBarBounds.height;
  889. focusBounds.height += folderBarBounds.height;
  890. GUIButton focusCatcher = new GUIButton("", EditorStyles.Blank);
  891. focusCatcher.OnFocusChanged += OnContentsFocusChanged;
  892. focusCatcher.Bounds = focusBounds;
  893. GUIPanel focusPanel = GUI.AddPanel(3);
  894. focusPanel.AddElement(focusCatcher);
  895. UpdateDragSelection(dragSelectionEnd);
  896. }
  897. private Vector2I WindowToScrollAreaCoords(Vector2I windowPos)
  898. {
  899. Rect2I scrollBounds = contentScrollArea.Layout.Bounds;
  900. Vector2I scrollPos = windowPos;
  901. scrollPos.x -= scrollBounds.x;
  902. scrollPos.y -= scrollBounds.y;
  903. return scrollPos;
  904. }
  905. private void StartDragSelection(Vector2I windowPos)
  906. {
  907. isDraggingSelection = true;
  908. dragSelectionStart = WindowToScrollAreaCoords(windowPos);
  909. dragSelectionEnd = dragSelectionStart;
  910. }
  911. private bool UpdateDragSelection(Vector2I windowPos)
  912. {
  913. if (!isDraggingSelection)
  914. return false;
  915. if (dragSelection == null)
  916. {
  917. dragSelection = new GUITexture(null, true, EditorStyles.SelectionArea);
  918. contentInfo.overlay.AddElement(dragSelection);
  919. }
  920. dragSelectionEnd = WindowToScrollAreaCoords(windowPos);
  921. Rect2I selectionArea = CalculateSelectionArea();
  922. SelectInArea(selectionArea);
  923. dragSelection.Bounds = selectionArea;
  924. return true;
  925. }
  926. private bool EndDragSelection()
  927. {
  928. if (!isDraggingSelection)
  929. return false;
  930. if (dragSelection != null)
  931. {
  932. dragSelection.Destroy();
  933. dragSelection = null;
  934. }
  935. Rect2I selectionArea = CalculateSelectionArea();
  936. SelectInArea(selectionArea);
  937. isDraggingSelection = false;
  938. return false;
  939. }
  940. private Rect2I CalculateSelectionArea()
  941. {
  942. Rect2I selectionArea = new Rect2I();
  943. if (dragSelectionStart.x < dragSelectionEnd.x)
  944. {
  945. selectionArea.x = dragSelectionStart.x;
  946. selectionArea.width = dragSelectionEnd.x - dragSelectionStart.x;
  947. }
  948. else
  949. {
  950. selectionArea.x = dragSelectionEnd.x;
  951. selectionArea.width = dragSelectionStart.x - dragSelectionEnd.x;
  952. }
  953. if (dragSelectionStart.y < dragSelectionEnd.y)
  954. {
  955. selectionArea.y = dragSelectionStart.y;
  956. selectionArea.height = dragSelectionEnd.y - dragSelectionStart.y;
  957. }
  958. else
  959. {
  960. selectionArea.y = dragSelectionEnd.y;
  961. selectionArea.height = dragSelectionStart.y - dragSelectionEnd.y;
  962. }
  963. return selectionArea;
  964. }
  965. private void SelectInArea(Rect2I scrollBounds)
  966. {
  967. ElementEntry[] foundElements = FindElementsOverlapping(scrollBounds);
  968. if (foundElements.Length > 0)
  969. {
  970. selectionAnchorStart = foundElements[0].index;
  971. selectionAnchorEnd = foundElements[foundElements.Length - 1].index;
  972. }
  973. else
  974. {
  975. selectionAnchorStart = -1;
  976. selectionAnchorEnd = -1;
  977. }
  978. List<string> elementPaths = new List<string>();
  979. foreach (var elem in foundElements)
  980. elementPaths.Add(elem.path);
  981. SetSelection(elementPaths);
  982. }
  983. private void RefreshDirectoryBar()
  984. {
  985. if (folderListLayout != null)
  986. {
  987. folderListLayout.Destroy();
  988. folderListLayout = null;
  989. }
  990. folderListLayout = folderBarLayout.AddLayoutX();
  991. string[] folders = null;
  992. string[] fullPaths = null;
  993. if (IsSearchActive)
  994. {
  995. folders = new[] {searchQuery};
  996. fullPaths = new[] { searchQuery };
  997. }
  998. else
  999. {
  1000. string currentDir = Path.Combine("Resources", currentDirectory);
  1001. folders = currentDir.Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar },
  1002. StringSplitOptions.RemoveEmptyEntries);
  1003. fullPaths = new string[folders.Length];
  1004. for (int i = 0; i < folders.Length; i++)
  1005. {
  1006. if (i == 0)
  1007. fullPaths[i] = "";
  1008. else
  1009. fullPaths[i] = Path.Combine(fullPaths[i - 1], folders[i]);
  1010. }
  1011. }
  1012. int availableWidth = folderBarLayout.Bounds.width - FOLDER_BUTTON_WIDTH * 2;
  1013. int numFolders = 0;
  1014. for (int i = folders.Length - 1; i >= 0; i--)
  1015. {
  1016. GUIButton folderButton = new GUIButton(folders[i]);
  1017. if (!IsSearchActive)
  1018. {
  1019. string fullPath = fullPaths[i];
  1020. folderButton.OnClick += () => OnFolderButtonClicked(fullPath);
  1021. }
  1022. GUILabel separator = new GUILabel("/", GUIOption.FixedWidth(FOLDER_SEPARATOR_WIDTH));
  1023. folderListLayout.InsertElement(0, separator);
  1024. folderListLayout.InsertElement(0, folderButton);
  1025. numFolders++;
  1026. Rect2I folderListBounds = folderListLayout.Bounds;
  1027. if (folderListBounds.width > availableWidth)
  1028. {
  1029. if (numFolders > 2)
  1030. {
  1031. separator.Destroy();
  1032. folderButton.Destroy();
  1033. break;
  1034. }
  1035. }
  1036. }
  1037. }
  1038. private void SortEntries(LibraryEntry[] input)
  1039. {
  1040. Array.Sort(input, (x, y) =>
  1041. {
  1042. if (x.Type == y.Type)
  1043. return x.Name.CompareTo(y.Name);
  1044. else
  1045. return x.Type == LibraryEntryType.File ? 1 : -1;
  1046. });
  1047. }
  1048. private void OnFolderButtonClicked(string path)
  1049. {
  1050. EnterDirectory(path);
  1051. }
  1052. private void OnContentsFocusChanged(bool focus)
  1053. {
  1054. hasContentFocus = focus;
  1055. }
  1056. private void OnEntryClicked(string path)
  1057. {
  1058. Select(path);
  1059. }
  1060. private void OnEntryDoubleClicked(string path)
  1061. {
  1062. LibraryEntry entry = ProjectLibrary.GetEntry(path);
  1063. if (entry != null && entry.Type == LibraryEntryType.Directory)
  1064. {
  1065. EnterDirectory(path);
  1066. }
  1067. }
  1068. private void OnCatchAllClicked()
  1069. {
  1070. DeselectAll();
  1071. }
  1072. private void OnHomeClicked()
  1073. {
  1074. currentDirectory = ProjectLibrary.Root.Path;
  1075. Refresh();
  1076. }
  1077. private void OnUpClicked()
  1078. {
  1079. currentDirectory = currentDirectory.Trim(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
  1080. if (!string.IsNullOrEmpty(currentDirectory))
  1081. {
  1082. string parent = Path.GetDirectoryName(currentDirectory);
  1083. currentDirectory = parent;
  1084. Refresh();
  1085. }
  1086. }
  1087. private void CutSelection()
  1088. {
  1089. if (selectionPaths.Count > 0)
  1090. Cut(selectionPaths);
  1091. }
  1092. private void CopySelection()
  1093. {
  1094. if (selectionPaths.Count > 0)
  1095. Copy(selectionPaths);
  1096. }
  1097. private void DuplicateSelection()
  1098. {
  1099. if (selectionPaths.Count > 0)
  1100. Duplicate(selectionPaths);
  1101. }
  1102. private void PasteToSelection()
  1103. {
  1104. DirectoryEntry selectedDirectory = null;
  1105. if (selectionPaths.Count == 1)
  1106. {
  1107. LibraryEntry entry = ProjectLibrary.GetEntry(selectionPaths[0]);
  1108. if (entry != null && entry.Type == LibraryEntryType.Directory)
  1109. selectedDirectory = (DirectoryEntry) entry;
  1110. }
  1111. if(selectedDirectory != null)
  1112. Paste(selectedDirectory.Path);
  1113. else
  1114. Paste(currentDirectory);
  1115. }
  1116. private void OnSearchChanged(string newValue)
  1117. {
  1118. searchQuery = newValue;
  1119. Refresh();
  1120. }
  1121. private void ClearSearch()
  1122. {
  1123. searchField.Value = "";
  1124. searchQuery = "";
  1125. Refresh();
  1126. }
  1127. private void OpenOptionsWindow()
  1128. {
  1129. Vector2I openPosition;
  1130. Rect2I buttonBounds = GUILayoutUtility.CalculateBounds(optionsButton, GUI);
  1131. openPosition.x = buttonBounds.x + buttonBounds.width / 2;
  1132. openPosition.y = buttonBounds.y + buttonBounds.height / 2;
  1133. ProjectDropDown dropDown = DropDownWindow.Open<ProjectDropDown>(this, openPosition);
  1134. dropDown.SetParent(this);
  1135. }
  1136. private void Reset()
  1137. {
  1138. currentDirectory = ProjectLibrary.Root.Path;
  1139. selectionAnchorStart = -1;
  1140. selectionAnchorEnd = -1;
  1141. selectionPaths.Clear();
  1142. pingPath = "";
  1143. hoverHighlightPath = "";
  1144. Refresh();
  1145. }
  1146. private Rect2I GetScrollAreaBounds()
  1147. {
  1148. Rect2I bounds = GUI.Bounds;
  1149. Rect2I folderListBounds = folderListLayout.Bounds;
  1150. Rect2I searchBarBounds = searchBarLayout.Bounds;
  1151. bounds.y += folderListBounds.height + searchBarBounds.height;
  1152. bounds.height -= folderListBounds.height + searchBarBounds.height;
  1153. return bounds;
  1154. }
  1155. protected override void WindowResized(int width, int height)
  1156. {
  1157. base.WindowResized(width, height);
  1158. Refresh();
  1159. dropTarget.Bounds = contentScrollArea.Bounds;
  1160. }
  1161. }
  1162. internal class ProjectDropDown : DropDownWindow
  1163. {
  1164. private ProjectWindow parent;
  1165. public ProjectDropDown()
  1166. :base(150, 30)
  1167. { }
  1168. internal void SetParent(ProjectWindow parent)
  1169. {
  1170. this.parent = parent;
  1171. GUIToggleGroup group = new GUIToggleGroup();
  1172. GUIToggle list16 = new GUIToggle("16", group, EditorStyles.Button, GUIOption.FixedWidth(30));
  1173. GUIToggle grid32 = new GUIToggle("32", group, EditorStyles.Button, GUIOption.FixedWidth(30));
  1174. GUIToggle grid48 = new GUIToggle("48", group, EditorStyles.Button, GUIOption.FixedWidth(30));
  1175. GUIToggle grid64 = new GUIToggle("64", group, EditorStyles.Button, GUIOption.FixedWidth(30));
  1176. ProjectViewType activeType = parent.ViewType;
  1177. switch (activeType)
  1178. {
  1179. case ProjectViewType.List16:
  1180. list16.ToggleOn();
  1181. break;
  1182. case ProjectViewType.Grid32:
  1183. grid32.ToggleOn();
  1184. break;
  1185. case ProjectViewType.Grid48:
  1186. grid48.ToggleOn();
  1187. break;
  1188. case ProjectViewType.Grid64:
  1189. grid64.ToggleOn();
  1190. break;
  1191. }
  1192. list16.OnToggled += (active) =>
  1193. {
  1194. if (active)
  1195. ChangeViewType(ProjectViewType.List16);
  1196. };
  1197. grid32.OnToggled += (active) =>
  1198. {
  1199. if (active)
  1200. ChangeViewType(ProjectViewType.Grid32);
  1201. };
  1202. grid48.OnToggled += (active) =>
  1203. {
  1204. if (active)
  1205. ChangeViewType(ProjectViewType.Grid48);
  1206. };
  1207. grid64.OnToggled += (active) =>
  1208. {
  1209. if (active)
  1210. ChangeViewType(ProjectViewType.Grid64);
  1211. };
  1212. GUILayoutY vertLayout = GUI.AddLayoutY();
  1213. vertLayout.AddFlexibleSpace();
  1214. GUILayoutX contentLayout = vertLayout.AddLayoutX();
  1215. contentLayout.AddFlexibleSpace();
  1216. contentLayout.AddElement(list16);
  1217. contentLayout.AddElement(grid32);
  1218. contentLayout.AddElement(grid48);
  1219. contentLayout.AddElement(grid64);
  1220. contentLayout.AddFlexibleSpace();
  1221. vertLayout.AddFlexibleSpace();
  1222. }
  1223. private void ChangeViewType(ProjectViewType viewType)
  1224. {
  1225. parent.ViewType = viewType;
  1226. }
  1227. }
  1228. }