Exemplo n.º 1
0
        // ========================================================================
        // Methods

        #region === Methods

        /// <summary>
        ///     Starts the functionality of the plugin.
        /// </summary>
        protected void Launch( )
        {
            if (!DocumentManager.HasDocument)
            {
                return;
            }

            string fileName;

            using (SaveFileDialog dialog = new SaveFileDialog( ))
            {
                dialog.Filter           = Strings.SaveDialogFilter;
                dialog.RestoreDirectory = true;
                if (dialog.ShowDialog( ) == DialogResult.Cancel)
                {
                    return;
                }
                fileName = dialog.FileName;
            }

            PDFExportOptions optionsForm = new PDFExportOptions( );

            if (optionsForm.ShowDialog( ) == DialogResult.Cancel)
            {
                return;
            }
            Padding padding = new Padding(( int )new XUnit(optionsForm.PDFPadding.Left, optionsForm.Unit).Point, ( int )new XUnit(optionsForm.PDFPadding.Top, optionsForm.Unit).Point, ( int )new XUnit(optionsForm.PDFPadding.Right, optionsForm.Unit).Point, ( int )new XUnit(optionsForm.PDFPadding.Bottom, optionsForm.Unit).Point);

            MainForm mainForm = Application.OpenForms.OfType <MainForm>( ).FirstOrDefault( );

            PDFExportProgress.ShowAsync(mainForm);

            PDFExporter exporter = new PDFExporter(fileName, DocumentManager.ActiveDocument, optionsForm.SelectedOnly, padding);

            Application.DoEvents( );
            exporter.Export( );

            // Running the exporter within an extra thread isn't a good idea since
            // the exporter uses GDI+. NClass uses GDI+ also if it has to redraw the
            // diagram. GDI+ can't be used by two threads at the same time.
            //Thread exportThread = new Thread(exporter.Export)
            //                        {
            //                          Name = "PDFExporterThread",
            //                          IsBackground = true
            //                        };
            //exportThread.Start();
            //while (exportThread.IsAlive)
            //{
            //  Application.DoEvents();
            //  exportThread.Join(5);
            //}
            //exportThread.Join();

            PDFExportProgress.CloseAsync( );

            if (exporter.Successful)
            {
                if (new PDFExportFinished( ).ShowDialog(mainForm) == DialogResult.OK)
                {
                    Process.Start(fileName);
                }
            }
        }
Exemplo n.º 2
0
    // ========================================================================
    // Methods

    #region === Methods

    /// <summary>
    /// Starts the functionality of the plugin.
    /// </summary>
    protected void Launch()
    {
      if(!DocumentManager.HasDocument)
      {
        return;
      }

      string fileName;
      using(SaveFileDialog dialog = new SaveFileDialog())
      {
        dialog.Filter = Strings.SaveDialogFilter;
        dialog.RestoreDirectory = true;
        if(dialog.ShowDialog() == DialogResult.Cancel)
        {
          return;
        }
        fileName = dialog.FileName;
      }

      PDFExportOptions optionsForm = new PDFExportOptions();
      if(optionsForm.ShowDialog() == DialogResult.Cancel)
      {
        return;
      }
      Padding padding = new Padding((int)new XUnit(optionsForm.PDFPadding.Left, optionsForm.Unit).Point,
                                    (int)new XUnit(optionsForm.PDFPadding.Top, optionsForm.Unit).Point,
                                    (int)new XUnit(optionsForm.PDFPadding.Right, optionsForm.Unit).Point,
                                    (int)new XUnit(optionsForm.PDFPadding.Bottom, optionsForm.Unit).Point);

      MainForm mainForm = Application.OpenForms.OfType<MainForm>().FirstOrDefault();

      PDFExportProgress.ShowAsync(mainForm);

      PDFExporter exporter = new PDFExporter(fileName, DocumentManager.ActiveDocument, optionsForm.SelectedOnly, padding);
	  Application.DoEvents();
      exporter.Export();

      // Running the exporter within an extra thread isn't a good idea since
      // the exporter uses GDI+. NClass uses GDI+ also if it has to redraw the
      // diagram. GDI+ can't be used by two threads at the same time.
      //Thread exportThread = new Thread(exporter.Export)
      //                        {
      //                          Name = "PDFExporterThread",
      //                          IsBackground = true
      //                        };
      //exportThread.Start();
      //while (exportThread.IsAlive)
      //{
      //  Application.DoEvents();
      //  exportThread.Join(5);
      //}
      //exportThread.Join();

      PDFExportProgress.CloseAsync();

      if(exporter.Successful)
      {
        if(new PDFExportFinished().ShowDialog(mainForm) == DialogResult.OK)
        {
          Process.Start(fileName);
        }
      }
    }