예제 #1
0
        public void PerformAddReference()
        {
            ProjectItemViewModel selected = SelectedItem;

            if (selected == null)
            {
                return;
            }
            if (selected.Type != ProjectItemType.References)
            {
                return;
            }

            string documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string initial   = Path.Combine(documents, "SEWorkbench");

            Views.AddReferenceView view = new Views.AddReferenceView()
            {
                Initial = initial
            };

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

            if (result != null && result.Value == true)
            {
                string path = view.Filename;
                string name = Path.GetFileNameWithoutExtension(path);

                ProjectItemViewModel existing = GetReferences().FirstOrDefault(i => i.Name == name);
                if (existing != null)
                {
                    Services.MessageBox.ShowMessage(String.Format("A reference with this name already exists ({0}).", name));
                    return;
                }

                try
                {
                    ProjectItemViewModel reference = null;

                    ProjectItem item = new ProjectItem()
                    {
                        Name    = name,
                        Path    = path,
                        Type    = ProjectItemType.Reference,
                        Project = this
                    };

                    reference = selected.AddChild(item);
                    if (reference != null)
                    {
                        RaiseReferenceAdded(reference);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.ShowError("Unable to create new file", ex);
                    return;
                }
                SaveProject();
            }
        }
예제 #2
0
        public void PerformAddReference()
        {
            ProjectItemViewModel selected = SelectedItem;
            if (selected == null)
            {
                return;
            }
            if (selected.Type != ProjectItemType.References)
            {
                return;
            }

            string documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string initial = Path.Combine(documents, "SEWorkbench");

            Views.AddReferenceView view = new Views.AddReferenceView()
            {
                Initial = initial
            };

            Nullable<bool> result = view.ShowDialog();
            if (result != null && result.Value == true)
            {
                string path = view.Filename;
                string name = Path.GetFileNameWithoutExtension(path);

                ProjectItemViewModel existing = GetReferences().FirstOrDefault(i => i.Name == name);
                if (existing != null)
                {
                    Services.MessageBox.ShowMessage(String.Format("A reference with this name already exists ({0}).", name));
                    return;
                }

                try
                {
                    ProjectItemViewModel reference = null;

                    ProjectItem item = new ProjectItem()
                    {
                        Name = name,
                        Path = path,
                        Type = ProjectItemType.Reference,
                        Project = this
                    };

                    reference = selected.AddChild(item);
                    if (reference != null)
                    {
                        RaiseReferenceAdded(reference);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.ShowError("Unable to create new file", ex);
                    return;
                }
                SaveProject();
            }
        }