-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Доблено редактирование и созранение даты фотографии.
- Loading branch information
1 parent
907122a
commit c74b1a8
Showing
9 changed files
with
324 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Windows.Input; | ||
|
||
namespace PhotoDateEditor.Commands | ||
{ | ||
class RealyCommand : ICommand | ||
{ | ||
private Action<object> _execute; | ||
private Func<object, bool> _canExecute; | ||
|
||
public RealyCommand(Action<object> execute, Func<object, bool> canExecute = null) | ||
{ | ||
_execute = execute; | ||
_canExecute = canExecute; | ||
} | ||
|
||
public event EventHandler CanExecuteChanged | ||
{ | ||
add { CommandManager.RequerySuggested += value; } | ||
remove { CommandManager.RequerySuggested -= value; } | ||
} | ||
|
||
public bool CanExecute(object parameter) | ||
{ | ||
return _canExecute == null || _canExecute(parameter); | ||
} | ||
|
||
public void Execute(object parameter) | ||
{ | ||
_execute(parameter); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using PhotoDateEditor.Utils; | ||
using System; | ||
using System.IO; | ||
|
||
namespace PhotoDateEditor.Image | ||
{ | ||
public class ImageMetadataModel : AbstractPropertyChangedClass | ||
{ | ||
private bool _isModified; | ||
public bool IsModified | ||
{ | ||
get => _isModified; | ||
set | ||
{ | ||
_isModified = value; | ||
OnPropertyChanged(nameof(IsModified)); | ||
OnPropertyChanged(nameof(ViewFileName)); | ||
} | ||
} | ||
|
||
private ImageMetadata _metadata; | ||
|
||
public string PathToFile { get => _metadata.PathToFile; } | ||
public string FileName { get => Path.GetFileName(PathToFile); } | ||
public string ViewFileName | ||
{ | ||
get | ||
{ | ||
if (IsModified) | ||
return $"*{FileName}"; | ||
else | ||
return FileName; | ||
} | ||
} | ||
|
||
public DateTime? CreateDateTime | ||
{ | ||
get => _metadata.CreateDateTime; | ||
set | ||
{ | ||
_metadata.CreateDateTime = value; | ||
IsModified = true; | ||
OnPropertyChanged(nameof(CreateDateTime)); | ||
} | ||
} | ||
public DateTime? ModifyImageDateTime | ||
{ | ||
get => _metadata.ModifyImageDateTime; | ||
set | ||
{ | ||
_metadata.ModifyImageDateTime = value; | ||
IsModified = true; | ||
OnPropertyChanged(nameof(ModifyImageDateTime)); | ||
} | ||
} | ||
public DateTime? ModifyFileDateTime | ||
{ | ||
get => _metadata.ModifyFileDateTime; | ||
set | ||
{ | ||
_metadata.ModifyFileDateTime = value; | ||
IsModified = true; | ||
OnPropertyChanged(nameof(ModifyFileDateTime)); | ||
} | ||
} | ||
|
||
public ImageMetadataModel(ImageMetadata metadata) | ||
{ | ||
_metadata = metadata; | ||
} | ||
|
||
public ImageMetadataModel(string filename) | ||
{ | ||
_metadata = new ImageMetadata(filename); | ||
} | ||
|
||
public void SaveFile() | ||
{ | ||
IsModified = false; | ||
_metadata.SaveFile(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace PhotoDateEditor.Utils | ||
{ | ||
public abstract class AbstractPropertyChangedClass : INotifyPropertyChanged | ||
{ | ||
public event PropertyChangedEventHandler PropertyChanged; | ||
protected void OnPropertyChanged(string propertyName) | ||
{ | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.IO; | ||
using System.Windows.Data; | ||
using System.Windows.Media.Imaging; | ||
|
||
namespace PhotoDateEditor.Utils | ||
{ | ||
class PathToImageConverter : IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
BitmapImage result = null; | ||
var path = (string)value; | ||
|
||
if (!string.IsNullOrEmpty(path) && File.Exists(path)) | ||
{ | ||
var image = new BitmapImage(); | ||
|
||
image.BeginInit(); | ||
image.CacheOption = BitmapCacheOption.OnLoad; | ||
image.UriSource = new Uri(path); ; | ||
image.EndInit(); | ||
|
||
result = image; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
throw new NotSupportedException("Two way conversion is not supported!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using PhotoDateEditor.Image; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Input; | ||
|
||
namespace PhotoDateEditor.ViewModels | ||
{ | ||
public interface IImagesViewModel | ||
{ | ||
public ObservableCollection<ImageMetadataModel> Images { get; set; } | ||
public ImageMetadataModel SelectImage { get; set; } | ||
public ICommand AddImagesCommand { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,65 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using PhotoDateEditor.Commands; | ||
using PhotoDateEditor.Image; | ||
using PhotoDateEditor.Utils; | ||
using System.Collections.ObjectModel; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Input; | ||
|
||
namespace PhotoDateEditor.ViewModels | ||
{ | ||
class MainWindowViewModel : INotifyPropertyChanged | ||
class MainWindowViewModel : AbstractPropertyChangedClass, IImagesViewModel | ||
{ | ||
public event PropertyChangedEventHandler PropertyChanged; | ||
protected void OnPropertyChanged(string propertyName) | ||
private ObservableCollection<ImageMetadataModel> _images = new(); | ||
public ObservableCollection<ImageMetadataModel> Images | ||
{ | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
get => _images; | ||
set | ||
{ | ||
_images = value; | ||
OnPropertyChanged(nameof(Images)); | ||
} | ||
} | ||
|
||
private ImageMetadataModel _selectImage; | ||
public ImageMetadataModel SelectImage | ||
{ | ||
get => _selectImage; | ||
set | ||
{ | ||
_selectImage = value; | ||
OnPropertyChanged(nameof(SelectImage)); | ||
} | ||
} | ||
|
||
private ICommand _addImagesCommand; | ||
public ICommand AddImagesCommand | ||
{ | ||
get | ||
{ | ||
return _addImagesCommand ?? | ||
(_addImagesCommand = new RealyCommand(obj => | ||
{ | ||
string[] fileNames = (string[])obj; | ||
|
||
ImageMetadataModel[] images = fileNames.Select(x => new ImageMetadataModel(x)).ToArray(); | ||
foreach (var i in images) | ||
Images.Add(i); | ||
})); | ||
} | ||
} | ||
|
||
private ICommand _saveCommand; | ||
public ICommand SaveCommand | ||
{ | ||
get | ||
{ | ||
return _saveCommand ?? | ||
(_saveCommand = new RealyCommand(obj => | ||
{ | ||
SelectImage.SaveFile(); | ||
}, obj => SelectImage != null)); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.