示例#1
0
文件: MDHandler.cs 项目: sispd/Wider
        public ContentViewModel NewContent(Object parameter)
        {
            MDViewModel vm    = _container.Resolve <MDViewModel>();
            MDModel     model = _container.Resolve <MDModel>();
            MDView      view  = _container.Resolve <MDView>();

            //Model details
            _loggerService.Log("Creating a new simple file using MDHandler", Category.Info, Priority.Low);

            view.DataContext = model;

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

            //Set the model and view
            vm.SetModel(model);
            vm.SetView(view);
            vm.Title = "untitled-MD";
            vm.SetHandler(this);
            model.SetDirty(true);

            return(vm);
        }
示例#2
0
文件: MDHandler.cs 项目: sispd/Wider
        /// <summary>
        /// Opens a file and returns the corresponding MDViewModel
        /// </summary>
        /// <param name="info">The string location of the file</param>
        /// <returns>The <see cref="MDViewModel"/> for the file.</returns>
        public ContentViewModel OpenContent(Object info)
        {
            if (info is String location)
            {
                MDViewModel vm    = _container.Resolve <MDViewModel>();
                MDModel     model = _container.Resolve <MDModel>();
                MDView      view  = _container.Resolve <MDView>();

                //Model details
                model.SetLocation(info);
                try
                {
                    model.Document.Text = File.ReadAllText(location);
                    model.SetDirty(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.SetModel(model);
                vm.SetView(view);
                vm.Title = Path.GetFileName(location);

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