void b_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
FrameworkElement fe = sender as FrameworkElement;
FrameworkElement tag = fe.Tag as FrameworkElement;
TabItem panel = tag as TabItem;
string fullpathdatasetname = (panel.Tag as DataSource).FileName;
if (System.Windows.MessageBox.Show("Do you want to close " + fullpathdatasetname + " Dataset?",
"Do you want to close Dataset?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
//Close Dataset in R first
IUnityContainer container = LifetimeService.Instance.Container;
IDataService service = container.Resolve<IDataService>();
IUIController controller = container.Resolve<IUIController>();
DataSource actds = controller.GetActiveDocument();//06Nov2012
if (actds == null)
return;
/////Save Prompt////13Mar2014
bool cancel = false;
string extension = controller.GetActiveDocument().Extension;
string filename = controller.GetActiveDocument().FileName;
if (controller.GetActiveDocument().Changed)//Changes has been done. Do you want to save or Discard
{
System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show("Do you want to save changes?",
"Save Changes?",
System.Windows.Forms.MessageBoxButtons.YesNoCancel,
System.Windows.Forms.MessageBoxIcon.Question);
if (result == System.Windows.Forms.DialogResult.Yes)//save
{
//If filetype=SPSS then save in RDATA format
//For other filetypes data grid can be saved but not the variable grid.
// For saving data grid and var grid only save in RDATA format
if (extension.Trim().Length < 1 || extension.Equals("sav")) //if no extension or if sav file. no extension in case of new dataset created.
{
Microsoft.Win32.SaveFileDialog saveasFileDialog = new Microsoft.Win32.SaveFileDialog();
saveasFileDialog.Filter = "R Obj (*.RData)|*.RData";
bool? output = saveasFileDialog.ShowDialog(System.Windows.Application.Current.MainWindow);
if (output.HasValue && output.Value)
{
service.SaveAs(saveasFileDialog.FileName, controller.GetActiveDocument());// #0
}
}
else
{
service.SaveAs(filename, controller.GetActiveDocument());// #0
}
}
else if (result == System.Windows.Forms.DialogResult.No)//Dont save
{
//Do nothing
}
else // Dont close the dataset/tab
{
cancel = true;
}
}
if (!cancel)
{
//// Dataset Closing in UI //////
service.Close(controller.GetActiveDocument());
// Close the Tab
docGroup.Items.Remove(tag);//OR//closeTab(panel);
////13Feb2013 Also remove related dialogs from sessiondialog list
RemoveSessionDialogs(panel);
}
}
}