Skip to content

Commit

Permalink
cool
Browse files Browse the repository at this point in the history
  • Loading branch information
vadimart92 committed Jul 4, 2014
1 parent fe42ca7 commit e1979fd
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 18 deletions.
6 changes: 6 additions & 0 deletions ImageRenamer/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
<setting name="ImgFilesExtensions" serializeAs="String">
<value>*.jpg|*.jpeg</value>
</setting>
<setting name="UseSubDirs" serializeAs="String">
<value>False</value>
</setting>
<setting name="SaveToSameFolder" serializeAs="String">
<value>False</value>
</setting>
</ImageTools.Properties.Settings>
</userSettings>
</configuration>
44 changes: 43 additions & 1 deletion ImageRenamer/ImageRenamer/ImageRenameConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using LevDan.Exif;

namespace ImageTools.ImageRenamer {
Expand All @@ -30,6 +31,44 @@ from fileName in Directory.EnumerateFiles(directory, ext, searchOption)
return result;
}

public static List<ExifTagInfo> GetExifTagInfos(IEnumerable<ImageRenameConfig> imagesConfig) {
var allTags = (from config in imagesConfig
from tag in config.ExifTags
select new ExifTagInfo {Name = tag.FieldName, TagNumber = tag.Id});
var result = new Dictionary<int,ExifTagInfo>();
foreach (var t in allTags) {
if (!result.ContainsKey(t.TagNumber)) {
result.Add(t.TagNumber, t);
}
}
return result.Values.ToList();
}
}
public class ExifTagInfo : IComparable<ExifTagInfo>, IEquatable<ExifTagInfo> {
public string Name {
get;
set;
}
public int TagNumber {
get;
set;
}

#region Члены IComparable<ExifTagInfo>

public int CompareTo(ExifTagInfo other) {
return TagNumber.CompareTo(other.TagNumber);
}

#endregion

#region Члены IEquatable<ExifTagInfo>

public bool Equals(ExifTagInfo other) {
return TagNumber == other.TagNumber;
}

#endregion
}
public class ImageRenameConfig : IComparable<ImageRenameConfig>,INotifyPropertyChanged {
public string OldDisplayValue {
Expand All @@ -38,14 +77,17 @@ public string OldDisplayValue {
}
}

public ExifTagCollection ExifTags {
get { return _fileInfo; }
}

public string NewFileName {
get { return _newFilename; }
set {
if (!value.Equals(_newFilename)) {
_newFilename = value;
PropertyChanged(this, GetArgs());
}

}
}

Expand Down
37 changes: 29 additions & 8 deletions ImageRenamer/ImageRenamer/ImageRenamer.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local ="clr-namespace:ImageTools.ImageRenamer"
mc:Ignorable="d"
d:DesignHeight="293.088" d:DesignWidth="523.963">
d:DesignHeight="292.085" d:DesignWidth="643.371">
<UserControl.Resources>
<Style TargetType="TextBlock" x:Key="FileNameStyle">
<Style.Triggers>
Expand All @@ -14,28 +14,39 @@
</DataTrigger>
</Style.Triggers>
</Style>
<local:BollValueInverter x:Key="boolInverter" />
</UserControl.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="3*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel>
<StackPanel Orientation="Horizontal" Height="30pt">
<TextBox Width="Auto" MinWidth="100pt" VerticalAlignment="Center" Name="InitFolder" Text="{Binding Path=InitDir, Mode=TwoWay}" ></TextBox>
<TextBox Width="Auto" MinWidth="100pt" MaxWidth="200pt" VerticalAlignment="Center"
Name="InitFolder"
Text="{Binding Path=InitDir, Mode=TwoWay}" ></TextBox>
<Button Name="selectFolder" VerticalAlignment="Center" Margin="10pt 0 0 0" Padding="10pt 0" Click="selectFolder_Click">...</Button>
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Name="UseSubFolders" IsChecked="{Binding Path=IncludeSubDirs, Mode=TwoWay}" Height="15pt">Include subfolders</CheckBox>
</StackPanel>
</StackPanel>
<ListView Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" Name="lv_files">
<ListView Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3" Name="lv_files">
<ListView.View>
<GridView>
<GridViewColumn Width="20pt" Header="Img" >
<GridViewColumn.CellTemplate>
<DataTemplate DataType="local:ImageRenameConfig">
<Image ></Image>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="150pt" Header="OldName" >
<GridViewColumn.CellTemplate>
<DataTemplate DataType="local:ImageRenameConfig">
Expand All @@ -62,17 +73,27 @@
</GridView>
</ListView.View>
</ListView>
<StackPanel Grid.Row="0" Margin="2,0,0,0" Grid.Column="1">
<StackPanel Grid.Row="0" Margin="2,0,0,0" Grid.Column="2">
<StackPanel Orientation="Horizontal" Height="30pt">
<TextBox Width="Auto" MinWidth="100pt" VerticalAlignment="Center"
<TextBox Width="Auto" MinWidth="100pt" MaxWidth="200pt" VerticalAlignment="Center"
Name="destFolder"
IsEnabled="{Binding ElementName=UseSubFolders, Path=IsChecked, Mode=TwoWay}"
IsEnabled="{Binding ElementName=saveToSameFolder, Path=IsChecked, Converter={StaticResource ResourceKey=boolInverter}}"
Text="{Binding Path=InitDir, Mode=TwoWay}" ></TextBox>
<Button Name="SelectDestFolder" VerticalAlignment="Center" Margin="10pt 0 0 0" Padding="10pt 0" Click="SelectDestFolder_Click">...</Button>
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Name="saveToSameFolder" IsChecked="{Binding Path=SaveToSameFolder, Mode=TwoWay}" Height="15pt">Save to same folder</CheckBox>
</StackPanel>
</StackPanel>
<StackPanel Grid.Column="1" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Top" MinWidth="100pt">
<TextBlock Text="Order by:" HorizontalAlignment="Center"/>
<ComboBox Name="orderByComboBox">
<ComboBox.ItemTemplate>
<DataTemplate DataType="local:ExifTagInfo">
<TextBlock Text="{Binding Path=Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
</Grid>
</UserControl>
52 changes: 45 additions & 7 deletions ImageRenamer/ImageRenamer/ImageRenamer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Forms;
using ImageTools.Properties;

Expand All @@ -13,12 +14,22 @@ namespace ImageTools.ImageRenamer {
public partial class ImageRenamer
{
public bool IncludeSubDirs {
get;
set;
get {
return Settings.Default.UseSubDirs;
}
set {
Settings.Default.UseSubDirs = value;
Settings.Default.Save();
}
}
public bool SaveToSameFolder {
get;
set;
get {
return Settings.Default.SaveToSameFolder;
}
set {
Settings.Default.SaveToSameFolder = value;
Settings.Default.Save();
}
}

public string InitDir {
Expand All @@ -31,7 +42,16 @@ public string InitDir {
}
}

private ObservableCollection<ImageRenameConfig> _images;
public string OutDir {
get { return _outDir; }
set {

}
}

private ObservableCollection<ExifTagInfo> _exifTags = new ObservableCollection<ExifTagInfo>();
private ObservableCollection<ImageRenameConfig> _images = new ObservableCollection<ImageRenameConfig>();
private string _outDir = string.Empty;
public ImageRenamer() {
InitializeComponent();
InitBindings();
Expand All @@ -42,6 +62,7 @@ private void InitBindings() {
_images = new ObservableCollection<ImageRenameConfig>();
lv_files.DataContext = this.DataContext;
lv_files.ItemsSource = _images;
orderByComboBox.ItemsSource = _exifTags;
}

private async void selectFolder_Click(object sender, RoutedEventArgs e) {
Expand All @@ -53,17 +74,20 @@ private async void selectFolder_Click(object sender, RoutedEventArgs e) {
}
var fileExtensions = Settings.Default.ImgFilesExtensions.Split('|');
if (fbd.ShowDialog() == DialogResult.OK) {
this.
InitDir = fbd.SelectedPath;
var cont = selectFolder.Content;
selectFolder.Content = "Loading...";
_images.Clear();
var infos = new List<ExifTagInfo>();
var config = await Task.Run(() => {
var c = ImageRenameUtils.GetImageRenameConfigFiles(fbd.SelectedPath, IncludeSubDirs, fileExtensions);
c.Sort();
infos = ImageRenameUtils.GetExifTagInfos(c);
return c;
});
selectFolder.Content = cont;
_images.Clear();
_exifTags.Clear();
infos.ForEach(i => _exifTags.Add(i));
config.ForEach(fc => _images.Add(fc));
}

Expand All @@ -75,4 +99,18 @@ private void SelectDestFolder_Click(object sender, RoutedEventArgs e) {
}
}
}
public class BollValueInverter : IValueConverter {

#region Члены IValueConverter

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
return !(bool) value;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
return !(bool)value;
}

#endregion
}
}
6 changes: 4 additions & 2 deletions ImageRenamer/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:imageRenamer="clr-namespace:ImageTools.ImageRenamer"
Title="MainWindow" Height="350" Width="525">
Title="MainWindow" Height="352" Width="804">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
Expand All @@ -11,6 +11,8 @@
<Border Grid.Row="0" Margin="10px" >
<imageRenamer:ImageRenamer></imageRenamer:ImageRenamer>
</Border>
<StatusBar Grid.Row="1" > <Label>Hi</Label> </StatusBar>
<StatusBar Grid.Row="1" >
<Label>Hi</Label>
</StatusBar>
</Grid>
</Window>
24 changes: 24 additions & 0 deletions ImageRenamer/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions ImageRenamer/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,11 @@
<Setting Name="ImgFilesExtensions" Type="System.String" Scope="User">
<Value Profile="(Default)">*.jpg|*.jpeg</Value>
</Setting>
<Setting Name="UseSubDirs" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="SaveToSameFolder" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>

0 comments on commit e1979fd

Please sign in to comment.