2024-07-17 00:56:17 +00:00
|
|
|
|
using System;
|
2021-09-07 11:32:24 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
2021-09-21 12:28:52 +00:00
|
|
|
|
using System.Drawing;
|
2024-07-17 00:56:17 +00:00
|
|
|
|
using System.Drawing.Imaging;
|
2021-09-07 11:32:24 +00:00
|
|
|
|
using System.IO;
|
2024-07-17 00:56:17 +00:00
|
|
|
|
using System.IO.Compression;
|
2021-09-07 11:32:24 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
2024-07-17 00:56:17 +00:00
|
|
|
|
using BookmarkManager;
|
|
|
|
|
using BookmarkManager.Models;
|
|
|
|
|
using bzit.bomg.Models;
|
|
|
|
|
using FizzyLauncher.Models;
|
|
|
|
|
using RyzStudio;
|
|
|
|
|
using RyzStudio.Windows.Forms;
|
2024-07-20 17:15:07 +00:00
|
|
|
|
using RyzStudio.Windows.ThemedForms;
|
2024-08-04 12:51:19 +00:00
|
|
|
|
using static RyzStudio.Windows.Forms.BookmarkTreeView;
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
|
|
|
|
namespace FizzyLauncher
|
|
|
|
|
{
|
|
|
|
|
public partial class MainForm : Form
|
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private readonly FileSessionManager _fileSessionManager;
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private bool _isBusy = false;
|
2021-09-09 21:39:23 +00:00
|
|
|
|
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
|
|
|
|
public MainForm()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
this.Text = Application.ProductName;
|
2021-09-21 12:28:52 +00:00
|
|
|
|
|
2024-08-04 01:47:25 +00:00
|
|
|
|
newToolStripMenuItem.Image = RyzStudio.Windows.ThemedForms.DefaultVisualStyle.GetImage("a", Color.Black, 2);
|
|
|
|
|
openToolStripMenuItem.Image = RyzStudio.Windows.ThemedForms.DefaultVisualStyle.GetImage("b", Color.Black, 2);
|
|
|
|
|
saveToolStripMenuItem.Image = RyzStudio.Windows.ThemedForms.DefaultVisualStyle.GetImage("c", Color.Black, 2);
|
|
|
|
|
findToolStripMenuItem.Image = RyzStudio.Windows.ThemedForms.DefaultVisualStyle.GetImage("d", Color.Black, 2);
|
|
|
|
|
optionsToolStripMenuItem.Image = RyzStudio.Windows.ThemedForms.DefaultVisualStyle.GetImage("i", Color.Black, 2);
|
|
|
|
|
viewHelpToolStripMenuItem1.Image = RyzStudio.Windows.ThemedForms.DefaultVisualStyle.GetImage("j", Color.Black, 2);
|
|
|
|
|
//aboutToolStripMenuItem1.Image = RyzStudio.Windows.ThemedForms.DefaultVisualStyle.GetImage("k", Color.Black, 2);
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
_fileSessionManager = new FileSessionManager();
|
|
|
|
|
_fileSessionManager.OpenFileDialog = openFileDialog1;
|
|
|
|
|
_fileSessionManager.SaveFileDialog = saveFileDialog1;
|
|
|
|
|
_fileSessionManager.OnNewing += fileSessionManager_OnNewSession;
|
|
|
|
|
_fileSessionManager.OnLoading += fileSessionManager_OnLoadSession;
|
|
|
|
|
_fileSessionManager.OnSaving += fileSessionManager_OnSaveSession;
|
|
|
|
|
_fileSessionManager.OnClearing += fileSessionManager_OnClearSession;
|
|
|
|
|
_fileSessionManager.OnFilenameChanged += fileSessionManager_OnFilenameChanged;
|
2021-09-21 12:28:52 +00:00
|
|
|
|
|
2021-09-07 11:32:24 +00:00
|
|
|
|
this.AutoScaleMode = AutoScaleMode.None;
|
|
|
|
|
this.StartPosition = FormStartPosition.WindowsDefaultLocation;
|
|
|
|
|
|
2021-09-12 13:40:44 +00:00
|
|
|
|
treeView1.RootContextMenu = rootContextMenu;
|
|
|
|
|
treeView1.FolderContextMenu = folderContextMenu;
|
|
|
|
|
treeView1.PageContextMenu = pageContextMenu;
|
|
|
|
|
treeView1.NodeMouseDoubleClick += treeView1_NodeMouseDoubleClick;
|
|
|
|
|
treeView1.PreviewKeyDown += treeView1_PreviewKeyDown;
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-09 21:39:23 +00:00
|
|
|
|
protected async override void OnShown(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnShown(e);
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
var args = WinApplication.GetCommandLine();
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
string jsonfigFilename = args.Where(x => (x.Key.Equals("o") || x.Key.Equals("open"))).Select(x => x.Value).FirstOrDefault();
|
|
|
|
|
//if (string.IsNullOrWhiteSpace(jsonfigFilename))
|
|
|
|
|
//{
|
|
|
|
|
// jsonfigFilename = Path.ChangeExtension(Application.ExecutablePath, "jsonfig");
|
|
|
|
|
//}
|
2021-09-09 21:39:23 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(jsonfigFilename) && File.Exists(jsonfigFilename))
|
2021-09-29 15:49:09 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
await _fileSessionManager.OpenSession(jsonfigFilename);
|
2021-09-29 15:49:09 +00:00
|
|
|
|
}
|
2024-07-17 00:56:17 +00:00
|
|
|
|
else
|
2021-09-07 16:21:28 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
this.CurrentSession = new AppOptions();
|
2021-09-09 21:39:23 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
InvalidateOptions();
|
2021-09-07 16:21:28 +00:00
|
|
|
|
}
|
2024-07-17 00:56:17 +00:00
|
|
|
|
}
|
2021-09-07 16:21:28 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
protected async override void OnClosing(CancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnClosing(e);
|
2021-09-07 16:21:28 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
await _fileSessionManager.CloseSession();
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
public AppOptions CurrentSession { get; set; } = null;
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
|
|
|
|
public bool IsBusy
|
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
get => _isBusy;
|
2021-09-07 11:32:24 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
treeView1.Enabled = !value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
|
|
|
|
|
private void InvalidateOptions()
|
2021-09-07 11:32:24 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
UIControl.SetTopMost(this, this.CurrentSession.AlwaysOnTop);
|
|
|
|
|
}
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private void menuStrip1_MenuActivate(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
closeToolStripMenuItem.Enabled = (_fileSessionManager.SessionState != FileSessionManager.SessionStateEnum.Close);
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
2024-07-18 16:28:21 +00:00
|
|
|
|
saveToolStripMenuItem.Enabled = (_fileSessionManager.SessionState == FileSessionManager.SessionStateEnum.Open) && treeView1.HasChanged;
|
2024-07-17 00:56:17 +00:00
|
|
|
|
saveAsToolStripMenuItem.Enabled = (_fileSessionManager.SessionState != FileSessionManager.SessionStateEnum.Close);
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
findToolStripMenuItem.Enabled = (_fileSessionManager.SessionState != FileSessionManager.SessionStateEnum.Close);
|
2021-09-07 16:21:28 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
collapseAllToolStripMenuItem.Enabled = (_fileSessionManager.SessionState != FileSessionManager.SessionStateEnum.Close);
|
|
|
|
|
expandAllToolStripMenuItem.Enabled = (_fileSessionManager.SessionState != FileSessionManager.SessionStateEnum.Close);
|
|
|
|
|
alwaysOnTopToolStripMenuItem.Checked = this.CurrentSession?.AlwaysOnTop ?? false;
|
|
|
|
|
|
|
|
|
|
toolStripMenuItem9.Enabled = (_fileSessionManager.SessionState != FileSessionManager.SessionStateEnum.Close);
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
#region Main Menu
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// New
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2021-09-07 16:21:28 +00:00
|
|
|
|
private async void newToolStripMenuItem_Click(object sender, EventArgs e)
|
2021-09-07 11:32:24 +00:00
|
|
|
|
{
|
|
|
|
|
if (this.IsBusy)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
await _fileSessionManager.NewSession();
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Open file
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private async void openToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (this.IsBusy)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
await _fileSessionManager.OpenSession();
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Close
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2021-09-07 16:21:28 +00:00
|
|
|
|
private async void closeToolStripMenuItem_Click(object sender, EventArgs e)
|
2021-09-07 11:32:24 +00:00
|
|
|
|
{
|
|
|
|
|
if (this.IsBusy)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
await _fileSessionManager.CloseSession();
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Save
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private async void saveToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (this.IsBusy)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
await _fileSessionManager.SaveSession();
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Save As
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private async void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (this.IsBusy)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
await _fileSessionManager.SaveAsSession();
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Exit
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (this.IsBusy)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
|
2021-09-07 11:32:24 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Find
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void findToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-07-18 16:28:21 +00:00
|
|
|
|
if (this.IsBusy)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-09-12 14:25:37 +00:00
|
|
|
|
|
2024-07-18 16:28:21 +00:00
|
|
|
|
var form = new FindForm(treeView1);
|
|
|
|
|
form.ShowDialog();
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Expand all
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void expandAllToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
if (this.IsBusy)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_fileSessionManager.SessionState == FileSessionManager.SessionStateEnum.Close)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
|
|
|
|
if (treeView1.SelectedNode == null)
|
|
|
|
|
{
|
|
|
|
|
treeView1.ExpandAll();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
treeView1.SelectedNode.ExpandAll();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Collapse all
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void collapseAllToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
if (this.IsBusy)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_fileSessionManager.SessionState == FileSessionManager.SessionStateEnum.Close)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
|
|
|
|
if (treeView1.SelectedNode == null)
|
|
|
|
|
{
|
|
|
|
|
treeView1.CollapseAll();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
treeView1.SelectedNode.Collapse(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Always on top
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void alwaysOnTopToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
if (this.CurrentSession == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
this.CurrentSession.AlwaysOnTop = !this.CurrentSession.AlwaysOnTop;
|
|
|
|
|
|
|
|
|
|
this.TopMost = this.CurrentSession.AlwaysOnTop;
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-09-30 21:26:17 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Update icons
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void toolStripMenuItem9_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (this.IsBusy)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
var form = new UpdateIconsForm(treeView1);
|
|
|
|
|
form.ShowDialog();
|
2021-09-30 21:26:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-07 11:32:24 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Options
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
|
2021-09-07 11:32:24 +00:00
|
|
|
|
{
|
|
|
|
|
if (this.IsBusy)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
var form = new OptionsForm(this.CurrentSession);
|
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
2021-09-09 21:39:23 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
this.CurrentSession = form.Result;
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
InvalidateOptions();
|
|
|
|
|
}
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// View help
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void viewHelpToolStripMenuItem1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
RyzStudio.Diagnostics.Process.Execute(AppResource.AppHelpURL);
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// About
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void aboutToolStripMenuItem1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
var form = new RyzStudio.Windows.ThemedForms.AboutForm();
|
|
|
|
|
form.ProductURL = AppResource.AppProductURL;
|
|
|
|
|
form.AuthorURL = AppResource.AppAuthorURL;
|
|
|
|
|
form.CompanyURL = AppResource.AppCompanyURL;
|
|
|
|
|
form.ProductCopyrightStartYear = 2012;
|
2024-07-19 20:22:24 +00:00
|
|
|
|
form.ProductLogo = AppResource.icon_64;
|
2024-07-17 00:56:17 +00:00
|
|
|
|
|
|
|
|
|
form.ShowDialog();
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
#endregion
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
#region Context Menu - Root
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
2021-09-12 13:40:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Add page
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void addPageToolStripMenuItem_Click(object sender, EventArgs e)
|
2021-09-09 21:39:23 +00:00
|
|
|
|
{
|
2021-09-12 13:40:44 +00:00
|
|
|
|
if (this.IsBusy)
|
2021-09-09 21:39:23 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
var nodeType = treeView1.GetNodeType();
|
|
|
|
|
if ((nodeType == BookmarkTreeView.NodeType.Root) || (nodeType == BookmarkTreeView.NodeType.Folder))
|
2021-09-28 20:19:34 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
treeView1.AddNode();
|
2021-09-28 20:19:34 +00:00
|
|
|
|
}
|
2021-09-09 21:39:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-15 14:50:53 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Add page (batch)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void toolStripMenuItem11_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (this.IsBusy)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var nodeType = treeView1.GetNodeType();
|
|
|
|
|
if ((nodeType != NodeType.Root) && (nodeType != NodeType.Folder))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var nodePath = treeView1.GetNodePath();
|
|
|
|
|
|
|
|
|
|
var form = new AddBatchPageForm(nodePath);
|
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in form.Result)
|
|
|
|
|
{
|
|
|
|
|
treeView1.AddNode(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-12 13:40:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Add folder
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private void addFolderToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (this.IsBusy)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var nodeType = treeView1.GetNodeType();
|
|
|
|
|
if ((nodeType == BookmarkTreeView.NodeType.Root) || (nodeType == BookmarkTreeView.NodeType.Folder))
|
|
|
|
|
{
|
|
|
|
|
treeView1.AddFolder();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Edit root node
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private void editToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (this.IsBusy)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
treeView1.EditNode();
|
|
|
|
|
}
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sort
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private void sortToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (this.IsBusy)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
treeView1.Sort();
|
|
|
|
|
}
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Context Menu - Folder
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Add page
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private void addPageToolStripMenuItem1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
addPageToolStripMenuItem_Click(sender, e);
|
|
|
|
|
}
|
2021-09-09 21:39:23 +00:00
|
|
|
|
|
2024-09-15 14:50:53 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Add page (batch)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void toolStripMenuItem10_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
toolStripMenuItem11_Click(this, e);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-12 13:40:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Add folder
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private void addFolderToolStripMenuItem1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
addFolderToolStripMenuItem_Click(sender, e);
|
|
|
|
|
}
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Open all pages
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private async void openAllToolStripMenuItem_Click(object sender, EventArgs e)
|
2021-09-09 21:39:23 +00:00
|
|
|
|
{
|
2021-09-12 13:40:44 +00:00
|
|
|
|
if (this.IsBusy)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-09-09 21:39:23 +00:00
|
|
|
|
|
2021-09-12 13:40:44 +00:00
|
|
|
|
if (treeView1.SelectedNode == null)
|
2021-09-09 21:39:23 +00:00
|
|
|
|
{
|
2021-09-12 13:40:44 +00:00
|
|
|
|
return;
|
2021-09-09 21:39:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-12 13:40:44 +00:00
|
|
|
|
if (treeView1.SelectedNode.Nodes.Count <= 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (TreeNode item in treeView1.SelectedNode.Nodes)
|
|
|
|
|
{
|
|
|
|
|
await OpenBookmark(item);
|
|
|
|
|
}
|
2021-09-09 21:39:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-12 13:40:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Edit folder name
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private void editToolStripMenuItem1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
editToolStripMenuItem_Click(sender, e);
|
|
|
|
|
}
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-07-17 00:56:17 +00:00
|
|
|
|
/// Delete folder
|
2021-09-12 13:40:44 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (this.IsBusy)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (MessageBox.Show("Delete?", "Delete?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
treeView1.DeleteNode();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sort children
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private void sortToolStripMenuItem1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
sortToolStripMenuItem_Click(sender, e);
|
|
|
|
|
}
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Move up
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private void moveUpToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (this.IsBusy)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
treeView1.MoveUp();
|
|
|
|
|
}
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Move down
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private void moveDownToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (this.IsBusy)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
treeView1.MoveDown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Context Menu - Bookmark
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Open page
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private async void openToolStripMenuItem1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
await OpenBookmark(treeView1.SelectedNode);
|
|
|
|
|
}
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Edit page
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void editToolStripMenuItem2_Click(object sender, EventArgs e)
|
2021-09-09 21:39:23 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
editToolStripMenuItem_Click(sender, e);
|
2021-09-12 13:40:44 +00:00
|
|
|
|
}
|
2021-09-09 21:39:23 +00:00
|
|
|
|
|
2021-09-12 13:40:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Delete page
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private void deleteToolStripMenuItem1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
deleteToolStripMenuItem_Click(sender, e);
|
|
|
|
|
}
|
2021-09-09 21:39:23 +00:00
|
|
|
|
|
2021-09-12 13:40:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Move up
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private void moveUpToolStripMenuItem1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
moveUpToolStripMenuItem_Click(sender, e);
|
|
|
|
|
}
|
2021-09-09 21:39:23 +00:00
|
|
|
|
|
2021-09-12 13:40:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Move down
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private void moveDownToolStripMenuItem1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
moveDownToolStripMenuItem_Click(sender, e);
|
|
|
|
|
}
|
2021-09-09 21:39:23 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
#endregion
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
2021-09-29 00:58:02 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
#region File Session Manager
|
|
|
|
|
|
|
|
|
|
private async Task<bool> fileSessionManager_OnNewSession(FileSessionManager sender)
|
2021-09-12 13:40:44 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
return await Task.Run(() =>
|
2021-09-12 13:40:44 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
treeView1.Clear("New Session");
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
if (treeView1.Nodes.Count >= 0)
|
|
|
|
|
{
|
|
|
|
|
UIControl.Invoke(treeView1, (x) =>
|
2021-09-09 21:39:23 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
treeView1.Nodes[0].Expand();
|
2021-09-09 21:39:23 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
treeView1.SelectedNode = treeView1.Nodes[0];
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-09-09 21:39:23 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
UIControl.SetFocus(treeView1);
|
2021-11-15 22:58:04 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
return true;
|
|
|
|
|
});
|
2021-09-09 21:39:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private async Task<bool> fileSessionManager_OnLoadSession(FileSessionManager sender, string filename, int formatType)
|
2021-09-29 15:20:46 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
return await Task.Run(async () =>
|
2021-09-29 15:20:46 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
var result = GenericResult.Create();
|
2021-09-29 15:20:46 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
switch (Path.GetExtension(filename?.ToLower()?.Trim() ?? string.Empty))
|
|
|
|
|
{
|
|
|
|
|
case ".json":
|
|
|
|
|
this.CurrentSession = RyzStudio.Text.Json.JsonSerialiser.DeserialiseFile<AppOptions>(filename);
|
2021-09-29 15:20:46 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
if (this.CurrentSession == null)
|
|
|
|
|
{
|
|
|
|
|
this.CurrentSession = LoadR4SaveFile(filename);
|
|
|
|
|
}
|
2021-09-29 15:20:46 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
break;
|
|
|
|
|
case ".jsnx":
|
|
|
|
|
this.CurrentSession = await RyzStudio.IO.Compression.ZFile.ReadFile<AppOptions>(filename, "Document.json");
|
2021-09-29 15:20:46 +00:00
|
|
|
|
|
2024-07-19 21:18:17 +00:00
|
|
|
|
if (this.CurrentSession == null)
|
|
|
|
|
{
|
|
|
|
|
this.CurrentSession = new AppOptions();
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
// Load icons
|
|
|
|
|
this.CurrentSession = await LoadIconsFromZipFile(filename, this.CurrentSession);
|
2021-09-29 15:20:46 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
this.CurrentSession = null;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
if (this.CurrentSession == null)
|
2021-09-07 11:32:24 +00:00
|
|
|
|
{
|
2024-07-20 17:15:07 +00:00
|
|
|
|
ThMessageBox.Show(this, "Unable to read session", "Load session", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2024-07-17 00:56:17 +00:00
|
|
|
|
|
|
|
|
|
return false;
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
2021-09-07 16:21:28 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
if (this.CurrentSession == null)
|
2021-09-07 11:32:24 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
this.CurrentSession = new AppOptions();
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
2021-09-07 16:21:28 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
// Reposition + resize
|
|
|
|
|
if (!this.CurrentSession.StartPosition.IsEmpty)
|
2021-09-07 11:32:24 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
UIControl.SetLocation(this, this.CurrentSession.StartPosition);
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
2024-07-17 00:56:17 +00:00
|
|
|
|
|
|
|
|
|
if (this.CurrentSession.Height > 0)
|
2021-09-07 11:32:24 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
UIControl.SetHeight(this, this.CurrentSession.Height);
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
2021-09-07 16:21:28 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
if (this.CurrentSession.Width > 0)
|
|
|
|
|
{
|
|
|
|
|
UIControl.SetWidth(this, this.CurrentSession.Width);
|
|
|
|
|
}
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
InvalidateOptions();
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
// Load items
|
|
|
|
|
treeView1.Clear("New Session");
|
|
|
|
|
|
|
|
|
|
foreach (var item in this.CurrentSession.Items ?? new List<BookmarkModel>())
|
2021-09-07 11:32:24 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
treeView1.AddNode(item);
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
if (treeView1.Nodes.Count >= 0)
|
2021-09-07 11:32:24 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
UIControl.Invoke(treeView1, (x) =>
|
|
|
|
|
{
|
|
|
|
|
treeView1.Nodes[0].Expand();
|
|
|
|
|
|
|
|
|
|
treeView1.SelectedNode = treeView1.Nodes[0];
|
|
|
|
|
});
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
UIControl.SetFocus(treeView1);
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
return true;
|
|
|
|
|
});
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private async Task<bool> fileSessionManager_OnSaveSession(FileSessionManager sender, string filename, int formatType, bool showNotices)
|
2021-09-29 15:20:46 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(filename))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-09-29 15:20:46 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
return await Task.Run(async () =>
|
2021-09-29 15:20:46 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
if (_isBusy)
|
2021-09-29 15:20:46 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
return false;
|
2021-09-29 15:20:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
_isBusy = true;
|
2021-09-29 15:20:46 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
// update session
|
|
|
|
|
if (this.CurrentSession == null)
|
|
|
|
|
{
|
|
|
|
|
this.CurrentSession = new AppOptions();
|
|
|
|
|
}
|
2021-09-29 15:20:46 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
this.CurrentSession.StartPosition = this.Location;
|
|
|
|
|
this.CurrentSession.Width = this.Width;
|
|
|
|
|
this.CurrentSession.Height = this.Height;
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
var nodeList = treeView1.ToNodeList<BookmarkModel>() ?? new List<KeyValuePair<TreeNode, BookmarkModel>>();
|
2024-07-21 17:44:05 +00:00
|
|
|
|
foreach (var node in nodeList)
|
|
|
|
|
{
|
|
|
|
|
node.Value.Path = treeView1.GetNodePath(node.Key);
|
|
|
|
|
|
|
|
|
|
if (node.Value.Path.Contains('\n'))
|
|
|
|
|
{
|
|
|
|
|
node.Value.Path = node.Value.Path.Substring(0, node.Value.Path.LastIndexOf('\n'));
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
this.CurrentSession.Items = nodeList.Select(x => x.Value).ToList();
|
2021-11-15 23:06:55 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
var result = GenericResult.Create();
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
switch (Path.GetExtension(filename?.ToLower()?.Trim() ?? string.Empty))
|
2021-09-12 13:40:44 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
case ".json":
|
|
|
|
|
case ".jsonfig":
|
|
|
|
|
result = RyzStudio.Text.Json.JsonSerialiser.SerialiseFile(filename, this.CurrentSession);
|
|
|
|
|
break;
|
|
|
|
|
case ".jsnx":
|
|
|
|
|
result = await RyzStudio.IO.Compression.ZFile.WriteFile(filename, "Document.json", this.CurrentSession);
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
if (result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
// Add icons to save file
|
2024-08-04 12:51:19 +00:00
|
|
|
|
var result2 = AddImagesToZipFile(filename, nodeList);
|
2024-07-17 00:56:17 +00:00
|
|
|
|
if (!result2.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
if (showNotices)
|
|
|
|
|
{
|
2024-07-20 17:15:07 +00:00
|
|
|
|
ThMessageBox.Show(this, "Unable to save icons", "Save session", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2024-07-17 00:56:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
result = GenericResult.Fault("Format not supported");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
if (result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
if (showNotices)
|
2021-09-12 13:40:44 +00:00
|
|
|
|
{
|
2024-07-20 17:15:07 +00:00
|
|
|
|
ThMessageBox.Show(this, "Session saved!", "Save session", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
2021-09-12 13:40:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
if (showNotices)
|
2021-09-12 13:40:44 +00:00
|
|
|
|
{
|
2024-07-20 17:15:07 +00:00
|
|
|
|
ThMessageBox.Show(this, result.Message, "Save session");
|
2021-09-12 13:40:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
_isBusy = false;
|
|
|
|
|
|
|
|
|
|
return result.IsSuccess;
|
2021-09-12 13:40:44 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private async Task<bool> fileSessionManager_OnClearSession(FileSessionManager sender)
|
2021-09-29 15:49:09 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
return await Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
UIControl.Clear(treeView1);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-09-29 15:49:09 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private async Task fileSessionManager_OnFilenameChanged(FileSessionManager sender, string filename)
|
|
|
|
|
{
|
|
|
|
|
await Task.Run(() =>
|
2021-09-29 15:49:09 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
switch (sender.SessionState)
|
2021-09-29 15:49:09 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
case FileSessionManager.SessionStateEnum.New:
|
|
|
|
|
UIControl.SetText(this, "New Session - " + Application.ProductName);
|
2021-09-29 15:49:09 +00:00
|
|
|
|
break;
|
2024-07-17 00:56:17 +00:00
|
|
|
|
case FileSessionManager.SessionStateEnum.Open:
|
|
|
|
|
UIControl.SetText(this, Path.GetFileNameWithoutExtension(filename) + " - " + Application.ProductName);
|
|
|
|
|
break;
|
|
|
|
|
case FileSessionManager.SessionStateEnum.Close:
|
|
|
|
|
UIControl.SetText(this, Application.ProductName);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2024-07-18 16:28:21 +00:00
|
|
|
|
|
|
|
|
|
treeView1.HasChanged = false;
|
2024-07-17 00:56:17 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
2021-09-29 15:49:09 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
#endregion
|
2021-09-29 15:49:09 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private async void treeView1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
TreeNode node = treeView1.SelectedNode;
|
|
|
|
|
if (node == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-09-29 15:49:09 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
BookmarkTreeView.NodeType nodeType = treeView1.GetNodeType();
|
2021-09-29 15:49:09 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
switch (e.KeyCode)
|
|
|
|
|
{
|
|
|
|
|
case Keys.Enter:
|
|
|
|
|
await OpenBookmark(node);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2021-09-29 15:49:09 +00:00
|
|
|
|
}
|
2024-07-17 00:56:17 +00:00
|
|
|
|
}
|
2021-09-29 15:49:09 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private async void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
await OpenBookmark(e.Node);
|
2021-09-29 15:49:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private AppOptions LoadR4SaveFile(string filename)
|
|
|
|
|
{
|
|
|
|
|
var session = RyzStudio.Text.Json.JsonSerialiser.DeserialiseFile<List<R4SaveFileModel>>(filename);
|
|
|
|
|
if (session == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = new AppOptions();
|
|
|
|
|
result.Items = new List<BookmarkModel>();
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
foreach (var item in session)
|
|
|
|
|
{
|
|
|
|
|
result.Items.Add(new BookmarkModel()
|
2021-09-07 11:32:24 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
Title = item.SiteName,
|
|
|
|
|
Address = item.SiteAddress,
|
|
|
|
|
Description = item.SiteDescription,
|
|
|
|
|
Notes = item.Notes,
|
|
|
|
|
Path = item.Path
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private async Task<AppOptions> LoadIconsFromZipFile(string filename, AppOptions session)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(filename))
|
|
|
|
|
{
|
|
|
|
|
return session;
|
|
|
|
|
}
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
return await Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
try
|
2021-09-07 11:32:24 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
using (var archive = ZipFile.Open(filename, ZipArchiveMode.Read))
|
2021-09-07 11:32:24 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
foreach (var item in session.Items)
|
|
|
|
|
{
|
|
|
|
|
if (item.Id == Guid.Empty)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var key = "icon\\" + item.Id.ToString() + ".png";
|
|
|
|
|
|
|
|
|
|
var zipEntry = archive.GetEntry(key);
|
|
|
|
|
if (zipEntry == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (Stream entryStream = zipEntry.Open())
|
|
|
|
|
{
|
|
|
|
|
item.Icon = Image.FromStream(entryStream);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-17 00:56:17 +00:00
|
|
|
|
catch (Exception)
|
2021-09-09 21:39:23 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
// do nothing
|
2021-09-09 21:39:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
return session;
|
2021-09-07 11:32:24 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
private async Task OpenBookmark(TreeNode node)
|
2021-09-12 13:40:44 +00:00
|
|
|
|
{
|
|
|
|
|
await Task.Run(() =>
|
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
if (treeView1.GetNodeType(node) != BookmarkTreeView.NodeType.Page)
|
2021-09-12 13:40:44 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
var model = UIControl.GetTag<BookmarkModel>(node);
|
|
|
|
|
if (model == null)
|
2021-09-12 13:40:44 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(model.Address))
|
2021-09-12 13:40:44 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
string cmd = (string.IsNullOrWhiteSpace(CurrentSession.RunCommand) ? model.Address : CurrentSession.RunCommand.Replace("{0}", model.Address));
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
RyzStudio.Diagnostics.Process.Execute(cmd);
|
2021-09-12 13:40:44 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-04 12:51:19 +00:00
|
|
|
|
private GenericResult AddImagesToZipFile(string zipFilename, List<KeyValuePair<TreeNode, BookmarkModel>> items)
|
2021-09-07 11:32:24 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(zipFilename))
|
2021-09-07 11:32:24 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
return GenericResult.Fault("Filename is blank");
|
|
|
|
|
}
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
var path = Path.GetDirectoryName(zipFilename);
|
|
|
|
|
if (!System.IO.Directory.Exists(path))
|
2021-09-12 13:40:44 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
System.IO.Directory.CreateDirectory(path);
|
2021-09-12 13:40:44 +00:00
|
|
|
|
}
|
2024-07-17 00:56:17 +00:00
|
|
|
|
catch (Exception exc)
|
2021-09-12 13:40:44 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
return GenericResult.Fault(exc.Message);
|
2021-09-12 13:40:44 +00:00
|
|
|
|
}
|
2024-07-17 00:56:17 +00:00
|
|
|
|
}
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
var options = RyzStudio.Text.Json.JsonSerialiser.GetPreferredOptions();
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
try
|
2021-09-07 11:32:24 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
using (var archive = ZipFile.Open(zipFilename, ZipArchiveMode.Update))
|
2021-09-07 11:32:24 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
foreach (var item in items)
|
2021-09-07 11:32:24 +00:00
|
|
|
|
{
|
2024-08-04 12:51:19 +00:00
|
|
|
|
var key = "icon\\" + item.Value.Id.ToString() + ".png";
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
var zipEntry = archive.GetEntry(key);
|
|
|
|
|
if (zipEntry != null)
|
|
|
|
|
{
|
|
|
|
|
zipEntry.Delete();
|
|
|
|
|
}
|
2021-09-21 14:27:00 +00:00
|
|
|
|
|
2024-08-04 12:51:19 +00:00
|
|
|
|
if (item.Key.ImageIndex == (int)NodeIcon.Default)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!treeView1.ImageList.Images.ContainsKey(item.Value.Id.ToString()))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var icon = treeView1.ImageList.Images[item.Value.Id.ToString()];
|
|
|
|
|
if (icon == null)
|
2024-07-18 16:28:21 +00:00
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-04 01:47:25 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2024-08-04 12:51:19 +00:00
|
|
|
|
if (icon.Width <= 0)
|
2024-08-04 01:47:25 +00:00
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-04 12:51:19 +00:00
|
|
|
|
catch (Exception)
|
2024-08-04 01:47:25 +00:00
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 00:56:17 +00:00
|
|
|
|
zipEntry = archive.CreateEntry(key, CompressionLevel.SmallestSize);
|
2021-09-21 14:27:00 +00:00
|
|
|
|
|
2024-07-19 21:18:17 +00:00
|
|
|
|
try
|
2024-07-17 00:56:17 +00:00
|
|
|
|
{
|
2024-07-19 21:18:17 +00:00
|
|
|
|
using (Stream entryStream = zipEntry.Open())
|
2024-07-17 00:56:17 +00:00
|
|
|
|
{
|
2024-08-04 12:51:19 +00:00
|
|
|
|
using (Image image = icon)
|
2024-07-19 21:18:17 +00:00
|
|
|
|
{
|
|
|
|
|
image.Save(entryStream, ImageFormat.Png);
|
|
|
|
|
}
|
2024-07-17 00:56:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-19 21:18:17 +00:00
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
2024-08-04 01:47:25 +00:00
|
|
|
|
zipEntry.Delete();
|
|
|
|
|
|
2024-07-19 21:18:17 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-07-17 00:56:17 +00:00
|
|
|
|
}
|
2021-09-21 14:27:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-17 00:56:17 +00:00
|
|
|
|
catch (Exception exc)
|
2021-09-21 14:27:00 +00:00
|
|
|
|
{
|
2024-07-17 00:56:17 +00:00
|
|
|
|
return GenericResult.Fault(exc.Message);
|
2021-09-21 14:27:00 +00:00
|
|
|
|
}
|
2024-07-17 00:56:17 +00:00
|
|
|
|
|
|
|
|
|
return GenericResult.Create();
|
2021-09-21 14:27:00 +00:00
|
|
|
|
}
|
2021-09-12 13:40:44 +00:00
|
|
|
|
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|