131 lines
3.8 KiB
C#
131 lines
3.8 KiB
C#
|
using System.Collections.ObjectModel;
|
||
|
using Eto.Forms;
|
||
|
using SixLabors.ImageSharp;
|
||
|
using SixLabors.ImageSharp.PixelFormats;
|
||
|
using TimelapseApi;
|
||
|
namespace Timelapse.Desktop;
|
||
|
internal class ExportWindow : Dialog
|
||
|
{
|
||
|
public class Export
|
||
|
{
|
||
|
public Export(string text)
|
||
|
{
|
||
|
Text=text;
|
||
|
}
|
||
|
|
||
|
public string Text {get;set;}
|
||
|
public override string ToString()
|
||
|
{
|
||
|
return Text;
|
||
|
}
|
||
|
}
|
||
|
public class Share
|
||
|
{
|
||
|
public Share(string text,Func<Window,string,Task> show)
|
||
|
{
|
||
|
ShowDialog = show;
|
||
|
Text = text;
|
||
|
}
|
||
|
public Func<Window,string,Task> ShowDialog {get;set;}
|
||
|
public string Text {get;set;}
|
||
|
public override string ToString()
|
||
|
{
|
||
|
return Text.ToString();
|
||
|
}
|
||
|
}
|
||
|
public ExportWindow(Form main,Api instance,GuiData guiData,bool share)
|
||
|
{
|
||
|
Title=share ? "Export and Share" : "Export";
|
||
|
DynamicLayout lyt=new DynamicLayout();
|
||
|
lyt.BeginHorizontal();
|
||
|
lyt.BeginVertical();
|
||
|
Button acceptBtn =new Button()
|
||
|
{
|
||
|
Text=share ? "Export and Share" : "Export",
|
||
|
Enabled=false
|
||
|
};
|
||
|
ObservableCollection<Share> shares=new ObservableCollection<Share>();
|
||
|
|
||
|
List<Export> exports=new List<Export>();
|
||
|
DropDown export = new DropDown();
|
||
|
lyt.Add(export,true);
|
||
|
DropDown shareDD = new DropDown() {Enabled=false,DataStore=shares};
|
||
|
if(share)
|
||
|
{
|
||
|
lyt.EndBeginHorizontal();
|
||
|
lyt.Add(shareDD);
|
||
|
}
|
||
|
lyt.EndHorizontal();
|
||
|
|
||
|
lyt.EndBeginVertical();
|
||
|
lyt.AddSpace(true,true);
|
||
|
lyt.BeginHorizontal();
|
||
|
lyt.AddSpace(true);
|
||
|
lyt.Add(acceptBtn);
|
||
|
lyt.EndHorizontal();
|
||
|
lyt.EndVertical();
|
||
|
|
||
|
this.Content=lyt;
|
||
|
|
||
|
|
||
|
if(guiData.Export != null)
|
||
|
{
|
||
|
foreach(var item in guiData.Export)
|
||
|
{
|
||
|
exports.Add(new Export(item.Text));
|
||
|
}
|
||
|
export.DataStore=exports;
|
||
|
export.SelectedIndexChanged += (sender,e)=>{
|
||
|
int index=export.SelectedIndex;
|
||
|
if(index > -1 && exports.Count > 0)
|
||
|
{
|
||
|
if(share)
|
||
|
{
|
||
|
acceptBtn.Enabled=false;
|
||
|
shareDD.Enabled=true;
|
||
|
shares.Clear();
|
||
|
if(guiData.Share != null)
|
||
|
{
|
||
|
|
||
|
|
||
|
foreach(var item in guiData.Share)
|
||
|
{
|
||
|
var j=new Share(item.Text,item.ShareActionAsync);
|
||
|
shares.Add(j);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}else{
|
||
|
acceptBtn.Enabled=true;
|
||
|
}
|
||
|
} else {
|
||
|
acceptBtn.Enabled=false;
|
||
|
shareDD.Enabled=false;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
|
||
|
shareDD.SelectedIndexChanged+=(sender,e)=>{
|
||
|
int index=shareDD.SelectedIndex;
|
||
|
|
||
|
acceptBtn.Enabled=index > -1 && shares.Count > 0;
|
||
|
|
||
|
};
|
||
|
|
||
|
acceptBtn.Click += async (sender,e)=>{
|
||
|
int pos = export.SelectedIndex;
|
||
|
|
||
|
Func<Window,string,Task>? dlg=null;
|
||
|
if(share)
|
||
|
dlg=shares[shareDD.SelectedIndex].ShowDialog;
|
||
|
|
||
|
var filename= await instance.Export(main,pos);
|
||
|
|
||
|
if(share && dlg != null && !string.IsNullOrWhiteSpace(filename) && File.Exists(filename))
|
||
|
{
|
||
|
await dlg(main,filename);
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
}
|
||
|
}
|