示例#1
0
        /// <summary>
        /// Remove a targe file from the collection of target files in viewmodel and underlying model.
        /// </summary>
        /// <param name="frViewModel"></param>
        /// <returns></returns>
        public bool RemoveTargetFile(FileReferenceViewModel frViewModel)
        {
            if (string.IsNullOrEmpty(frViewModel.ItemPathName) == true)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(frViewModel.Type) == true)
            {
                return(false);
            }

            var item = Children.SingleOrDefault(p => string.Compare(p.Path, frViewModel.ItemPathName, true) == 0);

            if (item != null)
            {
                var frVMColl = item as FileReferenceViewModel;

                var model = frVMColl.GetModel();

                var projectModel = mProjectModel.TargetFiles.SingleOrDefault(p => string.Compare(p.Path, frViewModel.ItemPathName, true) == 0);

                // Remove model and viewmodel from collection of target files
                mProjectModel.RemoveTargetFile(projectModel.Path);
                Children.Remove(frVMColl);

                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Copy Constructor
        /// </summary>
        /// <param name="copyThis"></param>
        public FileReferenceViewModel(FileReferenceViewModel copyThis)
            : this()
        {
            if (copyThis == null)
            {
                return;
            }

            mFile = new FileReference(copyThis.mFile);
        }
示例#3
0
        /// <summary>
        /// Class constructor
        /// </summary>
        public ProjectViewModel(Project projectModel, ISolutionItem parent)
            : this()
        {
            mParent = parent;

            // Copy target file entries from model into ViewModel
            foreach (var item in projectModel.TargetFiles)
            {
                mTargetFiles.Add(new FileReferenceViewModel(item, this));
            }

            mProjectModel = projectModel;

            if (mProjectModel.SourceFile != null)
            {
                mSourceFile = new FileReferenceViewModel(mProjectModel.SourceFile, this);
            }
        }
示例#4
0
        /// <summary>
        /// Add a targe file to the collection of target files in viewmodel and underlying model.
        /// </summary>
        /// <param name="fr"></param>
        /// <param name="updateFields"></param>
        public void AddTargetFile(FileReference fr, bool updateFields = true)
        {
            if (string.IsNullOrEmpty(fr.Path) == true)
            {
                return;
            }

            if (string.IsNullOrEmpty(fr.Type) == true)
            {
                return;
            }

            var frViewModel = new FileReferenceViewModel(fr, this);

            var item = Children.SingleOrDefault(p => string.Compare(p.Path, fr.Path, true) == 0);

            if (item == null)
            {
                mProjectModel.AddTargetFile(fr);
                Children.Add(frViewModel);
            }
            else
            {
                var fileRefViewModel = item as FileReferenceViewModel;

                if (fileRefViewModel != null)
                {
                    if (updateFields == true)
                    {
                        // Just adjust non key values if this item is already there
                        fileRefViewModel.Comment = fr.Comment;
                        fileRefViewModel.Type    = fr.Type;
                    }
                }
            }
        }