From 465a5f38e9308fcdea4c8cd88771ac688ab54b9b Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 13 Sep 2009 18:18:49 +0000 Subject: [PATCH] Fixed AvalonEdit bug when deleting text including a folded section. Fixed DBNull issue in UsageDataUploader.FetchDataForUpload. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4923 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../UsageDataSessionWriter.cs | 4 +++ .../UsageDataCollector/UsageDataUploader.cs | 6 ++-- .../Folding/FoldingManager.cs | 36 +++++++++++++++++-- .../Folding/FoldingSection.cs | 14 ++++---- 4 files changed, 50 insertions(+), 10 deletions(-) diff --git a/src/AddIns/Misc/UsageDataCollector/UsageDataSessionWriter.cs b/src/AddIns/Misc/UsageDataCollector/UsageDataSessionWriter.cs index 6844e59829..0c432a29cf 100644 --- a/src/AddIns/Misc/UsageDataCollector/UsageDataSessionWriter.cs +++ b/src/AddIns/Misc/UsageDataCollector/UsageDataSessionWriter.cs @@ -159,6 +159,8 @@ namespace ICSharpCode.UsageDataCollector /// ID that can be used for public long AddFeatureUse(string featureName, string activationMethod) { + if (featureName == null) + throw new ArgumentNullException("featureName"); long featureRowId; using (SQLiteTransaction transaction = this.connection.BeginTransaction()) { using (SQLiteCommand cmd = this.connection.CreateCommand()) { @@ -196,6 +198,8 @@ namespace ICSharpCode.UsageDataCollector /// Stacktrace public void AddException(string exceptionType, string stacktrace) { + if (exceptionType == null) + throw new ArgumentNullException("exceptionType"); using (SQLiteCommand cmd = this.connection.CreateCommand()) { cmd.CommandText = "INSERT INTO Exceptions (session, time, type, stackTrace)" + " VALUES (?, datetime('now'), ?, ?);"; diff --git a/src/AddIns/Misc/UsageDataCollector/UsageDataUploader.cs b/src/AddIns/Misc/UsageDataCollector/UsageDataUploader.cs index 887107bec5..d06886fa14 100644 --- a/src/AddIns/Misc/UsageDataCollector/UsageDataUploader.cs +++ b/src/AddIns/Misc/UsageDataCollector/UsageDataUploader.cs @@ -185,7 +185,8 @@ namespace ICSharpCode.UsageDataCollector if (!reader.IsDBNull(2)) featureUse.EndTime = reader.GetDateTime(2); featureUse.FeatureName = stringInterning.Intern(reader.GetString(3)); - featureUse.ActivationMethod = stringInterning.Intern(reader.GetString(4)); + if (!reader.IsDBNull(4)) + featureUse.ActivationMethod = stringInterning.Intern(reader.GetString(4)); session.FeatureUses.Add(featureUse); } } @@ -201,7 +202,8 @@ namespace ICSharpCode.UsageDataCollector UsageDataException exception = new UsageDataException(); exception.Time = reader.GetDateTime(1); exception.ExceptionType = stringInterning.Intern(reader.GetString(2)); - exception.StackTrace = stringInterning.Intern(reader.GetString(3)); + if (!reader.IsDBNull(3)) + exception.StackTrace = stringInterning.Intern(reader.GetString(3)); session.Exceptions.Add(exception); } } diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingManager.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingManager.cs index 23b1149973..36ef8ece7c 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingManager.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingManager.cs @@ -22,7 +22,7 @@ namespace ICSharpCode.AvalonEdit.Folding /// /// Stores a list of foldings for a specific TextView and TextDocument. /// - public class FoldingManager + public class FoldingManager : IWeakEventListener { internal readonly TextView textView; internal readonly TextDocument document; @@ -41,7 +41,39 @@ namespace ICSharpCode.AvalonEdit.Folding throw new ArgumentNullException("document"); this.textView = textView; this.document = document; - this.foldings = new TextSegmentCollection(document); + this.foldings = new TextSegmentCollection(); + document.VerifyAccess(); + TextDocumentWeakEventManager.Changed.AddListener(document, this); + } + #endregion + + #region ReceiveWeakEvent + /// + protected virtual bool ReceiveWeakEvent(Type managerType, object sender, EventArgs e) + { + if (managerType == typeof(TextDocumentWeakEventManager.Changed)) { + OnDocumentChanged((DocumentChangeEventArgs)e); + return true; + } + return false; + } + + bool IWeakEventListener.ReceiveWeakEvent(Type managerType, object sender, EventArgs e) + { + return ReceiveWeakEvent(managerType, sender, e); + } + + void OnDocumentChanged(DocumentChangeEventArgs e) + { + foldings.UpdateOffsets(e); + FoldingSection s = foldings.FindFirstSegmentWithStartAfter(e.Offset); + while (s != null && s.StartOffset == e.Offset) { + FoldingSection next = foldings.GetNextSegment(s); + if (s.Length == 0) { + RemoveFolding(s); + } + s = next; + } } #endregion diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingSection.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingSection.cs index 8ca722ddc1..43c3aabd7e 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingSection.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingSection.cs @@ -40,10 +40,7 @@ namespace ICSharpCode.AvalonEdit.Folding } } } else { - if (collapsedSection != null) { - collapsedSection.Uncollapse(); - collapsedSection = null; - } + RemoveCollapsedLineSection(); } if (manager != null) manager.textView.Redraw(this, DispatcherPriority.Normal); @@ -74,12 +71,17 @@ namespace ICSharpCode.AvalonEdit.Folding this.Length = endOffset - startOffset; } - internal void Removed() + void RemoveCollapsedLineSection() { if (collapsedSection != null) { - collapsedSection.Uncollapse(); + if (collapsedSection.Start != null) + collapsedSection.Uncollapse(); collapsedSection = null; } + } + + internal void Removed() + { manager = null; } }