private void ResourceCreated(object sender, FileSystemEventArgs e)
 {
     Dispatcher.BeginInvoke(new Action <String>((String p) =>
     {
         AddNode(p);
         ThomasEngine.Resources.AssetTypes assetType = ThomasEngine.Resources.GetResourceAssetType(p);
         if (assetType == ThomasEngine.Resources.AssetTypes.SCRIPT)
         {
             utils.ScriptAssemblyManager.AddScript(p);
         }
     }), e.FullPath);
 }
        private void OpenItem(TreeViewItem item)
        {
            StackPanel stack = item.Header as StackPanel;

            String file = stack.DataContext as String;

            ThomasEngine.Resources.AssetTypes assetType = ThomasEngine.Resources.GetResourceAssetType(file);
            if (assetType == ThomasEngine.Resources.AssetTypes.SCENE)
            {
                MainWindow._instance.LoadScene(file);
            }
            else if (assetType == ThomasEngine.Resources.AssetTypes.SHADER)
            {
                System.Diagnostics.Process.Start(file);
            }
        }
        private void ResourceRenamed(object sender, RenamedEventArgs e)
        {
            Dispatcher.BeginInvoke(new Action <String, String>((String oldPath, String newPath) =>
            {
                ThomasEngine.Resources.AssetTypes oldType = ThomasEngine.Resources.GetResourceAssetType(oldPath);
                ThomasEngine.Resources.AssetTypes newType = ThomasEngine.Resources.GetResourceAssetType(newPath);

                TreeViewItem foundItem = FindNode(oldPath);
                if (foundItem != null)
                {
                    if (oldType != newType)
                    {
                        return;
                    }

                    ThomasEngine.Resources.RenameResource(oldPath, newPath);

                    StackPanel stack  = foundItem.Header as StackPanel;
                    stack.DataContext = newPath;

                    String visibleName = Path.GetFileNameWithoutExtension(newPath);

                    (stack.Children[1] as EditableTextBlock).Text = visibleName;
                }
                else
                {
                    if (newType == ThomasEngine.Resources.AssetTypes.SHADER)
                    {
                        Resource shader = ThomasEngine.Resources.Find(newPath);
                        if (shader != null)
                        {
                            shader.Reload();
                        }
                    }
                }
            }), e.OldFullPath, e.FullPath);
        }
        private object CreateItem(string filePath)
        {
            if (Directory.Exists(filePath)) //dir
            {
                String dirName = new DirectoryInfo(filePath).Name;

                StackPanel stack = new StackPanel();
                stack.Orientation = Orientation.Horizontal;
                stack.Height      = 18;
                Image image = new Image();
                image.Source = new BitmapImage(new Uri("pack://application:,,/icons/assets/dir.png"));
                EditableTextBlock lbl = new EditableTextBlock {
                    Text = dirName
                };
                stack.Children.Add(image);
                stack.Children.Add(lbl);
                stack.DataContext = filePath;

                TreeViewItem item = new TreeViewItem {
                    Header = stack
                };
                foreach (object i in CreateTree(filePath))
                {
                    item.Items.Add(i);
                }

                return(item);
            }
            else if (File.Exists(filePath))
            {
                String fileName = Path.GetFileNameWithoutExtension(filePath);
                ThomasEngine.Resources.AssetTypes assetType = ThomasEngine.Resources.GetResourceAssetType(filePath);
                if (assetType == ThomasEngine.Resources.AssetTypes.UNKNOWN)
                {
                    return(null);
                }
                StackPanel stack = new StackPanel();
                stack.Orientation = Orientation.Horizontal;
                stack.Height      = 18;

                ImageSource source;
                if (assetType == ThomasEngine.Resources.AssetTypes.TEXTURE2D)
                {
                    source = new BitmapImage(new Uri(Path.GetFullPath(filePath)));
                }
                else
                {
                    source = assetImages[assetType];
                }

                Image image = new Image {
                    Source = source
                };

                EditableTextBlock lbl = new EditableTextBlock {
                    Text = fileName
                };
                stack.Children.Add(image);
                stack.Children.Add(lbl);
                stack.DataContext = filePath;

                return(new TreeViewItem {
                    Header = stack, DataContext = ThomasEngine.Resources.Load(filePath)
                });
            }
            return(null);
        }