Files
bluflame/evoke-64k/trunk/Tweaky/Backup/Tweaky/TweakyMainWindow.cs
2026-04-18 22:31:51 +02:00

105 lines
3.5 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Text.RegularExpressions;
using System.Globalization;
namespace Tweaky
{
public partial class TweakyMainWindow : Form
{
private Dictionary<TabPage, TweakyCore> loadedFilesMap = new Dictionary<TabPage, TweakyCore>();
public TweakyMainWindow()
{
InitializeComponent();
if (Properties.Settings.Default.LastOpenedFiles != null)
foreach (var filePath in Properties.Settings.Default.LastOpenedFiles)
this.AddFile(filePath);
}
private void fileTabControl_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Middle)
{
for (int i = fileTabControl.TabPages.Count - 1; i >= 0; i--)
{
if (fileTabControl.GetTabRect(i).Contains(e.Location))
{
var tabPage = (sender as TabControl).TabPages[i];
loadedFilesMap.Remove(tabPage);
(sender as TabControl).TabPages.Remove(tabPage);
if (loadedFilesMap.Count == 0)
{
fileTabControl.Visible = false;
descriptionLabel.Visible = true;
}
break;
}
}
}
}
private void TweakyMainWindow_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
var filePaths = (string[])(e.Data.GetData(DataFormats.FileDrop));
foreach (var fileLoc in filePaths)
this.AddFile(fileLoc);
}
}
private void AddFile(string filePath)
{
if (File.Exists(filePath) && !loadedFilesMap.Values.Any(p => p.FilePath == filePath))
{
var tweakyCore = new TweakyCore(filePath);
if (!tweakyCore.HasWatchableVarEntries)
return;
var tabPage = new TabPage(Path.GetFileName(filePath));
tabPage.AutoSize = true;
tabPage.AutoScroll = true;
fileTabControl.TabPages.Add(tabPage);
tweakyCore.BuildUiElements(tabPage);
loadedFilesMap.Add(tabPage, tweakyCore);
fileTabControl.Visible = true;
descriptionLabel.Visible = false;
}
}
private void TweakyMainWindow_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
private void TweakyMainWindow_FormClosing(object sender, FormClosingEventArgs e)
{
Properties.Settings.Default.LastOpenedFiles = new System.Collections.Specialized.StringCollection();
foreach (var tweakyCore in loadedFilesMap.Values)
{
tweakyCore.WriteFileContent();
Properties.Settings.Default.LastOpenedFiles.Add(tweakyCore.FilePath);
}
Properties.Settings.Default.Save();
}
}
}