Exemple #1
0
        public void PerformAddFile()
        {
            ProjectItemViewModel selected = SelectedItem;

            if (selected == null)
            {
                return;
            }
            if (selected.Type != ProjectItemType.Blueprints && selected.Type != ProjectItemType.Collection && selected.Type != ProjectItemType.Folder)
            {
                selected = GetParentFolder(selected);
            }
            if (selected == null || selected.Type == ProjectItemType.Root)
            {
                return;
            }

            Views.NewItemDialog view   = new Views.NewItemDialog();
            Nullable <bool>     result = view.ShowDialog();

            if (result != null && result.Value == true)
            {
                string fullpath = Path.Combine(selected.Path, String.Format("{0}.csx", view.ItemName));
                try
                {
                    string starter = Services.NewFile.Contents;

                    File.Write(fullpath, starter);

                    ProjectItemViewModel newfile = null;

                    string      name = Path.GetFileNameWithoutExtension(fullpath);
                    ProjectItem item = new ProjectItem()
                    {
                        Name    = name,
                        Path    = fullpath,
                        Type    = ProjectItemType.File,
                        Project = this
                    };
                    newfile             = selected.AddChild(item);
                    selected.IsExpanded = true;

                    if (newfile != null)
                    {
                        RaiseFileCreated(newfile);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.ShowError("Unable to create new file", ex);
                    return;
                }
                SaveProject();
            }
        }
Exemple #2
0
        public void PerformAddFolder()
        {
            ProjectItemViewModel selected = SelectedItem;

            if (selected == null)
            {
                return;
            }
            if (selected.Type != ProjectItemType.Root && selected.Type != ProjectItemType.Blueprints && selected.Type != ProjectItemType.Collection && selected.Type != ProjectItemType.Folder)
            {
                selected = GetParentFolder(selected);
            }
            if (selected == null)
            {
                return;
            }

            Views.NewItemDialog view   = new Views.NewItemDialog();
            Nullable <bool>     result = view.ShowDialog();

            if (result != null && result.Value == true)
            {
                string name = view.ItemName;

                string fullpath = Path.Combine(selected.Path, name);
                if (selected.Type == ProjectItemType.Root)
                {
                    fullpath = Path.Combine(Path.GetDirectoryName(selected.Path), name);
                }

                try
                {
                    Directory.CreateDirectory(fullpath);
                    ProjectItem item = new ProjectItem()
                    {
                        Name    = name,
                        Path    = fullpath,
                        Type    = ProjectItemType.Folder,
                        Project = this,
                    };
                    selected.AddChild(item);
                    selected.IsExpanded = true;
                }
                catch (Exception ex)
                {
                    MessageBox.ShowError("Unable to create new directory", ex);
                    return;
                }
                SaveProject();
            }
        }
Exemple #3
0
        public void PerformRename()
        {
            ProjectItemViewModel selected = SelectedItem;

            if (selected == null)
            {
                return;
            }
            if (selected.Type != ProjectItemType.Collection && selected.Type != ProjectItemType.Folder && selected.Type != ProjectItemType.File)
            {
                return;
            }

            Views.NewItemDialog view   = new Views.NewItemDialog();
            Nullable <bool>     result = view.ShowDialog();

            if (result != null && result.Value == true)
            {
                string source      = selected.Path;
                string destination = String.Empty;
                if (selected.Type == ProjectItemType.File)
                {
                    string filename = String.Format("{0}.csx", view.ItemName);
                    destination = Path.Combine(Path.GetDirectoryName(source), filename);
                    if (File.Exists(destination))
                    {
                        MessageBox.ShowMessage(String.Format("A file with the name \"{0}\" already exists.", destination));
                        return;
                    }
                    try
                    {
                        File.Move(source, destination);

                        selected.Name = view.ItemName;
                        selected.Path = destination;

                        SaveProject();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.ShowError("Unable to rename file", ex);
                        return;
                    }
                }

                if (selected.Type == ProjectItemType.Collection || selected.Type == ProjectItemType.Folder)
                {
                    destination = Path.Combine(Directory.GetParent(source).FullName, view.ItemName);
                    if (Directory.Exists(destination))
                    {
                        MessageBox.ShowMessage(String.Format("A folder with the name \"{0}\" already exists.", destination));
                        return;
                    }
                    try
                    {
                        Directory.Move(source, destination);

                        selected.Name = view.ItemName;
                        selected.Path = destination;

                        selected.UpdatePath(source, destination);

                        SaveProject();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.ShowError("Unable to rename directory", ex);
                        return;
                    }
                }
            }
        }
        public void PerformAddFolder()
        {
            ProjectItemViewModel selected = SelectedItem;
            if (selected == null)
            {
                return;
            }
            if (selected.Type != ProjectItemType.Root && selected.Type != ProjectItemType.Blueprints && selected.Type != ProjectItemType.Collection && selected.Type != ProjectItemType.Folder)
            {
                selected = GetParentFolder(selected);
            }
            if (selected == null)
            {
                return;
            }

            Views.NewItemDialog view = new Views.NewItemDialog();
            Nullable<bool> result = view.ShowDialog();
            if (result != null && result.Value == true)
            {
                string name = view.ItemName;

                string fullpath = Path.Combine(selected.Path, name);
                if (selected.Type == ProjectItemType.Root)
                {
                    fullpath = Path.Combine(Path.GetDirectoryName(selected.Path), name);
                }

                try
                {
                    Directory.CreateDirectory(fullpath);
                    ProjectItem item = new ProjectItem()
                    {
                        Name = name,
                        Path = fullpath,
                        Type = ProjectItemType.Folder,
                        Project = this,
                    };
                    selected.AddChild(item);
                    selected.IsExpanded = true;
                }
                catch (Exception ex)
                {
                    MessageBox.ShowError("Unable to create new directory", ex);
                    return;
                }
                SaveProject();
            }
        }
        public void PerformAddFile()
        {
            ProjectItemViewModel selected = SelectedItem;
            if (selected == null)
            {
                return;
            }
            if (selected.Type != ProjectItemType.Blueprints && selected.Type != ProjectItemType.Collection && selected.Type != ProjectItemType.Folder)
            {
                selected = GetParentFolder(selected);
            }
            if (selected == null || selected.Type == ProjectItemType.Root)
            {
                return;
            }

            Views.NewItemDialog view = new Views.NewItemDialog();
            Nullable<bool> result = view.ShowDialog();
            if (result != null && result.Value == true)
            {
                string fullpath = Path.Combine(selected.Path, String.Format("{0}.csx", view.ItemName));
                try
                {
                    string starter = Services.NewFile.Contents;

                    File.Write(fullpath, starter);

                    ProjectItemViewModel newfile = null;

                    string name = Path.GetFileNameWithoutExtension(fullpath);
                    ProjectItem item = new ProjectItem()
                    {
                        Name = name,
                        Path = fullpath,
                        Type = ProjectItemType.File,
                        Project = this
                    };
                    newfile = selected.AddChild(item);
                    selected.IsExpanded = true;

                    if (newfile != null)
                    {
                        RaiseFileCreated(newfile);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.ShowError("Unable to create new file", ex);
                    return;
                }
                SaveProject();
            }
        }
        public void PerformRename()
        {
            ProjectItemViewModel selected = SelectedItem;
            if (selected == null)
            {
                return;
            }
            if (selected.Type != ProjectItemType.Collection && selected.Type != ProjectItemType.Folder && selected.Type != ProjectItemType.File)
            {
                return;
            }

            Views.NewItemDialog view = new Views.NewItemDialog();
            Nullable<bool> result = view.ShowDialog();
            if (result != null && result.Value == true)
            {
                string source = selected.Path;
                string destination = String.Empty;
                if (selected.Type == ProjectItemType.File)
                {
                    string filename = String.Format("{0}.csx", view.ItemName);
                    destination = Path.Combine(Path.GetDirectoryName(source), filename);
                    if (File.Exists(destination))
                    {
                        MessageBox.ShowMessage(String.Format("A file with the name \"{0}\" already exists.", destination));
                        return;
                    }
                    try
                    {
                        File.Move(source, destination);

                        selected.Name = view.ItemName;
                        selected.Path = destination;

                        SaveProject();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.ShowError("Unable to rename file", ex);
                        return;
                    }
                }

                if (selected.Type == ProjectItemType.Collection || selected.Type == ProjectItemType.Folder)
                {
                    destination = Path.Combine(Directory.GetParent(source).FullName, view.ItemName);
                    if (Directory.Exists(destination))
                    {
                        MessageBox.ShowMessage(String.Format("A folder with the name \"{0}\" already exists.", destination));
                        return;
                    }
                    try
                    {
                        Directory.Move(source, destination);

                        selected.Name = view.ItemName;
                        selected.Path = destination;

                        selected.UpdatePath(source, destination);

                        SaveProject();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.ShowError("Unable to rename directory", ex);
                        return;
                    }
                }
            }
        }