261 lines
7.9 KiB
C#
261 lines
7.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using RokettoLaunch.Models.SaveFile;
|
|
using RyzStudio.Windows.Forms;
|
|
using RyzStudio.Windows.ThemedForms;
|
|
using RyzStudio.Windows.ThemedForms.ButtonTextBox;
|
|
|
|
namespace RokettoLaunch
|
|
{
|
|
public class EditFolderForm : Form
|
|
{
|
|
private Label label1;
|
|
private ThClearableTextBox textBox1;
|
|
private ThListBox listBox1;
|
|
private Label label2;
|
|
private RyzStudio.Windows.ThemedForms.Composite.DialogFooter dialogFooter1;
|
|
|
|
|
|
private App4Options.Item result = null;
|
|
|
|
|
|
public EditFolderForm(App4Options.Item model = null)
|
|
{
|
|
InitializeComponent();
|
|
|
|
UISetup.Dialog(this, true);
|
|
|
|
this.Text = (result == null) ? "Add Folder" : "Edit Folder";
|
|
|
|
result = model;
|
|
}
|
|
|
|
protected override void OnShown(EventArgs e)
|
|
{
|
|
base.OnShown(e);
|
|
|
|
textBox1.Text = result?.Title ?? "New Folder";
|
|
|
|
foreach (var item in result?.Items ?? new List<App4Options.Item>())
|
|
{
|
|
if (item.IsGroup)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
listBox1.ListBox.Items.Add(item);
|
|
}
|
|
}
|
|
|
|
private void InitializeComponent()
|
|
{
|
|
textBox1 = new ThClearableTextBox();
|
|
label1 = new Label();
|
|
listBox1 = new ThListBox();
|
|
label2 = new Label();
|
|
dialogFooter1 = new RyzStudio.Windows.ThemedForms.Composite.DialogFooter();
|
|
SuspendLayout();
|
|
//
|
|
// textBox1
|
|
//
|
|
textBox1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
|
textBox1.BackColor = Color.Transparent;
|
|
textBox1.ClearedValue = "";
|
|
textBox1.EnableMovable = false;
|
|
textBox1.Icon = "O";
|
|
textBox1.IconSize = 13F;
|
|
textBox1.Location = new Point(115, 20);
|
|
textBox1.Name = "textBox1";
|
|
textBox1.Size = new Size(260, 32);
|
|
textBox1.TabIndex = 152;
|
|
textBox1.TabStop = false;
|
|
textBox1.UseSystemPasswordChar = false;
|
|
//
|
|
// label1
|
|
//
|
|
label1.AutoSize = true;
|
|
label1.BackColor = Color.Transparent;
|
|
label1.ForeColor = SystemColors.ControlText;
|
|
label1.Location = new Point(10, 20);
|
|
label1.Margin = new Padding(0);
|
|
label1.Name = "label1";
|
|
label1.Padding = new Padding(0, 9, 0, 0);
|
|
label1.Size = new Size(29, 24);
|
|
label1.TabIndex = 153;
|
|
label1.Text = "Title";
|
|
label1.TextAlign = ContentAlignment.MiddleLeft;
|
|
//
|
|
// listBox1
|
|
//
|
|
listBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
|
listBox1.BackColor = Color.Transparent;
|
|
listBox1.EnableMovable = false;
|
|
listBox1.Location = new Point(115, 62);
|
|
listBox1.Name = "listBox1";
|
|
listBox1.Size = new Size(260, 366);
|
|
listBox1.TabIndex = 180;
|
|
listBox1.OnAdd += ListBox_OnAdd;
|
|
listBox1.OnEdit += ListBox_OnEdit;
|
|
listBox1.OnCopy += ListBox_OnCopy;
|
|
listBox1.DragDrop += ListBox_DragDrop;
|
|
listBox1.DragOver += ListBox_DragOver;
|
|
//
|
|
// label2
|
|
//
|
|
label2.AutoSize = true;
|
|
label2.BackColor = Color.Transparent;
|
|
label2.ForeColor = SystemColors.ControlText;
|
|
label2.Location = new Point(10, 62);
|
|
label2.Margin = new Padding(0);
|
|
label2.Name = "label2";
|
|
label2.Padding = new Padding(0, 9, 0, 0);
|
|
label2.Size = new Size(30, 24);
|
|
label2.TabIndex = 181;
|
|
label2.Text = "Tiles";
|
|
label2.TextAlign = ContentAlignment.MiddleLeft;
|
|
//
|
|
// dialogFooter1
|
|
//
|
|
dialogFooter1.BackColor = Color.FromArgb(240, 240, 240);
|
|
dialogFooter1.Dock = DockStyle.Bottom;
|
|
dialogFooter1.EnableMovable = false;
|
|
dialogFooter1.IsBusy = false;
|
|
dialogFooter1.Location = new Point(0, 451);
|
|
dialogFooter1.Name = "dialogFooter1";
|
|
dialogFooter1.Size = new Size(384, 70);
|
|
dialogFooter1.TabIndex = 0;
|
|
dialogFooter1.TabStop = false;
|
|
//
|
|
// EditFolderForm
|
|
//
|
|
BackColor = Color.White;
|
|
ClientSize = new Size(384, 521);
|
|
Controls.Add(dialogFooter1);
|
|
Controls.Add(label2);
|
|
Controls.Add(listBox1);
|
|
Controls.Add(label1);
|
|
Controls.Add(textBox1);
|
|
MinimumSize = new Size(400, 560);
|
|
Name = "EditFolderForm";
|
|
Text = "Add Tile Folder";
|
|
ResumeLayout(false);
|
|
PerformLayout();
|
|
}
|
|
|
|
public App4Options.Item Result
|
|
{
|
|
get
|
|
{
|
|
if (result == null)
|
|
{
|
|
result = new App4Options.Item();
|
|
}
|
|
|
|
result.Title = textBox1.Text?.Trim() ?? string.Empty;
|
|
result.IsGroup = true;
|
|
result.Items = new List<App4Options.Item>();
|
|
|
|
foreach (var item in listBox1.ListBox.Items.OfType<App4Options.Item>())
|
|
{
|
|
if (item.IsGroup)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
result.Items.Add(item);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
private void ListBox_OnAdd(object sender, EventArgs e)
|
|
{
|
|
var form = new EditTileForm();
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
{
|
|
listBox1.ListBox.Items.Add(form.Result);
|
|
};
|
|
}
|
|
|
|
private void ListBox_OnEdit(object sender, EventArgs e)
|
|
{
|
|
if (listBox1.ListBox.Items.Count <= 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var n = listBox1.ListBox.SelectedIndex;
|
|
if (n < 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (listBox1.ListBox.SelectedItem == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var form = new EditTileForm((App4Options.Item)listBox1.ListBox.SelectedItem);
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
{
|
|
listBox1.ListBox.Items.RemoveAt(n);
|
|
listBox1.ListBox.Items.Insert(n, form.Result);
|
|
};
|
|
}
|
|
|
|
private void ListBox_OnCopy(object sender, EventArgs e)
|
|
{
|
|
listBox1.ListBox.CopyItem<App4Options.Item>();
|
|
}
|
|
|
|
private void ListBox_DragOver(object sender, DragEventArgs e)
|
|
{
|
|
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
|
{
|
|
e.Effect = DragDropEffects.Link;
|
|
}
|
|
else
|
|
{
|
|
e.Effect = DragDropEffects.None;
|
|
}
|
|
}
|
|
|
|
private void ListBox_DragDrop(object sender, DragEventArgs e)
|
|
{
|
|
var fileList = e.Data.GetData(DataFormats.FileDrop) as string[];
|
|
if (fileList == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (fileList.Length <= 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (var item in fileList)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(item))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var model = new App4Options.Item()
|
|
{
|
|
TargetPath = item,
|
|
Title = RyzStudio.IO.File.GetName(item)
|
|
};
|
|
|
|
listBox1.ListBox.Items.Add(model);
|
|
}
|
|
}
|
|
|
|
}
|
|
} |