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 18 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. 18
      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. 15
      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. @@ -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
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
- You can ask questions about AddIn development in the SharpDevelop forum:
http://community.sharpdevelop.net/forums/
@ -10,14 +10,14 @@ to write SharpDevelop AddIns: @@ -10,14 +10,14 @@ to write SharpDevelop AddIns:
The next steps:
- 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.
You might want to compile against SharpDevelop 2.1.0.2429 (the first final release of SharpDevelop 2.1)
to ensure your AddIn runs with all 2.1.x versions.
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 later 2.x versions of SharpDevelop.
- Include a <Manifest> section to your .addin for use with the SharpDevelop AddIn Manager.
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!
http://wiki.sharpdevelop.net/default.aspx/SharpDevelop.ThirdPartyAddIns
- 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/3rdPartyAddins.ashx
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 @@ @@ -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 @@ -108,8 +108,10 @@ namespace Grunwald.BooBinding.CodeCompletion
public override void OnExceptionHandler(ExceptionHandler node)
{
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);
if (node.Declaration != null) {
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);
}

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

@ -641,6 +641,7 @@ @@ -641,6 +641,7 @@
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\DiscoveryNetworkCredential.cs" />
<Compile Include="Src\Services\ProjectService\ProjectLoader.cs" />
<Compile Include="Src\Util\HashSet.cs" />
<Compile Include="Src\Util\NativeMethods.cs" />
<Compile Include="Src\Util\ProcessRunnerException.cs" />
<Compile Include="Src\Util\LineReceivedEventArgs.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 @@ -232,12 +232,16 @@ namespace ICSharpCode.SharpDevelop.BrowserDisplayBinding
public void Navigate(string url)
{
webBrowser.Navigate(new Uri(url));
Navigate(new 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/";

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

@ -14,7 +14,8 @@ using System.Windows.Forms; @@ -14,7 +14,8 @@ using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui.OptionPanels;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.SharpDevelop.Gui
{
@ -223,26 +224,15 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -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)
{
Application.DoEvents();
Thread.Sleep(50);
Application.DoEvents();
lock (appendCallLock) {
SetUpdate(false);
NativeMethods.SetWindowRedraw(textEditorControl.Handle, false);
SetText(category, category.Text);
SetUpdate(true);
NativeMethods.SetWindowRedraw(textEditorControl.Handle, true);
textEditorControl.SelectionStart = textEditorControl.TextLength;
if (LoggingService.IsDebugEnabled) {
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; @@ -19,87 +19,39 @@ using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.SharpDevelop.Gui
{
public enum DriveType {
Unknown = 0,
NoRoot = 1,
Removeable = 2,
Fixed = 3,
Remote = 4,
Cdrom = 5,
Ramdisk = 6
}
public class DriveObject
{
DriveInfo driveInfo;
string text = null;
string drive = null;
public string Drive {
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)
{
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)) {
case DriveType.Removeable:
switch (driveInfo.DriveType) {
case DriveType.Removable:
text += " (${res:MainWindow.Windows.FileScout.DriveType.Removeable})";
break;
case DriveType.Fixed:
text += " (${res:MainWindow.Windows.FileScout.DriveType.Fixed})";
break;
case DriveType.Cdrom:
case DriveType.CDRom:
text += " (${res:MainWindow.Windows.FileScout.DriveType.CD})";
break;
case DriveType.Remote:
case DriveType.Network:
text += " (${res:MainWindow.Windows.FileScout.DriveType.Remote})";
break;
}
@ -490,27 +442,25 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -490,27 +442,25 @@ namespace ICSharpCode.SharpDevelop.Gui
computerNode.Tag = "C:\\";
}
foreach (string driveName in Environment.GetLogicalDrives()) {
DriveObject drive = new DriveObject(driveName);
foreach (DriveInfo info in DriveInfo.GetDrives()) {
DriveObject drive = new DriveObject(info);
TreeNode node = new TreeNode(drive.ToString());
node.Nodes.Add(new TreeNode(""));
node.Tag = driveName.Substring(0, driveName.Length - 1);
node.Tag = drive.Drive.Substring(0, 2);
computerNode.Nodes.Add(node);
switch(DriveObject.GetDriveType(driveName)) {
case DriveType.Removeable:
switch (info.DriveType) {
case DriveType.Removable:
node.ImageIndex = node.SelectedImageIndex = 2;
break;
case DriveType.Fixed:
node.ImageIndex = node.SelectedImageIndex = 3;
break;
case DriveType.Cdrom:
case DriveType.CDRom:
node.ImageIndex = node.SelectedImageIndex = 4;
break;
case DriveType.Remote:
case DriveType.Network:
node.ImageIndex = node.SelectedImageIndex = 5;
break;
default:

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

@ -154,17 +154,10 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -154,17 +154,10 @@ namespace ICSharpCode.SharpDevelop.Gui
public static class SingleInstanceHelper
{
const int WM_USER = 0x400;
const int CUSTOM_MESSAGE = WM_USER + 2;
const int CUSTOM_MESSAGE = NativeMethods.WM_USER + 2;
const int RESULT_FILES_HANDLED = 2;
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)
{
LoggingService.Info("Trying to pass arguments to previous instance...");
@ -181,7 +174,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -181,7 +174,7 @@ namespace ICSharpCode.SharpDevelop.Gui
if (FileUtility.IsEqualFileName(currentFile, p.MainModule.FileName)) {
IntPtr hWnd = p.MainWindowHandle;
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) {
return true;
} else if (result == RESULT_PROJECT_IS_OPEN) {
@ -191,7 +184,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -191,7 +184,7 @@ namespace ICSharpCode.SharpDevelop.Gui
}
}
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;
}
}
@ -213,7 +206,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -213,7 +206,7 @@ namespace ICSharpCode.SharpDevelop.Gui
} else {
m.Result = new IntPtr(RESULT_FILES_HANDLED);
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"))) {
WorkbenchSingleton.SafeThreadAsyncCall(delegate(string openFileName) { FileService.OpenFile(openFileName); }, file);
}
@ -633,14 +626,9 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -633,14 +626,9 @@ namespace ICSharpCode.SharpDevelop.Gui
}
}
const int VK_RMENU = 0xA5; // right alt key
[System.Runtime.InteropServices.DllImport("user32.dll", ExactSpelling=true)]
static extern short GetAsyncKeyState(int vKey);
public bool IsAltGRPressed {
public static bool IsAltGRPressed {
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 @@ -245,13 +245,10 @@ namespace ICSharpCode.SharpDevelop.Gui
return null;
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool LockWindowUpdate(IntPtr hWnd);
public void LoadConfiguration()
{
if (dockPanel != null) {
LockWindowUpdate(wbForm.Handle);
NativeMethods.SetWindowRedraw(wbForm.Handle, false);
try {
IViewContent activeView = GetActiveView();
dockPanel.ActiveDocumentChanged -= new EventHandler(ActiveMdiChanged);
@ -267,7 +264,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -267,7 +264,7 @@ namespace ICSharpCode.SharpDevelop.Gui
activeView.WorkbenchWindow.SelectWindow();
}
} finally {
LockWindowUpdate(IntPtr.Zero);
NativeMethods.SetWindowRedraw(wbForm.Handle, true);
}
}
}

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

@ -0,0 +1,45 @@ @@ -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;
}
}
}

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

@ -222,9 +222,7 @@ namespace ICSharpCode.SharpDevelop.Util @@ -222,9 +222,7 @@ namespace ICSharpCode.SharpDevelop.Util
process = null;
}
}
// Control-C does not seem to work.
//GenerateConsoleCtrlEvent((int)ConsoleEvent.ControlC, 0);
}
}
/// <summary>
/// Raises the <see cref="ProcessExited"/> event.
@ -262,15 +260,6 @@ namespace ICSharpCode.SharpDevelop.Util @@ -262,15 +260,6 @@ namespace ICSharpCode.SharpDevelop.Util
if (ErrorLineReceived != null) {
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