Refactored events
This commit is contained in:
Родитель
2b52529efb
Коммит
fbaa815c1f
|
@ -7,7 +7,8 @@
|
|||
mc:Ignorable="d"
|
||||
Title="MicroStation Tag Explorer" Height="650" Width="1000"
|
||||
WindowStartupLocation="CenterScreen" WindowState="Normal"
|
||||
UseLayoutRounding="True" TextOptions.TextFormattingMode="Display" SnapsToDevicePixels="True">
|
||||
UseLayoutRounding="True" TextOptions.TextFormattingMode="Display" SnapsToDevicePixels="True"
|
||||
PreviewKeyDown="Window_PreviewKeyDown">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
|
@ -17,13 +18,13 @@
|
|||
</Grid.RowDefinitions>
|
||||
<Menu x:Name="MainMenu" Background="Transparent" Grid.Row="0">
|
||||
<MenuItem x:Name="FileMenu" Header="_File">
|
||||
<MenuItem x:Name="FileAddFiles" Header="_Add Files..." Click="FileAddFiles_Click"/>
|
||||
<MenuItem x:Name="FileAddFiles" Header="_Add Files..." InputGestureText="Ctrl+O" Click="FileAddFiles_Click"/>
|
||||
<Separator/>
|
||||
<MenuItem x:Name="FileGetTags" Header="_Get Tags" Click="FileGetTags_Click"/>
|
||||
<MenuItem x:Name="FileGetTags" Header="_Get Tags" InputGestureText="F5" Click="FileGetTags_Click"/>
|
||||
<Separator/>
|
||||
<MenuItem x:Name="FileImportTags" Header="_Import Tags..." Click="FileImportTags_Click"/>
|
||||
<MenuItem x:Name="FileImportTags" Header="_Import Tags..." InputGestureText="Ctrl+I" Click="FileImportTags_Click"/>
|
||||
<Separator/>
|
||||
<MenuItem x:Name="FileExportTags" Header="_Export Tags..." Click="FileExportTags_Click"/>
|
||||
<MenuItem x:Name="FileExportTags" Header="_Export Tags..." InputGestureText="Ctrl+E" Click="FileExportTags_Click"/>
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
<DataGrid x:Name="DataGridFiles"
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using Microsoft.Win32;
|
||||
using MicroStationTagExplorer.Model;
|
||||
using Excel = Microsoft.Office.Interop.Excel;
|
||||
|
@ -11,12 +13,16 @@ namespace MicroStationTagExplorer
|
|||
{
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private volatile bool IsRunning = false;
|
||||
private CancellationTokenSource TokenSource;
|
||||
private CancellationToken Token;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void FileAddFiles_Click(object sender, RoutedEventArgs e)
|
||||
private void AddFiles()
|
||||
{
|
||||
var dlg = new OpenFileDialog
|
||||
{
|
||||
|
@ -45,55 +51,80 @@ namespace MicroStationTagExplorer
|
|||
files.Add(file);
|
||||
}
|
||||
|
||||
DataGridFiles.DataContext = null;
|
||||
DataGridFiles.DataContext = files;
|
||||
}
|
||||
}
|
||||
|
||||
private void FileGetTags_Click(object sender, RoutedEventArgs e)
|
||||
private void GetTags()
|
||||
{
|
||||
if (DataGridFiles.DataContext != null)
|
||||
if (DataGridFiles.DataContext == null)
|
||||
return;
|
||||
|
||||
if (IsRunning == false)
|
||||
{
|
||||
int selectedIndex = DataGridFiles.SelectedIndex;
|
||||
IList<File> files = DataGridFiles.DataContext as IList<File>;
|
||||
if (files != null)
|
||||
{
|
||||
MainMenu.IsEnabled = false;
|
||||
TextBoxStatus.Text = "";
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var dgnFile in files)
|
||||
{
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
TextBoxStatus.Text = System.IO.Path.GetFileName(dgnFile.Path);
|
||||
});
|
||||
Microstation.GetTagData(dgnFile);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine(ex.Message);
|
||||
Debug.WriteLine(ex.StackTrace);
|
||||
}
|
||||
if (files == null)
|
||||
return;
|
||||
|
||||
Dispatcher.Invoke(() =>
|
||||
IsRunning = true;
|
||||
FileGetTags.Header = "S_top";
|
||||
TextBoxStatus.Text = "";
|
||||
TokenSource = new CancellationTokenSource();
|
||||
Token = TokenSource.Token;
|
||||
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
Token.ThrowIfCancellationRequested();
|
||||
try
|
||||
{
|
||||
foreach (var dgnFile in files)
|
||||
{
|
||||
TextBoxStatus.Text = "";
|
||||
MainMenu.IsEnabled = true;
|
||||
});
|
||||
if (Token.IsCancellationRequested)
|
||||
{
|
||||
Token.ThrowIfCancellationRequested();
|
||||
return;
|
||||
}
|
||||
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
TextBoxStatus.Text = System.IO.Path.GetFileName(dgnFile.Path);
|
||||
});
|
||||
|
||||
Microstation.GetTagData(dgnFile);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine(ex.Message);
|
||||
Debug.WriteLine(ex.StackTrace);
|
||||
}
|
||||
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
FileGetTags.Header = "_Get Tags";
|
||||
TextBoxStatus.Text = "";
|
||||
});
|
||||
}
|
||||
|
||||
TokenSource.Dispose();
|
||||
IsRunning = false;
|
||||
}, Token);
|
||||
}
|
||||
else
|
||||
{
|
||||
TokenSource.Cancel();
|
||||
TokenSource.Dispose();
|
||||
FileGetTags.Header = "_Get Tags";
|
||||
TextBoxStatus.Text = "";
|
||||
}
|
||||
}
|
||||
|
||||
private void FileImportTags_Click(object sender, RoutedEventArgs e)
|
||||
private void ImportTags()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void FileExportTags_Click(object sender, RoutedEventArgs e)
|
||||
private void ExportTags()
|
||||
{
|
||||
Excel.Application app = Utilities.CreateObject<Excel.Application>("Excel.Application");
|
||||
app.Visible = true;
|
||||
|
@ -101,5 +132,53 @@ namespace MicroStationTagExplorer
|
|||
Excel.Workbook wb = app.Workbooks.Add();
|
||||
Excel.Worksheet ws = wb.Worksheets.Add();
|
||||
}
|
||||
|
||||
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
bool bNone = Keyboard.Modifiers == ModifierKeys.None;
|
||||
bool bControl = Keyboard.Modifiers == ModifierKeys.Control;
|
||||
if (bNone)
|
||||
{
|
||||
if (e.Key == Key.F5)
|
||||
{
|
||||
GetTags();
|
||||
}
|
||||
}
|
||||
else if (bControl)
|
||||
{
|
||||
if (e.Key == Key.O)
|
||||
{
|
||||
AddFiles();
|
||||
}
|
||||
else if (e.Key == Key.I)
|
||||
{
|
||||
ImportTags();
|
||||
}
|
||||
else if (e.Key == Key.E)
|
||||
{
|
||||
ExportTags();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void FileAddFiles_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
AddFiles();
|
||||
}
|
||||
|
||||
private void FileGetTags_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
GetTags();
|
||||
}
|
||||
|
||||
private void FileImportTags_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ImportTags();
|
||||
}
|
||||
|
||||
private void FileExportTags_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ExportTags();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче