From 9dce11b6b23329d9dfb447bfc5dd96228005056c Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Mon, 8 Feb 2010 19:00:07 +0000 Subject: [PATCH] Manipulate ReportSettings inside ReportLoad to set absolute ReportFilename, otherwise no relative filename are working git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@5482 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../ReportDefinitionDeserializer.cs | 17 ++++++++++++----- .../Project/ReportDesignerView.cs | 19 ++++++++----------- .../Project/ReportItems/BaseImageItem.cs | 10 +++++----- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Addin/Project/DesignerBinding/ReportDefinitionDeserializer.cs b/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Addin/Project/DesignerBinding/ReportDefinitionDeserializer.cs index 8bf727f8df..30d364a019 100644 --- a/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Addin/Project/DesignerBinding/ReportDefinitionDeserializer.cs +++ b/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Addin/Project/DesignerBinding/ReportDefinitionDeserializer.cs @@ -3,7 +3,7 @@ using System.ComponentModel.Design; using System.IO; using System.Windows.Forms; using System.Xml; - +using ICSharpCode.SharpDevelop; using ICSharpCode.Core; using ICSharpCode.Reports.Core; @@ -11,9 +11,9 @@ namespace ICSharpCode.Reports.Addin { internal class ReportDefinitionDeserializer : ReportDefinitionParser { - IDesignerHost host; - ReportSettings reportSettings; - Stream stream; + private IDesignerHost host; + private ReportSettings reportSettings; + private Stream stream; #region Constructor @@ -48,12 +48,19 @@ namespace ICSharpCode.Reports.Addin private ReportModel LoadObjectFromXmlDocument(XmlElement elem) { //ReportSettings + OpenedFile file =(OpenedFile) host.GetService(typeof(OpenedFile)); BaseItemLoader baseItemLoader = new BaseItemLoader(); XmlNodeList n = elem.FirstChild.ChildNodes; XmlElement rse = (XmlElement) n[0]; ReportModel model = ReportModel.Create(); - + + // manipulate reportSettings if Filename differs this.reportSettings = baseItemLoader.Load(rse) as ReportSettings; + if (this.reportSettings.FileName != file.FileName) { + System.Diagnostics.Trace.WriteLine("LoadObjectFromXmlDocument - filename changed" ); + this.reportSettings.FileName = file.FileName; + } + model.ReportSettings = this.reportSettings; host.Container.Add(this.reportSettings); diff --git a/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Addin/Project/ReportDesignerView.cs b/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Addin/Project/ReportDesignerView.cs index 313f43fe97..b0906f06ff 100644 --- a/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Addin/Project/ReportDesignerView.cs +++ b/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Addin/Project/ReportDesignerView.cs @@ -132,6 +132,12 @@ namespace ICSharpCode.Reports.Addin defaultServiceContainer.AddService(typeof(MemberRelationshipService), new DefaultMemberRelationshipService()); + //need this to resolve the filename and manipulate + //ReportSettings in ReportDefinitionDeserializer.LoadObjectFromXmlDocument + //if the filename in ReportSettings is different from load location + + defaultServiceContainer.AddService(typeof(OpenedFile),base.PrimaryFile); + DesignerOptionService dos = new System.Windows.Forms.Design.WindowsFormsDesignerOptionService(); dos.Options.Properties.Find( "UseSmartTags", true ).SetValue( dos, true ); dos.Options.Properties.Find( "ShowGrid", true ).SetValue( dos, false ); @@ -700,29 +706,20 @@ namespace ICSharpCode.Reports.Addin public override void Load(OpenedFile file, Stream stream) { + LoggingService.Debug("ReportDesigner: Load from: " + file.FileName); base.Load(file, stream); this.LoadDesigner(stream); this.SetupSecondaryView(); - - //Always set Filename, otherwise rel path didn#t work - ComponentCollection c = Host.Container.Components; - foreach (IComponent component in c) { - if (component is ReportSettings) { - var r = component as ReportSettings; - r.FileName = file.FileName; - } - } } public override void Save(ICSharpCode.SharpDevelop.OpenedFile file,Stream stream) { - LoggingService.Debug("ReportDesigner: Save " + file.FileName); + LoggingService.Debug("ReportDesigner: Save to: " + file.FileName); if (hasUnmergedChanges) { this.MergeFormChanges(); } - using(StreamWriter writer = new StreamWriter(stream)) { writer.Write(this.ReportFileContent); } diff --git a/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Addin/Project/ReportItems/BaseImageItem.cs b/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Addin/Project/ReportItems/BaseImageItem.cs index 2955250192..b838ac93b6 100644 --- a/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Addin/Project/ReportItems/BaseImageItem.cs +++ b/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Addin/Project/ReportItems/BaseImageItem.cs @@ -242,12 +242,12 @@ namespace ICSharpCode.Reports.Addin string absolute = FileUtility.GetAbsolutePath(reportFileName,imageFileName); if (File.Exists(absolute)){ System.Diagnostics.Trace.WriteLine("Image.AbsoluteFileName"); - System.Diagnostics.Trace.WriteLine(String.Format("Load from {0}",absolute)); - System.Diagnostics.Trace.WriteLine(String.Format("report {0}",this.reportFileName)); - System.Diagnostics.Trace.WriteLine(String.Format("img ab {0}",this.ImageFileName)); - System.Diagnostics.Trace.WriteLine(String.Format("im rel {0}",this.relativeFileName)); + System.Diagnostics.Trace.WriteLine(String.Format("Absolute FIleN {0}",absolute)); + System.Diagnostics.Trace.WriteLine(String.Format("Report FileNam {0}",this.reportFileName)); + System.Diagnostics.Trace.WriteLine(String.Format("Image absolute {0}",this.ImageFileName)); + System.Diagnostics.Trace.WriteLine(String.Format("Image relative {0}",this.relativeFileName)); string t = FileUtility.NormalizePath(Path.Combine(Path.GetDirectoryName(this.reportFileName),this.relativeFileName)); - System.Diagnostics.Trace.WriteLine(String.Format("rebuild {0}",t)); + System.Diagnostics.Trace.WriteLine(String.Format("rebuild {0}",t)); System.Diagnostics.Trace.WriteLine("---------"); return absolute; }