Skip to content

Commit

Permalink
add file delete and recycle
Browse files Browse the repository at this point in the history
  • Loading branch information
jarvisniu committed Mar 4, 2016
1 parent 339743a commit d61c6a0
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 40 deletions.
9 changes: 8 additions & 1 deletion Niv.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
<Compile Include="src\com.jarvisniu\ButtonAnimator.cs" />
<Compile Include="src\com.jarvisniu\FPS.cs" />
<Compile Include="src\com.jarvisniu\I18n.cs" />
<Compile Include="src\Recycle.cs" />
<Compile Include="src\RecycleImageInfo.cs" />
<Compile Include="src\Walker.cs" />
<Compile Include="src\ImageInfo.cs" />
<Compile Include="src\Controller.cs" />
Expand Down Expand Up @@ -187,6 +189,11 @@
<ItemGroup>
<Resource Include="res\theme-light\icon-help.png" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Resource Include="res\theme-light\icon-undelete.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="res\theme-dark\icon-undelete.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Binary file modified exe/Niv.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions prop/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
ResourceDictionaryLocation.SourceAssembly
)]

[assembly: AssemblyVersion("0.3.2.0")]
[assembly: AssemblyFileVersion("0.3.2.0")]
[assembly: AssemblyVersion("0.4.0.0")]
[assembly: AssemblyFileVersion("0.4.0.0")]
Binary file added res/theme-dark/icon-undelete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/theme-light/icon-undelete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 86 additions & 0 deletions src/Recycle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Windows;

namespace Niv
{
class Recycle
{
// Folder of recycle
private static string recyclePath = Environment.CurrentDirectory + @"\Recycle\";
private DirectoryInfo di = new DirectoryInfo(recyclePath);

// Id counter for every recycle files.
private int recycleId = 0;

// List of deleted files
private List<RecycleImageInfo> recycleInfos = new List<RecycleImageInfo>();

// Get the image count in recycle list.
public int count
{
get
{
return recycleInfos.Count;
}
}

public Recycle()
{
clean();
}

// Move a image here.
public void recieve(ImageInfo info, int index)
{
// Create the recycle folder if not exists.
di.Refresh();
if (!di.Exists) di.Create();

// Create the info
RecycleImageInfo recycleInfo = new RecycleImageInfo(info, recycleId, index);

// Move the file and rename it.
FileInfo fi = new FileInfo(info.filename);
string newName = recyclePath + recycleId + Path.GetExtension(info.filename);
recycleInfo.newFilename = newName;
fi.MoveTo(newName);

// Record the info
recycleInfos.Add(recycleInfo);

recycleId++;
}

// Move back the last deleted image.
public RecycleImageInfo undeleteLast()
{
return undelete(recycleInfos.Count - 1);
}

// Move a image out of here, return the original index.
public RecycleImageInfo undelete(int index)
{
RecycleImageInfo recycleInfo = recycleInfos[index];

// Move the file back.
FileInfo fi = new FileInfo(recycleInfo.newFilename);
fi.MoveTo(recycleInfo.originalInfo.filename);

recycleInfos.Remove(recycleInfo);

return recycleInfo;
}

// Delete all the files in recycle and the recycle folder.
public void clean()
{
if (di.Exists) di.Delete(true);
}

// EOC
}
}
31 changes: 31 additions & 0 deletions src/RecycleImageInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Niv
{
class RecycleImageInfo
{
// The original ImageInfo, used to undelete it.
public ImageInfo originalInfo;

// The id(filename) in recycle folder.
public int id;

// The original index in the image list. Used to insert it in the original index.
public int originalIndex;

// New filename
public string newFilename;

public RecycleImageInfo(ImageInfo info, int id, int originalIndex)
{
this.originalInfo = info;
this.id = id;
this.originalIndex = originalIndex;
}

// EOC
}
}
6 changes: 6 additions & 0 deletions src/Walker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ public void removeCurrentImageInfo()
if (currentIndex == imageInfos.Count) currentIndex = 0;
}

public void insertImageInfo(int index, ImageInfo info)
{
imageInfos.Insert(index, info);

}

