A list of files (pictures) can be searched and shown in listbox
This commit is contained in:
@ -1,6 +1,8 @@
|
|||||||
using ImageHandlingLibrary.InterFaces;
|
using ImageHandlingLibrary.InterFaces;
|
||||||
|
using ImageHandlingLibrary.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -41,5 +43,93 @@ namespace ImageHandlingLibrary
|
|||||||
var output = _registring.GetRegistryRootDir();
|
var output = _registring.GetRegistryRootDir();
|
||||||
return $"Root directory value is {output} OBS Test!!";
|
return $"Root directory value is {output} OBS Test!!";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<LocalPicture> CreateListBoxDataSource(List<FileInfo> fileInfos, string rootCatalog)
|
||||||
|
{
|
||||||
|
|
||||||
|
var outPut = new List<LocalPicture>();
|
||||||
|
|
||||||
|
foreach (var fi in fileInfos)
|
||||||
|
{
|
||||||
|
var bufPicture = new LocalPicture();
|
||||||
|
|
||||||
|
bufPicture.RootPosition = rootCatalog;
|
||||||
|
|
||||||
|
bufPicture.PictureFileName = fi.Name;
|
||||||
|
|
||||||
|
bufPicture.InitialPath = fi.DirectoryName;
|
||||||
|
|
||||||
|
bufPicture.AktImage = Image.FromFile(bufPicture.PictureFullPath);
|
||||||
|
|
||||||
|
bufPicture.AktImWidth = bufPicture.AktImage.Width;
|
||||||
|
bufPicture.AktImHeight = bufPicture.AktImage.Height;
|
||||||
|
|
||||||
|
bufPicture.CreatedDate = TakenDate(bufPicture.AktImage);
|
||||||
|
|
||||||
|
outPut.Add(bufPicture);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return FillupDateGaps(outPut);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string TakenDate(Image aktImage)
|
||||||
|
{
|
||||||
|
string sPropDatTaken = "";
|
||||||
|
for (int i = 0; i < aktImage.PropertyIdList.Length; i++)
|
||||||
|
{
|
||||||
|
if (aktImage.PropertyIdList[i] == 306)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < aktImage.PropertyItems[i].Len; j++)
|
||||||
|
{
|
||||||
|
sPropDatTaken += Convert.ToChar(aktImage.PropertyItems[i].Value[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sPropDatTaken;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<LocalPicture> FillupDateGaps(List<LocalPicture> inPut)
|
||||||
|
{
|
||||||
|
var picReg = new SortedList<string, LocalPicture>();
|
||||||
|
foreach (var pict in inPut)
|
||||||
|
{
|
||||||
|
picReg.Add(pict.PictureFileName, pict);
|
||||||
|
}
|
||||||
|
var tmpPicture = new LocalPicture();
|
||||||
|
tmpPicture.CreatedDate = "";
|
||||||
|
Stack<string> stack = new Stack<string>();
|
||||||
|
var outPut = new List<LocalPicture>();
|
||||||
|
|
||||||
|
foreach (KeyValuePair<string, LocalPicture> lPic in picReg)
|
||||||
|
{
|
||||||
|
if (lPic.Value.CreatedDate == "")
|
||||||
|
{
|
||||||
|
if (tmpPicture.CreatedDate != "")
|
||||||
|
{
|
||||||
|
lPic.Value.CreatedDate = tmpPicture.CreatedDate;
|
||||||
|
lPic.Value.CreatedDateChanged = true;
|
||||||
|
outPut.Add(lPic.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stack.Push(lPic.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tmpPicture = lPic.Value;
|
||||||
|
while (stack.Count > 0)
|
||||||
|
{
|
||||||
|
var picRegKey = stack.Pop();
|
||||||
|
picReg[picRegKey].CreatedDate = tmpPicture.CreatedDate;
|
||||||
|
picReg[picRegKey].CreatedDateChanged = true;
|
||||||
|
outPut.Add(picReg[picRegKey]);
|
||||||
|
}
|
||||||
|
outPut.Add(lPic.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return outPut;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
63
ImageHandlingLibrary/Helpers/Dialogs.cs
Normal file
63
ImageHandlingLibrary/Helpers/Dialogs.cs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.IO;
|
||||||
|
using ImageHandlingLibrary.InterFaces;
|
||||||
|
|
||||||
|
namespace ImageHandlingLibrary.Helpers
|
||||||
|
{
|
||||||
|
public class Dialogs : IDialogs
|
||||||
|
{
|
||||||
|
|
||||||
|
public List<FileInfo> ChooseFiles()
|
||||||
|
{
|
||||||
|
using (OpenFileDialog ofd = new OpenFileDialog())
|
||||||
|
{
|
||||||
|
var outPut = new List<FileInfo>();
|
||||||
|
ofd.Title = "Välj bild-fil!";
|
||||||
|
ofd.InitialDirectory = "C:\\";
|
||||||
|
ofd.Filter = "Picture files (*.jpg)|*.jpg;*.jpeg|All files (*.*)|*.*";
|
||||||
|
ofd.FilterIndex = 1;
|
||||||
|
ofd.RestoreDirectory = true;
|
||||||
|
ofd.Multiselect = true;
|
||||||
|
ofd.ShowDialog();
|
||||||
|
var fnames = ofd.FileNames;
|
||||||
|
if (fnames.Length > 1)
|
||||||
|
{
|
||||||
|
foreach (var fname in fnames)
|
||||||
|
{
|
||||||
|
outPut.Add(new FileInfo(fname));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// string fName = ofd.FileName;
|
||||||
|
// if (fName.Trim() != "")
|
||||||
|
// {
|
||||||
|
// int fNamePos = fName.LastIndexOf(@"\") + 1;
|
||||||
|
// lblFileName.Text = fName.Substring(fNamePos);
|
||||||
|
// lblPath.Text = fName.Substring(0, fNamePos);
|
||||||
|
// listLocalFiles();
|
||||||
|
|
||||||
|
// for (int i = 0; i < lstPicFiles.Items.Count; i++)
|
||||||
|
// {
|
||||||
|
// if (lstPicFiles.Items[i].ToString() == lblFileName.Text)
|
||||||
|
// {
|
||||||
|
// lstPicFiles.SelectedIndex = i;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
//}
|
||||||
|
return outPut;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -32,9 +32,11 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="PresentationCore" />
|
<Reference Include="PresentationCore" />
|
||||||
|
<Reference Include="PresentationFramework" />
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
|
<Reference Include="System.Windows.Forms" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
@ -45,6 +47,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Filing.cs" />
|
<Compile Include="Filing.cs" />
|
||||||
|
<Compile Include="Helpers\Dialogs.cs" />
|
||||||
|
<Compile Include="InterFaces\IDialogs.cs" />
|
||||||
<Compile Include="InterFaces\IFiling.cs" />
|
<Compile Include="InterFaces\IFiling.cs" />
|
||||||
<Compile Include="InterFaces\IRegistring.cs" />
|
<Compile Include="InterFaces\IRegistring.cs" />
|
||||||
<Compile Include="Models\LocalPicture.cs" />
|
<Compile Include="Models\LocalPicture.cs" />
|
||||||
|
|||||||
14
ImageHandlingLibrary/InterFaces/IDialogs.cs
Normal file
14
ImageHandlingLibrary/InterFaces/IDialogs.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ImageHandlingLibrary.InterFaces
|
||||||
|
{
|
||||||
|
public interface IDialogs
|
||||||
|
{
|
||||||
|
List<FileInfo> ChooseFiles();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,8 @@
|
|||||||
using System;
|
using ImageHandlingLibrary.Models;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -11,6 +13,9 @@ namespace ImageHandlingLibrary.InterFaces
|
|||||||
public interface IFiling
|
public interface IFiling
|
||||||
{
|
{
|
||||||
BitmapImage ConvertFromDrawImage(Image _image);
|
BitmapImage ConvertFromDrawImage(Image _image);
|
||||||
|
List<LocalPicture> CreateListBoxDataSource(List<FileInfo> fileInfos, string rootCatalog);
|
||||||
string ShowText();
|
string ShowText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using Caliburn.Micro;
|
using Caliburn.Micro;
|
||||||
using ImageHandlingLibrary;
|
using ImageHandlingLibrary;
|
||||||
|
using ImageHandlingLibrary.Helpers;
|
||||||
using ImageHandlingLibrary.InterFaces;
|
using ImageHandlingLibrary.InterFaces;
|
||||||
using ImageHandlingUI.ViewModels;
|
using ImageHandlingUI.ViewModels;
|
||||||
using System;
|
using System;
|
||||||
@ -33,6 +34,7 @@ namespace ImageHandlingUI
|
|||||||
|
|
||||||
_container
|
_container
|
||||||
.PerRequest<IRegistring, Registring>()
|
.PerRequest<IRegistring, Registring>()
|
||||||
|
.PerRequest<IDialogs, Dialogs>()
|
||||||
.PerRequest<IFiling, Filing>();
|
.PerRequest<IFiling, Filing>();
|
||||||
|
|
||||||
GetType().Assembly.GetTypes()
|
GetType().Assembly.GetTypes()
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using Caliburn.Micro;
|
using Caliburn.Micro;
|
||||||
using ImageHandlingLibrary.InterFaces;
|
using ImageHandlingLibrary.InterFaces;
|
||||||
|
using ImageHandlingLibrary.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
@ -9,6 +10,7 @@ using System.Text;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
|
|
||||||
@ -19,16 +21,22 @@ namespace ImageHandlingUI.ViewModels
|
|||||||
private string _rootCatalog;
|
private string _rootCatalog;
|
||||||
private readonly IRegistring _registring;
|
private readonly IRegistring _registring;
|
||||||
private readonly IFiling _filing;
|
private readonly IFiling _filing;
|
||||||
|
private readonly IDialogs _dialogs;
|
||||||
private string initialFileName;
|
private string initialFileName;
|
||||||
ImageSource _selectedImage = null;
|
ImageSource _selectedImage = null;
|
||||||
|
private List<FileInfo> fileInfos;
|
||||||
|
private bool canChooseFile = true;
|
||||||
|
private BindableCollection<LocalPicture> picList = new BindableCollection<LocalPicture>();
|
||||||
|
|
||||||
public ShellViewModel(IRegistring registring, IFiling filing)
|
|
||||||
|
public ShellViewModel(IRegistring registring, IFiling filing, IDialogs dialogs)
|
||||||
{
|
{
|
||||||
|
|
||||||
initialFileName = @"D:\CsharpDevelop\PictureHandlingProject\pictures\AgueroVillage.JPG";
|
initialFileName = @"D:\CsharpDevelop\PictureHandlingProject\pictures\AgueroVillage.JPG";
|
||||||
_selectedImage = filing.ConvertFromDrawImage(System.Drawing.Image.FromFile(InitialFileName));
|
_selectedImage = filing.ConvertFromDrawImage(System.Drawing.Image.FromFile(InitialFileName));
|
||||||
_registring = registring;
|
_registring = registring;
|
||||||
_filing = filing;
|
_filing = filing;
|
||||||
|
_dialogs = dialogs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -47,7 +55,8 @@ namespace ImageHandlingUI.ViewModels
|
|||||||
|
|
||||||
public string RootCatalog
|
public string RootCatalog
|
||||||
{
|
{
|
||||||
get {
|
get
|
||||||
|
{
|
||||||
_rootCatalog = _registring.GetRegistryRootDir();
|
_rootCatalog = _registring.GetRegistryRootDir();
|
||||||
return _rootCatalog;
|
return _rootCatalog;
|
||||||
}
|
}
|
||||||
@ -57,19 +66,53 @@ namespace ImageHandlingUI.ViewModels
|
|||||||
{
|
{
|
||||||
_registring.SetRegistryValues(value);
|
_registring.SetRegistryValues(value);
|
||||||
}
|
}
|
||||||
_rootCatalog = value; }
|
_rootCatalog = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string _groundPath;
|
private string _groundPath;
|
||||||
|
|
||||||
public string GroundPath
|
public string GroundPath
|
||||||
{
|
{
|
||||||
get {
|
get
|
||||||
|
{
|
||||||
_groundPath = _filing.ShowText();
|
_groundPath = _filing.ShowText();
|
||||||
return _groundPath;
|
return _groundPath;
|
||||||
}
|
}
|
||||||
set { _groundPath = value; }
|
set { _groundPath = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public bool CanChooseFile
|
||||||
|
{
|
||||||
|
get { return canChooseFile; }
|
||||||
|
set { canChooseFile = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void ChooseFile()
|
||||||
|
{
|
||||||
|
fileInfos = _dialogs.ChooseFiles();
|
||||||
|
if (fileInfos.Count > 0)
|
||||||
|
{
|
||||||
|
//Cursor.Current = Cursors.WaitCursor;
|
||||||
|
var localPicList = _filing.CreateListBoxDataSource(fileInfos, _rootCatalog);
|
||||||
|
foreach (var lPicture in localPicList)
|
||||||
|
{
|
||||||
|
picList.Add(lPicture);
|
||||||
|
}
|
||||||
|
NotifyOfPropertyChange(() => PicList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public BindableCollection<LocalPicture> PicList
|
||||||
|
{
|
||||||
|
get { return picList; }
|
||||||
|
set { picList = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -103,8 +103,13 @@
|
|||||||
Grid.Row="6" Grid.Column="1"
|
Grid.Row="6" Grid.Column="1"
|
||||||
Grid.ColumnSpan="2" Margin="3,3,0,3"
|
Grid.ColumnSpan="2" Margin="3,3,0,3"
|
||||||
MinHeight="300" MinWidth="150"
|
MinHeight="300" MinWidth="150"
|
||||||
HorizontalAlignment="Left" Width="150">
|
HorizontalAlignment="Left" Width="150"
|
||||||
|
ItemsSource="{Binding PicList}">
|
||||||
|
<ListBox.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<TextBlock Text="{Binding PictureFileName}"/>
|
||||||
|
</DataTemplate>
|
||||||
|
</ListBox.ItemTemplate>
|
||||||
</ListBox>
|
</ListBox>
|
||||||
|
|
||||||
<!--Row 7-->
|
<!--Row 7-->
|
||||||
|
|||||||
Reference in New Issue
Block a user