Browse Source

Implemented SD2-1371: Use recycle bin to delete files.

Fixed bug introduced in last revision that caused the unit tests to fail.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2690 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
9dbecc48ee
  1. 2
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/DefaultLineManager.cs
  2. 35
      src/Main/Base/Project/Resources/LoadSaveOptionPanel.xfrm
  3. 5
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/LoadSavePanel.cs
  4. 19
      src/Main/Base/Project/Src/Services/File/FileService.cs
  5. 68
      src/Main/Base/Project/Src/Util/NativeMethods.cs
  6. 2
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/DefaultProjectContent.cs
  7. 5
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/ReflectionProjectContent.cs

2
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/DefaultLineManager.cs

@ -77,7 +77,7 @@ namespace ICSharpCode.TextEditor.Document @@ -77,7 +77,7 @@ namespace ICSharpCode.TextEditor.Document
public void Replace(int offset, int length, string text)
{
Console.WriteLine("Replace offset="+offset+" length="+length+" text.Length="+text.Length);
// Console.WriteLine("Replace offset="+offset+" length="+length+" text.Length="+text.Length);
int lineStart = GetLineNumberForOffset(offset);
int oldNumberOfLines = this.TotalNumberOfLines;
RemoveInternal(offset, length);

35
src/Main/Base/Project/Resources/LoadSaveOptionPanel.xfrm

@ -1,31 +1,50 @@ @@ -1,31 +1,50 @@
<Components version="1.0">
<System.Windows.Forms.UserControl>
<Name value="MyUserControl" />
<ClientSize value="{Width=280, Height=233}" />
<ClientSize value="{Width=280, Height=332}" />
<Controls>
<System.Windows.Forms.GroupBox>
<Name value="groupBox1" />
<Location value="8, 226" />
<Text value="Delete" />
<Size value="264, 51" />
<Anchor value="Top, Left, Right" />
<TabIndex value="2" />
<Controls>
<System.Windows.Forms.CheckBox>
<Name value="useRecycleBinCheckBox" />
<Location value="8, 19" />
<Text value="Use recycle bin when deleting files" />
<TabIndex value="0" />
<Size value="248, 24" />
<UseVisualStyleBackColor value="True" />
<Anchor value="Top, Left, Right" />
</System.Windows.Forms.CheckBox>
</Controls>
</System.Windows.Forms.GroupBox>
<System.Windows.Forms.GroupBox>
<Name value="groupBox2" />
<Location value="8, 108" />
<Text value="${res:Dialog.Options.IDEOptions.LoadSaveOptions.SaveLabel}" />
<Anchor value="Top, Left, Right" />
<Size value="264, 112" />
<Anchor value="Top, Left, Right" />
<TabIndex value="1" />
<Controls>
<System.Windows.Forms.ComboBox>
<Name value="lineTerminatorStyleComboBox" />
<Size value="104, 21" />
<TabIndex value="2" />
<DropDownStyle value="DropDownList" />
<Location value="8, 72" />
<Anchor value="Top, Left, Right" />
<Size value="104, 21" />
<DropDownStyle value="DropDownList" />
</System.Windows.Forms.ComboBox>
<System.Windows.Forms.Label>
<Name value="label" />
<Location value="8, 49" />
<Text value="${res:Dialog.Options.IDEOptions.LoadSaveOptions.LineTerminatorStyleGroupBox}" />
<Anchor value="Top, Left, Right" />
<TextAlign value="BottomLeft" />
<Size value="248, 23" />
<TextAlign value="BottomLeft" />
<Anchor value="Top, Left, Right" />
<TabIndex value="1" />
</System.Windows.Forms.Label>
<System.Windows.Forms.CheckBox>
@ -42,8 +61,8 @@ @@ -42,8 +61,8 @@
<Name value="groupBox" />
<Location value="8, 8" />
<Text value="${res:Dialog.Options.IDEOptions.LoadSaveOptions.LoadLabel}" />
<Anchor value="Top, Left, Right" />
<Size value="264, 94" />
<Anchor value="Top, Left, Right" />
<TabIndex value="0" />
<Controls>
<System.Windows.Forms.CheckBox>
@ -76,4 +95,4 @@ @@ -76,4 +95,4 @@
</System.Windows.Forms.GroupBox>
</Controls>
</System.Windows.Forms.UserControl>
</Components>
</Components>

5
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/LoadSavePanel.cs

@ -27,7 +27,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -27,7 +27,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
const string createBackupCopyCheckBox = "createBackupCopyCheckBox";
const string lineTerminatorStyleComboBox = "lineTerminatorStyleComboBox";
CheckBox autoLoadExternalChangesCheckBox, detectExternalChangesCheckBox;
CheckBox autoLoadExternalChangesCheckBox, detectExternalChangesCheckBox, useRecycleBinCheckBox;
public override void LoadPanelContents()
{
@ -44,6 +44,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -44,6 +44,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
autoLoadExternalChangesCheckBox = Get<CheckBox>("autoLoadExternalChanges");
detectExternalChangesCheckBox = Get<CheckBox>("detectExternalChanges");
useRecycleBinCheckBox = Get<CheckBox>("useRecycleBin");
detectExternalChangesCheckBox.CheckedChanged += delegate {
autoLoadExternalChangesCheckBox.Enabled = detectExternalChangesCheckBox.Checked;
@ -52,6 +53,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -52,6 +53,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
detectExternalChangesCheckBox.Checked = FileChangeWatcher.DetectExternalChangesOption;
autoLoadExternalChangesCheckBox.Checked = FileChangeWatcher.AutoLoadExternalChangesOption;
useRecycleBinCheckBox.Checked = FileService.DeleteToRecycleBin;
}
public override bool StorePanelContents()
@ -62,6 +64,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -62,6 +64,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
FileChangeWatcher.DetectExternalChangesOption = detectExternalChangesCheckBox.Checked;
FileChangeWatcher.AutoLoadExternalChangesOption = autoLoadExternalChangesCheckBox.Checked;
FileService.DeleteToRecycleBin = useRecycleBinCheckBox.Checked;
return true;
}

19
src/Main/Base/Project/Src/Services/File/FileService.cs

@ -294,6 +294,15 @@ namespace ICSharpCode.SharpDevelop @@ -294,6 +294,15 @@ namespace ICSharpCode.SharpDevelop
return null;
}
public static bool DeleteToRecycleBin {
get {
return PropertyService.Get("SharpDevelop.DeleteToRecycleBin", true);
}
set {
PropertyService.Set("SharpDevelop.DeleteToRecycleBin", value);
}
}
/// <summary>
/// Removes a file, raising the appropriate events. This method may show message boxes.
/// </summary>
@ -307,7 +316,10 @@ namespace ICSharpCode.SharpDevelop @@ -307,7 +316,10 @@ namespace ICSharpCode.SharpDevelop
if (isDirectory) {
try {
if (Directory.Exists(fileName)) {
Directory.Delete(fileName, true);
if (DeleteToRecycleBin)
NativeMethods.DeleteToRecycleBin(fileName);
else
Directory.Delete(fileName, true);
}
} catch (Exception e) {
MessageService.ShowError(e, "Can't remove directory " + fileName);
@ -316,7 +328,10 @@ namespace ICSharpCode.SharpDevelop @@ -316,7 +328,10 @@ namespace ICSharpCode.SharpDevelop
} else {
try {
if (File.Exists(fileName)) {
File.Delete(fileName);
if (DeleteToRecycleBin)
NativeMethods.DeleteToRecycleBin(fileName);
else
File.Delete(fileName);
}
} catch (Exception e) {
MessageService.ShowError(e, "Can't remove file " + fileName);

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

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
// </file>
using System;
using System.IO;
using System.Security;
using System.Runtime.InteropServices;
using System.Windows.Forms;
@ -41,5 +42,72 @@ namespace ICSharpCode.SharpDevelop @@ -41,5 +42,72 @@ namespace ICSharpCode.SharpDevelop
{
return GetKeyState((int)key) < 0;
}
#region SHFileOperation
enum FO_FUNC : uint
{
FO_MOVE = 0x0001,
FO_COPY = 0x0002,
FO_DELETE = 0x0003,
FO_RENAME = 0x0004,
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
struct SHFILEOPSTRUCT
{
public IntPtr hwnd;
public FO_FUNC wFunc;
[MarshalAs(UnmanagedType.LPWStr)]
public string pFrom;
[MarshalAs(UnmanagedType.LPWStr)]
public string pTo;
public FILEOP_FLAGS fFlags;
public bool fAnyOperationsAborted;
public IntPtr hNameMappings;
[MarshalAs(UnmanagedType.LPWStr)]
public string lpszProgressTitle;
}
[Flags]
private enum FILEOP_FLAGS : ushort
{
None = 0,
FOF_MULTIDESTFILES = 0x0001,
FOF_CONFIRMMOUSE = 0x0002,
FOF_SILENT = 0x0004, // don't create progress/report
FOF_RENAMEONCOLLISION = 0x0008,
FOF_NOCONFIRMATION = 0x0010, // Don't prompt the user.
FOF_WANTMAPPINGHANDLE = 0x0020, // Fill in SHFILEOPSTRUCT.hNameMappings
// Must be freed using SHFreeNameMappings
FOF_ALLOWUNDO = 0x0040,
FOF_FILESONLY = 0x0080, // on *.*, do only files
FOF_SIMPLEPROGRESS = 0x0100, // means don't show names of files
FOF_NOCONFIRMMKDIR = 0x0200, // don't confirm making any needed dirs
FOF_NOERRORUI = 0x0400, // don't put up error UI
FOF_NOCOPYSECURITYATTRIBS = 0x0800, // dont copy NT file Security Attributes
FOF_NORECURSION = 0x1000, // don't recurse into directories.
FOF_NO_CONNECTED_ELEMENTS = 0x2000, // don't operate on connected elements.
FOF_WANTNUKEWARNING = 0x4000, // during delete operation, warn if nuking instead of recycling (partially overrides FOF_NOCONFIRMATION)
FOF_NORECURSEREPARSE = 0x8000, // treat reparse points as objects, not containers
}
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
static extern int SHFileOperation([In] ref SHFILEOPSTRUCT lpFileOp);
public static void DeleteToRecycleBin(string fileName)
{
if (!File.Exists(fileName))
throw new FileNotFoundException("File not found.", fileName);
SHFILEOPSTRUCT info = new SHFILEOPSTRUCT();
info.hwnd = Gui.WorkbenchSingleton.MainForm.Handle;
info.wFunc = FO_FUNC.FO_DELETE;
info.fFlags = FILEOP_FLAGS.FOF_ALLOWUNDO | FILEOP_FLAGS.FOF_NOCONFIRMATION;
info.lpszProgressTitle = "Delete " + Path.GetFileName(fileName);
info.pFrom = fileName + "\0"; // pFrom is double-null-terminated
int result = SHFileOperation(ref info);
if (result != 0)
throw new IOException("Could not delete file " + fileName + ". Error " + result);
}
#endregion
}
}

2
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/DefaultProjectContent.cs

@ -512,7 +512,7 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -512,7 +512,7 @@ namespace ICSharpCode.SharpDevelop.Dom
}
}
void RemoveClass(IClass @class)
protected void RemoveClass(IClass @class)
{
string fullyQualifiedName = @class.FullyQualifiedName;
int typeParameterCount = @class.TypeParameters.Count;

5
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/ReflectionProjectContent.cs

@ -130,7 +130,10 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -130,7 +130,10 @@ namespace ICSharpCode.SharpDevelop.Dom
public void InitializeSpecialClasses()
{
if (GetClassInternal(VoidClass.VoidName, 0, Language) != null) {
// Replace the class representing System.Void with VoidClass.Instance
IClass voidClass = GetClassInternal(VoidClass.VoidName, 0, Language);
if (voidClass != null) {
RemoveClass(voidClass);
AddClassToNamespaceList(VoidClass.Instance);
}
}

Loading…
Cancel
Save