Skip to content

Commit

Permalink
added drag drop
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyeao committed Jan 27, 2024
1 parent 2e20f98 commit 74df15a
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 7 deletions.
4 changes: 2 additions & 2 deletions MP3joiner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<AssemblyVersion>1.0.0.59</AssemblyVersion>
<FileVersion>1.0.0.59</FileVersion>
<AssemblyVersion>1.0.0.68</AssemblyVersion>
<FileVersion>1.0.0.68</FileVersion>
<ApplicationIcon>logo (1).ico</ApplicationIcon>
<PackageIcon>logo.png</PackageIcon>
</PropertyGroup>
Expand Down
20 changes: 15 additions & 5 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"

Background="#0A4185"
FontFamily="{DynamicResource MaterialDesignFont}">

Expand Down Expand Up @@ -70,16 +71,25 @@
<TextBlock Text="Join Files" Foreground="White"/>
</StackPanel>
</Button>
<Button x:Name="btnclearList" Style="{StaticResource MaterialDesignFlatButton}" Foreground="White" Click="btnclearList_Click">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="BrushOff" Margin="0,0,5,0" Foreground="White"/>
<TextBlock Text="Clear List" Foreground="White"/>
</StackPanel>
</Button>

</StackPanel>

<materialDesign:Card Grid.Row="1" Grid.Column="0" Margin="10,10,10,10" Grid.ColumnSpan="3">
<DataGrid AutoGenerateColumns="False"
HeadersVisibility="Column"
ItemsSource="{Binding FileList}"
dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True"
dd:DragDrop.DropHandler="{Binding DropHandler}">
HeadersVisibility="Column"
AllowDrop="True"
Drop="Window_Drop"
DragEnter="Window_DragEnter"
ItemsSource="{Binding FileList}"
dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True"
dd:DragDrop.DropHandler="{Binding DropHandler}">
<DataGrid.Columns>
<DataGridTextColumn Header="Filename" Binding="{Binding FileName, Mode=OneWay}" Width="*"/>
</DataGrid.Columns>
Expand Down
78 changes: 78 additions & 0 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,84 @@ public MainWindow()
#endregion Public Constructors

#region Private Methods
private void Window_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effects = DragDropEffects.Copy; // Show copy cursor
}
else
{
e.Effects = DragDropEffects.None; // Show no-entry cursor
}

e.Handled = true;
}

private void Window_Drop(object sender, DragEventArgs e)
{
// Check if the drop is from an external source (Windows Explorer)
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
HandleFileDrop(files);
e.Handled = true; // Mark the event as handled
}
else
{
// If the drop is not from an external source,
// it might be an internal drag-and-drop for reordering.
// Do not set e.Handled to true here.
// This allows GongSolutions.Wpf.DragDrop to handle internal reordering.
}
}


private void HandleFileDrop(string[] files)
{
var viewModel = DataContext as YourViewModel;
if (viewModel == null) return;
var firstadded = true;
// Your existing logic for handling file drops
foreach (string file in files)
{

// Add each file to your file list, for example:
// Assuming 'fileList' is your ObservableCollection<string> that's bound to the UI
if (viewModel.FileList.Any() && viewModel.FileList.All(f => f.FilePath != file) && firstadded == true)
{
// Create a new instance of AddFilesDialog
var dialog = new AddFilesDialog();

// Set the main window as the owner of the dialog
dialog.Owner = this;

// Show the dialog and wait for the user to close it
dialog.ShowDialog();

// Check the result of the dialog
if (dialog.DialogResult == "NewList")
{
viewModel.FileList.Clear(); // Clear the existing list in the view model
firstadded = false;
}
else if (dialog.DialogResult == "Cancel")
{
return; // Cancel the operation and return from the event handler
}
}
viewModel.FileList.Add(new FileInfo { FilePath = file });
firstadded = false;

}
}


private void btnclearList_Click(object sender, RoutedEventArgs e)
{
var viewModel = DataContext as YourViewModel;
viewModel.FileList.Clear();
}

// This method is used to animate a progress bar to zero value
private void AnimateProgressBarToZero()
Expand Down

0 comments on commit 74df15a

Please sign in to comment.