Exemple #1
0
        public bool OpenDocument(string fileName)
        {
            // 如果文件不存在,则退出;
            if (!File.Exists(fileName))
            {
                return(false);
            }

            // 2、判断当前文件是否已经打开,如果已经打开,则将其状态置为Active;
            DocumentViewModel model = this.GetDocModel(fileName);

            if (model != null)
            {
                model.IsSelected = true;
                model.IsActive   = true;
                return(true);
            }

            // 3、目标文档未打开,则获取对应的工厂实例,并创建相关视图对象;
            IViEditorFactory factory = this.GetEditorFactory(fileName);

            if (factory == null)
            {
                return(false);
            }
            IViEditor editor = factory.CreateEditorInstance();

            // 4、加载相关数据;
            editor.Load(fileName);

            this.AddDocModel(new DocumentViewModel(editor, this));
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// 根据扩展名获取对应的 EditorFactory;
        /// </summary>
        private IViEditorFactory GetEditorFactory(String extention)
        {
            extention = Path.GetExtension(extention);
            if (String.IsNullOrEmpty(extention))
            {
                return(null);
            }

            String key = extention.ToUpper();
            // 如果已经有,则直接返回;
            IViEditorFactory factory = this.DEditorFactorys.ContainsKey(key) ? this.DEditorFactorys[key] : null;

            if (factory != null)
            {
                return(factory);
            }

            factory = ViShellManager.GetEditorFactory(key);
            if (factory != null)
            {
                this.DEditorFactorys[key] = factory;
            }

            return(factory);
        }
        /// <summary>
        /// 根据给定的扩展名,获取目标编辑器工厂实例;
        /// </summary>
        public static IViEditorFactory GetEditorFactory(String extention)
        {
            if (String.IsNullOrEmpty(extention))
                return null;

            String key = extention.ToUpper();
            Type factoryType = DFactoryTypes.ContainsKey(key) ? DFactoryTypes[key] : null;
            if (factoryType == null)
                return null;

            try
            {
                IViEditorFactory factory = DEditorFactorys.ContainsKey(factoryType) ? DEditorFactorys[factoryType] : null;
                if (factory == null)
                {
                    factory = Activator.CreateInstance(factoryType) as IViEditorFactory;
                    DEditorFactorys[factoryType] = factory;
                }

                return factory;
            }
            catch (Exception ee)
            {
                return null;
            }
        }