// EOC
}
}
4 changes: 4 additions & 0 deletions src/com.jarvisniu/I18n.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ private static void loadLanguageData()
langData["zh-CN"]["tooltip.delete"] = "删除";
langData["zh-TW"]["tooltip.delete"] = "刪除";

langData["en-US"]["tooltip.undelete"] = "Undo Delete";
langData["zh-CN"]["tooltip.undelete"] = "撤销删除";
langData["zh-TW"]["tooltip.undelete"] = "撤銷刪除";

langData["en-US"]["tooltip.prev-image"] = "Previous";
langData["zh-CN"]["tooltip.prev-image"] = "上一张";
langData["zh-TW"]["tooltip.prev-image"] = "上一張";
Expand Down
15 changes: 9 additions & 6 deletions xaml/NivWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@

</Grid>
<Grid x:Name="toolbar" Margin="0" Background="#BF202020" Height="48" VerticalAlignment="Bottom">
<Border x:Name="btnDelete" BorderBrush="#FF484848" BorderThickness="0" Height="48" VerticalAlignment="Top" HorizontalAlignment="Left" Width="48" Margin="96,0,0,0">
<Image x:Name="imageDelete" Margin="15" Source="/Niv;component/res/theme-dark/icon-delete.png"/>
</Border>
<Border x:Name="btnRotateLeft" BorderBrush="#FF484848" BorderThickness="0" Height="48" VerticalAlignment="Top" HorizontalAlignment="Left" Width="48" Margin="0">
<Image x:Name="imageRotateLeft" Margin="15" Source="/Niv;component/res/theme-dark/icon-rotate-left.png"/>
</Border>
<Border x:Name="btnRotateRight" BorderBrush="#FF484848" BorderThickness="0" Height="48" VerticalAlignment="Top" HorizontalAlignment="Left" Width="48" Margin="48,0,0,0">
<Image x:Name="imageRotateRight" Margin="15" Source="/Niv;component/res/theme-dark/icon-rotate-right.png"/>
</Border>
<Grid Height="48" Margin="150,0" VerticalAlignment="Top" HorizontalAlignment="Center" Width="172">
<Border x:Name="btnPrevImage" BorderBrush="#FF484848" BorderThickness="0" HorizontalAlignment="Left" Height="48" VerticalAlignment="Top" Width="48" Margin="38,0,0,0">
<Border x:Name="btnDelete" BorderBrush="#FF484848" BorderThickness="0" Height="48" VerticalAlignment="Top" HorizontalAlignment="Left" Width="48" Margin="96,0,0,0">
<Image x:Name="imageDelete" Margin="15" Source="/Niv;component/res/theme-dark/icon-delete.png"/>
</Border>
<Border x:Name="btnUndelete" BorderBrush="#FF484848" BorderThickness="0" Height="48" VerticalAlignment="Top" HorizontalAlignment="Left" Width="48" Margin="144,0,0,0">
<Image x:Name="imageUndelete" Margin="15" Source="/Niv;component/res/theme-dark/icon-undelete.png"/>
</Border>
<Grid x:Name="gridSwitch" Height="48" Margin="150,0" VerticalAlignment="Top" HorizontalAlignment="Center" Width="96">
<Border x:Name="btnPrevImage" BorderBrush="#FF484848" BorderThickness="0" HorizontalAlignment="Left" Height="48" VerticalAlignment="Top" Width="48" Margin="0,0,0,0">
<Image x:Name="imagePrev" Margin="15" Source="/Niv;component/res/theme-dark/icon-prev.png"/>
</Border>
<Border x:Name="btnNextImage" BorderBrush="#FF484848" BorderThickness="0" HorizontalAlignment="Left" Height="48" VerticalAlignment="Top" Width="48" Margin="86,0,0,0">
<Border x:Name="btnNextImage" BorderBrush="#FF484848" BorderThickness="0" HorizontalAlignment="Left" Height="48" VerticalAlignment="Top" Width="48" Margin="48,0,0,0">
<Image x:Name="imageNext" Margin="15" Source="/Niv;component/res/theme-dark/icon-next.png"/>
</Border>
</Grid>
Expand Down
Loading

0 comments on commit d61c6a0

Please sign in to comment.