private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this._ProjectItem = this.CurrentProjectFolder;
            this._AllTree = Service.GetFileTree(this.CurrentProjectFolder, this.RootPath);
            this._TopFolder = this.CurrentProjectFolder;

            this.CurrentProjectFolder.Expand();
            this.treeProjectFolder.ItemsSource = this._AllTree;

            this.cbRoles.ItemsSource = Enum.GetValues(typeof(ProjectFolderRole)).Cast<ProjectFolderRole>();
            this.cbRoles.SelectedValue = this.CurrentProjectFolder.ProjectFolderRole;
            this.cbRoles.IsEnabled = true;

            this.SetVisibility(this.CurrentProjectFolder.ProjectFolderRole);
            this.SetForm();
        }
        private void TreeViewItem_Checked(object sender, RoutedEventArgs e)
        {
            this._ProjectItem = ((CheckBox)e.OriginalSource).DataContext as ProjectItemInfo;
            if (this._ProjectItem == null)
                return;

            if (this._ProjectItem.Handled)
                return;

            ProjectFolderInfo selectedFolder = Service.GetSelectedFolderFromTree(this._AllTree);
            if (selectedFolder != null)
                this._TopFolder = selectedFolder;

            this.SetChildProperties(this._ProjectItem as ProjectFolderInfo);

            this.SetParentProperties(this._ProjectItem);
        }
        private void TreeViewItem_Selected(object sender, RoutedEventArgs e)
        {
            this._ProjectItem = ((TreeViewItem)e.OriginalSource).DataContext as ProjectItemInfo;
            if (this._ProjectItem == null)
                return;

            ProjectFolderInfo selectedFolder = Service.GetSelectedFolderFromTree(this._AllTree);
            if (selectedFolder != null)
                this._TopFolder = selectedFolder;

            if (this._TopFolder != null)
                this.SetVisibility(this._TopFolder.ProjectFolderRole);

            this.SetForm();
        }
        private void SetChildProperties(ProjectFolderInfo folder)
        {
            if (folder == null)
                return;

            if (folder.Checked == null)
            {
                folder.Handled = true;
                folder.Checked = false;
                folder.Handled = false;
            }

            if ((folder.Checked == true || folder.Checked == false) && folder.ChildItems != null)
            {
                foreach (ProjectItemInfo child in folder.ChildItems)
                {
                    child.Handled = true;
                    child.Checked = folder.Checked;
                    child.Handled = false;
                }
            }
        }
        private void SetChildRoles(ProjectFolderInfo folder)
        {
            if (folder == null)
                return;

            if (folder.ChildItems != null)
            {
                foreach (ProjectItemInfo child in folder.ChildItems)
                {
                    if (!child.IsFolder) continue;

                    ProjectFolderInfo childFolder = (ProjectFolderInfo)child;
                    childFolder.ProjectFolderRole = folder.ProjectFolderRole;
                    SetChildRoles(childFolder);
                }
            }
        }
        private static string GetContainerTcmId(MappingInfo mapping, TridionRole tridionRole, ProjectFolderInfo folder, string path)
        {
            if (folder != null && !String.IsNullOrEmpty(folder.TcmId))
                return folder.TcmId;

            if (mapping.TridionFolders.Any(x => x.TridionRole == tridionRole))
            {
                if (mapping.TridionFolders.Count(x => x.TridionRole == tridionRole) == 1)
                {
                    string tcm = mapping.TridionFolders.First(x => x.TridionRole == tridionRole).TcmId;
                    if (folder != null)
                        folder.TcmId = tcm;
                    return tcm;
                }

                SelectTridionFolderDialogWindow dialog = new SelectTridionFolderDialogWindow();
                dialog.Path = path;
                dialog.TridionFolders = mapping.TridionFolders.Where(x => x.TridionRole == tridionRole).ToList().FillNamedPath(mapping);
                bool res = dialog.ShowDialog() == true;
                if (res)
                {
                    return dialog.SelectedTridionFolder.TcmId;
                }
            }

            return String.Empty;
        }
 private static string GetContainerTcmId(MappingInfo mapping, TridionRole tridionRole, ProjectFolderInfo folder)
 {
     if(folder == null)
         return String.Empty;
     return GetContainerTcmId(mapping, tridionRole, folder, folder.Path);
 }
        public static void ProcessTridionItem(MappingInfo mapping, ItemInfo item, TridionFolderInfo folder)
        {
            //todo: nested folders?

            if (item == null || folder == null)
                return;

            if (!folder.ScanForItems)
                return;

            if (mapping.ProjectFolders.Any(projectFolder => projectFolder.ExistsTcmId(item.TcmId)))
                return;

            if (folder.TridionRole == TridionRole.PageLayoutContainer || folder.TridionRole == TridionRole.ComponentLayoutContainer)
            {
                TemplateBuildingBlockData tridionItem = ReadItem(mapping, item.TcmId) as TemplateBuildingBlockData;
                if (tridionItem == null || tridionItem.VersionInfo.RevisionDate == null)
                    return;

                ShowMessage(item.Title + "...");

                if (ProjectDestination_Skip)
                {
                    //skip checkbox is pressed

                    ProjectFolderInfo projectFolder = null;
                    if (folder.TridionRole == TridionRole.PageLayoutContainer)
                    {
                        projectFolder = mapping.ProjectFolders.FirstOrDefault(x => x.ProjectFolderRole == ProjectFolderRole.PageLayout);
                    }
                    if (folder.TridionRole == TridionRole.ComponentLayoutContainer)
                    {
                        projectFolder = mapping.ProjectFolders.FirstOrDefault(x => x.ProjectFolderRole == ProjectFolderRole.ComponentLayout);
                    }
                    if (projectFolder == null)
                        projectFolder = new ProjectFolderInfo();

                    if (projectFolder.ChildItems == null)
                        projectFolder.ChildItems = new List<ProjectItemInfo>();

                    string path = Path.Combine(projectFolder.Path, item.Title.Replace(".cshtml", "") + ".cshtml");

                    ProjectFileInfo projectFile = projectFolder.ChildItems.OfType<ProjectFileInfo>().FirstOrDefault(x => x.Path == path) ?? new ProjectFileInfo();
                    projectFile.Parent = projectFolder;
                    projectFile.RootPath = projectFolder.RootPath;
                    projectFile.Path = path;
                    projectFile.TcmId = item.TcmId;
                    projectFile.Checked = true;
                    projectFile.SyncTemplate = Common.IsolatedStorage.Service.GetFromIsolatedStorage(Common.IsolatedStorage.Service.GetId(mapping.Host, "ProjectDestination_SyncTemplate")) == "true";

                    if (projectFolder.ChildItems.OfType<ProjectFileInfo>().All(x => x.Path != path))
                    {
                        projectFolder.ChildItems.Add(projectFile);
                    }

                    string fullPath = projectFile.FullPath;
                    DateTime tridionDate = (DateTime)tridionItem.VersionInfo.RevisionDate;
                    DateTime tridionLocalDate = tridionDate.GetLocalTime(mapping.TimeZoneId);
                    SaveVSItem(fullPath, tridionItem.Content);
                    File.SetAttributes(fullPath, FileAttributes.Normal);
                    File.SetLastWriteTime(fullPath, tridionLocalDate);
                    WriteSuccessLog(fullPath + " - Saved to Visual Studio");
                }
                else
                {
                    ProjectDestinationDialogWindow dialog = new ProjectDestinationDialogWindow();
                    dialog.Mapping = mapping;
                    dialog.TridionRole = folder.TridionRole;
                    dialog.TridionTcmId = item.TcmId;
                    dialog.TridionTitle = item.Title;
                    dialog.TridionContent = tridionItem.Content;

                    bool res = dialog.ShowDialog() == true;
                    if (res)
                    {
                        ProjectFolderInfo projectFolder = dialog.ProjectFolder;
                        ProjectFileInfo projectFile = dialog.ProjectFile;

                        if (projectFolder != null && projectFile != null)
                        {
                            string fullPath = projectFile.FullPath;
                            DateTime tridionDate = (DateTime)tridionItem.VersionInfo.RevisionDate;
                            DateTime tridionLocalDate = tridionDate.GetLocalTime(mapping.TimeZoneId);
                            SaveVSItem(fullPath, tridionItem.Content);
                            File.SetAttributes(fullPath, FileAttributes.Normal);
                            File.SetLastWriteTime(fullPath, tridionLocalDate);
                            WriteSuccessLog(fullPath + " - Saved to Visual Studio");
                        }
                    }
                }

                ShowMessage(String.Empty);
            }

            if (folder.TridionRole == TridionRole.MultimediaComponentContainer)
            {
                ComponentData tridionItem = GetComponent(mapping, item.TcmId);
                if (tridionItem == null || tridionItem.VersionInfo.RevisionDate == null)
                    return;

                ShowMessage(item.Title + "...");

                if (ProjectDestination_Skip)
                {
                    ProjectFolderInfo projectFolder = mapping.ProjectFolders.FirstOrDefault(x => x.ProjectFolderRole == ProjectFolderRole.Binary) ?? new ProjectFolderInfo();
                    if (projectFolder.ChildItems == null)
                        projectFolder.ChildItems = new List<ProjectItemInfo>();

                    string path = Path.Combine(projectFolder.Path, item.Title);

                    ProjectFileInfo projectFile = projectFolder.ChildItems.OfType<ProjectFileInfo>().FirstOrDefault(x => x.Path == path) ?? new ProjectFileInfo();
                    projectFile.Parent = projectFolder;
                    projectFile.RootPath = projectFolder.RootPath;
                    projectFile.Path = path;
                    projectFile.TcmId = item.TcmId;
                    projectFile.Checked = true;

                    if (projectFolder.ChildItems.OfType<ProjectFileInfo>().All(x => x.Path != path))
                    {
                        projectFolder.ChildItems.Add(projectFile);
                    }

                    string fullPath = projectFile.FullPath;
                    DateTime tridionDate = (DateTime)tridionItem.VersionInfo.RevisionDate;
                    DateTime tridionLocalDate = tridionDate.GetLocalTime(mapping.TimeZoneId);
                    SaveVSBinaryItem(mapping, projectFile.TcmId, fullPath);
                    File.SetAttributes(fullPath, FileAttributes.Normal);
                    File.SetLastWriteTime(fullPath, tridionLocalDate);
                    WriteSuccessLog(fullPath + " - Saved to Visual Studio");
                }
                else
                {
                    ProjectBinaryDestinationDialogWindow dialog = new ProjectBinaryDestinationDialogWindow();
                    dialog.Mapping = mapping;
                    dialog.TridionTcmId = item.TcmId;
                    dialog.TridionTitle = item.Title;

                    bool res = dialog.ShowDialog() == true;
                    if (res)
                    {
                        ProjectFolderInfo projectFolder = dialog.ProjectFolder;
                        ProjectFileInfo projectFile = dialog.ProjectFile;

                        if (projectFolder != null && projectFile != null)
                        {
                            string fullPath = projectFile.FullPath;
                            DateTime tridionDate = (DateTime)tridionItem.VersionInfo.RevisionDate;
                            DateTime tridionLocalDate = tridionDate.GetLocalTime(mapping.TimeZoneId);
                            SaveVSBinaryItem(mapping, projectFile.TcmId, fullPath);
                            File.SetAttributes(fullPath, FileAttributes.Normal);
                            File.SetLastWriteTime(fullPath, tridionLocalDate);
                            WriteSuccessLog(fullPath + " - Saved to Visual Studio");
                        }
                    }
                }

                ShowMessage(String.Empty);
            }
        }
        public static void ProcessFolder(MappingInfo mapping, ProjectFolderInfo folder)
        {
            if (folder == null || folder.ChildItems == null)
                return;

            if (folder.Checked == false)
                return;

            ProjectFolderRole role = folder.ProjectFolderRole;
            TridionRole tridionRole = TridionRole.Other;

            if (role == ProjectFolderRole.PageLayout)
            {
                tridionRole = TridionRole.PageLayoutContainer;
            }

            if (role == ProjectFolderRole.ComponentLayout)
            {
                tridionRole = TridionRole.ComponentLayoutContainer;
            }

            if (role == ProjectFolderRole.Binary)
            {
                tridionRole = TridionRole.MultimediaComponentContainer;
            }

            string tcmItemContainer = GetContainerTcmId(mapping, tridionRole, folder);

            if (String.IsNullOrEmpty(tcmItemContainer))
            {
                WriteErrorLog("Could not find Tridion mapping for role " + tridionRole);
                return;
            }

            foreach (ProjectItemInfo item in folder.ChildItems)
            {
                item.Parent = folder;

                if (item.IsFile)
                {
                    ProcessFile(mapping, (ProjectFileInfo)item);
                }
                if (item.IsFolder)
                {
                    ProcessFolder(mapping, (ProjectFolderInfo)item);
                }
            }
        }
