예제 #1
0
        /// <summary>
        /// Opens a file and returns the corresponding ContentViewModel
        /// </summary>
        /// <param name="info">The string location of the file</param>
        /// <returns>The <see cref="TextViewModel"/> for the file.</returns>
        public ContentViewModel OpenContent(Object info)
        {
            if (info is String location)
            {
                TextViewModel vm    = _container.Resolve <TextViewModel>();
                TextModel     model = _container.Resolve <TextModel>();
                TextView      view  = _container.Resolve <TextView>();

                //Model details
                model.SetLocation(info);
                try
                {
                    model.Document.Text = File.ReadAllText(location);
                    model.IsDirty       = false;
                }
                catch (Exception exception)
                {
                    _loggerService.Log(exception.Message, Category.Exception, Priority.High);
                    _loggerService.Log(exception.StackTrace, Category.Exception, Priority.High);
                    return(null);
                }

                view.DataContext = model;

                //Clear the undo stack
                model.Document.UndoStack.ClearAll();

                //Set the model and view
                vm.Model = model;
                vm.View  = view;
                vm.Title = Path.GetFileName(location);

                return(vm);
            }
            return(null);
        }