diff --git a/src/Main/Base/Project/Src/Bookmarks/BookmarkConverter.cs b/src/Main/Base/Project/Src/Bookmarks/BookmarkConverter.cs index c910200964..1d29c73dd6 100644 --- a/src/Main/Base/Project/Src/Bookmarks/BookmarkConverter.cs +++ b/src/Main/Base/Project/Src/Bookmarks/BookmarkConverter.cs @@ -31,33 +31,36 @@ namespace ICSharpCode.SharpDevelop.Bookmarks FileName fileName = FileName.Create(v[1]); int lineNumber = int.Parse(v[2], culture); int columnNumber = int.Parse(v[3], culture); - Debugging.BreakpointAction action = Debugging.BreakpointAction.Break; - string scriptLanguage = ""; - string script = ""; - if (v[0] == "Breakpoint") { - action = (Debugging.BreakpointAction)Enum.Parse(typeof(Debugging.BreakpointAction), v[5]); - scriptLanguage = v[6]; - script = v[7]; - } if (lineNumber < 0) return null; if (columnNumber < 0) return null; + SDBookmark bookmark; switch (v[0]) { case "Breakpoint": + Debugging.BreakpointAction action = Debugging.BreakpointAction.Break; + string scriptLanguage = ""; + string script = ""; + action = (Debugging.BreakpointAction)Enum.Parse(typeof(Debugging.BreakpointAction), v[5]); + scriptLanguage = v[6]; + script = v[7]; var bbm = new Debugging.BreakpointBookmark(fileName, new Location(columnNumber, lineNumber), action, scriptLanguage, script); bbm.IsEnabled = bool.Parse(v[4]); bookmark = bbm; + bbm.Action = action; + bbm.ScriptLanguage = scriptLanguage; + bbm.Condition = script; break; - case "PinBookmark": - var pin = new PinBookmark(fileName, new Location(columnNumber, lineNumber)); - for (int i = 4; i < v.Length; i+=2) { - pin.SavedNodes.Add(new Tuple(v[i], v[i+1])); - } - - bookmark = pin; - break; +// case "PinBookmark": +// var pin = new PinBookmark(fileName, new Location(columnNumber, lineNumber)); +// pin.Comment = v[3]; +// for (int i = 4; i < v.Length; i+=2) { +// pin.SavedNodes.Add(new Tuple(v[i], v[i+1])); +// } +// +// bookmark = pin; +// break; default: bookmark = new SDBookmark(fileName, new Location(columnNumber, lineNumber)); break; @@ -100,15 +103,16 @@ namespace ICSharpCode.SharpDevelop.Bookmarks b.Append(bbm.Condition); } - if (bookmark is PinBookmark) { - var pin = (PinBookmark)bookmark; - b.Append(pin.Comment); - foreach(var node in pin.Nodes) { - b.Append(node.Name); - b.Append('|'); - b.Append(node.Text); - } - } +// if (bookmark is PinBookmark) { +// var pin = (PinBookmark)bookmark; +// b.Append(pin.Comment ?? string.Empty); +// foreach(var node in pin.Nodes) { +// b.Append('|'); +// b.Append(node.Name); +// b.Append('|'); +// b.Append(node.Text); +// } +// } return b.ToString(); } else { return base.ConvertTo(context, culture, value, destinationType); diff --git a/src/Main/Base/Project/Src/Services/Debugger/Tooltips/DebuggerPopup.cs b/src/Main/Base/Project/Src/Services/Debugger/Tooltips/DebuggerPopup.cs index 6f422cf640..265976a5f7 100644 --- a/src/Main/Base/Project/Src/Services/Debugger/Tooltips/DebuggerPopup.cs +++ b/src/Main/Base/Project/Src/Services/Debugger/Tooltips/DebuggerPopup.cs @@ -9,6 +9,7 @@ using System.Windows.Input; using ICSharpCode.Core; using ICSharpCode.SharpDevelop.Gui; +using Services.Debugger.Tooltips; namespace ICSharpCode.SharpDevelop.Debugging { @@ -33,6 +34,8 @@ namespace ICSharpCode.SharpDevelop.Debugging this.AllowsTransparency = true; //this.PopupAnimation = PopupAnimation.Slide; } + + public PinBookmark Mark { get; set; } // attempt to propagate shortcuts to main windows when Popup is focusable (needed for keyboard scrolling + editing) /*void DebuggerPopup_KeyDown(object sender, KeyEventArgs e) diff --git a/src/Main/Base/Project/Src/Services/Debugger/Tooltips/DebuggerTooltipControl.xaml b/src/Main/Base/Project/Src/Services/Debugger/Tooltips/DebuggerTooltipControl.xaml index 04d7a99ca6..f8b7659af3 100644 --- a/src/Main/Base/Project/Src/Services/Debugger/Tooltips/DebuggerTooltipControl.xaml +++ b/src/Main/Base/Project/Src/Services/Debugger/Tooltips/DebuggerTooltipControl.xaml @@ -230,9 +230,8 @@ Style="{StaticResource TextStyle}" IsEnabled="{Binding CanSetText}" KeyUp="TextBox_KeyUp" - LostFocus="TextBox_LostFocus" Margin="4 0" - Text="{Binding Path=Text, Mode=OneWay}"/> + Text="{Binding Path=Text}"/> @@ -263,7 +262,7 @@ - + diff --git a/src/Main/Base/Project/Src/Services/Debugger/Tooltips/DebuggerTooltipControl.xaml.cs b/src/Main/Base/Project/Src/Services/Debugger/Tooltips/DebuggerTooltipControl.xaml.cs index 2340fa1bb9..d1c366f637 100644 --- a/src/Main/Base/Project/Src/Services/Debugger/Tooltips/DebuggerTooltipControl.xaml.cs +++ b/src/Main/Base/Project/Src/Services/Debugger/Tooltips/DebuggerTooltipControl.xaml.cs @@ -110,11 +110,6 @@ namespace ICSharpCode.SharpDevelop.Debugging } } - public string Comment { - get { return CommentTextBox.Text; } - set { CommentTextBox.Text = value; } - } - /// /// Position within the document /// @@ -201,6 +196,7 @@ namespace ICSharpCode.SharpDevelop.Debugging if (this.containingPopup != null) { this.containingPopup.IsLeaf = false; } + this.childPopup.contentControl.LogicalPosition = LogicalPosition; this.childPopup.IsLeaf = true; this.childPopup.HorizontalOffset = buttonPos.X + ChildPopupOpenXOffet; this.childPopup.VerticalOffset = buttonPos.Y + ChildPopupOpenYOffet; @@ -244,17 +240,9 @@ namespace ICSharpCode.SharpDevelop.Debugging } } - void TextBox_LostFocus(object sender, RoutedEventArgs e) - { - // set new value - var textBox = (TextBox)sender; - var node = ((FrameworkElement)sender).DataContext as ITreeNode; - SaveNewValue(node, textBox.Text); - } - void SaveNewValue(ITreeNode node, string newValue) { - if(node != null && node.SetText(newValue)) { + if(node != null && node.SetText(newValue)) { // show adorner var adornerLayer = AdornerLayer.GetAdornerLayer(dataGrid); var adorners = adornerLayer.GetAdorners(dataGrid); @@ -268,57 +256,77 @@ namespace ICSharpCode.SharpDevelop.Debugging void PinButton_Checked(object sender, RoutedEventArgs e) { ITextEditorProvider provider = WorkbenchSingleton.Workbench.ActiveContent as ITextEditorProvider; - ToggleButton button = (ToggleButton)sender; + ToggleButton button = (ToggleButton)e.OriginalSource; if (provider != null) { ITextEditor editor = provider.TextEditor; - if (!string.IsNullOrEmpty(editor.FileName)) { + if (!string.IsNullOrEmpty(editor.FileName)) { + + var location = LogicalPosition; - var pin = new PinBookmark(editor.FileName, LogicalPosition); - if (!BookmarkManager.Bookmarks.Contains(pin)) { + var pin = BookmarkManager.Bookmarks.Find(b => b is PinBookmark && + b.FileName == editor.FileName && + b.Location.Line == location.Line) as PinBookmark; + bool found = false; + if (pin == null) { + pin = new PinBookmark(editor.FileName, location); + } + else { + found = true; + } + + var popup = pin.Popup; + if (!found) { + // TODO set the pin inside the code editor pinning surface // show pinned DebuggerPopup - if (pin.Popup == null) { - pin.Popup = new DebuggerPopup(this, true); - pin.Popup.Placement = PlacementMode.Absolute; - Rect rect = new Rect(this.DesiredSize); - var point = this.PointToScreen(rect.TopRight); - pin.Popup.HorizontalOffset = point.X + 150; - pin.Popup.VerticalOffset = point.Y - 20; - pin.Popup.Open(); + if (popup == null) { + popup = new DebuggerPopup(null, true); } - pin.Nodes.Add(button.DataContext as ITreeNode); + popup.Mark = pin; + popup.Placement = PlacementMode.Absolute; + Rect rect = new Rect(this.DesiredSize); + var point = this.PointToScreen(rect.TopRight); + popup.HorizontalOffset = 650; + popup.StaysOpen = true; + popup.VerticalOffset = point.Y - 50; + pin.Popup = popup; + pin.Nodes.Add((ITreeNode)button.DataContext); BookmarkManager.ToggleBookmark( editor, - LogicalPosition.Line, - b => b.CanToggle && b is PinBookmark, - location => pin); + location.Line, + b => b is PinBookmark, + l => pin); + + popup.Open(); } else { - pin.Nodes.Add(button.DataContext as ITreeNode); + popup = pin.Popup; + pin.Nodes.Add((ITreeNode)button.DataContext); } + + popup.ItemsSource = pin.Nodes; } } } void PinButton_Unchecked(object sender, RoutedEventArgs e) { - if (!showPinControl) - return; - - ITextEditorProvider provider = WorkbenchSingleton.Workbench.ActiveContent as ITextEditorProvider; + // remove from pinned DebuggerPopup + ITextEditorProvider provider = WorkbenchSingleton.Workbench.ActiveContent as ITextEditorProvider; if (provider != null) { ITextEditor editor = provider.TextEditor; if (!string.IsNullOrEmpty(editor.FileName)) { - // remove from pinned DebuggerPopup - var pin = new PinBookmark(editor.FileName, LogicalPosition); - if (!BookmarkManager.Bookmarks.Contains(pin)) - return; - ToggleButton button = (ToggleButton)sender; - pin.Nodes.Remove(button.DataContext as ITreeNode); + var pin = BookmarkManager.Bookmarks.Find(b => b is PinBookmark && + b.FileName == editor.FileName && + b.Location.Line == LogicalPosition.Line) as PinBookmark; + + ToggleButton button = (ToggleButton)e.OriginalSource; + pin.Nodes.Remove((ITreeNode)button.DataContext); + pin.Popup.ItemsSource = pin.Nodes; } - } + } } public void ShowComment(bool show) @@ -341,6 +349,20 @@ namespace ICSharpCode.SharpDevelop.Debugging board.Begin(this); } + public string Comment { + get { return CommentTextBox.Text; } + set { CommentTextBox.Text = value; } + } + + public event EventHandler CommentChanged; + + void CommentTextBox_TextChanged(object sender, TextChangedEventArgs e) + { + var handler = CommentChanged; + if(handler != null) + handler(this, EventArgs.Empty); + } + class SavedAdorner : Adorner { public SavedAdorner(UIElement adornedElement) : base(adornedElement) diff --git a/src/Main/Base/Project/Src/Services/Debugger/Tooltips/PinBookmark.cs b/src/Main/Base/Project/Src/Services/Debugger/Tooltips/PinBookmark.cs index 50e05496e5..4ab10f5713 100644 --- a/src/Main/Base/Project/Src/Services/Debugger/Tooltips/PinBookmark.cs +++ b/src/Main/Base/Project/Src/Services/Debugger/Tooltips/PinBookmark.cs @@ -11,7 +11,6 @@ using ICSharpCode.NRefactory; using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Bookmarks; using ICSharpCode.SharpDevelop.Debugging; -using ICSharpCode.SharpDevelop.Editor; namespace Services.Debugger.Tooltips { @@ -19,22 +18,26 @@ namespace Services.Debugger.Tooltips { string tooltip; - public DebuggerPopup Popup { get; set; } + public event NotifyCollectionChangedEventHandler CollectionChanged; public static readonly IImage PinImage = new ResourceServiceImage("Bookmarks.Pin"); public PinBookmark(FileName fileName, Location location) : base(fileName, location) { Nodes = new ObservableCollection(); + SavedNodes = new List>(); Nodes.CollectionChanged += new NotifyCollectionChangedEventHandler(Nodes_CollectionChanged); IsVisibleInBookmarkPad = false; } + + //TODO this should not be here but onto pinning surface of the code editor + public DebuggerPopup Popup { get; set; } void Nodes_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { - if (e.Action == NotifyCollectionChangedAction.Add || - e.Action == NotifyCollectionChangedAction.Remove) - Popup.contentControl.ItemsSource = Nodes; + var handler = CollectionChanged; + if (handler != null) + handler.Invoke(this, e); } public ObservableCollection Nodes { get; set; } diff --git a/src/Main/Base/Project/Src/Services/Debugger/Tooltips/PinCloseControl.xaml.cs b/src/Main/Base/Project/Src/Services/Debugger/Tooltips/PinCloseControl.xaml.cs index 12f9f5c416..d26dcb1b98 100644 --- a/src/Main/Base/Project/Src/Services/Debugger/Tooltips/PinCloseControl.xaml.cs +++ b/src/Main/Base/Project/Src/Services/Debugger/Tooltips/PinCloseControl.xaml.cs @@ -2,15 +2,9 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Specialized; using System.Windows; using System.Windows.Controls; -using System.Windows.Controls.Primitives; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; using ICSharpCode.SharpDevelop.Bookmarks; using ICSharpCode.SharpDevelop.Debugging; @@ -19,48 +13,43 @@ using ICSharpCode.SharpDevelop.Gui; namespace Services.Debugger.Tooltips { - /// - /// Interaction logic for PinCloseControl.xaml - /// public partial class PinCloseControl : UserControl { - readonly DebuggerTooltipControl toolTipControl; - - public PinCloseControl(DebuggerTooltipControl parent) + readonly DebuggerTooltipControl control; + + public PinCloseControl(DebuggerTooltipControl control) { Margin = new Thickness(5, 0, 0, 0); InitializeComponent(); - - this.toolTipControl = parent; + + this.control = control; + this.control.CommentChanged += delegate { Mark.Comment = control.Comment; }; + } + + private PinBookmark Mark { + get { return this.control.containingPopup.Mark; } } void Unpin() { - ITextEditorProvider provider = WorkbenchSingleton.Workbench.ActiveContent as ITextEditorProvider; - if (provider != null) { - ITextEditor editor = provider.TextEditor; - if (!string.IsNullOrEmpty(editor.FileName)) { - - var pin = new PinBookmark(editor.FileName, toolTipControl.LogicalPosition); - BookmarkManager.RemoveMark(pin); - } - } + BookmarkManager.RemoveMark(Mark); } void CloseButton_Click(object sender, RoutedEventArgs e) { Unpin(); - toolTipControl.containingPopup.CloseSelfAndChildren(); + + this.control.containingPopup.CloseSelfAndChildren(); } void CommentButton_Checked(object sender, RoutedEventArgs e) { - toolTipControl.ShowComment(true); + this.control.ShowComment(true); } void CommentButton_Unchecked(object sender, RoutedEventArgs e) { - toolTipControl.ShowComment(false); + this.control.ShowComment(false); } void UnpinButton_Checked(object sender, RoutedEventArgs e) @@ -75,13 +64,11 @@ namespace Services.Debugger.Tooltips ITextEditor editor = provider.TextEditor; if (!string.IsNullOrEmpty(editor.FileName)) { - var pin = new PinBookmark(editor.FileName, toolTipControl.LogicalPosition); - BookmarkManager.ToggleBookmark( editor, - toolTipControl.LogicalPosition.Line, + Mark.Location.Line, b => b.CanToggle && b is PinBookmark, - location => pin); + location => Mark); } } }