Click here to Skip to main content
15,896,063 members
Articles / Desktop Programming / WPF

How To Embed An Application Into a Docking Library

Rate me:
Please Sign up or sign in to vote.
5.00/5 (6 votes)
3 Sep 2011CPOL7 min read 29.3K   2.5K   19  
Step by Step conversion of an application into a Docking application component
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using Sofa.Container;
using Sofa.Commons;
using System.IO;
using System.Windows;
using System.Deployment.Application;
using System.Windows.Controls;


namespace CSWPFMasterDetailBinding
{
    public enum Mode
    {
        Perspectives,
        All
    }

    public class PerspectiveHelper
    {
        #region Declarations

        SofaContainer sofaContainer;
        UserControl baseWindow;

        string optionalTemplateSelection = "<Optional template selection>";

        //Used for BaseWindow menu
        public List<string> perspectivesList
        {
            get
            {
                //List all perspectives (and not templates) in the Perspective directory.
                return listPerspectives(Mode.Perspectives);
            }
        }

        string _perspectiveDirectoryName
        {
            get
            {
                if (!ApplicationDeployment.IsNetworkDeployed)
                    return string.Concat(ContainerParameter.DebugDirectoryLocation, "\\Sofa\\Perspectives");
                else
                    return string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "\\Sofa\\Perspectives");
            }
        }

        #endregion Declarations

        public PerspectiveHelper(SofaContainer sofaContainer, UserControl baseWindow)
        {
            this.sofaContainer = sofaContainer;
            this.baseWindow = baseWindow;
        }

        #region Methods

        public void SaveCurrentPerspective()
        {
            if (sofaContainer.CurrentPerspective != null)
            {
                sofaContainer.SavePerspective(sofaContainer.CurrentPerspective);
            }
        }

 
        public void LoadPerspective(string perspectiveName)
        {
            SaveCurrentPerspective();
            Perspective p = sofaContainer.LoadPerspective(perspectiveName);
        }



        #endregion Methods

        #region Utils

        string getNameFromFileName(string fileName)
        {
            fileName = fileName == null ? "" : fileName;
            int p = fileName.IndexOf(".xml");
            if (p != -1) fileName = fileName.Substring(0, p);
            string[] fileNames = fileName.Split('\\');
            if (fileNames.Length >= 1) return fileNames[fileNames.Length - 1];
            else return "";
        }


        List<string> listPerspectives(Mode mode)
        {
            List<string> templatesList = new List<string>();
            //Add "<Optional template selection>"
            if (mode == Mode.All) templatesList.Add(optionalTemplateSelection);
            
            DirectoryInfo di = new DirectoryInfo(_perspectiveDirectoryName);            
            FileInfo[] rgFiles = null;
            rgFiles = di.GetFiles("*.xml");

            foreach (FileInfo fi in rgFiles)
            {
                //tests should be improved, but this is an example...
                //"_XFileExplorerPerspectiveTemplate" specific template, cannot be used
                //fi.Name.Length != 36: Templates used by SofaExplorer instances, name includes SofaComponent's GUI
                if ((mode == Mode.All) | (!fi.Name.StartsWith("_") && fi.Name != "_XFileExplorerPerspectiveTemplate" && fi.Name.Length != 36))
                {
                    templatesList.Add(getNameFromFileName(fi.Name));
                }
            }
            return templatesList;
        }

        #endregion Utils

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions