From 4bb60397c7b78b0bbf328dff3ff1fd5f57d34c67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Sun, 2 Apr 2006 17:30:52 +0000 Subject: [PATCH 01/44] Current* functions renamed to Selected* and modified to simple read/write properties. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1253 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/Pads/CallStackPad.cs | 8 ++-- .../Project/Src/Pads/RunningThreadsPad.cs | 4 +- .../Project/Src/Service/WindowsDebugger.cs | 20 +++++----- .../Src/Debugger/Internal/ManagedCallback.cs | 25 ++++++------ .../Src/Debugger/NDebugger-StateControl.cs | 40 ++++++++----------- .../Project/Src/Debugger/NDebugger.cs | 12 +++--- .../Project/Src/Threads/Function.cs | 6 +-- .../Project/Src/Threads/Process.cs | 25 +++--------- .../Project/Src/Threads/Thread.cs | 29 +++----------- .../Src/Variables/Evals/NDebugger-Evals.cs | 2 +- .../Project/Src/Variables/ObjectValue.cs | 4 +- .../Project/Src/DebuggerTests.cs | 38 +++++++++--------- 12 files changed, 89 insertions(+), 124 deletions(-) diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs index 5d3c7717ca..49832b8737 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs @@ -169,8 +169,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads if (debuggerCore.IsPaused) { Function f = (Function)(callStackList.SelectedItems[0].Tag); if (f.HasSymbols) { - if (debuggerCore.CurrentThread != null) { - debuggerCore.CurrentThread.SetCurrentFunction(f); + if (debuggerCore.SelectedThread != null) { + debuggerCore.SelectedThread.SelectedFunction = f; } } else { MessageBox.Show("You can not switch to function without symbols", "Function switch"); @@ -200,8 +200,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads callStackList.BeginUpdate(); callStackList.Items.Clear(); - if (debuggerCore != null && debuggerCore.CurrentThread != null) { - foreach (Function f in debuggerCore.CurrentThread.Callstack) { + if (debuggerCore != null && debuggerCore.SelectedThread != null && debuggerCore.IsPaused) { + foreach (Function f in debuggerCore.SelectedThread.Callstack) { ListViewItem item; if (f.HasSymbols || showExternalMethods) { // Show the method in the list diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs index fa385ed301..9c1444b460 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs @@ -158,8 +158,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads void RunningThreadsListItemActivate(object sender, EventArgs e) { if (debuggerCore.IsPaused) { - if (debuggerCore.CurrentProcess != null) { - debuggerCore.CurrentProcess.SetCurrentThread((Thread)(runningThreadsList.SelectedItems[0].Tag)); + if (debuggerCore.SelectedProcess != null) { + debuggerCore.SelectedProcess.SelectedThread = (Thread)(runningThreadsList.SelectedItems[0].Tag); } } else { MessageBox.Show("You can not switch threads while the debugger is running.", "Thread switch"); diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs index d59ae06758..257e2d7744 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs @@ -138,7 +138,7 @@ namespace ICSharpCode.SharpDevelop.Services public void StepInto() { - if (debugger.CurrentFunction == null) { + if (debugger.SelectedFunction == null || debugger.IsRunning) { MessageBox.Show("You can not step because there is no function selected to be stepped","Step into"); } else { debugger.StepInto(); @@ -147,7 +147,7 @@ namespace ICSharpCode.SharpDevelop.Services public void StepOver() { - if (debugger.CurrentFunction == null) { + if (debugger.SelectedFunction == null || debugger.IsRunning) { MessageBox.Show("You can not step because there is no function selected to be stepped","Step over"); } else { debugger.StepOver(); @@ -156,7 +156,7 @@ namespace ICSharpCode.SharpDevelop.Services public void StepOut() { - if (debugger.CurrentFunction == null) { + if (debugger.SelectedFunction == null || debugger.IsRunning) { MessageBox.Show("You can not step because there is no function selected to be stepped","Step out"); } else { debugger.StepOut(); @@ -244,8 +244,8 @@ namespace ICSharpCode.SharpDevelop.Services public bool CanSetInstructionPointer(string filename, int line, int column) { - if (debugger != null && debugger.IsPaused && debugger.CurrentFunction != null) { - SourcecodeSegment seg = debugger.CurrentFunction.CanSetIP(filename, line, column); + if (debugger != null && debugger.IsPaused && debugger.SelectedFunction != null) { + SourcecodeSegment seg = debugger.SelectedFunction.CanSetIP(filename, line, column); return seg != null; } else { return false; @@ -255,7 +255,7 @@ namespace ICSharpCode.SharpDevelop.Services public bool SetInstructionPointer(string filename, int line, int column) { if (CanSetInstructionPointer(filename, line, column)) { - SourcecodeSegment seg = debugger.CurrentFunction.SetIP(filename, line, column); + SourcecodeSegment seg = debugger.SelectedFunction.SetIP(filename, line, column); return seg != null; } else { return false; @@ -368,9 +368,9 @@ namespace ICSharpCode.SharpDevelop.Services OnIsProcessRunningChanged(EventArgs.Empty); if (e.Reason == PausedReason.Exception) { - exceptionHistory.Add(debugger.CurrentThread.CurrentException); + exceptionHistory.Add(debugger.SelectedThread.CurrentException); OnExceptionHistoryModified(); - if (debugger.CurrentThread.CurrentException.ExceptionType != ExceptionType.DEBUG_EXCEPTION_UNHANDLED) { + if (debugger.SelectedThread.CurrentException.ExceptionType != ExceptionType.DEBUG_EXCEPTION_UNHANDLED) { // Ignore the exception e.ResumeDebuggingAfterEvent(); return; @@ -378,14 +378,14 @@ namespace ICSharpCode.SharpDevelop.Services JumpToCurrentLine(); - switch (ExceptionForm.Show(debugger.CurrentThread.CurrentException)) { + switch (ExceptionForm.Show(debugger.SelectedThread.CurrentException)) { case ExceptionForm.Result.Break: break; case ExceptionForm.Result.Continue: e.ResumeDebuggingAfterEvent(); return; case ExceptionForm.Result.Ignore: - debugger.CurrentThread.InterceptCurrentException(); + debugger.SelectedThread.InterceptCurrentException(); break; } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs index ad0d346f46..df6a2639c3 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs @@ -39,8 +39,8 @@ namespace Debugger debugger.TraceMessage("Callback: " + name); debugger.AssertRunning(); debugger.PauseSession = new PauseSession(pausedReason); - debugger.CurrentProcess = debugger.GetProcess(pProcess); - debugger.CurrentProcess.IsRunning = false; + debugger.SelectedProcess = debugger.GetProcess(pProcess); + debugger.SelectedProcess.IsRunning = false; } void EnterCallback(PausedReason pausedReason, string name, ICorDebugAppDomain pAppDomain) @@ -55,20 +55,21 @@ namespace Debugger if (name != "ExitProcess") debugger.AssertRunning(); Thread thread = debugger.GetThread(pThread); debugger.PauseSession = new PauseSession(pausedReason); - debugger.CurrentProcess = thread.Process; - debugger.CurrentProcess.IsRunning = false; - debugger.CurrentProcess.CurrentThread = thread; + debugger.SelectedProcess = thread.Process; + debugger.SelectedProcess.IsRunning = false; + debugger.SelectedProcess.SelectedThread = thread; } void ExitCallback_Continue() { - debugger.CurrentProcess.Continue(); + debugger.SelectedProcess.Continue(); } void ExitCallback_Paused() { - if (debugger.CurrentThread != null) { - debugger.CurrentThread.DeactivateAllSteppers(); + if (debugger.SelectedThread != null) { + debugger.SelectedThread.DeactivateAllSteppers(); + debugger.SelectedThread.SelectedFunction = debugger.SelectedThread.LastFunctionWithLoadedSymbols; } debugger.Pause(); } @@ -89,7 +90,7 @@ namespace Debugger } } - if (!debugger.CurrentThread.LastFunction.HasSymbols) { + if (!debugger.SelectedThread.LastFunction.HasSymbols) { // This should not happen with JMC enabled debugger.TraceMessage(" - leaving code without symbols"); @@ -339,8 +340,8 @@ namespace Debugger debugger.RemoveThread(thread); - if (thread.Process.CurrentThread == thread) { - thread.Process.CurrentThread = null; + if (thread.Process.SelectedThread == thread) { + thread.Process.SelectedThread = null; } ExitCallback_Continue(); @@ -400,7 +401,7 @@ namespace Debugger // Whatch out for the zeros and null! // Exception -> Exception2(pAppDomain, pThread, null, 0, exceptionType, 0); - debugger.CurrentThread.CurrentExceptionType = (ExceptionType)exceptionType; + debugger.SelectedThread.CurrentExceptionType = (ExceptionType)exceptionType; if (ExceptionType.DEBUG_EXCEPTION_UNHANDLED != (ExceptionType)exceptionType) { // Handled exception diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs index 0ed8842dbc..0028c4f671 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs @@ -24,7 +24,7 @@ namespace Debugger PauseSession pauseSession; DebugeeState debugeeState; - Process currentProcess; + Process selectedProcess; public event EventHandler DebuggingResumed; public event EventHandler DebuggingPaused; @@ -67,35 +67,31 @@ namespace Debugger } } - public Process CurrentProcess { + public Process SelectedProcess { get { - if (IsRunning) return null; - if (currentProcess == null) { - return null; - } else { - return currentProcess; - } + return selectedProcess; } set { - currentProcess = value; + selectedProcess = value; } } - public Thread CurrentThread { + public Thread SelectedThread { get { - if (IsRunning) return null; - if (CurrentProcess == null) return null; - return CurrentProcess.CurrentThread; + if (SelectedProcess == null) { + return null; + } else { + return SelectedProcess.SelectedThread; + } } } - public Function CurrentFunction { + public Function SelectedFunction { get { - if (IsRunning) return null; - if (CurrentThread == null) { + if (SelectedThread == null) { return null; } else { - return CurrentThread.CurrentFunction; + return SelectedThread.SelectedFunction; } } } @@ -187,8 +183,6 @@ namespace Debugger pausedHandle.Reset(); pauseSession = null; - - currentProcess = null; } /// @@ -230,22 +224,22 @@ namespace Debugger public void StepInto() { - CurrentFunction.StepInto(); + SelectedFunction.StepInto(); } public void StepOver() { - CurrentFunction.StepOver(); + SelectedFunction.StepOver(); } public void StepOut() { - CurrentFunction.StepOut(); + SelectedFunction.StepOut(); } public void Continue() { - CurrentProcess.Continue(); + SelectedProcess.Continue(); } public void Terminate() diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs index d56d5be9ad..2846127f23 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs @@ -130,7 +130,7 @@ namespace Debugger ClearThreads(); - currentProcess = null; + selectedProcess = null; pausedHandle.Reset(); pauseSession = null; @@ -201,10 +201,10 @@ namespace Debugger public SourcecodeSegment NextStatement { get { - if (CurrentFunction == null) { + if (SelectedFunction == null || IsRunning) { return null; } else { - return CurrentFunction.NextStatement; + return SelectedFunction.NextStatement; } } } @@ -218,11 +218,11 @@ namespace Debugger void OnUpdatingLocalVariables(object sender, VariableCollectionEventArgs e) { - if (CurrentFunction == null) { + if (SelectedFunction == null || IsRunning) { e.VariableCollection.UpdateTo(new Variable[] {}); // Make it empty } else { - e.VariableCollection.UpdateTo(CurrentFunction.Variables); - CurrentFunction.Expired += delegate { + e.VariableCollection.UpdateTo(SelectedFunction.Variables); + SelectedFunction.Expired += delegate { e.VariableCollection.UpdateTo(new Variable[] {}); }; } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs index 94e52016a1..9bce372c46 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs @@ -182,7 +182,7 @@ namespace Debugger ICorDebugStepper stepper = CorILFrame.CreateStepper(); stepper.StepOut(); - debugger.CurrentThread.AddActiveStepper(stepper); + thread.AddActiveStepper(stepper); debugger.Continue(); } @@ -214,7 +214,7 @@ namespace Debugger stepper.StepRange(1 /* true - step in*/ , (IntPtr)ranges, (uint)nextSt.StepRanges.Length / 2); } - debugger.CurrentThread.AddActiveStepper(stepper); + thread.AddActiveStepper(stepper); } // Mind that step in which ends in code without symblols is cotinued @@ -231,7 +231,7 @@ namespace Debugger stepper.StepRange(0 /* false - step over*/ , (IntPtr)ranges, (uint)nextSt.StepRanges.Length / 2); } - debugger.CurrentThread.AddActiveStepper(stepper); + thread.AddActiveStepper(stepper); debugger.Continue(); } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs index 65a646ed45..8e48553c53 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs @@ -20,7 +20,7 @@ namespace Debugger ICorDebugProcess corProcess; - Thread currentThread; + Thread selectedThread; bool isProcessRunning = true; public NDebugger Debugger { @@ -41,27 +41,14 @@ namespace Debugger } } - public Thread CurrentThread { + public Thread SelectedThread { get { - if (currentThread == null) { - IList threads = Threads; - if (threads.Count > 0) { - currentThread = threads[0]; - } - } - return currentThread; + return selectedThread; } - internal set { - currentThread = value; + set { + selectedThread = value; } } - - public void SetCurrentThread(Thread thread) - { - CurrentThread = thread; - - debugger.Pause(); - } public IList Threads { get { @@ -127,7 +114,7 @@ namespace Debugger isProcessRunning = false; debugger.PauseSession = new PauseSession(PausedReason.Break); - debugger.CurrentProcess = this; + debugger.SelectedProcess = this; debugger.Pause(); } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Thread.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Thread.cs index 83fb4f0a2d..bed5587464 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Thread.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Thread.cs @@ -32,7 +32,7 @@ namespace Debugger string lastName = string.Empty; bool hasBeenLoaded = false; - Function currentFunction; + Function selectedFunction; public NDebugger Debugger { get { @@ -290,36 +290,19 @@ namespace Debugger } } - public Function CurrentFunction { + public Function SelectedFunction { get { - process.AssertPaused(); - - if (currentFunction == null) { - currentFunction = LastFunctionWithLoadedSymbols; - } - - if (currentFunction != null && currentFunction.HasSymbols) { - return currentFunction; - } else { - return null; - } + return selectedFunction; } - internal set { + set { if (value != null && !value.HasSymbols) { - throw new DebuggerException("CurrentFunction must have symbols"); + throw new DebuggerException("SelectedFunction must have symbols"); } - currentFunction = value; + selectedFunction = value; } } - public void SetCurrentFunction(Function function) - { - CurrentFunction = function; - - debugger.Pause(); - } - public Function LastFunctionWithLoadedSymbols { get { foreach (Function function in Callstack) { diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/NDebugger-Evals.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/NDebugger-Evals.cs index b09bbff6b5..5c1cbdab26 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/NDebugger-Evals.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/NDebugger-Evals.cs @@ -110,7 +110,7 @@ namespace Debugger this.AssertPaused(); // TODO: Investigate other threads, are they alowed to run? - if (SetupNextEvaluation(CurrentThread)) { + if (SetupNextEvaluation(SelectedThread)) { evaluating = true; this.Continue(); return true; diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectValue.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectValue.cs index 316e72a751..271fae0f0a 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectValue.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectValue.cs @@ -209,8 +209,8 @@ namespace Debugger { // Current frame is used to resolve context specific static values (eg. ThreadStatic) ICorDebugFrame curFrame = null; - if (debugger.CurrentThread != null && debugger.CurrentThread.LastFunction != null && debugger.CurrentThread.LastFunction.CorILFrame != null) { - curFrame = debugger.CurrentThread.LastFunction.CorILFrame.CastTo(); + if (debugger.IsPaused && debugger.SelectedThread != null && debugger.SelectedThread.LastFunction != null && debugger.SelectedThread.LastFunction.CorILFrame != null) { + curFrame = debugger.SelectedThread.LastFunction.CorILFrame.CastTo(); } try { diff --git a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTests.cs b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTests.cs index bb92006faf..d0ffe2cb9b 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTests.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTests.cs @@ -227,20 +227,20 @@ namespace Debugger.Tests StartProgram("Callstack"); WaitForPause(PausedReason.Break, null); - callstack = new List(debugger.CurrentThread.Callstack); + callstack = new List(debugger.SelectedThread.Callstack); Assert.AreEqual("Sub2", callstack[0].Name); Assert.AreEqual("Sub1", callstack[1].Name); Assert.AreEqual("Main", callstack[2].Name); debugger.StepOut(); WaitForPause(PausedReason.StepComplete, null); - callstack = new List(debugger.CurrentThread.Callstack); + callstack = new List(debugger.SelectedThread.Callstack); Assert.AreEqual("Sub1", callstack[0].Name); Assert.AreEqual("Main", callstack[1].Name); debugger.StepOut(); WaitForPause(PausedReason.StepComplete, null); - callstack = new List(debugger.CurrentThread.Callstack); + callstack = new List(debugger.SelectedThread.Callstack); Assert.AreEqual("Main", callstack[0].Name); debugger.Continue(); @@ -258,7 +258,7 @@ namespace Debugger.Tests for(int i = 0; i < 2; i++) { debugger.Continue(); WaitForPause(PausedReason.Break, null); - args = new List(debugger.CurrentFunction.ArgumentVariables); + args = new List(debugger.SelectedFunction.ArgumentVariables); // names Assert.AreEqual("i", args[0].Name); Assert.AreEqual("s", args[1].Name); @@ -274,7 +274,7 @@ namespace Debugger.Tests debugger.Continue(); WaitForPause(PausedReason.Break, null); - args = new List(debugger.CurrentFunction.ArgumentVariables); + args = new List(debugger.SelectedFunction.ArgumentVariables); // types Assert.AreEqual(typeof(PrimitiveValue), args[0].Value.GetType()); Assert.AreEqual(typeof(PrimitiveValue), args[1].Value.GetType()); @@ -286,7 +286,7 @@ namespace Debugger.Tests debugger.Continue(); WaitForPause(PausedReason.Break, null); - args = new List(debugger.CurrentFunction.ArgumentVariables); + args = new List(debugger.SelectedFunction.ArgumentVariables); // types Assert.AreEqual(typeof(PrimitiveValue), args[0].Value.GetType()); Assert.AreEqual(typeof(NullValue), args[1].Value.GetType()); @@ -308,7 +308,7 @@ namespace Debugger.Tests StartProgram("FunctionLocalVariables"); WaitForPause(PausedReason.Break, null); - args = new List(debugger.CurrentFunction.LocalVariables); + args = new List(debugger.SelectedFunction.LocalVariables); // names Assert.AreEqual("i", args[0].Name); Assert.AreEqual("s", args[1].Name); @@ -339,7 +339,7 @@ namespace Debugger.Tests StartProgram("FunctionLifetime"); WaitForPause(PausedReason.Break, null); - function = debugger.CurrentFunction; + function = debugger.SelectedFunction; Assert.IsNotNull(function); Assert.AreEqual("Function", function.Name); Assert.AreEqual(false, function.HasExpired); @@ -347,19 +347,19 @@ namespace Debugger.Tests debugger.Continue(); // Go to the SubFunction WaitForPause(PausedReason.Break, null); - Assert.AreEqual("SubFunction", debugger.CurrentFunction.Name); + Assert.AreEqual("SubFunction", debugger.SelectedFunction.Name); Assert.AreEqual(false, function.HasExpired); Assert.AreEqual("1", function.GetArgumentVariable(0).Value.AsString); debugger.Continue(); // Go back to Function WaitForPause(PausedReason.Break, null); - Assert.AreEqual("Function", debugger.CurrentFunction.Name); + Assert.AreEqual("Function", debugger.SelectedFunction.Name); Assert.AreEqual(false, function.HasExpired); Assert.AreEqual("1", function.GetArgumentVariable(0).Value.AsString); debugger.Continue(); // Setp out of function WaitForPause(PausedReason.Break, null); - Assert.AreEqual("Main", debugger.CurrentFunction.Name); + Assert.AreEqual("Main", debugger.SelectedFunction.Name); Assert.AreEqual(true, function.HasExpired); debugger.Continue(); @@ -377,7 +377,7 @@ namespace Debugger.Tests StartProgram("FunctionVariablesLifetime"); // 1 - Enter program WaitForPause(PausedReason.Break, null); - function = debugger.CurrentFunction; + function = debugger.SelectedFunction; Assert.IsNotNull(function); Assert.AreEqual("Function", function.Name); argument = function.GetArgumentVariable(0); @@ -443,7 +443,7 @@ namespace Debugger.Tests StartProgram("ArrayValue"); WaitForPause(PausedReason.Break, null); - foreach(Variable var in debugger.CurrentFunction.LocalVariables) { + foreach(Variable var in debugger.SelectedFunction.LocalVariables) { local = var; break; } Assert.AreEqual("array", local.Name); @@ -471,7 +471,7 @@ namespace Debugger.Tests StartProgram("ObjectValue"); WaitForPause(PausedReason.Break, null); - foreach(Variable var in debugger.CurrentFunction.LocalVariables) { + foreach(Variable var in debugger.SelectedFunction.LocalVariables) { local = var; } Assert.AreEqual("val", local.Name); @@ -514,7 +514,7 @@ namespace Debugger.Tests StartProgram("PropertyVariable"); WaitForPause(PausedReason.Break, null); - foreach(Variable var in debugger.CurrentFunction.LocalVariables) { + foreach(Variable var in debugger.SelectedFunction.LocalVariables) { local = var; } foreach(Variable var in local.SubVariables) { @@ -559,7 +559,7 @@ namespace Debugger.Tests StartProgram("PropertyVariableForm"); WaitForPause(PausedReason.Break, null); - foreach(Variable var in debugger.CurrentFunction.LocalVariables) { + foreach(Variable var in debugger.SelectedFunction.LocalVariables) { local = var; } Assert.AreEqual("form", local.Name); @@ -596,9 +596,9 @@ namespace Debugger.Tests StartProgram("SetIP"); WaitForPause(PausedReason.Break, "1"); - Assert.IsNotNull(debugger.CurrentFunction.CanSetIP("SetIP.cs", 16, 0)); - Assert.IsNull(debugger.CurrentFunction.CanSetIP("SetIP.cs", 100, 0)); - debugger.CurrentFunction.SetIP("SetIP.cs", 16, 0); + Assert.IsNotNull(debugger.SelectedFunction.CanSetIP("SetIP.cs", 16, 0)); + Assert.IsNull(debugger.SelectedFunction.CanSetIP("SetIP.cs", 100, 0)); + debugger.SelectedFunction.SetIP("SetIP.cs", 16, 0); debugger.Continue(); WaitForPause(PausedReason.Break, "1"); Assert.AreEqual("1\r\n1\r\n", log); From 25af9021c27f0851ca1bd700c7b10bb5fd3ad4e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Sun, 2 Apr 2006 18:18:11 +0000 Subject: [PATCH 02/44] Refactoring debugger pads - all pads are based at DebuggerPad git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1254 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Debugger.AddIn.csproj | 3 + .../Project/Src/Pads/CallStackPad.Menu.cs | 100 ++++++++++++++ .../Project/Src/Pads/CallStackPad.cs | 123 +----------------- .../Project/Src/Pads/DebuggerPad.cs | 60 +++++++++ .../Project/Src/Pads/ExceptionHistoryPad.cs | 44 ++----- .../Project/Src/Pads/LoadedModulesPad.cs | 43 ++---- .../Project/Src/Pads/LocalVarPad.cs | 47 +++---- .../Src/Pads/RunningThreadsPad.Menu.cs | 76 +++++++++++ .../Project/Src/Pads/RunningThreadsPad.cs | 119 +++-------------- 9 files changed, 298 insertions(+), 317 deletions(-) create mode 100644 src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.Menu.cs create mode 100644 src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/DebuggerPad.cs create mode 100644 src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.Menu.cs diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj index 801df42a63..f4dc63cdcf 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj @@ -59,6 +59,9 @@ + + + diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.Menu.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.Menu.cs new file mode 100644 index 0000000000..6908b0ea5c --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.Menu.cs @@ -0,0 +1,100 @@ +// +// +// +// +// $Revision: 1253 $ +// + +using System; +using System.Windows.Forms; +using System.Drawing; +using System.CodeDom.Compiler; +using System.Collections; +using System.ComponentModel; +using System.IO; +using System.Diagnostics; +using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Services; + +using Debugger; + +namespace ICSharpCode.SharpDevelop.Gui.Pads +{ + public partial class CallStackPad + { + public bool ShowArgumentNames { + get { + return debugger.Properties.Get("ShowArgumentNames", true); + } + set { + debugger.Properties.Set("ShowArgumentNames", value); + } + } + + public bool ShowArgumentValues { + get { + return debugger.Properties.Get("ShowArgumentValues", true); + } + set { + debugger.Properties.Set("ShowArgumentValues", value); + } + } + + public bool ShowExternalMethods { + get { + return debugger.Properties.Get("ShowExternalMethods", false); + } + set { + debugger.Properties.Set("ShowExternalMethods", value); + } + } + + ContextMenuStrip CreateContextMenuStrip() + { + ContextMenuStrip menu = new ContextMenuStrip(); + menu.Opening += FillContextMenuStrip; + return menu; + } + + void FillContextMenuStrip(object sender, CancelEventArgs e) + { + ContextMenuStrip menu = sender as ContextMenuStrip; + menu.Items.Clear(); + + ToolStripMenuItem argNamesItem; + argNamesItem = new ToolStripMenuItem(); + argNamesItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ShowArgumentNames"); + argNamesItem.Checked = ShowArgumentNames; + argNamesItem.Click += delegate { + ShowArgumentNames = !ShowArgumentNames; + RefreshPad(); + }; + + ToolStripMenuItem argValuesItem; + argValuesItem = new ToolStripMenuItem(); + argValuesItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ShowArgumentValues"); + argValuesItem.Checked = ShowArgumentValues; + argValuesItem.Click += delegate { + ShowArgumentValues = !ShowArgumentValues; + RefreshPad(); + }; + + ToolStripMenuItem extMethodsItem; + extMethodsItem = new ToolStripMenuItem(); + extMethodsItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ShowExternalMethods"); + extMethodsItem.Checked = ShowExternalMethods; + extMethodsItem.Click += delegate { + ShowExternalMethods = !ShowExternalMethods; + RefreshPad(); + }; + + menu.Items.AddRange(new ToolStripItem[] { + argNamesItem, + argValuesItem, + extMethodsItem + }); + + e.Cancel = false; + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs index 49832b8737..082822c851 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs @@ -20,11 +20,8 @@ using Debugger; namespace ICSharpCode.SharpDevelop.Gui.Pads { - public class CallStackPad : AbstractPadContent + public partial class CallStackPad : DebuggerPad { - WindowsDebugger debugger; - NDebugger debuggerCore; - ListView callStackList; ColumnHeader name = new ColumnHeader(); @@ -36,15 +33,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads } } - public CallStackPad()// : base("${res:MainWindow.Windows.Debug.CallStack}", null) - { - InitializeComponents(); - } - - void InitializeComponents() + protected override void InitializeComponents() { - debugger = (WindowsDebugger)DebuggerService.CurrentDebugger; - callStackList = new ListView(); callStackList.FullRowSelect = true; callStackList.AutoArrange = true; @@ -60,24 +50,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads language.Width = 50; RedrawContent(); - - if (debugger.ServiceInitialized) { - InitializeDebugger(); - } else { - debugger.Initialize += delegate { - InitializeDebugger(); - }; - } - } - - public void InitializeDebugger() - { - debuggerCore = debugger.DebuggerCore; - - debuggerCore.DebuggeeStateChanged += DebuggeeStateChanged; - debuggerCore.DebuggingResumed += DebuggingResumed; - - RefreshList(); } public override void RedrawContent() @@ -86,82 +58,11 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads language.Text = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.Language"); } - public bool ShowArgumentNames { - get { - return debugger.Properties.Get("ShowArgumentNames", true); - } - set { - debugger.Properties.Set("ShowArgumentNames", value); - } - } - - public bool ShowArgumentValues { - get { - return debugger.Properties.Get("ShowArgumentValues", true); - } - set { - debugger.Properties.Set("ShowArgumentValues", value); - } - } - - public bool ShowExternalMethods { - get { - return debugger.Properties.Get("ShowExternalMethods", false); - } - set { - debugger.Properties.Set("ShowExternalMethods", value); - } - } - - ContextMenuStrip CreateContextMenuStrip() + + protected override void RegisterDebuggerEvents() { - ContextMenuStrip menu = new ContextMenuStrip(); - menu.Opening += FillContextMenuStrip; - return menu; - } - - void FillContextMenuStrip(object sender, CancelEventArgs e) - { - ContextMenuStrip menu = sender as ContextMenuStrip; - menu.Items.Clear(); - - ToolStripMenuItem argNamesItem; - argNamesItem = new ToolStripMenuItem(); - argNamesItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ShowArgumentNames"); - argNamesItem.Checked = ShowArgumentNames; - argNamesItem.Click += - delegate { - ShowArgumentNames = !ShowArgumentNames; - RefreshList(); - }; - - ToolStripMenuItem argValuesItem; - argValuesItem = new ToolStripMenuItem(); - argValuesItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ShowArgumentValues"); - argValuesItem.Checked = ShowArgumentValues; - argValuesItem.Click += - delegate { - ShowArgumentValues = !ShowArgumentValues; - RefreshList(); - }; - - ToolStripMenuItem extMethodsItem; - extMethodsItem = new ToolStripMenuItem(); - extMethodsItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ShowExternalMethods"); - extMethodsItem.Checked = ShowExternalMethods; - extMethodsItem.Click += - delegate { - ShowExternalMethods = !ShowExternalMethods; - RefreshList(); - }; - - menu.Items.AddRange(new ToolStripItem[] { - argNamesItem, - argValuesItem, - extMethodsItem - }); - - e.Cancel = false; + debuggerCore.DebuggeeStateChanged += delegate { RefreshPad(); }; + debuggerCore.DebuggingResumed += delegate { RefreshPad(); }; } void CallStackListItemActivate(object sender, EventArgs e) @@ -179,18 +80,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads MessageBox.Show("You can not switch functions while the debugger is running.", "Function switch"); } } - - void DebuggeeStateChanged(object sender, DebuggerEventArgs e) - { - RefreshList(); - } - - void DebuggingResumed(object sender, DebuggerEventArgs e) - { - RefreshList(); - } - public void RefreshList() + public override void RefreshPad() { bool showArgumentNames = ShowArgumentNames; bool showArgumentValues = ShowArgumentValues; diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/DebuggerPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/DebuggerPad.cs new file mode 100644 index 0000000000..ecbb249341 --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/DebuggerPad.cs @@ -0,0 +1,60 @@ +// +// +// +// +// $Revision: 1064 $ +// + +using System; +using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Services; + +using Debugger; + +namespace ICSharpCode.SharpDevelop.Gui.Pads +{ + public abstract class DebuggerPad: AbstractPadContent + { + protected WindowsDebugger debugger; + protected NDebugger debuggerCore; + + public DebuggerPad() + { + debugger = (WindowsDebugger)DebuggerService.CurrentDebugger; + + InitializeComponents(); + + if (debugger.ServiceInitialized) { + InitializeDebugger(); + } else { + debugger.Initialize += delegate { + InitializeDebugger(); + }; + } + } + + protected virtual void InitializeComponents() + { + + } + + void InitializeDebugger() + { + debuggerCore = debugger.DebuggerCore; + + RegisterDebuggerEvents(); + + RefreshPad(); + } + + protected virtual void RegisterDebuggerEvents() + { + + } + + public virtual void RefreshPad() + { + + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/ExceptionHistoryPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/ExceptionHistoryPad.cs index 110d07b163..2ac8227057 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/ExceptionHistoryPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/ExceptionHistoryPad.cs @@ -19,11 +19,8 @@ using Debugger; namespace ICSharpCode.SharpDevelop.Gui.Pads { - public class ExceptionHistoryPad : AbstractPadContent + public class ExceptionHistoryPad : DebuggerPad { - WindowsDebugger debugger; - NDebugger debuggerCore; - ListView exceptionHistoryList; ColumnHeader time = new ColumnHeader(); @@ -36,15 +33,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads } } - public ExceptionHistoryPad() + protected override void InitializeComponents() { - InitializeComponents(); - } - - void InitializeComponents() - { - debugger = (WindowsDebugger)DebuggerService.CurrentDebugger; - exceptionHistoryList = new ListView(); exceptionHistoryList.FullRowSelect = true; exceptionHistoryList.AutoArrange = true; @@ -60,25 +50,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads time.Width = 80; RedrawContent(); - - if (debugger.ServiceInitialized) { - InitializeDebugger(); - } else { - debugger.Initialize += delegate { - InitializeDebugger(); - }; - } } - public void InitializeDebugger() - { - debuggerCore = debugger.DebuggerCore; - - debugger.ExceptionHistoryModified += new EventHandler(ExceptionHistoryModified); - - RefreshList(); - } - public override void RedrawContent() { time.Text = ResourceService.GetString("MainWindow.Windows.Debug.ExceptionHistory.Time"); @@ -86,6 +59,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads location.Text = ResourceService.GetString("AddIns.HtmlHelp2.Location"); } + + protected override void RegisterDebuggerEvents() + { + debugger.ExceptionHistoryModified += delegate { RefreshPad(); }; + } + void ExceptionHistoryListItemActivate(object sender, EventArgs e) { SourcecodeSegment nextStatement = ((Debugger.Exception)(exceptionHistoryList.SelectedItems[0].Tag)).Location; @@ -115,13 +94,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads }*/ } } - - void ExceptionHistoryModified(object sender, EventArgs e) - { - RefreshList(); - } - public void RefreshList() + public override void RefreshPad() { exceptionHistoryList.BeginUpdate(); exceptionHistoryList.Items.Clear(); diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LoadedModulesPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LoadedModulesPad.cs index 328bbaa214..072661368a 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LoadedModulesPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LoadedModulesPad.cs @@ -19,11 +19,8 @@ using Debugger; namespace ICSharpCode.SharpDevelop.Gui.Pads { - public class LoadedModulesPad : AbstractPadContent + public class LoadedModulesPad : DebuggerPad { - WindowsDebugger debugger; - NDebugger debuggerCore; - ListView loadedModulesList; ColumnHeader name = new ColumnHeader(); @@ -41,16 +38,9 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads return loadedModulesList; } } - - public LoadedModulesPad() //: base("${res:MainWindow.Windows.Debug.Modules}", null) - { - InitializeComponents(); - } - - void InitializeComponents() + + protected override void InitializeComponents() { - debugger = (WindowsDebugger)DebuggerService.CurrentDebugger; - loadedModulesList = new ListView(); loadedModulesList.FullRowSelect = true; loadedModulesList.AutoArrange = true; @@ -70,24 +60,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads information.Width = 130; RedrawContent(); - - if (debugger.ServiceInitialized) { - InitializeDebugger(); - } else { - debugger.Initialize += delegate { - InitializeDebugger(); - }; - } - } - - public void InitializeDebugger() - { - debuggerCore = debugger.DebuggerCore; - - debuggerCore.ModuleLoaded += new EventHandler(AddModule); - debuggerCore.ModuleUnloaded += new EventHandler(RemoveModule); - - RefreshList(); } public override void RedrawContent() @@ -101,8 +73,15 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads timestamp.Text = StringParser.Parse("${res:MainWindow.Windows.Debug.TimestampColumn}"); information.Text = StringParser.Parse("${res:MainWindow.Windows.Debug.InformationColumn}"); } + + + protected override void RegisterDebuggerEvents() + { + debuggerCore.ModuleLoaded += AddModule; + debuggerCore.ModuleUnloaded += RemoveModule; + } - void RefreshList() + public override void RefreshPad() { loadedModulesList.Items.Clear(); foreach(Module m in debuggerCore.Modules) { diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LocalVarPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LocalVarPad.cs index d052ca1a83..8e709e4851 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LocalVarPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LocalVarPad.cs @@ -20,11 +20,8 @@ using System.Collections.Generic; namespace ICSharpCode.SharpDevelop.Gui.Pads { - public class LocalVarPad : AbstractPadContent + public class LocalVarPad : DebuggerPad { - WindowsDebugger debugger; - NDebugger debuggerCore; - TreeListView localVarList; ColumnHeader name = new ColumnHeader(); @@ -37,15 +34,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads } } - public LocalVarPad() //: base("${res:MainWindow.Windows.Debug.Local}", null) - { - InitializeComponents(); - } - - void InitializeComponents() + protected override void InitializeComponents() { - debugger = (WindowsDebugger)DebuggerService.CurrentDebugger; - //iconsService = (ClassBrowserIconsService)ServiceManager.Services.GetService(typeof(ClassBrowserIconsService)); localVarList = new TreeListView(); localVarList.SmallImageList = DebuggerIcons.ImageList; @@ -65,14 +55,13 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads RedrawContent(); - - if (debugger.ServiceInitialized) { - InitializeDebugger(); - } else { - debugger.Initialize += delegate { - InitializeDebugger(); - }; - } + } + + public override void RedrawContent() + { + name.Text = ResourceService.GetString("Global.Name"); + val.Text = ResourceService.GetString("Dialog.HighlightingEditor.Properties.Value"); + type.Text = ResourceService.GetString("ResourceEditor.ResourceEdit.TypeColumn"); } // This is a walkarond for a visual issue @@ -81,13 +70,16 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads localVarList.Visible = true; } - public void InitializeDebugger() + + protected override void RegisterDebuggerEvents() { - debuggerCore = debugger.DebuggerCore; - debuggerCore.DebuggeeStateChanged += delegate { debuggerCore.LocalVariables.Update(); }; - + } + + public override void RefreshPad() + { localVarList.BeginUpdate(); + localVarList.Items.Clear(); AddVariableCollectionToTree(debuggerCore.LocalVariables, localVarList.Items); localVarList.EndUpdate(); } @@ -109,13 +101,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads tree.Add(newItem); } - - public override void RedrawContent() - { - name.Text = ResourceService.GetString("Global.Name"); - val.Text = ResourceService.GetString("Dialog.HighlightingEditor.Properties.Value"); - type.Text = ResourceService.GetString("ResourceEditor.ResourceEdit.TypeColumn"); - } private void localVarList_BeforeExpand(object sender, TreeListViewCancelEventArgs e) { diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.Menu.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.Menu.cs new file mode 100644 index 0000000000..2ff067a778 --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.Menu.cs @@ -0,0 +1,76 @@ +// +// +// +// +// $Revision: 1253 $ +// + +using System; +using System.Windows.Forms; +using System.Drawing; +using System.CodeDom.Compiler; +using System.Collections; +using System.ComponentModel; +using System.IO; +using System.Diagnostics; +using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Services; + +using Debugger; + +namespace ICSharpCode.SharpDevelop.Gui.Pads +{ + public partial class RunningThreadsPad + { + ContextMenuStrip CreateContextMenuStrip() + { + ContextMenuStrip menu = new ContextMenuStrip(); + menu.Opening += FillContextMenuStrip; + return menu; + } + + void FillContextMenuStrip(object sender, CancelEventArgs e) + { + ListView.SelectedListViewItemCollection items = runningThreadsList.SelectedItems; + + if (items.Count == 0) { + e.Cancel = true; + return; + } + + ListViewItem item = items[0]; + + ContextMenuStrip menu = sender as ContextMenuStrip; + menu.Items.Clear(); + + ToolStripMenuItem freezeItem; + freezeItem = new ToolStripMenuItem(); + freezeItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.Threads.Freeze"); + freezeItem.Checked = (item.Tag as Thread).Suspended; + freezeItem.Click += + delegate { + ListView.SelectedListViewItemCollection selItems = runningThreadsList.SelectedItems; + if (selItems.Count == 0) { + return; + } + bool suspended = (selItems[0].Tag as Thread).Suspended; + + if (!debuggerCore.IsPaused) { + MessageBox.Show("You can not freeze or thaw thread while the debugger is running.", "Thread freeze"); + return; + } + + foreach(ListViewItem i in selItems) { + (i.Tag as Thread).Suspended = !suspended; + } + RefreshPad(); + }; + + menu.Items.AddRange(new ToolStripItem[] { + freezeItem, + }); + + e.Cancel = false; + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs index 9c1444b460..25512651a5 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs @@ -20,11 +20,8 @@ using Debugger; namespace ICSharpCode.SharpDevelop.Gui.Pads { - public class RunningThreadsPad : AbstractPadContent + public partial class RunningThreadsPad : DebuggerPad { - WindowsDebugger debugger; - NDebugger debuggerCore; - ListView runningThreadsList; ColumnHeader id = new ColumnHeader(); @@ -38,16 +35,9 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads return runningThreadsList; } } - - public RunningThreadsPad() //: base("${res:MainWindow.Windows.Debug.Threads}", null) - { - InitializeComponents(); - } - - void InitializeComponents() - { - debugger = (WindowsDebugger)DebuggerService.CurrentDebugger; + protected override void InitializeComponents() + { runningThreadsList = new ListView(); runningThreadsList.FullRowSelect = true; runningThreadsList.AutoArrange = true; @@ -66,26 +56,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads breaked.Width = 80; RedrawContent(); - - if (debugger.ServiceInitialized) { - InitializeDebugger(); - } else { - debugger.Initialize += delegate { - InitializeDebugger(); - }; - } - } - - public void InitializeDebugger() - { - debuggerCore = debugger.DebuggerCore; - - debuggerCore.DebuggeeStateChanged += DebuggeeStateChanged; - debuggerCore.ThreadStarted += ThreadStarted; - debuggerCore.ThreadStateChanged += ThreadStateChanged; - debuggerCore.ThreadExited += ThreadExited; - - RefreshList(); } public override void RedrawContent() @@ -97,58 +67,22 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads breaked.Text = ResourceService.GetString("MainWindow.Windows.Debug.Threads.Frozen"); } - ContextMenuStrip CreateContextMenuStrip() - { - ContextMenuStrip menu = new ContextMenuStrip(); - menu.Opening += FillContextMenuStrip; - return menu; - } - - void FillContextMenuStrip(object sender, CancelEventArgs e) + + protected override void RegisterDebuggerEvents() { - ListView.SelectedListViewItemCollection items = runningThreadsList.SelectedItems; - - if (items.Count == 0) { - e.Cancel = true; - return; - } - - ListViewItem item = items[0]; - - ContextMenuStrip menu = sender as ContextMenuStrip; - menu.Items.Clear(); - - ToolStripMenuItem freezeItem; - freezeItem = new ToolStripMenuItem(); - freezeItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.Threads.Freeze"); - freezeItem.Checked = (item.Tag as Thread).Suspended; - freezeItem.Click += - delegate { - ListView.SelectedListViewItemCollection selItems = runningThreadsList.SelectedItems; - if (selItems.Count == 0) { - return; - } - bool suspended = (selItems[0].Tag as Thread).Suspended; - - if (!debuggerCore.IsPaused) { - MessageBox.Show("You can not freeze or thaw thread while the debugger is running.", "Thread freeze"); - return; - } - - foreach(ListViewItem i in selItems) { - (i.Tag as Thread).Suspended = !suspended; - } - RefreshList(); + debuggerCore.DebuggeeStateChanged += delegate { RefreshPad(); }; + debuggerCore.ThreadStarted += delegate(object sender, ThreadEventArgs e) { + AddThread(e.Thread); + }; + debuggerCore.ThreadStateChanged += delegate(object sender, ThreadEventArgs e) { + RefreshThread(e.Thread); + }; + debuggerCore.ThreadExited += delegate(object sender, ThreadEventArgs e) { + RemoveThread(e.Thread); }; - - menu.Items.AddRange(new ToolStripItem[] { - freezeItem, - }); - - e.Cancel = false; } - void RefreshList() + public override void RefreshPad() { foreach (Thread t in debuggerCore.Threads) { RefreshThread(t); @@ -164,28 +98,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads } else { MessageBox.Show("You can not switch threads while the debugger is running.", "Thread switch"); } - } - - void DebuggeeStateChanged(object sender, DebuggerEventArgs e) - { - RefreshList(); - } - - void ThreadStarted(object sender, ThreadEventArgs e) - { - AddThread(e.Thread); - } - - void ThreadStateChanged(object sender, ThreadEventArgs e) - { - RefreshThread(e.Thread); - } - - void ThreadExited(object sender, ThreadEventArgs e) - { - RemoveThread(e.Thread); - } - + } void AddThread(Thread thread) { From 48adfe8ff3ca8d7c3a2264f1bc77b0f334d9af78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Sun, 2 Apr 2006 22:42:20 +0000 Subject: [PATCH 03/44] Fixed callstack browsing; Moved some exception history code git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1255 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/Pads/CallStackPad.cs | 1 + .../Project/Src/Pads/ExceptionHistoryPad.cs | 27 ++++---- .../Project/Src/Pads/RunningThreadsPad.cs | 1 + .../Project/Src/Service/WindowsDebugger.cs | 69 ++++--------------- .../Src/Debugger/NDebugger-StateControl.cs | 18 ++--- 5 files changed, 38 insertions(+), 78 deletions(-) diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs index 082822c851..e4f2583788 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs @@ -72,6 +72,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads if (f.HasSymbols) { if (debuggerCore.SelectedThread != null) { debuggerCore.SelectedThread.SelectedFunction = f; + debuggerCore.OnDebuggeeStateChanged(); // Force refresh of pads } } else { MessageBox.Show("You can not switch to function without symbols", "Function switch"); diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/ExceptionHistoryPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/ExceptionHistoryPad.cs index 2ac8227057..e245e4212d 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/ExceptionHistoryPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/ExceptionHistoryPad.cs @@ -10,6 +10,7 @@ using System.Windows.Forms; using System.Drawing; using System.CodeDom.Compiler; using System.Collections; +using System.Collections.Generic; using System.IO; using System.Diagnostics; using ICSharpCode.Core; @@ -23,6 +24,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads { ListView exceptionHistoryList; + List exceptions = new List(); + ColumnHeader time = new ColumnHeader(); ColumnHeader exception = new ColumnHeader(); ColumnHeader location = new ColumnHeader(); @@ -62,7 +65,16 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads protected override void RegisterDebuggerEvents() { - debugger.ExceptionHistoryModified += delegate { RefreshPad(); }; + debuggerCore.ProcessExited += delegate { + exceptions.Clear(); + RefreshPad(); + }; + debuggerCore.DebuggingPaused += delegate (object sender, DebuggingPausedEventArgs e) { + if (e.Reason == PausedReason.Exception) { + exceptions.Add(debuggerCore.SelectedThread.CurrentException); + RefreshPad(); + } + }; } void ExceptionHistoryListItemActivate(object sender, EventArgs e) @@ -81,17 +93,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads if (content is IPositionable) { ((IPositionable)content).JumpTo((int)nextStatement.StartLine - 1, (int)nextStatement.StartColumn - 1); } - - /*if (content.Control is TextEditorControl) { - IDocument document = ((TextEditorControl)content.Control).Document; - LineSegment line = document.GetLineSegment((int)nextStatement.StartLine - 1); - int offset = line.Offset + (int)nextStatement.StartColumn; - currentLineMarker = new TextMarker(offset, (int)nextStatement.EndColumn - (int)nextStatement.StartColumn, TextMarkerType.SolidBlock, Color.Yellow); - currentLineMarkerParent = document; - currentLineMarkerParent.MarkerStrategy.TextMarker.Add(currentLineMarker); - document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea)); - document.CommitUpdate(); - }*/ } } @@ -100,7 +101,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads exceptionHistoryList.BeginUpdate(); exceptionHistoryList.Items.Clear(); - foreach(Debugger.Exception exception in debugger.ExceptionHistory) { + foreach(Debugger.Exception exception in exceptions) { string location; if (exception.Location != null) { location = exception.Location.SourceFilename + ":" + exception.Location.StartLine; diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs index 25512651a5..0c81bb734a 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs @@ -94,6 +94,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads if (debuggerCore.IsPaused) { if (debuggerCore.SelectedProcess != null) { debuggerCore.SelectedProcess.SelectedThread = (Thread)(runningThreadsList.SelectedItems[0].Tag); + debuggerCore.OnDebuggeeStateChanged(); // Force refresh of pads } } else { MessageBox.Show("You can not switch threads while the debugger is running.", "Thread switch"); diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs index 257e2d7744..f5056e6f1b 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs @@ -39,21 +39,8 @@ namespace ICSharpCode.SharpDevelop.Services Properties properties; - bool isDebuggingCache = false; - bool isProcessRunningCache = false; bool serviceInitialized = false; - - List exceptionHistory = new List(); - - public event EventHandler ExceptionHistoryModified; - - protected virtual void OnExceptionHistoryModified() - { - if (ExceptionHistoryModified != null) { - ExceptionHistoryModified(this, EventArgs.Empty); - } - } - + public NDebugger DebuggerCore { get { return debugger; @@ -71,12 +58,6 @@ namespace ICSharpCode.SharpDevelop.Services return serviceInitialized; } } - - public IList ExceptionHistory { - get { - return exceptionHistory.AsReadOnly(); - } - } public WindowsDebugger() { @@ -87,13 +68,13 @@ namespace ICSharpCode.SharpDevelop.Services public bool IsDebugging { get { - return isDebuggingCache; + return serviceInitialized && (debugger.Processes.Count > 0); } } public bool IsProcessRunning { get { - return isProcessRunningCache; + return IsDebugging && debugger.IsRunning; } } @@ -164,15 +145,7 @@ namespace ICSharpCode.SharpDevelop.Services } public event EventHandler DebugStarted; - - protected virtual void OnDebugStarted(EventArgs e) - { - if (DebugStarted != null) { - DebugStarted(this, e); - } - } - - + public event EventHandler DebugStopped; public event EventHandler IsProcessRunningChanged; protected virtual void OnIsProcessRunningChanged(EventArgs e) @@ -181,16 +154,6 @@ namespace ICSharpCode.SharpDevelop.Services IsProcessRunningChanged(this, e); } } - - - public event EventHandler DebugStopped; - - protected virtual void OnDebugStopped(EventArgs e) - { - if (DebugStopped != null) { - DebugStopped(this, e); - } - } /// /// Gets variable of given name. @@ -296,9 +259,6 @@ namespace ICSharpCode.SharpDevelop.Services foreach (BreakpointBookmark b in DebuggerService.Breakpoints) { AddBreakpoint(b); } - - isDebuggingCache = false; - isProcessRunningCache = true; if (Initialize != null) { Initialize(this, null); @@ -346,30 +306,26 @@ namespace ICSharpCode.SharpDevelop.Services void ProcessStarted(object sender, ProcessEventArgs e) { if (debugger.Processes.Count == 1) { - OnDebugStarted(EventArgs.Empty); - isDebuggingCache = true; - isProcessRunningCache = true; + if (DebugStarted != null) { + DebugStarted(this, EventArgs.Empty); + } } } void ProcessExited(object sender, ProcessEventArgs e) { if (debugger.Processes.Count == 0) { - exceptionHistory.Clear(); - OnDebugStopped(EventArgs.Empty); - isDebuggingCache = false; - isProcessRunningCache = false; + if (DebugStopped != null) { + DebugStopped(this, e); + } } } void DebuggingPaused(object sender, DebuggingPausedEventArgs e) { - isProcessRunningCache = false; OnIsProcessRunningChanged(EventArgs.Empty); if (e.Reason == PausedReason.Exception) { - exceptionHistory.Add(debugger.SelectedThread.CurrentException); - OnExceptionHistoryModified(); if (debugger.SelectedThread.CurrentException.ExceptionType != ExceptionType.DEBUG_EXCEPTION_UNHANDLED) { // Ignore the exception e.ResumeDebuggingAfterEvent(); @@ -398,7 +354,6 @@ namespace ICSharpCode.SharpDevelop.Services void DebuggingResumed(object sender, DebuggerEventArgs e) { - isProcessRunningCache = true; if (!debugger.Evaluating) { DebuggerService.RemoveCurrentLineMarker(); } @@ -410,9 +365,9 @@ namespace ICSharpCode.SharpDevelop.Services SourcecodeSegment nextStatement = debugger.NextStatement; if (nextStatement == null) { DebuggerService.RemoveCurrentLineMarker(); - return; + } else { + DebuggerService.JumpToCurrentLine(nextStatement.SourceFullFilename, nextStatement.StartLine, nextStatement.StartColumn, nextStatement.EndLine, nextStatement.EndColumn); } - DebuggerService.JumpToCurrentLine(nextStatement.SourceFullFilename, nextStatement.StartLine, nextStatement.StartColumn, nextStatement.EndLine, nextStatement.EndColumn); } } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs index 0028c4f671..a8e2d64959 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs @@ -59,7 +59,8 @@ namespace Debugger } } - protected virtual void OnDebuggeeStateChanged() + // HACK: should not be public + public virtual void OnDebuggeeStateChanged() { TraceMessage ("Debugger event: OnDebuggeeStateChanged (" + PausedReason.ToString() + ")"); if (DebuggeeStateChanged != null) { @@ -115,6 +116,10 @@ namespace Debugger get { return debugeeState; } + private set { + debugeeState = value; + OnDebuggeeStateChanged(); + } } public void AssertPaused() @@ -156,17 +161,14 @@ namespace Debugger internal void Pause() { + if (PausedReason != PausedReason.EvalComplete) { + DebugeeState = new DebugeeState(); + } + OnDebuggingPaused(); // Debugger state is unknown after calling OnDebuggingPaused (it may be resumed) - if (IsPaused) { - if (PausedReason != PausedReason.EvalComplete) { - debugeeState = new DebugeeState(); - OnDebuggeeStateChanged(); - } - } - if (IsPaused) { pausedHandle.Set(); } From e232f55c7c17c5ac1431e825c24ab6e54e41c6ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Mon, 3 Apr 2006 13:53:57 +0000 Subject: [PATCH 04/44] Minnor bugfixes git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1257 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/Debugger/Internal/ManagedCallback.cs | 3 ++- .../Project/Src/Debugger/NDebugger-StateControl.cs | 6 ++---- .../Debugger/Debugger.Core/Project/Src/Threads/Process.cs | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs index df6a2639c3..cd6ac8d86c 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs @@ -37,7 +37,8 @@ namespace Debugger void EnterCallback(PausedReason pausedReason, string name, ICorDebugProcess pProcess) { debugger.TraceMessage("Callback: " + name); - debugger.AssertRunning(); + // ExitProcess may be called at any time when debuggee is killed + if (name != "ExitProcess") debugger.AssertRunning(); debugger.PauseSession = new PauseSession(pausedReason); debugger.SelectedProcess = debugger.GetProcess(pProcess); debugger.SelectedProcess.IsRunning = false; diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs index a8e2d64959..47477bbed9 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs @@ -179,12 +179,10 @@ namespace Debugger if (IsRunning) { throw new DebuggerException("Already resumed"); } - + + pauseSession = null; OnDebuggingResumed(); - pausedHandle.Reset(); - - pauseSession = null; } /// diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs index 8e48553c53..6dd1633642 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs @@ -133,7 +133,7 @@ namespace Debugger { // Resume stoped tread if (corProcess.IsRunning == 0) { - Continue(); // TODO: Remove this... + corProcess.Continue(0); // TODO: Remove this... } // Stop&terminate - both must be called corProcess.Stop(5000); // TODO: ...and this From 98e7ddff447abca264aa614af52b159f9eda2822 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Mon, 3 Apr 2006 14:24:39 +0000 Subject: [PATCH 05/44] Comment positions inside enum are preserved (forum-6415). git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1259 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Src/Output/CSharp/CSharpOutputVisitor.cs | 17 ++++---- .../Src/Output/VBNet/VBNetOutputVisitor.cs | 2 + .../Test/Output/SpecialOutputVisitor.cs | 42 +++++++++++++++++++ 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs b/src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs index 1a394ff7e0..417edef8dc 100644 --- a/src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs @@ -320,14 +320,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter void OutputEnumMembers(TypeDeclaration typeDeclaration, object data) { - bool first = true; - foreach (FieldDeclaration fieldDeclaration in typeDeclaration.Children) { - if (first) { - first = false; - } else { - outputFormatter.PrintToken(Tokens.Comma); - outputFormatter.NewLine(); - } + for (int i = 0; i < typeDeclaration.Children.Count; i++) { + FieldDeclaration fieldDeclaration = (FieldDeclaration)typeDeclaration.Children[i]; + nodeTracker.BeginNode(fieldDeclaration); VariableDeclaration f = (VariableDeclaration)fieldDeclaration.Fields[0]; VisitAttributes(fieldDeclaration.Attributes, data); outputFormatter.Indent(); @@ -338,8 +333,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); nodeTracker.TrackedVisit(f.Initializer, data); } + if (i < typeDeclaration.Children.Count - 1) { + outputFormatter.PrintToken(Tokens.Comma); + } + outputFormatter.NewLine(); + nodeTracker.EndNode(fieldDeclaration); } - outputFormatter.NewLine(); } TypeDeclaration currentType = null; diff --git a/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs b/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs index 52c8a2313d..63c415ce85 100644 --- a/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs @@ -374,6 +374,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter void OutputEnumMembers(TypeDeclaration typeDeclaration, object data) { foreach (FieldDeclaration fieldDeclaration in typeDeclaration.Children) { + nodeTracker.BeginNode(fieldDeclaration); VariableDeclaration f = (VariableDeclaration)fieldDeclaration.Fields[0]; VisitAttributes(fieldDeclaration.Attributes, data); outputFormatter.Indent(); @@ -385,6 +386,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter nodeTracker.TrackedVisit(f.Initializer, data); } outputFormatter.NewLine(); + nodeTracker.EndNode(fieldDeclaration); } } diff --git a/src/Libraries/NRefactory/Test/Output/SpecialOutputVisitor.cs b/src/Libraries/NRefactory/Test/Output/SpecialOutputVisitor.cs index 8aee4dbd56..bad08317d5 100644 --- a/src/Libraries/NRefactory/Test/Output/SpecialOutputVisitor.cs +++ b/src/Libraries/NRefactory/Test/Output/SpecialOutputVisitor.cs @@ -32,6 +32,21 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter parser.Dispose(); } + void TestProgramVB(string program) + { + IParser parser = ParserFactory.CreateParser(SupportedLanguage.VBNet, new StringReader(program)); + parser.Parse(); + Assert.AreEqual("", parser.Errors.ErrorOutput); + VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor(); + using (SpecialNodesInserter.Install(parser.Lexer.SpecialTracker.RetrieveSpecials(), + outputVisitor)) { + outputVisitor.Visit(parser.CompilationUnit, null); + } + Assert.AreEqual("", outputVisitor.Errors.ErrorOutput); + Assert.AreEqual(program, outputVisitor.Text.TrimEnd().Replace("\r", "")); + parser.Dispose(); + } + [Test] public void SimpleComments() { @@ -63,5 +78,32 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter "}\n" + "#end if"); } + + [Test] + public void Enum() + { + TestProgram("enum Test\n" + + "{\n" + + "\t// a\n" + + "\tm1,\n" + + "\t// b\n" + + "\tm2\n" + + "\t// c\n" + + "}\n" + + "// d"); + } + + [Test] + public void EnumVB() + { + TestProgramVB("Enum Test\n" + + "\t' a\n" + + "\tm1\n" + + "\t' b\n" + + "\tm2\n" + + "\t' c\n" + + "End Enum\n" + + "' d"); + } } } From f93aa9c02dc19de509e308267135b86dd3e46ad9 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Mon, 3 Apr 2006 16:22:49 +0000 Subject: [PATCH 06/44] SD2-567. Implemented search and replace inside the current text selection. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1261 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/ICSharpCode.SharpDevelop.csproj | 1 + .../Commands/SearchMainMenuCommands.cs | 24 +- .../SearchAndReplace/Engine/Search.cs | 32 +++ .../Engine/SearchReplaceInFilesManager.cs | 48 ++++ .../Engine/SearchReplaceManager.cs | 96 ++++++- .../Engine/SearchReplaceUtilities.cs | 22 ++ .../BruteForceSearchStrategy.cs | 27 ++ .../Engine/SearchStrategy/ISearchStrategy.cs | 5 + .../SearchStrategy/RegExSearchStrategy.cs | 25 ++ .../SearchStrategy/WildcardSearchStrategy.cs | 27 ++ .../SearchAndReplace/Engine/TextSelection.cs | 49 ++++ .../Gui/SearchAndReplaceDialog.cs | 9 +- .../Gui/SearchAndReplacePanel.cs | 262 +++++++++++++++++- 13 files changed, 600 insertions(+), 27 deletions(-) create mode 100644 src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/TextSelection.cs diff --git a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj index 19e60f5894..aeeeeafdcc 100644 --- a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj +++ b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj @@ -752,6 +752,7 @@ + diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Commands/SearchMainMenuCommands.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Commands/SearchMainMenuCommands.cs index 5511552e58..60ebb429d5 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Commands/SearchMainMenuCommands.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Commands/SearchMainMenuCommands.cs @@ -32,14 +32,10 @@ namespace SearchAndReplace public static void SetSearchPattern() { // Get Highlighted value and set it to FindDialog.searchPattern - IWorkbenchWindow window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow; - - if (window != null && (window.ViewContent is ITextEditorControlProvider)) { - TextEditorControl textarea = ((ITextEditorControlProvider)window.ViewContent).TextEditorControl; - string selectedText = textarea.ActiveTextAreaControl.TextArea.SelectionManager.SelectedText; - if (selectedText != null && selectedText.Length > 0) { - SearchOptions.CurrentFindPattern = selectedText; - } + TextEditorControl textArea = SearchReplaceUtilities.GetActiveTextEditor(); + string selectedText = textArea.ActiveTextAreaControl.TextArea.SelectionManager.SelectedText; + if (selectedText != null && selectedText.Length > 0 && !IsMultipleLines(selectedText)) { + SearchOptions.CurrentFindPattern = selectedText; } } @@ -48,13 +44,23 @@ namespace SearchAndReplace SetSearchPattern(); SearchAndReplaceDialog.ShowSingleInstance(SearchAndReplaceMode.Search); } + + static bool IsMultipleLines(string text) + { + return text.IndexOf('\n') != -1; + } } public class FindNext : AbstractMenuCommand { public override void Run() { - SearchReplaceManager.FindNext(); + if (SearchOptions.CurrentFindPattern.Length > 0) { + SearchReplaceManager.FindNext(); + } else { + Find find = new Find(); + find.Run(); + } } } diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/Search.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/Search.cs index 7ad01b5a94..2505d82edb 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/Search.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/Search.cs @@ -119,5 +119,37 @@ namespace SearchAndReplace } return null; } + + public SearchResult FindNext(int offset, int length) + { + if (info != null && textIterator != null && documentIterator.CurrentFileName != null) { + if (info.FileName != documentIterator.CurrentFileName) { // create new iterator, if document changed + info = documentIterator.Current; + textIterator = textIteratorBuilder.BuildTextIterator(info); + } else { // old document -> initialize iterator position to caret pos + textIterator.Position = info.CurrentOffset; + } + + SearchResult result = CreateNamedSearchResult(searchStrategy.FindNext(textIterator, offset, length)); + if (result != null) { + info.CurrentOffset = textIterator.Position; + return result; + } + } + + // not found or first start -> move forward to the next document + if (documentIterator.MoveForward()) { + info = documentIterator.Current; + // document is valid for searching -> set iterator & fileName + if (info != null && info.TextBuffer != null && info.EndOffset >= 0 && info.EndOffset < info.TextBuffer.Length) { + textIterator = textIteratorBuilder.BuildTextIterator(info); + } else { + textIterator = null; + } + + return FindNext(offset, length); + } + return null; + } } } diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceInFilesManager.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceInFilesManager.cs index 6fd4816d9e..02d690e4db 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceInFilesManager.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceInFilesManager.cs @@ -100,6 +100,37 @@ namespace SearchAndReplace FinishSearchInFiles(results); } + public static void ReplaceAll(int offset, int length) + { + if (!InitializeSearchInFiles()) { + return; + } + + List results = new List(); + + while (true) { + SearchResult result = find.FindNext(offset, length); + if (result == null) { + break; + } + + string replacement = result.TransformReplacePattern(SearchOptions.ReplacePattern); + find.Replace(result.Offset, + result.Length, + replacement); + length -= result.Length - replacement.Length; + + // HACK - Move the cursor to the correct offset - the caret gets + // moved before the replace range if we replace a string with a + // single character. The ProvidedDocInfo.Replace method assumes that + // the current offset is at the end of the found text which it is not. + find.CurrentDocumentInformation.CurrentOffset = result.Offset + replacement.Length - 1; + results.Add(result); + } + + FinishSearchInFiles(results); + } + public static void FindAll() { if (!InitializeSearchInFiles()) { @@ -116,6 +147,23 @@ namespace SearchAndReplace } FinishSearchInFiles(results); } + + public static void FindAll(int offset, int length) + { + if (!InitializeSearchInFiles()) { + return; + } + + List results = new List(); + while (true) { + SearchResult result = find.FindNext(offset, length); + if (result == null) { + break; + } + results.Add(result); + } + FinishSearchInFiles(results); + } static void OnSearchAllFinished(SearchAllFinishedEventArgs e) { diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs index 9a084d4aab..7ebcd66562 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs @@ -63,6 +63,42 @@ namespace SearchAndReplace FindNext(); } + static TextSelection textSelection; + + public static void ReplaceFirstInSelection(int offset, int length) + { + SetSearchOptions(); + FindFirstInSelection(offset, length); + } + + public static bool ReplaceNextInSelection() + { + if (lastResult != null && WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) { + ITextEditorControlProvider provider = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent as ITextEditorControlProvider; + if (provider != null) { + TextEditorControl textarea = provider.TextEditorControl; + SelectionManager selectionManager = textarea.ActiveTextAreaControl.TextArea.SelectionManager; + + if (selectionManager.SelectionCollection.Count == 1 + && selectionManager.SelectionCollection[0].Offset == lastResult.Offset + && selectionManager.SelectionCollection[0].Length == lastResult.Length + && lastResult.FileName == textarea.FileName) + { + string replacePattern = lastResult.TransformReplacePattern(SearchOptions.ReplacePattern); + + textarea.BeginUpdate(); + selectionManager.ClearSelection(); + textarea.Document.Replace(lastResult.Offset, lastResult.Length, replacePattern); + textarea.ActiveTextAreaControl.Caret.Position = textarea.Document.OffsetToPosition(lastResult.Offset + replacePattern.Length); + textarea.EndUpdate(); + + textSelection.Length -= lastResult.Length - replacePattern.Length; + } + } + } + return FindNextInSelection(); + } + public static void MarkAll() { SetSearchOptions(); @@ -185,15 +221,65 @@ namespace SearchAndReplace int startPos = Math.Min(textArea.Document.TextLength, Math.Max(0, result.Offset)); int endPos = Math.Min(textArea.Document.TextLength, startPos + result.Length); - textArea.ActiveTextAreaControl.Caret.Position = textArea.Document.OffsetToPosition(endPos); - textArea.ActiveTextAreaControl.TextArea.SelectionManager.ClearSelection(); - textArea.ActiveTextAreaControl.TextArea.SelectionManager.SetSelection(new DefaultSelection(textArea.Document, textArea.Document.OffsetToPosition(startPos), - textArea.Document.OffsetToPosition(endPos))); - textArea.Refresh(); + SearchReplaceUtilities.SelectText(textArea, startPos, endPos); + lastResult = result; + } + } + } + } + + static bool foundAtLeastOneItem = false; + + public static void FindFirstInSelection(int offset, int length) + { + foundAtLeastOneItem = false; + textSelection = null; + SetSearchOptions(); + + if (find == null || + SearchOptions.FindPattern == null || + SearchOptions.FindPattern.Length == 0) { + return; + } + + if (!find.SearchStrategy.CompilePattern()) { + find.Reset(); + lastResult = null; + return; + } + + textSelection = new TextSelection(offset, length); + FindNextInSelection(); + } + + public static bool FindNextInSelection() + { + TextEditorControl textArea = null; + while (textArea == null) { + SearchResult result = find.FindNext(textSelection.Offset, textSelection.Length); + if (result == null) { + if (!foundAtLeastOneItem) { + ShowNotFoundMessage(); + } + find.Reset(); + lastResult = null; + foundAtLeastOneItem = false; + return false; + } else { + textArea = OpenTextArea(result.FileName); + if (textArea != null) { + foundAtLeastOneItem = true; + if (lastResult != null && lastResult.FileName == result.FileName && + textArea.ActiveTextAreaControl.Caret.Offset != lastResult.Offset + lastResult.Length) { + } + int startPos = Math.Min(textArea.Document.TextLength, Math.Max(0, result.Offset)); + int endPos = Math.Min(textArea.Document.TextLength, startPos + result.Length); + SearchReplaceUtilities.SelectText(textArea, startPos, endPos); lastResult = result; } } } + return true; } static void ShowNotFoundMessage() diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceUtilities.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceUtilities.cs index 446f784d73..9225144ce2 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceUtilities.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceUtilities.cs @@ -26,6 +26,15 @@ namespace SearchAndReplace } } + public static TextEditorControl GetActiveTextEditor() + { + IWorkbenchWindow window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow; + if (window != null && (window.ViewContent is ITextEditorControlProvider)) { + return ((ITextEditorControlProvider)window.ViewContent).TextEditorControl; + } + return null; + } + public static bool IsWholeWordAt(ITextBufferStrategy document, int offset, int length) { return (offset - 1 < 0 || Char.IsWhiteSpace(document.GetCharAt(offset - 1))) && @@ -95,5 +104,18 @@ namespace SearchAndReplace } return true; } + + public static void SelectText(TextEditorControl textArea, int offset, int endOffset) + { + int textLength = textArea.ActiveTextAreaControl.Document.TextLength; + if (textLength < endOffset) { + endOffset = textLength - 1; + } + textArea.ActiveTextAreaControl.Caret.Position = textArea.Document.OffsetToPosition(endOffset); + textArea.ActiveTextAreaControl.TextArea.SelectionManager.ClearSelection(); + textArea.ActiveTextAreaControl.TextArea.SelectionManager.SetSelection(new DefaultSelection(textArea.Document, textArea.Document.OffsetToPosition(offset), + textArea.Document.OffsetToPosition(endOffset))); + textArea.Refresh(); + } } } diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/BruteForceSearchStrategy.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/BruteForceSearchStrategy.cs index e58f079faf..857156e65d 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/BruteForceSearchStrategy.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/BruteForceSearchStrategy.cs @@ -58,6 +58,22 @@ namespace SearchAndReplace return -1; } + int InternalFindNext(ITextIterator textIterator, int offset, int length) + { + while (textIterator.MoveAhead(1) && TextSelection.IsInsideRange(textIterator.Position, offset, length)) { + if (SearchOptions.MatchCase ? MatchCaseSensitive(textIterator.TextBuffer, textIterator.Position, searchPattern) : MatchCaseInsensitive(textIterator.TextBuffer, textIterator.Position, searchPattern)) { + if (!SearchOptions.MatchWholeWord || IsWholeWordAt(textIterator.TextBuffer, textIterator.Position, searchPattern.Length)) { + if (TextSelection.IsInsideRange(textIterator.Position + searchPattern.Length - 1, offset, length)) { + return textIterator.Position; + } else { + return -1; + } + } + } + } + return -1; + } + public bool CompilePattern() { searchPattern = SearchOptions.MatchCase ? SearchOptions.FindPattern : SearchOptions.FindPattern.ToUpper(); @@ -67,6 +83,17 @@ namespace SearchAndReplace public SearchResult FindNext(ITextIterator textIterator) { int offset = InternalFindNext(textIterator); + return GetSearchResult(offset); + } + + public SearchResult FindNext(ITextIterator textIterator, int offset, int length) + { + int foundOffset = InternalFindNext(textIterator, offset, length); + return GetSearchResult(foundOffset); + } + + SearchResult GetSearchResult(int offset) + { return offset >= 0 ? new SearchResult(offset, searchPattern.Length) : null; } } diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/ISearchStrategy.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/ISearchStrategy.cs index 1f84f7bf45..6f2d4e061c 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/ISearchStrategy.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/ISearchStrategy.cs @@ -31,5 +31,10 @@ namespace SearchAndReplace /// compiled pattern in the text using the textIterator and options. /// SearchResult FindNext(ITextIterator textIterator); + + /// + /// Find only in the specified range. + /// + SearchResult FindNext(ITextIterator textIterator, int offset, int length); } } diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/RegExSearchStrategy.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/RegExSearchStrategy.cs index a6d09517b0..657787fce2 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/RegExSearchStrategy.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/RegExSearchStrategy.cs @@ -53,6 +53,31 @@ namespace SearchAndReplace return null; } + public SearchResult FindNext(ITextIterator textIterator, int offset, int length) + { + string document = textIterator.TextBuffer.GetText(0, textIterator.TextBuffer.Length); + + while (textIterator.MoveAhead(1) && TextSelection.IsInsideRange(textIterator.Position, offset, length)) { + Match m = regex.Match(document, textIterator.Position); + if (m == null || m.Index <= 0 || m.Length <= 0) { + + } else { + int delta = m.Index - textIterator.Position; + if (delta <= 0 || textIterator.MoveAhead(delta)) { + if (TextSelection.IsInsideRange(m.Index + m.Length - 1, offset, length)) { + return new RegexSearchResult(m); + } else { + return null; + } + } else { + return null; + } + } + } + + return null; + } + private class RegexSearchResult : SearchResult { Match m; diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/WildcardSearchStrategy.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/WildcardSearchStrategy.cs index 5f606ff318..18d9e383d1 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/WildcardSearchStrategy.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/WildcardSearchStrategy.cs @@ -144,6 +144,22 @@ namespace SearchAndReplace return -1; } + int InternalFindNext(ITextIterator textIterator, int offset, int length) + { + while (textIterator.MoveAhead(1) && TextSelection.IsInsideRange(textIterator.Position, offset, length)) { + if (Match(textIterator.TextBuffer, textIterator.Position, !SearchOptions.MatchCase, 0)) { + if (!SearchOptions.MatchWholeWord || SearchReplaceUtilities.IsWholeWordAt(textIterator.TextBuffer, textIterator.Position, curMatchEndOffset - textIterator.Position)) { + if (TextSelection.IsInsideRange(curMatchEndOffset - 1, offset, length)) { + return textIterator.Position; + } else { + return -1; + } + } + } + } + return -1; + } + public bool CompilePattern() { CompilePattern(SearchOptions.FindPattern, !SearchOptions.MatchCase); @@ -153,6 +169,17 @@ namespace SearchAndReplace public SearchResult FindNext(ITextIterator textIterator) { int offset = InternalFindNext(textIterator); + return GetSearchResult(offset); + } + + public SearchResult FindNext(ITextIterator textIterator, int offset, int length) + { + int foundOffset = InternalFindNext(textIterator, offset, length); + return GetSearchResult(foundOffset); + } + + SearchResult GetSearchResult(int offset) + { return offset >= 0 ? new SearchResult(offset, curMatchEndOffset - offset) : null; } } diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/TextSelection.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/TextSelection.cs new file mode 100644 index 0000000000..9d570f389b --- /dev/null +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/TextSelection.cs @@ -0,0 +1,49 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace SearchAndReplace +{ + public class TextSelection + { + int offset; + int length; + + public TextSelection(int offset, int length) + { + this.offset = offset; + this.length = length; + } + + public int Length { + get { + return length; + } + set { + length = value; + } + } + + public int Offset { + get { + return offset; + } + set { + offset = value; + } + } + + /// + /// Checks whether a position is in a specified range. + /// + public static bool IsInsideRange(int position, int offset, int length) + { + return position >= offset && position < offset + length; + } + } +} diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplaceDialog.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplaceDialog.cs index 374184669d..5d478636dc 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplaceDialog.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplaceDialog.cs @@ -11,6 +11,7 @@ using System.Windows.Forms; using ICSharpCode.Core; using ICSharpCode.SharpDevelop.Gui; +using ICSharpCode.TextEditor.Document; namespace SearchAndReplace { @@ -21,8 +22,8 @@ namespace SearchAndReplace public class SearchAndReplaceDialog : Form { - public static string SearchPattern = ""; - public static string ReplacePattern = ""; + public static string SearchPattern = String.Empty; + public static string ReplacePattern = String.Empty; static SearchAndReplaceDialog Instance; @@ -45,7 +46,7 @@ namespace SearchAndReplace ToolStripButton replaceButton = new ToolStripButton(); SearchAndReplacePanel searchAndReplacePanel; - + public SearchAndReplaceDialog(SearchAndReplaceMode searchAndReplaceMode) { this.Owner = WorkbenchSingleton.MainForm; @@ -96,7 +97,6 @@ namespace SearchAndReplace } } - void SearchButtonClick(object sender, EventArgs e) { if (!searchButton.Checked) { @@ -126,6 +126,5 @@ namespace SearchAndReplace this.ClientSize = new Size(430, 385); } } - } } diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplacePanel.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplacePanel.cs index fb44eb18a9..f157c219a8 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplacePanel.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplacePanel.cs @@ -24,6 +24,10 @@ namespace SearchAndReplace public class SearchAndReplacePanel : BaseSharpDevelopUserControl { SearchAndReplaceMode searchAndReplaceMode; + ISelection selection; + TextEditorControl textEditor; + bool ignoreSelectionChanges; + bool findFirst; public SearchAndReplaceMode SearchAndReplaceMode { get { @@ -36,12 +40,12 @@ namespace SearchAndReplace switch (searchAndReplaceMode) { case SearchAndReplaceMode.Search: SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("Resources.FindPanel.xfrm")); - Get