Inheritance: IModifiable
Exemplo n.º 1
0
		/// <exception cref="ArgumentNullException">
		/// <paramref name="project"/> is null.
		/// </exception>
		public Generator(Project project, SolutionType type)
		{
			if (project == null)
				throw new ArgumentNullException("project");

			solutionGenerator = CreateSolutionGenerator(project, type);
		}
Exemplo n.º 2
0
		/// <exception cref="ArgumentNullException">
		/// <paramref name="project"/> is null.
		/// </exception>
		protected SolutionGenerator(Project project)
		{
			if (project == null)
				throw new ArgumentNullException("project");

			this.project = project;
		}
Exemplo n.º 3
0
		/// <exception cref="ArgumentNullException">
		/// <paramref name="project"/> is null.
		/// </exception>
		public EmptyProjectNode(Project project)
		{
			if (project == null)
				throw new ArgumentNullException("project");

			this.project = project;
			project.ItemAdded += new ProjectItemEventHandler(project_ItemAdded);

			this.Text = Strings.DoubleClickToAddDiagram;
			this.ImageKey = "diagram";
			this.SelectedImageKey = "diagram";
		}
Exemplo n.º 4
0
		/// <exception cref="ArgumentNullException">
		/// <paramref name="project"/> is null.
		/// </exception>
		public ProjectNode(Project project)
		{
			if (project == null)
				throw new ArgumentNullException("project");

			this.project = project;
			this.Text = project.Name;
			this.ImageKey = "project";
			this.SelectedImageKey = "project";

			AddProjectItemNodes(project);
			project.Renamed += new EventHandler(project_Renamed);
			project.ItemAdded += new ProjectItemEventHandler(project_ItemAdded);
			project.ItemRemoved += new ProjectItemEventHandler(project_ItemRemoved);
		}
Exemplo n.º 5
0
		private void AddProject(Project project)
		{
			ModelNode projectNode = new ProjectNode(project);
			Nodes.Add(projectNode);
			projectNode.AfterInitialized();

			SelectedNode = projectNode;
			projectNode.Expand();
			lblAddProject.Visible = false;

			if (project.ItemCount == 1)
			{
				foreach (IProjectItem item in project.Items)
				{
					IDocument document = item as IDocument;
					if (document != null)
						OnDocumentOpening(new DocumentEventArgs(document));
				}
			}
			if (project.IsUntitled)
			{
				projectNode.EditLabel();
			}
		}
Exemplo n.º 6
0
		/// <exception cref="ArgumentNullException">
		/// <paramref name="project"/> is null.
		/// </exception>
		public bool SaveProject(Project project)
		{
			if (project == null)
				throw new ArgumentNullException("project");

			if (project.FilePath == null || project.IsReadOnly)
			{
				return SaveProjectAs(project);
			}
			else
			{
				try
				{
					project.Save();
					return true;
				}
				catch (Exception ex)
				{
					MessageBox.Show(Strings.Error + ": " + ex.Message,
						Strings.SaveAs, MessageBoxButtons.OK, MessageBoxIcon.Error);
					return false;
				}
			}
		}
Exemplo n.º 7
0
		private void AddProjectItemNodes(Project project)
		{
			if (project.IsEmpty)
			{
				ModelNode node = new EmptyProjectNode(project);
				Nodes.Add(node);
				if (TreeView != null)
					node.AfterInitialized();
			}
			else
			{
				foreach (IProjectItem projectItem in project.Items)
				{
					AddProjectItemNode(projectItem);
				}
			}
		}
Exemplo n.º 8
0
		private void RemoveProject(Project project)
		{
			foreach (ProjectNode projectNode in Nodes)
			{
				if (projectNode.Project == project)
				{
					projectNode.Delete();
					break;
				}
			}
			if (!workspace.HasProject)
				lblAddProject.Visible = true;
		}
Exemplo n.º 9
0
		/// <exception cref="IOException">
		/// Could not load the project.
		/// </exception>
		/// <exception cref="InvalidDataException">
		/// The save file is corrupt and could not be loaded.
		/// </exception>
		/// <exception cref="ArgumentException">
		/// <paramref name="fileName"/> is empty string.
		/// </exception>
		public static Project Load(string fileName)
		{
			if (string.IsNullOrEmpty(fileName))
				throw new ArgumentException(Strings.ErrorBlankFilename, "fileName");

			if (!File.Exists(fileName))
				throw new FileNotFoundException(Strings.ErrorFileNotFound);

			XmlDocument document = new XmlDocument();
			try
			{
				document.Load(fileName);
			}
			catch (Exception ex)
			{
				throw new IOException(Strings.ErrorCouldNotLoadFile, ex);
			}

			XmlElement root = document["Project"];
			if (root == null)
			{
				root = document["ClassProject"]; // Old file format
				if (root == null)
				{
					throw new InvalidDataException(Strings.ErrorCorruptSaveFile);
				}
				else
				{
					Project oldProject = LoadWithPreviousFormat(root);
					oldProject.FilePath = fileName;
					oldProject.name = Path.GetFileNameWithoutExtension(fileName);
					oldProject.isUntitled = false;
					return oldProject;
				}
			}

			Project project = new Project();
			project.loading = true;
			try
			{
				project.Deserialize(root);
			}
			catch (Exception ex)
			{
				throw new InvalidDataException(Strings.ErrorCorruptSaveFile, ex);
			}
			project.loading = false;
			project.FilePath = fileName;
			project.isReadOnly = project.projectFile.IsReadOnly;

			return project;
		}
