Esempio n. 1
0
		public void AddProject(Project project)
		{
			ItemNode projectNode = new ProjectNode(project);
			Nodes.Add(projectNode);
			projectNode.AfterInitialized();

			SelectedNode = projectNode;
            if(!project.Collapsed)
                projectNode.Expand();
			lblAddProject.Visible = false;

			if (project.ItemCount == 1)
			{
				foreach (IProjectItem item in project.Items)
				{
					IDiagram document = item as IDiagram;
                    if (document != null)
                        DockForm.OpenDocument(document);
				}
			}
			if (project.IsUntitled)
			{
				projectNode.EditLabel();
			}
		}
		/// <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";
		}
Esempio n. 3
0
		public void RemoveProject(Project project)
		{
			foreach (ProjectNode projectNode in Nodes)
			{
				if (projectNode.Project == project)
				{
					projectNode.Delete();
					break;
				}
			}
            if (Nodes.Count == 0)
                lblAddProject.Visible = true;
		}
Esempio n. 4
0
        public ProjectNode(Project project)
        {
            if (project == null)
                throw new ArgumentNullException("project");

            Project = project;
            Text = project.Name;

            AddProjectItems(Project);
            Project.ItemAdded += new ProjectItemEventHandler(Project_ItemAdded);
            Project.ItemRemoved += new ProjectItemEventHandler(Project_ItemRemoved);
            Project.Renamed += new EventHandler(Project_Renamed);
        }
Esempio n. 5
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)
                throw new InvalidDataException(Strings.ErrorCorruptSaveFile);

            Project project = new Project();
            project.loading = true;
            try
            {
                DeserializeContext context = new DeserializeContext();
                project.Deserialize(context, root);
                foreach (var p in context.Models)
                {
                    p.Key.Deserialize(p.Value);
                    ((IModifiable)p.Key).Clean();
                }
            }
            catch (Exception ex)
            {
                throw new InvalidException(Strings.ErrorCorruptSaveFile + "\r\n" + ex.ToString(), ex);
            }
            project.loading = false;
            project.FilePath = fileName;
            project.isReadOnly = project.projectFile.IsReadOnly;
            project.Clean();
            return project;
        }
Esempio n. 6
0
 void AddProjectItems(Project project)
 {
     if (project.IsEmpty)
     {
         ItemNode node = new EmptyProjectNode(project);
         Nodes.Add(node);
         if (TreeView != null)
             node.AfterInitialized();
     }
     else
     {
         foreach (IProjectItem projectItem in project.Items)
             AddProjectItemNode(projectItem);
     }
 }
Esempio n. 7
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.ModelFirstProjectFiles + " (*{0})|*{0}".FormatArgs(Project.FileExtension);

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        project.Save(dialog.FileName);
                        Settings.Default.AddRecentFile(project.FilePath);
                        return true;
                    }
                    catch (Exception ex)
                    {
                        Client.ShowError(Strings.Error + ": " + ex);
                    }
                }
                return false;
            }
        }
Esempio n. 8
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)
                {
                    Client.ShowError(Strings.Error + ": " + ex);
                    return false;
                }
            }
        }
Esempio n. 9
0
        private bool RemoveProject(Project project, bool saveConfirmation)
        {
            if (saveConfirmation && project.IsDirty)
            {
                DialogResult result = Client.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.Modified -= new EventHandler(project_StateChanged);
                project.FileStateChanged -= new EventHandler(project_StateChanged);
                OnProjectRemoved(new ProjectEventArgs(project));
                if (ActiveProject == project)
                    ActiveProject = null;
                return true;
            }
            return false;
        }
Esempio n. 10
0
 public bool RemoveProject(Project project)
 {
     return RemoveProject(project, true);
 }
Esempio n. 11
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));
            }
        }
Esempio n. 12
0
 public ProjectEventArgs(Project project)
 {
     this.project = project;
 }