Browse Source

Move P/Invoke calls to NativeMethods.cs.

Fixed NullReferenceException in BooBinding.VariableLookupVisitor.
Catch exceptions when calling WebBrowser.Navigate.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2505 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
6beeb1734d
  1. 10
      data/templates/project/AddInWritingHelp.txt
  2. 2
      doc/technotes/AddIn Writing Help.url
  3. 6
      src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/VariableLookupVisitor.cs
  4. 1
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  5. 8
      src/Main/Base/Project/Src/Gui/BrowserDisplayBinding/HtmlViewPane.cs
  6. 16
      src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/CompilerMessageView.cs
  7. 82
      src/Main/Base/Project/Src/Gui/Pads/FileScout.cs
  8. 24
      src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs
  9. 7
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/SdiWorkspaceLayout.cs
  10. 45
      src/Main/Base/Project/Src/Util/NativeMethods.cs
  11. 11
      src/Main/Base/Project/Src/Util/ProcessRunner.cs

10
data/templates/project/AddInWritingHelp.txt

@ -2,7 +2,7 @@ You have created a new SharpDevelop AddIn project.
We would like to point out that there are three locations where you can get information on how We would like to point out that there are three locations where you can get information on how
to write SharpDevelop AddIns: to write SharpDevelop AddIns:
- http://wiki.sharpdevelop.net/default.aspx/SharpDevelop.AddInWritingTutorials - http://wiki.sharpdevelop.net/ (section Developer Zone)
- The folder "doc/techtones" in the SharpDevelop source code download - The folder "doc/techtones" in the SharpDevelop source code download
- You can ask questions about AddIn development in the SharpDevelop forum: - You can ask questions about AddIn development in the SharpDevelop forum:
http://community.sharpdevelop.net/forums/ http://community.sharpdevelop.net/forums/
@ -10,14 +10,14 @@ to write SharpDevelop AddIns:
The next steps: The next steps:
- First, you have to add references to the SharpDevelop assemblies. - First, you have to add references to the SharpDevelop assemblies.
An AddIn will work with the SharpDevelop version it was compiled for, or later service releases. An AddIn will work with the SharpDevelop version it was compiled for, or later service releases.
You might want to compile against SharpDevelop 2.1.0.2429 (the first final release of SharpDevelop 2.1) You might want to compile against SharpDevelop 2.1.0.2429 (the first official release of SharpDevelop 2.1)
to ensure your AddIn runs with all 2.1.x versions. to ensure your AddIn runs with all later 2.x versions of SharpDevelop.
- Include a <Manifest> section to your .addin for use with the SharpDevelop AddIn Manager. - Include a <Manifest> section to your .addin for use with the SharpDevelop AddIn Manager.
See SharpDevelop/doc/technotes/AddInManager.rtf for more information. See SharpDevelop/doc/technotes/AddInManager.rtf for more information.
- Once have published your AddIn on the Internet, please add it to the SharpDevelop wiki to let other users know! - Once you have published your AddIn on the Internet, please add it to the SharpDevelop wiki to let other users know!
http://wiki.sharpdevelop.net/default.aspx/SharpDevelop.ThirdPartyAddIns http://wiki.sharpdevelop.net/3rdPartyAddins.ashx
This file serves as a reminder for you on how to find information on SharpDevelop AddIn development, you can This file serves as a reminder for you on how to find information on SharpDevelop AddIn development, you can

2
doc/technotes/AddIn Writing Help.url

@ -0,0 +1,2 @@
[InternetShortcut]
URL=http://wiki.sharpdevelop.net/AddinWritingHelp.ashx

6
src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/VariableLookupVisitor.cs

