146 lines
4.5 KiB
C#
146 lines
4.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace Txt2Bib
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for MainWindow.xaml
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
OutputDir = $@"{Directory.GetCurrentDirectory()}\bibtex";
|
|
Directory.CreateDirectory(OutputDir);
|
|
DropArea.AllowDrop = true;
|
|
InitialDropText = DropArea.Text;
|
|
}
|
|
|
|
private string OutputDir { get; }
|
|
private string InitialDropText { get; }
|
|
|
|
private void Execute()
|
|
{
|
|
if (DropArea.Text == InitialDropText)
|
|
{
|
|
MessageBox.Show("Nessun percorso disponibile...");
|
|
return;
|
|
}
|
|
var txt2bib = new Text2Bib();
|
|
var result = txt2bib.Generate(DropArea.Text);
|
|
Debug.Text = result;
|
|
using var outputFile = new StreamWriter($@"{OutputDir}\output_bibtex.bib");
|
|
outputFile.Write(result);
|
|
}
|
|
|
|
private void DropArea_Drop(object sender, DragEventArgs e)
|
|
{
|
|
// Get data object
|
|
var dataObject = e.Data as DataObject;
|
|
|
|
if (dataObject == null )
|
|
{
|
|
MessageBox.Show("Nessun percorso disponibile...");
|
|
return;
|
|
}
|
|
|
|
// Check for file list
|
|
if (dataObject.ContainsFileDropList())
|
|
{
|
|
// Clear values
|
|
if (DropArea.Text == InitialDropText) DropArea.Text = string.Empty;
|
|
|
|
// Process file names
|
|
var fileNames = dataObject.GetFileDropList();
|
|
var bd = new StringBuilder();
|
|
foreach (var fileName in fileNames)
|
|
{
|
|
bd.Append(fileName + "\n");
|
|
}
|
|
// Set text
|
|
DropArea.Text += bd.ToString();
|
|
}
|
|
}
|
|
|
|
private void DropArea_PreviewDragEnter(object sender, DragEventArgs e)
|
|
{
|
|
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
|
{
|
|
e.Effects = DragDropEffects.Copy;
|
|
}
|
|
else
|
|
{
|
|
e.Effects = DragDropEffects.None;
|
|
}
|
|
}
|
|
|
|
private void DropArea_PreviewDragOver(object sender, DragEventArgs e)
|
|
{
|
|
e.Handled = true;
|
|
}
|
|
|
|
private void GoBtn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
Execute();
|
|
}
|
|
|
|
private void CopyDebug_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
Debug.SelectAll();
|
|
Debug.Copy();
|
|
}
|
|
|
|
private void OpenDestFolderBtn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
System.Diagnostics.Process.Start("explorer.exe", OutputDir);
|
|
}
|
|
|
|
private void ToggleMenu_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (FileMenu.Visibility == Visibility.Collapsed)
|
|
{
|
|
FileMenu.Visibility = Visibility.Visible;
|
|
}
|
|
else
|
|
{
|
|
FileMenu.Visibility = Visibility.Collapsed;
|
|
}
|
|
}
|
|
|
|
private void OpenOutputDir_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
{
|
|
System.Diagnostics.Process.Start("explorer.exe", OutputDir);
|
|
}
|
|
|
|
private void Exit_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
{
|
|
Environment.Exit(0);
|
|
}
|
|
|
|
private void Help_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
{
|
|
MessageBox.Show("Trascinare i file txt da elaborare nella casella in alto e premere 'Esegui'.\n" +
|
|
"Il file BibTeX viene generato in una cartella dedicata, che si può aprire selezionando " +
|
|
"'Apri cartella output' dal menu.", "Help", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
|
|
private void FileMenu_LostMouseFocus(object sender, RoutedEventArgs e)
|
|
{
|
|
FileMenu.Visibility = Visibility.Collapsed;
|
|
}
|
|
|
|
private void About_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
{
|
|
MessageBox.Show($"Txt2Bib version {Assembly.GetExecutingAssembly().GetName().Version}\n" +
|
|
"Powered by Nicopa", "About", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
}
|
|
}
|