コード例 #1
0
 public /* Interface KGuiControl */ void GuiChartData()
 {
     if (NSThread.IsMain)
     {
         // because of sandboxing, we must use the official Save Dialog to automatically create an exception and allow writing the file?
         var dlg = new NSSavePanel();
         dlg.Title            = "Save CSV File";
         dlg.AllowedFileTypes = new string[] { "csv" };
         dlg.Directory        = MacControls.modelsDirectory;
         if (dlg.RunModal() == 1)
         {
             var path = "";
             try {
                 path = dlg.Url.Path;
                 File.WriteAllText(path, KChartHandler.ToCSV(), System.Text.Encoding.Unicode);
             } catch {
                 var alert = new NSAlert()
                 {
                     AlertStyle      = NSAlertStyle.Critical,
                     MessageText     = "Could not write this file:",
                     InformativeText = path
                 };
                 alert.RunModal();
             }
         }
     }
     else
     {
         _ = BeginInvokeOnMainThreadAsync(() => { GuiChartData(); return(ack); }).Result;
     }
 }
コード例 #2
0
ファイル: WinGui.cs プロジェクト: luca-cardelli/KaemikaXM
 public /* Interface KGuiControl */ void GuiChartData()
 {
     if (!this.InvokeRequired)
     {
         SaveFileDialog saveFileDialog = new SaveFileDialog();
         saveFileDialog.Filter           = "CSV files (*.csv)|*.csv|All files (*.*)|*.*";
         saveFileDialog.InitialDirectory = WinControls.modelsDirectory;
         saveFileDialog.FilterIndex      = 1;
         saveFileDialog.RestoreDirectory = false;
         if (saveFileDialog.ShowDialog() == DialogResult.OK)
         {
             try {
                 File.WriteAllText(saveFileDialog.FileName, KChartHandler.ToCSV(), System.Text.Encoding.Unicode);
             } catch {
                 MessageBox.Show(saveFileDialog.FileName, "Could not write this file:", MessageBoxButtons.OK);
             }
         }
     }
     else
     {
         this.Invoke((Action) delegate { GuiChartData(); });
     }
 }