/// <inheritdoc /> public override bool Save() { try { Cursor.Current = Cursors.WaitCursor; tvTokens_BeforeSelect(tvTokens, new TreeViewCancelEventArgs( tvTokens.SelectedNode, false, TreeViewAction.Unknown)); if (this.IsDirty) { tokens.Save(); this.Text = Path.GetFileName(this.ToolTipText); this.IsDirty = false; } return(true); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); MessageBox.Show("Unable to save file. Reason: " + ex.Message, "Token File Editor", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } finally { Cursor.Current = Cursors.Default; } }
/// <summary> /// This converts the token entries to a token file and adds it to /// the project. /// </summary> private void CreateTokenFile() { XmlReader xr = converter.Reader; StreamWriter sw = null; string tokenFile = Path.Combine(converter.ProjectFolder, Path.GetFileNameWithoutExtension(converter.Project.Filename) + ".tokens"); // Create an empty token file try { sw = File.CreateText(tokenFile); sw.WriteLine("<content/>"); } finally { if (sw != null) { sw.Close(); } } FileItem fileItem = converter.Project.AddFileToProject(tokenFile, tokenFile); TokenCollection tokens = new TokenCollection(fileItem); while (!xr.EOF && xr.NodeType != XmlNodeType.EndElement) { if (xr.NodeType == XmlNodeType.Element && xr.Name == "token") { tokens.Add(new Token(xr.GetAttribute("name"), xr.GetAttribute("value"))); } xr.Read(); } tokens.Save(); }
/// <summary> /// This converts the token entries to a token file and adds it to /// the project. /// </summary> private void CreateTokenFile() { XmlReader xr = converter.Reader; StreamWriter sw = null; string tokenFile = Path.Combine(converter.ProjectFolder, Path.GetFileNameWithoutExtension(converter.Project.Filename) + ".tokens"); // Create an empty token file try { sw = File.CreateText(tokenFile); sw.WriteLine("<content/>"); } finally { if(sw != null) sw.Close(); } FileItem fileItem = converter.Project.AddFileToProject(tokenFile, tokenFile); TokenCollection tokens = new TokenCollection(fileItem.FullPath); while(!xr.EOF && xr.NodeType != XmlNodeType.EndElement) { if(xr.NodeType == XmlNodeType.Element && xr.Name == "token") tokens.Add(new Token(xr.GetAttribute("name"), xr.GetAttribute("value"))); xr.Read(); } tokens.Save(); }