public static void OpenPackageControlPanelWindow(Rect position, UFramePackageDescriptor package)
 {
     var packageControlPanel = EditorWindow.CreateInstance<PackageControlPanel>();
     packageControlPanel.minSize = packageControlPanel.maxSize = new Vector2(200, 200);
     packageControlPanel.Package = package;
     Debug.Log("Showing at position "+position.x+" , "+position.y);
     packageControlPanel.ShowAsDropDown(position ,new Vector2(200, 200));
     packageControlPanel.Repaint();
     packageControlPanel.Focus();
 }
        public void DrawPackagePage(Rect bounds, UFramePackageDescriptor package)
        {

            var imageBounds = new Rect(bounds.x + 5, bounds.y + 5, 150, 150);
            var titleBounds = new Rect(imageBounds)
            {
                x = imageBounds.xMax + 5,
                width = bounds.width - imageBounds.width - 10,
                height = 20
            };
            var descriptionBounds = new Rect(titleBounds)
            {
                y = titleBounds.yMax + 10,
                height = 120,
                width = 400
            };

            var backButtonRect = new Rect(descriptionBounds)
            {
                y = descriptionBounds.yMax + 20,
                height = 30,
                width = 100
            };

            GUI.DrawTexture(imageBounds, GetImage(package.ProjectIconUrl), ScaleMode.ScaleToFit, true);
            GUI.Label(titleBounds, package.Title, ProjectPreviewTitleStyle);
            GUI.Label(descriptionBounds, package.Description, ProjectPageDescriptionStyle);

            if (GUI.Button(backButtonRect, "Back"))
            {
                InvertApplication.ExecuteInBackground(new SelectPackageCommand() {Id = null});
            }

            var revButtonRect = new Rect(backButtonRect)
            {
                x = backButtonRect.xMax + 5,
                width = 200
            };

            foreach (var revision in KoinoniaSystem.SelectedPackageRevisions)
            {

                if (GUI.Button(revButtonRect, string.Format("Install {1} {0}", revision.VersionTag, package.Title)))
                {
                    InvertApplication.ExecuteInBackground(new QueueRevisionForInstallCommand()
                    {
                        PackageDescriptor = package,
                        RevisionDescriptor = revision
                    });
                    //Debug.Log("Will download revision from "+ revision.SnapshotUri);
                }

                revButtonRect = new Rect(revButtonRect)
                {
                    y = revButtonRect.yMax
                };
            }


        }
 private void UpdateCacheWithPackageDescriptor(UFramePackageDescriptor descriptor)
 {
     var oldEntry = Cache.All<UFramePackageDescriptor>().FirstOrDefault(d=>d.Id == descriptor.Id);
     if (oldEntry != null) Cache.Remove(oldEntry);
     descriptor.CacheExpireTime = DateTime.Now.AddMinutes(30);
     Cache.Add(descriptor);
     Cache.Commit();
 }      
        private void DrawPackagePreview(Rect bounds, UFramePackageDescriptor descriptor, Action leftClick = null, Action rightClick= null)
        {
            var borderRect = new Rect(bounds);
            var previewImageRect = new Rect(borderRect)
            {
                x = borderRect.x + 5,
                y = borderRect.y + 5,
                width = bounds.width - 10,
                height = bounds.width - 10
            };

            var latestVersionRect = new Rect()
            {
                x = previewImageRect.x + previewImageRect.width/2,
                y = previewImageRect.yMax - 15,
                width = previewImageRect.width/2,
                height = 15
            };

            var titleRect = new Rect()
            {
                x = previewImageRect.x,
                y = previewImageRect.yMax,
                width = previewImageRect.width,
                height = bounds.height - 10 - previewImageRect.height
            };


            if (GUI.Button(borderRect, ""))
            {
                if (leftClick != null) leftClick();
            }


            GUI.DrawTexture(previewImageRect,GetImage(descriptor.ProjectIconUrl),ScaleMode.ScaleToFit,true );
            //GUI.Label(latestVersionRect,descriptor.LatestPublicVersionTag,ProjectPreviewVersionStyle);
            GUI.Label(titleRect,descriptor.Title,ProjectPreviewTitleStyle);


        }
        public IEnumerable<UFramePackageRevisionDescriptor> GetRevisionsByProject(UFramePackageDescriptor package)
        {
            var revisionsToRequest = package.RevisionIds.Where(CachedRevisionDescriptorNeedsUpdate).ToArray();
            var upToDateRevisions = package.RevisionIds.Except(revisionsToRequest);
            var newRevisions = RequestPackageRevisionsByIds(revisionsToRequest).ToArray();

            foreach (var revision in newRevisions)
            {
                UpdateCacheWithPackageRevisionDescriptor(revision);
            }

            Cache.Commit();
            //Get new updated revisions
            //Concat with up-to-date shit
            //?????
            //Profit
            return upToDateRevisions.Select(_=>GetRevisionById(_)).Concat(newRevisions);

        }