@ -108,8 +108,10 @@ namespace Grunwald.BooBinding.CodeCompletion
public override void OnExceptionHandler(ExceptionHandler node) public override void OnExceptionHandler(ExceptionHandler node)
{ {
if (node.LexicalInfo.Line <= resolver.CaretLine && GetEndSourceLocation(node).Line >= resolver.CaretLine) { if (node.Declaration != null) {
DeclarationFound(node.Declaration.Name, node.Declaration.Type ?? new SimpleTypeReference("System.Exception"), null, node.Declaration.LexicalInfo); if (node.LexicalInfo.Line <= resolver.CaretLine && GetEndSourceLocation(node).Line >= resolver.CaretLine) {
DeclarationFound(node.Declaration.Name, node.Declaration.Type ?? new SimpleTypeReference("System.Exception"), null, node.Declaration.LexicalInfo);
}
} }
base.OnExceptionHandler(node); base.OnExceptionHandler(node);
} }

1
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -641,6 +641,7 @@
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\DiscoveryNetworkCredential.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\DiscoveryNetworkCredential.cs" />
<Compile Include="Src\Services\ProjectService\ProjectLoader.cs" /> <Compile Include="Src\Services\ProjectService\ProjectLoader.cs" />
<Compile Include="Src\Util\HashSet.cs" /> <Compile Include="Src\Util\HashSet.cs" />
<Compile Include="Src\Util\NativeMethods.cs" />
<Compile Include="Src\Util\ProcessRunnerException.cs" /> <Compile Include="Src\Util\ProcessRunnerException.cs" />
<Compile Include="Src\Util\LineReceivedEventArgs.cs" /> <Compile Include="Src\Util\LineReceivedEventArgs.cs" />
<Compile Include="Src\Util\OutputReader.cs" /> <Compile Include="Src\Util\OutputReader.cs" />

8
src/Main/Base/Project/Src/Gui/BrowserDisplayBinding/HtmlViewPane.cs

@ -232,12 +232,16 @@ namespace ICSharpCode.SharpDevelop.BrowserDisplayBinding
public void Navigate(string url) public void Navigate(string url)
{ {
webBrowser.Navigate(new Uri(url)); Navigate(new Uri(url));
} }
public void Navigate(Uri url) public void Navigate(Uri url)
{ {
webBrowser.Navigate(url); try {
webBrowser.Navigate(url);
} catch (Exception ex) {
LoggingService.Warn("Error navigating to " + url.ToString(), ex);
}
} }
public const string DefaultHomepage = "http://www.icsharpcode.net/"; public const string DefaultHomepage = "http://www.icsharpcode.net/";

16
src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/CompilerMessageView.cs

