@ -615,7 +615,23 @@ namespace ICSharpCode.SharpDevelop.Project
@@ -615,7 +615,23 @@ namespace ICSharpCode.SharpDevelop.Project
CopyDirectoryHere ( node . Directory , performMove ) ;
}
/// <summary>
/// Copies or moves a file to this directory, discarding its DependentUpon value.
/// </summary>
/// <param name="fileName">The name of the file to copy or move.</param>
/// <param name="performMove">true to move the file, false to copy it.</param>
public void CopyFileHere ( string fileName , bool performMove )
{
this . CopyFileHere ( fileName , performMove , false ) ;
}
/// <summary>
/// Copies or moves a file to this directory.
/// </summary>
/// <param name="fileName">The name of the file to copy or move.</param>
/// <param name="performMove">true to move the file, false to copy it.</param>
/// <param name="keepDependency">true to copy the DependentUpon value of the file to the target if possible, false to discard the DependentUpon value.</param>
public void CopyFileHere ( string fileName , bool performMove , bool keepDependency )
{
string shortFileName = Path . GetFileName ( fileName ) ;
string copiedFileName = Path . Combine ( Directory , shortFileName ) ;
@ -644,6 +660,11 @@ namespace ICSharpCode.SharpDevelop.Project
@@ -644,6 +660,11 @@ namespace ICSharpCode.SharpDevelop.Project
continue ;
if ( newItem ! = null & & FileUtility . IsEqualFileName ( fileItem . FileName , fileName ) ) {
fileItem . CopyMetadataTo ( newItem ) ;
if ( ! keepDependency ) {
// Prevent the DependentUpon from being copied
// because the referenced file is now in a different directory.
newItem . DependentUpon = String . Empty ;
}
}
if ( ! string . Equals ( fileItem . DependentUpon , shortFileName , StringComparison . OrdinalIgnoreCase ) )
continue ;
@ -651,7 +672,7 @@ namespace ICSharpCode.SharpDevelop.Project
@@ -651,7 +672,7 @@ namespace ICSharpCode.SharpDevelop.Project
if ( ! FileUtility . IsEqualFileName ( sourceDirectory , Path . GetDirectoryName ( itemPath ) ) )
continue ;
// this file is dependend on the file being copied/moved: copy it, too
CopyFileHere ( itemPath , performMove ) ;
CopyFileHere ( itemPath , performMove , true ) ;
dependendElementsCopied = true ;
}
if ( dependendElementsCopied )
@ -672,6 +693,12 @@ namespace ICSharpCode.SharpDevelop.Project
@@ -672,6 +693,12 @@ namespace ICSharpCode.SharpDevelop.Project
}
}
/// <summary>
/// Copies or moves a file node (and the corresponding file, if applicable) to this directory,
/// discarding its DependentUpon value.
/// </summary>
/// <param name="fileNode">The file node to copy or move.</param>
/// <param name="performMove">true to move the file node, false to copy it.</param>
public void CopyFileHere ( FileNode node , bool performMove )
{
if ( node . FileNodeStatus = = FileNodeStatus . None ) {
@ -743,6 +770,13 @@ namespace ICSharpCode.SharpDevelop.Project
@@ -743,6 +770,13 @@ namespace ICSharpCode.SharpDevelop.Project
return DragDropEffects . Copy ;
}
return proposedEffect ;
} else {
// Dragging a dependent file onto its parent directory
// removes the dependency.
FileProjectItem fpi = fileNode . ProjectItem as FileProjectItem ;
if ( fpi ! = null & & ! String . IsNullOrEmpty ( fpi . DependentUpon ) ) {
return DragDropEffects . Move ;
}
}
}
@ -771,7 +805,24 @@ namespace ICSharpCode.SharpDevelop.Project
@@ -771,7 +805,24 @@ namespace ICSharpCode.SharpDevelop.Project
try {
if ( dataObject . GetDataPresent ( typeof ( FileNode ) ) ) {
FileNode fileNode = ( FileNode ) dataObject . GetData ( typeof ( FileNode ) ) ;
CopyFileHere ( fileNode , effect = = DragDropEffects . Move ) ;
LoggingService . Debug ( "ProjectBrowser: Dragging file '" + fileNode . FileName + "' onto directory '" + this . Directory + "'" ) ;
if ( ! FileUtility . IsEqualFileName ( Directory , fileNode . FileName ) & & ! FileUtility . IsEqualFileName ( Directory , Path . GetDirectoryName ( fileNode . FileName ) )
& & ! ( fileNode . ProjectItem is FileProjectItem & & FileUtility . IsEqualFileName ( Directory , Path . GetDirectoryName ( GetFullVirtualName ( ( FileProjectItem ) fileNode . ProjectItem ) ) ) ) ) {
LoggingService . Debug ( "-> Not in same directory, performing " + effect . ToString ( ) ) ;
CopyFileHere ( fileNode , effect = = DragDropEffects . Move ) ;
} else {
// Dragging a dependent file onto its parent directory
// removes the dependency.
LoggingService . Debug ( "-> In same directory, removing dependency" ) ;
( ( FileProjectItem ) fileNode . ProjectItem ) . DependentUpon = String . Empty ;
fileNode . Remove ( ) ;
if ( ! File . Exists ( fileNode . FileName ) ) {
fileNode . FileNodeStatus = FileNodeStatus . Missing ;
} else {
fileNode . FileNodeStatus = FileNodeStatus . InProject ;
}
fileNode . AddTo ( this ) ;
}
} else if ( dataObject . GetDataPresent ( typeof ( DirectoryNode ) ) ) {
DirectoryNode directoryNode = ( DirectoryNode ) dataObject . GetData ( typeof ( DirectoryNode ) ) ;
CopyDirectoryHere ( directoryNode , effect = = DragDropEffects . Move ) ;
@ -793,6 +844,16 @@ namespace ICSharpCode.SharpDevelop.Project
@@ -793,6 +844,16 @@ namespace ICSharpCode.SharpDevelop.Project
MessageService . ShowError ( e ) ;
}
}
static string GetFullVirtualName ( FileProjectItem item )
{
if ( Path . IsPathRooted ( item . VirtualName ) ) {
return item . VirtualName ;
} else if ( item . Project ! = null ) {
return Path . Combine ( item . Project . Directory , item . VirtualName ) ;
}
return item . VirtualName ;
}
#endregion
}
}