Esempio n. 10
0
 internal void AddProjectFolderInfo(ProjectFolderInfo afInfo)
 {
     m_ProjectFolderList.Add(afInfo);
 }
Esempio n. 11
0
    private void drawAssetFolderInfoRecursively(ProjectFolderInfo assetFolder, int indentLevel)
    {
        EditorGUI.indentLevel = indentLevel;

        if (!assetFolder.ShouldBeListed(m_unusedTypeDict))
        {
            return;
        }
        else
        {
            int assetCount = assetFolder.GetAssetCountInChildren();
            EditorGUILayout.BeginHorizontal();

            Color initialColor = GUI.color;
            GUI.color = Color.yellow;
            float buttonSizeSelect = 60;
            float buttonSizeDelete = 100;

            if (GUILayout.Button("Delete all " + assetCount, GUILayout.Width(buttonSizeDelete)))
            {
                m_folderMarkedForDeletion = assetFolder;
            }

            //Add space to align UI elements
            GUILayout.Space(buttonSizeSelect);

            //Create new style to have a bold foldout
            GUIStyle  style         = EditorStyles.foldout;
            FontStyle previousStyle = style.fontStyle;
            style.fontStyle = FontStyle.Bold;

            //Show foldout
            assetFolder.FoldOut = EditorGUILayout.Foldout(assetFolder.FoldOut, assetFolder.DirectoryName + " (" + assetCount + ")", style);

            //Reset style
            style.fontStyle = previousStyle;

            //Reset color
            GUI.color = initialColor;

            EditorGUILayout.EndHorizontal();
            if (assetFolder.FoldOut)
            {
                foreach (AssetObjectInfo aInfo in assetFolder.AssetList)
                {
                    if ((m_unusedTypeDict.ContainsKey(aInfo.m_Type) && m_unusedTypeDict[aInfo.m_Type] == false))
                    {
                        continue;
                    }

                    EditorGUI.indentLevel = (indentLevel + 1);
                    EditorGUILayout.BeginHorizontal();
                    GUI.color = Color.grey;
                    if (GUILayout.Button("Delete", GUILayout.Width(buttonSizeDelete)))
                    {
                        m_assetMarkedForDeletion = aInfo;
                    }
                    GUI.color = initialColor;
                    if (GUILayout.Button("Select", GUILayout.Width(buttonSizeSelect)))
                    {
                        Selection.activeObject = AssetDatabase.LoadAssetAtPath(aInfo.m_Path, aInfo.m_Type.SystemType);
                    }

                    EditorGUILayout.LabelField(aInfo.m_Name, GUILayout.MaxWidth(600));
                    EditorGUILayout.EndHorizontal();
                }

                foreach (int childFolder in assetFolder.ChildFolderIndexers)
                {
                    drawAssetFolderInfoRecursively(m_ProjectFolderList[childFolder], (indentLevel + 1));
                }
            }
        }
    }
