Skip to content

Commit

Permalink
Include in conversion checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
JeppeSRC committed Feb 3, 2018
1 parent 9cd00ad commit dcb00df
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 15 deletions.
9 changes: 6 additions & 3 deletions FDconverter/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ private static FileType GetFileTypeFromExtension(String filename) {

private int _progress;
private FileType _type;
private bool _included;

public string path { get; }
public long size { get; }
public string sizeString { get; set; }
public FileType type { get { return _type; } set { _type = value; OnPropertyChanged(); } }
public int progress { get { return _progress; } set { _progress = value; OnPropertyChanged(); } }
public bool included { get { return _included; } set { _included = value; OnPropertyChanged(); Console.WriteLine("SA"); } }

public event PropertyChangedEventHandler PropertyChanged;

Expand All @@ -54,13 +56,14 @@ public FDFile(string path, long size) {
this.size = size;
this.type = GetFileTypeFromExtension(path);
progress = 0;
included = true;

if (size >= 1024 * 1024 * 1024) {
sizeString = string.Format("{0:F2} GB", (float)size / (1024.0f * 1024.0f * 1024.0f));
sizeString = string.Format("{0:F2} GB", size / (1024.0f * 1024.0f * 1024.0f));
} else if (size >= 1024 * 1024) {
sizeString = string.Format("{0:F2} MB", (float)size / (1024.0f * 1024.0f));
sizeString = string.Format("{0:F2} MB", size / (1024.0f * 1024.0f));
} else if (size >= 1024) {
sizeString = string.Format("{0:F2} KB", (float)size / (1024.0f));
sizeString = string.Format("{0:F2} KB", size / (1024.0f));
} else {
sizeString = string.Format("{0:F2} Bytes", size);
}
Expand Down
28 changes: 21 additions & 7 deletions FDconverter/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@
Title="Frodo Converter" Width="1000" Height="600"
ResizeMode="CanMinimize">
<Grid Margin="10,10,10,10">
<ListView x:Name="lvFiles" HorizontalAlignment="Left" Margin="10,329,0,0" Width="954" DragDrop.Drop="lvFiles_Drop" AllowDrop="True" KeyDown="lvFiles_KeyDown" MouseDown="lvFiles_MouseDown" Height="182" VerticalAlignment="Top">
<ListView x:Name="lvFiles" HorizontalAlignment="Left" Margin="10,329,0,0" Width="954" DragDrop.Drop="lvFiles_Drop" AllowDrop="True" KeyDown="lvFiles_KeyDown" SelectionChanged="lvFiles_SelectionChanged" Height="182" VerticalAlignment="Top">
<ListView.View>
<GridView>
<GridViewColumn Header="Path" Width="500" DisplayMemberBinding="{Binding path}"/>
<GridViewColumn Header="Included" Width="30">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Name="ckbItem" HorizontalAlignment="Center" VerticalAlignment="Center" Width="20" IsChecked="{Binding included}" Checked="ckbItem_Checked" Unchecked="ckbItem_Unchecked"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Path" Width="472" DisplayMemberBinding="{Binding path}"/>
<GridViewColumn Header="Type" Width="100" DisplayMemberBinding="{Binding type}"/>
<GridViewColumn Header="Size" Width="150" DisplayMemberBinding="{Binding sizeString}"/>
<GridViewColumn Header="Progress" Width="175" >
Expand All @@ -27,11 +34,18 @@
<Button Content="Add" HorizontalAlignment="Left" Margin="10,304,0,0" VerticalAlignment="Top" Width="100" Click="Button_Click_Add"/>
<Button Content="Remove" HorizontalAlignment="Left" Margin="115,304,0,0" VerticalAlignment="Top" Width="100" Click="Button_Click_Remove"/>
<Button Content="Start" HorizontalAlignment="Left" Margin="220,304,0,0" VerticalAlignment="Top" Width="100"/>
<ProgressBar HorizontalAlignment="Left" Height="20" Margin="325,304,0,0" VerticalAlignment="Top" Width="639"/>
<Label Content="Type: " HorizontalAlignment="Left" Margin="10,-4,0,0" VerticalAlignment="Top" Width="50"/>
<ComboBox x:Name="cbType" HorizontalAlignment="Left" Margin="65,0,0,0" VerticalAlignment="Top" Width="150" SelectionChanged="cbType_SelectionChanged"/>
<ProgressBar x:Name="pbTotal" HorizontalAlignment="Left" Height="20" Margin="325,304,0,0" VerticalAlignment="Top" Width="639"/>
<Label Content="Type: " HorizontalAlignment="Left" Margin="10,-4,0,0" VerticalAlignment="Top" Width="41" />
<ComboBox x:Name="cbType" HorizontalAlignment="Left" Margin="51,0,0,0" VerticalAlignment="Top" Width="150" SelectionChanged="cbType_SelectionChanged"/>
<Button Content="Destination" HorizontalAlignment="Left" Margin="10,521,0,0" VerticalAlignment="Top" Width="100" Click="Button_Click_Destination"/>
<TextBox x:Name="tvDstPath" HorizontalAlignment="Left" Height="20" Margin="115,521,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="849"/>

<TextBox x:Name="tvDstPath" HorizontalAlignment="Left" Height="20" Margin="115,521,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="849"/>
<GroupBox x:Name="imageOptionsGroup" Header="Image Options" HorizontalAlignment="Left" Height="272" Margin="10,27,0,0" VerticalAlignment="Top" Width="454" Visibility="Hidden">
<Label Content="DankLabel" HorizontalAlignment="Left" VerticalAlignment="Top" Width="100"/>
</GroupBox>
<GroupBox x:Name="modelOptionsGroup" Header="Image Options" HorizontalAlignment="Left" Height="272" Margin="10,27,0,0" VerticalAlignment="Top" Width="366" Visibility="Hidden">
<Label Content="model" HorizontalAlignment="Left" VerticalAlignment="Top" Width="100"/>
</GroupBox>
<Label Content="Included: " HorizontalAlignment="Left" Margin="206,-4,0,0" VerticalAlignment="Top" Width="60"/>
<CheckBox x:Name="ckbIncluded" HorizontalAlignment="Left" Margin="266,2,0,0" VerticalAlignment="Top" Width="18" Height="16" Checked="ckbIncluded_Checked" Unchecked="ckbIncluded_Unchecked"/>
</Grid>
</Window>
113 changes: 108 additions & 5 deletions FDconverter/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ public MainWindow() {

lvFiles.ItemsSource = files;
exePath = Assembly.GetEntryAssembly().Location;
exePath = exePath.Remove(exePath.Length - 15, 15);

FileType[] types = new FileType[3];

types[(int)FileType.Unknown] = FileType.Unknown;
types[(int)FileType.Image] = FileType.Image;
types[(int)FileType.Model] = FileType.Model;

cbType.ItemsSource = types;

tvDstPath.Text = exePath + "ouput\\";
}

private bool AddFolder(string folder) {
Expand Down Expand Up @@ -91,6 +102,50 @@ private void AddFiles(string[] files) {
}
}

private void SetOptionsGroupVisibility(FileType type) {
switch (type) {
case FileType.Unknown:
imageOptionsGroup.Visibility = Visibility.Hidden;
modelOptionsGroup.Visibility = Visibility.Hidden;
break;
case FileType.Image:
imageOptionsGroup.Visibility = Visibility.Visible;
modelOptionsGroup.Visibility = Visibility.Hidden;
break;
case FileType.Model:
modelOptionsGroup.Visibility = Visibility.Visible;
imageOptionsGroup.Visibility = Visibility.Hidden;
break;
}
}

private void UpdateIncludeAllCheckbox() {
if (lvFiles.SelectedItems.Count == 0) return;

FDFile tmp = (FDFile)lvFiles.SelectedItems[0];

if (lvFiles.SelectedItems.Count == 1) {
ckbIncluded.IsChecked = tmp.included;
return;
}

bool isAllIncluded = true;

for (int i = 1; i < lvFiles.SelectedItems.Count; i++) {
FDFile file = (FDFile)lvFiles.SelectedItems[i];

if (tmp.included != file.included && isAllIncluded) {
isAllIncluded = false;
}
}

if (!isAllIncluded) {
ckbIncluded.IsChecked = null;
} else {
ckbIncluded.IsChecked = tmp.included;
}
}

private void lvFiles_Drop(object sender, DragEventArgs e) {
AddFiles((string[])e.Data.GetData(DataFormats.FileDrop));
}
Expand Down Expand Up @@ -146,21 +201,69 @@ private void Button_Click_Remove(object sender, RoutedEventArgs e) {
}
}

private void lvFiles_MouseDown(object sender, MouseButtonEventArgs e) {

}

private void Button_Click_Destination(object sender, RoutedEventArgs e) {
System.Windows.Forms.FolderBrowserDialog diag = new System.Windows.Forms.FolderBrowserDialog();

diag.RootFolder = Environment.SpecialFolder.MyComputer;
if (diag.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
tvDstPath.Text = diag.SelectedPath;
tvDstPath.Text = diag.SelectedPath + "\\";
}
}

private void cbType_SelectionChanged(object sender, SelectionChangedEventArgs e) {
if (cbType.SelectedIndex == -1) return;
for (int i = 0; i < lvFiles.SelectedItems.Count; i++) {
((FDFile)lvFiles.SelectedItems[i]).type = (FileType)cbType.SelectedIndex;
}

SetOptionsGroupVisibility((FileType)cbType.SelectedIndex);
}

private void lvFiles_SelectionChanged(object sender, SelectionChangedEventArgs e) {
FDFile tmp = (FDFile)lvFiles.SelectedItems[0];

cbType.SelectionChanged -= cbType_SelectionChanged;

cbType.SelectedIndex = 0;

for (int i = 1; i < lvFiles.SelectedItems.Count; i++) {
FDFile file = (FDFile)lvFiles.SelectedItems[i];
if (tmp.type != file.type) {
cbType.SelectedIndex = -1;
}
}

if (cbType.SelectedIndex == 0) {
cbType.SelectedIndex = (int)tmp.type;
SetOptionsGroupVisibility(tmp.type);
} else {
imageOptionsGroup.Visibility = Visibility.Hidden;
modelOptionsGroup.Visibility = Visibility.Hidden;
}

cbType.SelectionChanged += cbType_SelectionChanged;

UpdateIncludeAllCheckbox();
}

private void ckbIncluded_Checked(object sender, RoutedEventArgs e) {
for (int i = 0; i < lvFiles.SelectedItems.Count; i++) {
((FDFile)lvFiles.SelectedItems[i]).included = true;
}
}

private void ckbIncluded_Unchecked(object sender, RoutedEventArgs e) {
for (int i = 0; i < lvFiles.SelectedItems.Count; i++) {
((FDFile)lvFiles.SelectedItems[i]).included = false;
}
}

private void ckbItem_Checked(object sender, RoutedEventArgs e) {
UpdateIncludeAllCheckbox();
}

private void ckbItem_Unchecked(object sender, RoutedEventArgs e) {
UpdateIncludeAllCheckbox();
}
}
}

0 comments on commit dcb00df

Please sign in to comment.