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); }
public DocumentViewModel(IViEditor editor, ViDocManager docManager) { this.editor = editor; this.FilePath = editor.FileName; this.Title = this.FileName; this.Control = editor.Control; this.docManager = docManager; }
public void AddDocModel(IViEditor editor) { if (editor == null) { return; } var model = this.GetDocModel(editor); if (model != null) { return; } this.AddDocModel(new DocumentViewModel(editor, this)); }
public DocumentViewModel GetDocModel(IViEditor editor) { return(editor == null ? null : this.GetDocModel(editor.FileName)); }