/// <summary> /// Loads a project file and reconfigures the specified TreeView to match /// </summary> /// <param name="sFile">The project file to load</param> /// <param name="tvMain">The treeview to populate</param> /// <returns></returns> public static Project LoadProject(string sFile) { Project zProject = null; // reset the collection of CardLayout objects if (File.Exists(sFile)) { if (!SerializationUtils.DeserializeFromXmlFile(sFile, XML_ENCODING, ref zProject)) { Logger.AddLogLine("Failed to load project. Attempting upgrade from previous version."); string sContents = File.ReadAllText(sFile); // Fix the previous version's mistakes! sContents = sContents.Replace("xmlns=\"http://tempuri.org/Project.xsd\"", String.Empty); if (!SerializationUtils.DeserializeFromXmlString(sContents, XML_ENCODING, ref zProject)) { Logger.AddLogLine("Failed to load project. The project file appears to be corrupt."); } else { Logger.AddLogLine("This project file is in an older format. Please save it using this version."); } } } else { Logger.AddLogLine("No existing file specified. Loading defaults..."); zProject = new Project { Layout = new ProjectLayout[] { new ProjectLayout("Default") } }; } return zProject; }
/// <summary> /// Resets the treeview to the specified project /// </summary> /// <param name="zProject">The project to display</param> public void ResetTreeToProject(Project zProject) { if (null != treeView) { treeView.Nodes.Clear(); var tnRoot = new TreeNode("Layouts") { Tag = zProject }; treeView.Nodes.Add(tnRoot); foreach (var zLayout in zProject.Layout) { // no need to update the project AddProjectLayout(zLayout, null); Core.InitializeElementCache(zLayout); } tnRoot.ExpandAll(); } }
/// <summary> /// Adds a project layout tree node /// </summary> /// <param name="tnRoot"></param> /// <param name="zLayout"></param> /// <param name="zProject"></param> /// <returns></returns> public TreeNode AddProjectLayout(ProjectLayout zLayout, Project zProject) { TreeNode tnLayout = treeView.Nodes[0].Nodes.Add(zLayout.Name); tnLayout.Tag = zLayout; if (null != zProject) { // update the Project (no null check on zProject.Layout necessary... can never have 0 layouts) var listLayouts = new List<ProjectLayout>(zProject.Layout); listLayouts.Add(zLayout); zProject.Layout = listLayouts.ToArray(); } if (null != zLayout.Reference) { foreach (ProjectLayoutReference zReference in zLayout.Reference) { // no need to update the layout AddReferenceNode(tnLayout, zReference, null); } tnLayout.Expand(); } return tnLayout; }
private void newToolStripMenuItem_Click(object sender, EventArgs e) { var eCancel = new CancelEventArgs(); SaveOnEvent(eCancel, true); if (!eCancel.Cancel) { m_zLoadedProject = Core.LoadProject(null); MDIProject.Instance.ResetTreeToProject(m_zLoadedProject); SetLoadedProjectFile(null); // reset the currently loaded file in the AbstractDirtyForm SetLoadedFile(string.Empty); ResetToNoLayout(); } }
protected override bool OpenFormData(string sFileName) { Cursor = Cursors.WaitCursor; try { m_zLoadedProject = Core.LoadProject(sFileName); MDIProject.Instance.ResetTreeToProject(m_zLoadedProject); } catch (Exception ex) { ShowErrorMessage("Failed to load: " + sFileName + "::" + ex); } Cursor = Cursors.Default; if (null != m_zLoadedProject) { SetLoadedProjectFile(sFileName); ResetToNoLayout(); m_listRecentFiles.Remove(sFileName); m_listRecentFiles.Insert(0, sFileName); while (MAX_RECENT_PROJECTS < m_listRecentFiles.Count) { m_listRecentFiles.RemoveAt(MAX_RECENT_PROJECTS); } bool bHasExternalReference = m_zLoadedProject.HasExternalReference(); if (bHasExternalReference) { UpdateGoogleAuth(null, () => { MessageBox.Show(this, "You will be unable to view the layouts for any references that are Google Spreadsheets.", "Reference Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); }); } return true; } return false; }
public ProjectEventArgs(Project zProject, string sProjectFilePath) : this(zProject, sProjectFilePath, false) { }
public ProjectEventArgs(Project zProject, string sProjectFilePath, bool bDataChange) { Project = zProject; ProjectFilePath = sProjectFilePath; DataChange = bDataChange; }