Esempio n. 12
0
    private void showUnusedAssets()
    {
        EditorGUILayout.Separator();
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Collapse All", GUILayout.Width(btnMinWidth)))
        {
            foreach (ProjectFolderInfo folder in m_ProjectFolderList)
            {
                folder.FoldOut = false;
            }
        }

        EditorGUILayout.Space();

        if (GUILayout.Button("Expand All", GUILayout.Width(btnMinWidth)))
        {
            foreach (ProjectFolderInfo folder in m_ProjectFolderList)
            {
                folder.FoldOut = true;
            }
        }
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Separator();
        EditorGUILayout.Separator();
        int indentLevel = 0;

        drawAssetFolderInfoRecursively(m_ProjectFolderList[0], indentLevel);

        if (m_assetMarkedForDeletion != null)
        {
            if (EditorUtility.DisplayDialog("Delete asset", "Are you sure you want to delete " + m_assetMarkedForDeletion.m_Name, "Yes", "No"))
            {
                m_assetMarkedForDeletion.Delete(m_unusedTypeDict);
                //Delete potential empty folders
                processDirectory(getSystemFolderPath(m_assetMarkedForDeletion.m_ParentPath));
                m_assetMarkedForDeletion = null;
            }
            else
            {
                m_assetMarkedForDeletion = null;
            }
        }
        else if (m_folderMarkedForDeletion != null)
        {
            if (EditorUtility.DisplayDialog("Delete all assets in folder", "Are you sure you want to delete all " + m_folderMarkedForDeletion.GetAssetCountInChildren() + " assets in: " + m_folderMarkedForDeletion.DirectoryName, "Yes", "No"))
            {
                List <AssetObjectInfo> objectsToDelete = new List <AssetObjectInfo>();
                getObjectsMarkedForDeletion(m_folderMarkedForDeletion, ref objectsToDelete);

                deleteSelected(objectsToDelete);
                //Delete potential empty folders
                processDirectory(getSystemFolderPath(m_folderMarkedForDeletion.DirectoryName));
                m_folderMarkedForDeletion = null;
                refreshUnusedAssets();
            }
            else
            {
                m_folderMarkedForDeletion = null;
            }
        }
    }