Exemplo n.º 10
0
		private static Project LoadWithPreviousFormat(XmlElement root)
		{
			Project project = new Project();
			project.loading = true;

			Assembly assembly = Assembly.Load("NClass.DiagramEditor");
			IProjectItem projectItem = (IProjectItem) assembly.CreateInstance(
				"NClass.DiagramEditor.ClassDiagram.Diagram", false,
				BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
				null, null, null, null);

			try
			{
				projectItem.Deserialize(root);
			}
			catch (Exception ex)
			{
				throw new InvalidDataException(Strings.ErrorCorruptSaveFile, ex);
			}
			project.Add(projectItem);
			project.loading = false;
			project.isReadOnly = true;
			return project;
		}
Exemplo n.º 11
0
		public Project AddEmptyProject()
		{
			Project project = new Project();
			projects.Add(project);
			project.Modified += new EventHandler(project_StateChanged);
			project.FileStateChanged += new EventHandler(project_StateChanged);
			OnProjectAdded(new ProjectEventArgs(project));
			return project;
		}
Exemplo n.º 12
0
		/// <exception cref="ArgumentNullException">
		/// <paramref name="project"/> is null.
		/// </exception>
		public VSSolutionGenerator(Project project, SolutionType version) : base(project)
		{
			Version = version;
		}
Exemplo n.º 13
0
		public void ShowDialog(Project project)
		{
			this.project = project;

			UpdateTexts();
			UpdateValues();
			ShowDialog();
			
			if (DialogResult == DialogResult.OK)
				Settings.Default.Save();
			else
				Settings.Default.Reload();
		}
Exemplo n.º 14
0
		public ProjectEventArgs(Project project)
		{
			this.project = project;
		}
Exemplo n.º 15
0
		private bool RemoveProject(Project project, bool saveConfirmation)
		{
			if (saveConfirmation && project.IsDirty)
			{
				DialogResult result = MessageBox.Show(
					Strings.AskSaveChanges, Strings.Confirmation,
					MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

				if (result == DialogResult.Yes)
				{
					if (!SaveProject(project))
						return false;
				}
				else if (result == DialogResult.Cancel)
				{
					return false;
				}
			}

			if (projects.Remove(project))
			{
				project.CloseItems();
				project.Modified -= new EventHandler(project_StateChanged);
				project.FileStateChanged -= new EventHandler(project_StateChanged);
				OnProjectRemoved(new ProjectEventArgs(project));
				if (ActiveProject == project)
					ActiveProject = null;
				return true;
			}
			return false;
		}
Exemplo n.º 16
0
		public bool RemoveProject(Project project)
		{
			return RemoveProject(project, true);
		}
Exemplo n.º 17
0
		/// <exception cref="ArgumentNullException">
		/// <paramref name="project"/> is null.
		/// </exception>
		public void AddProject(Project project)
		{
			if (project == null)
				throw new ArgumentNullException("project");

			if (!projects.Contains(project))
			{
				projects.Add(project);
				project.Modified += new EventHandler(project_StateChanged);
				project.FileStateChanged += new EventHandler(project_StateChanged);
				if (project.FilePath != null)
					Settings.Default.AddRecentFile(project.FilePath);
				OnProjectAdded(new ProjectEventArgs(project));
			}
		}
Exemplo n.º 18
0
		protected virtual SolutionGenerator CreateSolutionGenerator(Project project, SolutionType type)
		{
			return new VSSolutionGenerator(project, type);
		}
Exemplo n.º 19
0
		/// <exception cref="ArgumentNullException">
		/// <paramref name="project"/> is null.
		/// </exception>
		public bool SaveProjectAs(Project project)
		{
			if (project == null)
				throw new ArgumentNullException("project");

			using (SaveFileDialog dialog = new SaveFileDialog())
			{
				dialog.FileName = project.Name;
				dialog.InitialDirectory = project.GetProjectDirectory();
				dialog.Filter = Strings.NClassProjectFiles + " (*.ncp)|*.ncp";

				if (dialog.ShowDialog() == DialogResult.OK)
				{
					try
					{
						project.Save(dialog.FileName);
						Settings.Default.AddRecentFile(project.FilePath);
						return true;
					}
					catch (Exception ex)
					{
						MessageBox.Show(Strings.Error + ": " + ex.Message,
							Strings.SaveAs, MessageBoxButtons.OK, MessageBoxIcon.Error);
					}
				}
				return false;
			}
		}