@ -16,6 +16,7 @@ using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui.OptionPanels; using ICSharpCode.SharpDevelop.Gui.OptionPanels;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.SharpDevelop.Gui namespace ICSharpCode.SharpDevelop.Gui
{ {
/// <summary> /// <summary>
@ -223,26 +224,15 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
} }
const int WM_SETREDRAW = 0x00B;
[System.Security.SuppressUnmanagedCodeSecurityAttribute]
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
void SetUpdate(bool update)
{
SendMessage(textEditorControl.Handle, WM_SETREDRAW, update ? new IntPtr(1) : IntPtr.Zero, IntPtr.Zero);
}
void AppendTextCombined(MessageViewCategory category) void AppendTextCombined(MessageViewCategory category)
{ {
Application.DoEvents(); Application.DoEvents();
Thread.Sleep(50); Thread.Sleep(50);
Application.DoEvents(); Application.DoEvents();
lock (appendCallLock) { lock (appendCallLock) {
SetUpdate(false); NativeMethods.SetWindowRedraw(textEditorControl.Handle, false);
SetText(category, category.Text); SetText(category, category.Text);
SetUpdate(true); NativeMethods.SetWindowRedraw(textEditorControl.Handle, true);
textEditorControl.SelectionStart = textEditorControl.TextLength; textEditorControl.SelectionStart = textEditorControl.TextLength;
if (LoggingService.IsDebugEnabled) { if (LoggingService.IsDebugEnabled) {
LoggingService.Debug("Replaced " + pendingAppendCalls + " appends with one set call"); LoggingService.Debug("Replaced " + pendingAppendCalls + " appends with one set call");

82
src/Main/Base/Project/Src/Gui/Pads/FileScout.cs

@ -19,87 +19,39 @@ using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.SharpDevelop.Gui namespace ICSharpCode.SharpDevelop.Gui
{ {
public enum DriveType {
Unknown = 0,
NoRoot = 1,
Removeable = 2,
Fixed = 3,
Remote = 4,
Cdrom = 5,
Ramdisk = 6
}
public class DriveObject public class DriveObject
{ {
DriveInfo driveInfo;
string text = null; string text = null;
string drive = null;
public string Drive { public string Drive {
get { get {
return drive; return driveInfo.Name;
} }
} }
class NativeMethods {
[DllImport("kernel32.dll", SetLastError=true)]
public static extern int GetVolumeInformation(string volumePath,
StringBuilder volumeNameBuffer,
int volNameBuffSize,
ref int volumeSerNr,
ref int maxComponentLength,
ref int fileSystemFlags,
StringBuilder fileSystemNameBuffer,
int fileSysBuffSize);
[DllImport("kernel32.dll")]
public static extern DriveType GetDriveType(string driveName);
}
public static string VolumeLabel(string volumePath)
{
try {
StringBuilder volumeName = new StringBuilder(128);
int dummyInt = 0;
NativeMethods.GetVolumeInformation(volumePath,
volumeName,
128,
ref dummyInt,
ref dummyInt,
ref dummyInt,
null,
0);
return volumeName.ToString();
} catch (Exception) {
return String.Empty;
}
}
public static DriveType GetDriveType(string driveName)
{
return NativeMethods.GetDriveType(driveName);
}
public static Image GetImageForFile(string fileName) public static Image GetImageForFile(string fileName)
{ {
return IconService.GetBitmap(IconService.GetImageForFile(fileName)); return IconService.GetBitmap(IconService.GetImageForFile(fileName));
} }
public DriveObject(string drive) public DriveObject(DriveInfo driveInfo)
{ {
this.drive = drive; this.driveInfo = driveInfo;
text = drive.Substring(0, 2); text = this.Drive.Substring(0, 2);
switch(GetDriveType(drive)) { switch (driveInfo.DriveType) {
case DriveType.Removeable: case DriveType.Removable:
text += " (${res:MainWindow.Windows.FileScout.DriveType.Removeable})"; text += " (${res:MainWindow.Windows.FileScout.DriveType.Removeable})";
break; break;
case DriveType.Fixed: case DriveType.Fixed:
text += " (${res:MainWindow.Windows.FileScout.DriveType.Fixed})"; text += " (${res:MainWindow.Windows.FileScout.DriveType.Fixed})";
break; break;
case DriveType.Cdrom: case DriveType.CDRom:
text += " (${res:MainWindow.Windows.FileScout.DriveType.CD})"; text += " (${res:MainWindow.Windows.FileScout.DriveType.CD})";
break; break;
case DriveType.Remote: case DriveType.Network:
text += " (${res:MainWindow.Windows.FileScout.DriveType.Remote})"; text += " (${res:MainWindow.Windows.FileScout.DriveType.Remote})";
break; break;
} }
@ -490,27 +442,25 @@ namespace ICSharpCode.SharpDevelop.Gui
computerNode.Tag = "C:\\"; computerNode.Tag = "C:\\";
} }
foreach (string driveName in Environment.GetLogicalDrives()) { foreach (DriveInfo info in DriveInfo.GetDrives()) {
DriveObject drive = new DriveObject(driveName); DriveObject drive = new DriveObject(info);
TreeNode node = new TreeNode(drive.ToString()); TreeNode node = new TreeNode(drive.ToString());
node.Nodes.Add(new TreeNode("")); node.Nodes.Add(new TreeNode(""));
node.Tag = driveName.Substring(0, driveName.Length - 1); node.Tag = drive.Drive.Substring(0, 2);
computerNode.Nodes.Add(node); computerNode.Nodes.Add(node);
switch (info.DriveType) {
case DriveType.Removable:
switch(DriveObject.GetDriveType(driveName)) {
case DriveType.Removeable:
node.ImageIndex = node.SelectedImageIndex = 2; node.ImageIndex = node.SelectedImageIndex = 2;
break; break;
case DriveType.Fixed: case DriveType.Fixed:
node.ImageIndex = node.SelectedImageIndex = 3; node.ImageIndex = node.SelectedImageIndex = 3;
break; break;
case DriveType.Cdrom: case DriveType.CDRom:
node.ImageIndex = node.SelectedImageIndex = 4; node.ImageIndex = node.SelectedImageIndex = 4;
break; break;
case DriveType.Remote: case DriveType.Network:
node.ImageIndex = node.SelectedImageIndex = 5; node.ImageIndex = node.SelectedImageIndex = 5;
break; break;
default: default:

24
src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs

@ -154,17 +154,10 @@ namespace ICSharpCode.SharpDevelop.Gui
public static class SingleInstanceHelper public static class SingleInstanceHelper
{ {
const int WM_USER = 0x400; const int CUSTOM_MESSAGE = NativeMethods.WM_USER + 2;
const int CUSTOM_MESSAGE = WM_USER + 2;
const int RESULT_FILES_HANDLED = 2; const int RESULT_FILES_HANDLED = 2;
const int RESULT_PROJECT_IS_OPEN = 3; const int RESULT_PROJECT_IS_OPEN = 3;
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern IntPtr SetForegroundWindow(IntPtr hWnd);
public static bool OpenFilesInPreviousInstance(string[] fileList) public static bool OpenFilesInPreviousInstance(string[] fileList)
{ {
LoggingService.Info("Trying to pass arguments to previous instance..."); LoggingService.Info("Trying to pass arguments to previous instance...");
@ -181,7 +174,7 @@ namespace ICSharpCode.SharpDevelop.Gui
if (FileUtility.IsEqualFileName(currentFile, p.MainModule.FileName)) { if (FileUtility.IsEqualFileName(currentFile, p.MainModule.FileName)) {
IntPtr hWnd = p.MainWindowHandle; IntPtr hWnd = p.MainWindowHandle;
if (hWnd != IntPtr.Zero) { if (hWnd != IntPtr.Zero) {
long result = SendMessage(hWnd, CUSTOM_MESSAGE, new IntPtr(number), IntPtr.Zero).ToInt64(); long result = NativeMethods.SendMessage(hWnd, CUSTOM_MESSAGE, new IntPtr(number), IntPtr.Zero).ToInt64();
if (result == RESULT_FILES_HANDLED) { if (result == RESULT_FILES_HANDLED) {
return true; return true;
} else if (result == RESULT_PROJECT_IS_OPEN) { } else if (result == RESULT_PROJECT_IS_OPEN) {
@ -191,7 +184,7 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
} }
foreach (IntPtr hWnd in alternatives) { foreach (IntPtr hWnd in alternatives) {
if (SendMessage(hWnd, CUSTOM_MESSAGE, new IntPtr(number), new IntPtr(1)).ToInt64()== RESULT_FILES_HANDLED) { if (NativeMethods.SendMessage(hWnd, CUSTOM_MESSAGE, new IntPtr(number), new IntPtr(1)).ToInt64()== RESULT_FILES_HANDLED) {
return true; return true;
} }
} }
@ -213,7 +206,7 @@ namespace ICSharpCode.SharpDevelop.Gui
} else { } else {
m.Result = new IntPtr(RESULT_FILES_HANDLED); m.Result = new IntPtr(RESULT_FILES_HANDLED);
try { try {
WorkbenchSingleton.SafeThreadAsyncCall(delegate { SetForegroundWindow(WorkbenchSingleton.MainForm.Handle) ; }); WorkbenchSingleton.SafeThreadAsyncCall(delegate { NativeMethods.SetForegroundWindow(WorkbenchSingleton.MainForm.Handle) ; });
foreach (string file in File.ReadAllLines(Path.Combine(Path.GetTempPath(), "sd" + fileNumber + ".tmp"))) { foreach (string file in File.ReadAllLines(Path.Combine(Path.GetTempPath(), "sd" + fileNumber + ".tmp"))) {
WorkbenchSingleton.SafeThreadAsyncCall(delegate(string openFileName) { FileService.OpenFile(openFileName); }, file); WorkbenchSingleton.SafeThreadAsyncCall(delegate(string openFileName) { FileService.OpenFile(openFileName); }, file);
} }
@ -633,14 +626,9 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
} }
const int VK_RMENU = 0xA5; // right alt key public static bool IsAltGRPressed {
[System.Runtime.InteropServices.DllImport("user32.dll", ExactSpelling=true)]
static extern short GetAsyncKeyState(int vKey);
public bool IsAltGRPressed {
get { get {
return GetAsyncKeyState(VK_RMENU) < 0 && (Control.ModifierKeys & Keys.Control) == Keys.Control; return NativeMethods.IsKeyPressed(Keys.RMenu) && (Control.ModifierKeys & Keys.Control) == Keys.Control;
} }
} }

7
src/Main/Base/Project/Src/Gui/Workbench/Layouts/SdiWorkspaceLayout.cs

@ -245,13 +245,10 @@ namespace ICSharpCode.SharpDevelop.Gui
return null; return null;
} }
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool LockWindowUpdate(IntPtr hWnd);
public void LoadConfiguration() public void LoadConfiguration()
{ {
if (dockPanel != null) { if (dockPanel != null) {
LockWindowUpdate(wbForm.Handle); NativeMethods.SetWindowRedraw(wbForm.Handle, false);
try { try {
IViewContent activeView = GetActiveView(); IViewContent activeView = GetActiveView();
dockPanel.ActiveDocumentChanged -= new EventHandler(ActiveMdiChanged); dockPanel.ActiveDocumentChanged -= new EventHandler(ActiveMdiChanged);
@ -267,7 +264,7 @@ namespace ICSharpCode.SharpDevelop.Gui
activeView.WorkbenchWindow.SelectWindow(); activeView.WorkbenchWindow.SelectWindow();
} }
} finally { } finally {
LockWindowUpdate(IntPtr.Zero); NativeMethods.SetWindowRedraw(wbForm.Handle, true);
} }
} }
} }

45
src/Main/Base/Project/Src/Util/NativeMethods.cs

@ -0,0 +1,45 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Security;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace ICSharpCode.SharpDevelop
{
/// <summary>
/// Contains P/Invoke methods for functions in the Windows API.
/// </summary>
static class NativeMethods
{
static readonly IntPtr FALSE = new IntPtr(0);
static readonly IntPtr TRUE = new IntPtr(1);
public const int WM_SETREDRAW = 0x00B;
public const int WM_USER = 0x400;
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
public static extern IntPtr SetForegroundWindow(IntPtr hWnd);
public static void SetWindowRedraw(IntPtr hWnd, bool allowRedraw)
{
SendMessage(hWnd, WM_SETREDRAW, allowRedraw ? TRUE : FALSE, IntPtr.Zero);
}
[DllImport("user32.dll", ExactSpelling=true)]
static extern short GetKeyState(int vKey);
public static bool IsKeyPressed(Keys key)
{
return GetKeyState((int)key) < 0;
}
}
}

11
src/Main/Base/Project/Src/Util/ProcessRunner.cs

@ -222,8 +222,6 @@ namespace ICSharpCode.SharpDevelop.Util
process = null; process = null;
} }
} }
// Control-C does not seem to work.
//GenerateConsoleCtrlEvent((int)ConsoleEvent.ControlC, 0);
} }
/// <summary> /// <summary>
@ -263,14 +261,5 @@ namespace ICSharpCode.SharpDevelop.Util
ErrorLineReceived(this, e); ErrorLineReceived(this, e);
} }
} }
enum ConsoleEvent
{
ControlC = 0,
ControlBreak = 1
};
[DllImport("kernel32.dll", SetLastError=true)]
static extern int GenerateConsoleCtrlEvent(int dwCtrlEvent, int dwProcessGroupId);
} }
} }

Loading…
Cancel
Save