Handle empty volume line; output directory
This commit is contained in:
parent
768278c234
commit
f56028b6a2
@ -21,7 +21,7 @@
|
|||||||
</Button.RenderTransform>
|
</Button.RenderTransform>
|
||||||
</Button>
|
</Button>
|
||||||
<Label Content="Debug" HorizontalAlignment="Left" Margin="44,544,0,0" VerticalAlignment="Top" Foreground="White"/>
|
<Label Content="Debug" HorizontalAlignment="Left" Margin="44,544,0,0" VerticalAlignment="Top" Foreground="White"/>
|
||||||
<Button x:Name="CopyDebug" Content="Button" HorizontalAlignment="Left" Margin="111,547,0,0" VerticalAlignment="Top" Foreground="{x:Null}" BorderBrush="{x:Null}" Width="23" Background="White" Click="CopyDebug_Click">
|
<Button x:Name="CopyDebug" ToolTip="Copia contenuto debug negli appunti" Cursor="Hand" Content="Button" HorizontalAlignment="Left" Margin="111,547,0,0" VerticalAlignment="Top" Foreground="{x:Null}" BorderBrush="{x:Null}" Width="23" Background="White" Click="CopyDebug_Click">
|
||||||
<Button.OpacityMask>
|
<Button.OpacityMask>
|
||||||
<ImageBrush ImageSource="/copy-icon.png"/>
|
<ImageBrush ImageSource="/copy-icon.png"/>
|
||||||
</Button.OpacityMask>
|
</Button.OpacityMask>
|
||||||
|
@ -16,9 +16,13 @@ namespace Txt2Bib
|
|||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
OutputDir = $@"{Directory.GetCurrentDirectory()}\bibtex";
|
||||||
|
Directory.CreateDirectory(OutputDir);
|
||||||
DropArea.AllowDrop = true;
|
DropArea.AllowDrop = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string OutputDir { get; }
|
||||||
|
|
||||||
private void DropArea_Drop(object sender, DragEventArgs e)
|
private void DropArea_Drop(object sender, DragEventArgs e)
|
||||||
{
|
{
|
||||||
// Get data object
|
// Get data object
|
||||||
@ -38,7 +42,7 @@ namespace Txt2Bib
|
|||||||
|
|
||||||
// Process file names
|
// Process file names
|
||||||
var fileNames = dataObject.GetFileDropList();
|
var fileNames = dataObject.GetFileDropList();
|
||||||
StringBuilder bd = new StringBuilder();
|
var bd = new StringBuilder();
|
||||||
foreach (var fileName in fileNames)
|
foreach (var fileName in fileNames)
|
||||||
{
|
{
|
||||||
bd.Append(fileName + "\n");
|
bd.Append(fileName + "\n");
|
||||||
@ -70,7 +74,7 @@ namespace Txt2Bib
|
|||||||
var txt2bib = new Text2Bib();
|
var txt2bib = new Text2Bib();
|
||||||
var result = txt2bib.Generate(DropArea.Text);
|
var result = txt2bib.Generate(DropArea.Text);
|
||||||
Debug.Text = result;
|
Debug.Text = result;
|
||||||
using var outputFile = new StreamWriter("output_bibtex.bib");
|
using var outputFile = new StreamWriter($@"{OutputDir}\output_bibtex.bib");
|
||||||
outputFile.Write(result);
|
outputFile.Write(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +86,7 @@ namespace Txt2Bib
|
|||||||
|
|
||||||
private void OpenDestFolderBtn_Click(object sender, RoutedEventArgs e)
|
private void OpenDestFolderBtn_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
|
System.Diagnostics.Process.Start("explorer.exe", OutputDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
20
Records.cs
20
Records.cs
@ -2,6 +2,7 @@
|
|||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Windows.Navigation;
|
||||||
|
|
||||||
namespace Txt2Bib.Records
|
namespace Txt2Bib.Records
|
||||||
{
|
{
|
||||||
@ -29,14 +30,19 @@ namespace Txt2Bib.Records
|
|||||||
a = a.Trim();
|
a = a.Trim();
|
||||||
var s = a.Split(' ');
|
var s = a.Split(' ');
|
||||||
return $"{s[1]} {s[0]}";
|
return $"{s[1]} {s[0]}";
|
||||||
};
|
};
|
||||||
|
var checkVol = (string v) =>
|
||||||
|
{
|
||||||
|
if (v.Length == 0) return byte.MinValue;
|
||||||
|
return v.Split(',').Length == 2 ?
|
||||||
|
byte.Parse(v.Split(',')[0]) :
|
||||||
|
byte.Parse(v);
|
||||||
|
};
|
||||||
Author = temp.Select(a => rearrange(a)).ToArray();
|
Author = temp.Select(a => rearrange(a)).ToArray();
|
||||||
Year = ushort.Parse(entryLines[2]);
|
Year = ushort.Parse(entryLines[2]);
|
||||||
Title = entryLines[3];
|
Title = entryLines[3];
|
||||||
Journal = entryLines[4];
|
Journal = entryLines[4];
|
||||||
Volume = entryLines[5].Split(',').Length == 2 ?
|
Volume = checkVol(entryLines[5]);
|
||||||
byte.Parse(entryLines[5].Split(',')[0]) :
|
|
||||||
byte.Parse(entryLines[5]);
|
|
||||||
Issue = entryLines[5].Split(',').Length == 2 ?
|
Issue = entryLines[5].Split(',').Length == 2 ?
|
||||||
byte.Parse(entryLines[5].Split(',')[1]) : null;
|
byte.Parse(entryLines[5].Split(',')[1]) : null;
|
||||||
FirstPage = ushort.Parse(entryLines[6].Split('-')[0]);
|
FirstPage = ushort.Parse(entryLines[6].Split('-')[0]);
|
||||||
@ -48,12 +54,14 @@ namespace Txt2Bib.Records
|
|||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"@{Type}" + "{" +$"{Author[0][..5]}_{Year},\n" +
|
var volNum = Volume.Equals(byte.MinValue) ? "" : $"\"{Volume}\"";
|
||||||
|
|
||||||
|
return $"@{Type}{{{Author[0][..5]}_{Year},\n" +
|
||||||
$"\tauthor = \"{string.Join(" and ", Author)}\",\n" +
|
$"\tauthor = \"{string.Join(" and ", Author)}\",\n" +
|
||||||
$"\ttitle = {{{Title}}},\n" +
|
$"\ttitle = {{{Title}}},\n" +
|
||||||
$"\tjournal = \"{Journal}\",\n" +
|
$"\tjournal = \"{Journal}\",\n" +
|
||||||
$"\tyear = \"{Year}\",\n" +
|
$"\tyear = \"{Year}\",\n" +
|
||||||
$"\tvolume = \"{Volume}\",\n" +
|
$"\tvolume = \"{volNum}\",\n" +
|
||||||
$"\tnumber = \"{Issue}\",\n" +
|
$"\tnumber = \"{Issue}\",\n" +
|
||||||
$"\tpages = \"{FirstPage}--{LastPage}\",\n" +
|
$"\tpages = \"{FirstPage}--{LastPage}\",\n" +
|
||||||
$"\tdoi = \"{Doi}\",\n" +
|
$"\tdoi = \"{Doi}\",\n" +
|
||||||
|
Loading…
Reference in New Issue
Block a user