Exemplo n.º 1
0
        internal SolutionFileBase GetOrCreateFileReference(string path)
        {
            path = path.TrimStart('/', '\\');
            if (Path.IsPathRooted(path))
            {
                path = path.Substring(this.curWorkspace.WorkingDir.Length + 1);
            }
            ICollection <SolutionFileBase> sfbCollection = null;
            SolutionFileBase sfbCollectionOwner          = null;
            var parent   = Path.GetDirectoryName(path);
            var filename = Path.GetFileName(path);

            if (string.IsNullOrWhiteSpace(parent))
            {
                sfbCollection = this.FilesCollection;
            }
            else
            {
                SolutionFileBase.WalkThrough(this.FilesCollection, (it) =>
                {
                    if (it.RelativePath.Equals(parent, StringComparison.CurrentCultureIgnoreCase))
                    {
                        sfbCollectionOwner = it;
                        sfbCollection      = it.Children;
                        return(true);
                    }
                    return(false);
                });
            }
            if (sfbCollection == null)
            {
                sfbCollectionOwner = GetOrCreateFileReference(parent);
                sfbCollection      = sfbCollectionOwner.Children;
            }
            foreach (var it in sfbCollection)
            {
                if (it.FileName.Equals(filename, StringComparison.CurrentCultureIgnoreCase))
                {
                    return(it);
                }
            }
            SolutionFileBase sfb;

            if ((File.GetAttributes(Path.Combine(this.curWorkspace.WorkingDir, path)) & FileAttributes.Directory) > 0)
            {
                sfb = new SolutionFolder()
                {
                    FileName = filename, Parent = sfbCollectionOwner
                };
            }
            else
            {
                sfb = new SolutionFile()
                {
                    FileName = filename, Parent = sfbCollectionOwner
                };
            }
            sfbCollection.Add(sfb);
            return(sfb);
        }
Exemplo n.º 2
0
 public DocumentBase GetDocumentOfSolutionFileBase(SolutionUtil.SolutionFileBase sfb)
 {
     foreach (var it in this.DocumentsDisplayed)
     {
         if (it.FilePath == sfb.FullPath)
         {
             return(it);
         }
     }
     return(null);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Displays the <see cref="Dialogs.CreateNewFileDialog"/> and creates the file.
        /// </summary>
        /// <param name="fileDirectory">Base directory (relative or full) to use.</param>
        /// <param name="newFile">Will be either null if user aborted or the created <see cref="SolutionFileBase"/>.</param>
        /// <returns><see cref="true"/> if file was created, <see cref="false"/> if not.</returns>
        public bool ShowCreateFileDialog(string fileDirectory, out SolutionFileBase newFile)
        {
            try
            {
                var dlgDc = new Dialogs.CreateNewFileDialogDataContext();
                var dlg   = new Dialogs.CreateNewFileDialog(dlgDc);
                fileDirectory = fileDirectory.TrimStart('/', '\\');
                if (!Path.IsPathRooted(fileDirectory))
                {
                    fileDirectory = Path.Combine(this.curWorkspace.WorkingDir, fileDirectory);
                }

                var dlgResult = dlg.ShowDialog();
                if (dlgResult.HasValue && dlgResult.Value)
                {
                    var fName = dlgDc.FinalName;
                    if (!Path.HasExtension(fName))
                    {
                        fName = string.Concat(fName, '.', ((Dialogs.FileType)dlgDc.SelectedItem).Extension);
                    }
                    using (var writer = File.CreateText(Path.Combine(fileDirectory, fName)))
                    {
                        writer.Write(((Dialogs.FileType)dlgDc.SelectedItem).DefaultContent);
                    }
                    newFile = GetOrCreateFileReference(Path.Combine(fileDirectory, fName));

                    //Expand the tree till here
                    var current = newFile.Parent;
                    while (current != null)
                    {
                        current.IsExpanded = true;
                        current            = current.Parent;
                    }
                    //Select new file
                    newFile.IsSelected = true;
                    return(true);
                }
                else
                {
                    newFile = null;
                    return(false);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format(Properties.Localization.MessageBoxOperationFailed_Body, ex.Message, ex.GetType().FullName, ex.StackTrace), Properties.Localization.MessageBoxOperationFailed_Title, MessageBoxButton.OK, MessageBoxImage.Warning);
                newFile = null;
                return(false);
            }
        }
Exemplo n.º 4
0
 internal void RestoreFromXml()
 {
     SolutionFileBase.WalkThrough(this.FilesCollection, (it) =>
     {
         if (it.Children != null)
         {
             foreach (var child in it.Children)
             {
                 if (child.Parent != it)
                 {
                     child.Parent = it;
                 }
             }
         }
         return(false);
     });
 }
Exemplo n.º 5
0
        private void FSWatcher_Changed(object sender, FileSystemEventArgs e)
        {
            SolutionFile solutionFile = null;

            var existsInSolution = SolutionFileBase.WalkThrough(this.FilesCollection, (sfb) =>
            {
                if (sfb is SolutionFile && sfb.FullPath.Equals(sfb.FullPath, StringComparison.CurrentCultureIgnoreCase))
                {
                    solutionFile = sfb as SolutionFile;
                    return(true);
                }
                return(false);
            });

            if (existsInSolution)
            {
                DocumentBase docBase = null;
                foreach (var it in this.curWorkspace.DocumentsDisplayed)
                {
                    if (it.FilePath == e.FullPath)
                    {
                        docBase = it;
                        break;
                    }
                }
                if (docBase == null)
                {
                    return;
                }
                var msgBoxResult = MessageBox.Show(Properties.Localization.MessageBoxFileChanged_Body, Properties.Localization.MessageBoxFileChanged_Title, MessageBoxButton.YesNo, MessageBoxImage.Information);
                if (msgBoxResult != MessageBoxResult.Yes)
                {
                    return;
                }
                docBase.ReloadDocument();
            }
        }