Example #1
0
        public AdvancedTextEditor()
        {
            InitializeComponent();
            this.autocompleteMenu1.Show(this.TextEditor, false);
            this.mnuRuler.Checked       = true;
            this.mnuMainToolbar.Checked = true;
            this.mnuFormatting.Checked  = true;

            System.Drawing.Text.InstalledFontCollection col = new System.Drawing.Text.InstalledFontCollection();

            this.cmbFontName.Items.Clear();

            foreach (FontFamily ff in col.Families)
            {
                this.cmbFontName.Items.Add(ff.Name);
            }

            col.Dispose();

            this.TextEditor.Select(0, 0);
            this.Ruler.LeftIndent                  = 0;
            this.Ruler.LeftHangingIndent           = 0;
            this.Ruler.RightIndent                 = 0;
            this.TextEditor.SelectionIndent        = 0;
            this.TextEditor.SelectionRightIndent   = 0;
            this.TextEditor.SelectionHangingIndent = 0;
        }
Example #2
0
        IEnumerable <CompletionResult> IArgumentCompleter.CompleteArgument(string commandName,
                                                                           string parameterName,
                                                                           string wordToComplete,
                                                                           CommandAst commandAst,
                                                                           IDictionary fakeBoundParameters)
        {
            List <CompletionResult> completionResults = new List <CompletionResult>();

            System.Drawing.Text.InstalledFontCollection installedFonts = new System.Drawing.Text.InstalledFontCollection();
            foreach (FontFamily f in installedFonts.Families)
            {
                if (f.Name.Contains(wordToComplete, StringComparison.CurrentCultureIgnoreCase))
                {
                    completionResults.Add(new CompletionResult("'" + f.Name + "'"));
                }
            }
            installedFonts.Dispose();
            return(completionResults);
        }
Example #3
0
        public AdvancedTextEditor()
        {
            InitializeComponent();
            //cause SelectionChange event to occur
            this.TextEditor.Select(0, 0);
            this.Ruler.LeftIndent        = 1;
            this.Ruler.LeftHangingIndent = 1;
            this.Ruler.RightIndent       = 1;

            this.mnuRuler.Checked       = true;
            this.mnuMainToolbar.Checked = true;
            this.mnuFormatting.Checked  = true;

            System.Drawing.Text.InstalledFontCollection col = new System.Drawing.Text.InstalledFontCollection();

            this.cmbFontName.Items.Clear();

            foreach (FontFamily ff in col.Families)
            {
                this.cmbFontName.Items.Add(ff.Name);
            }

            col.Dispose();
        }
Example #4
0
        protected override void BeginProcessing()
        {
            base.BeginProcessing();
            OriginalPrinterName = PrintDocument.PrinterSettings.PrinterName;
            #region Select printer (and set any output file), paper size and orientation
            // The printer name paramter has been validated, if a bad one got in it would cause an error here (don't want to continue with the wrong printer so that's OK).
            // Paper size and font parameters have not been validated yet - check here and use defaults if invalid ones.
            // Could allow a Printer object instead of the name as a string (ditto paper size)
            //but these aren't piped in - it is not asking too much to say "pass the .Name property not the whole object"
            if (null != PrinterName)
            {
                PrintDocument.PrinterSettings.PrinterName = PrinterName;
            }
            string layoutMsg = string.Format("Printing to '{0}'", PrintDocument.PrinterSettings.PrinterName);
            if (null != Destination)
            {
                Destination = GetUnresolvedProviderPathFromPSPath(Destination);
                if (System.IO.File.Exists(Destination))
                {
                    System.IO.File.Delete(Destination);
                }
                PrintDocument.PrinterSettings.PrintToFile   = true;
                PrintDocument.PrinterSettings.PrintFileName = Destination;
                layoutMsg = layoutMsg + " (" + Destination + ")";
            }
            if (null != PaperSize)
            {
                var psize = from ps in PrintDocument.PrinterSettings.PaperSizes.Cast <PaperSize>().ToArray()
                            where string.Equals(ps.Kind.ToString(), PaperSize, StringComparison.CurrentCultureIgnoreCase)
                            select ps;
                if (psize.Count() == 0)
                {
                    WriteWarning(string.Format("{0} doesn't appear to be a valid paper size; will use the default:{1}.", PaperSize, PrintDocument.DefaultPageSettings.PaperSize.Kind));
                }
                else
                {
                    PrintDocument.DefaultPageSettings.PaperSize = psize.First();
                }
            }
            layoutMsg = layoutMsg + string.Format(". Paper is {0}", PrintDocument.DefaultPageSettings.PaperSize.Kind);
            if (LandScape)
            {
                PrintDocument.DefaultPageSettings.Landscape = true;
                WriteVerbose(layoutMsg + " landscape.");
            }
            else
            {
                PrintDocument.DefaultPageSettings.Landscape = false;
                WriteVerbose(layoutMsg + " portrait.");
            }
            #endregion
            #region Set page margins (if any were passed), checking minimum values
            //DefaultPageSettings includes hard margins but they are calculated from the known printable area and ints. Better to work off printable area,
            // area has X,Y of top left corner, width and height.  Min top/left margins set by X & Y;
            // min bottom is  paperHeight - Y - printable height ; min right margin is paperWdith - x - printable width
            //  if margin passed > min we set that, between zero and Min we set the min value, below zero tells us nothing was passed.
            PageSettings DefPS = PrintDocument.DefaultPageSettings;
            if (TopMargin > DefPS.PrintableArea.Y)
            {
                PrintDocument.DefaultPageSettings.Margins.Top = TopMargin;
            }
            else if (TopMargin >= 0)
            {
                PrintDocument.DefaultPageSettings.Margins.Top = Convert.ToInt32(DefPS.PrintableArea.Y);
            }
            if (DefPS.PrintableArea.Y + DefPS.PrintableArea.Height + BottomMargin > DefPS.PaperSize.Height)
            {
                PrintDocument.DefaultPageSettings.Margins.Bottom = BottomMargin;
            }
            else if (BottomMargin >= 0)
            {
                PrintDocument.DefaultPageSettings.Margins.Bottom = DefPS.PaperSize.Height - Convert.ToInt32(DefPS.PrintableArea.Y + DefPS.PrintableArea.Height);
            }
            if (LeftMargin > DefPS.PrintableArea.X)
            {
                PrintDocument.DefaultPageSettings.Margins.Left = LeftMargin;
            }
            else if (LeftMargin >= 0)
            {
                PrintDocument.DefaultPageSettings.Margins.Left = Convert.ToInt32(DefPS.PrintableArea.X);
            }
            if (DefPS.PrintableArea.X + DefPS.PrintableArea.Width + RightMargin > DefPS.PaperSize.Width)
            {
                PrintDocument.DefaultPageSettings.Margins.Right = RightMargin;
            }
            else if (RightMargin >= 0)
            {
                PrintDocument.DefaultPageSettings.Margins.Right = DefPS.PaperSize.Width - Convert.ToInt32(DefPS.PrintableArea.X + DefPS.PrintableArea.Width);
            }
            WriteVerbose(string.Format("Set margins to: top={0}, bottom={1}, left={2}, right={3}.", new object [] { DefPS.Margins.Top, DefPS.Margins.Bottom, DefPS.Margins.Left, DefPS.Margins.Right }));

            float WidthInHundreths  = DefPS.PaperSize.Width - DefPS.Margins.Left - DefPS.Margins.Right;
            float HeightInHundreths = DefPS.PaperSize.Height - DefPS.Margins.Top - DefPS.Margins.Bottom;
            #endregion
            #region Decide print job name - use file name if there is one and construct header/footers
            if (null != ImagePath)
            {
                PrintDocument.DocumentName = ImagePath;
            }
            else if (null != Path)
            {
                PrintDocument.DocumentName = Path;
                if (!String.IsNullOrEmpty(Header))
                {
                    Header = Header.Replace("&[Path]", Path, StringComparison.CurrentCultureIgnoreCase);
                }
                if (!String.IsNullOrEmpty(Footer))
                {
                    Footer = Footer.Replace("&[Path]", Path, StringComparison.CurrentCultureIgnoreCase);
                }
            }
            else
            {
                PrintDocument.DocumentName = "PowerShell Print Job";
            }
            Regex reg = new Regex("\\s*\\|\\s*(lp|Out-Printer).*$");
            if (!String.IsNullOrEmpty(Header))
            {
                Header = Header.Replace("&[Date]", System.DateTime.Now.ToString("d"), StringComparison.CurrentCultureIgnoreCase);
                Header = Header.Replace("&[Time]", System.DateTime.Now.ToString("t"), StringComparison.CurrentCultureIgnoreCase);
                Header = Header.Replace("&[Line]", reg.Replace(MyInvocation.Line, ""), StringComparison.CurrentCultureIgnoreCase);
                Header = Header.Replace("&[HistoryId]", MyInvocation.HistoryId.ToString(), StringComparison.CurrentCultureIgnoreCase);
            }
            if (!String.IsNullOrEmpty(Footer))
            {
                Footer = Footer.Replace("&[Date]", System.DateTime.Now.ToString("d"), StringComparison.CurrentCultureIgnoreCase);
                Footer = Footer.Replace("&[Time]", System.DateTime.Now.ToString("t"), StringComparison.CurrentCultureIgnoreCase);
                Footer = Footer.Replace("&[Line]", reg.Replace(MyInvocation.Line, ""), StringComparison.CurrentCultureIgnoreCase);
                Footer = Footer.Replace("&[HistoryId]", MyInvocation.HistoryId.ToString(), StringComparison.CurrentCultureIgnoreCase);
            }
            #endregion
            #region Check user-specificed font exists, or fall back to lucida console. Determine chars per line.
            System.Drawing.Text.InstalledFontCollection installedFonts = new System.Drawing.Text.InstalledFontCollection();
            var fontq = from font in installedFonts.Families where font.Name == FontName select font;
            if (fontq.Count() == 0)
            {
                WriteWarning(string.Format("'{0}' does not seem to be a valid font. Switching to default.", FontName));
                FontName = "Lucida Console";
            }
            installedFonts.Dispose();
            PrintFont = new Font(FontName, FontSize);

            //Page size is hundreths of an inch. Font is in points @ 120 points : 1 inch, so page width in points is 1.2 x width in Hundredths.
            WidthInChars = (int)Math.Truncate(WidthInHundreths * 1.2 / PrintFont.Size);
            //We won't text wrap if the regex is left empty.
            //Regex will treat end of line as $ and match either on a line of 1 to Width, or that number of chars -1  followed by space(s) or punctuation
            if (!NoTextWrapping)
            {
                string r = "(.{1,XXX}$)|".Replace("XXX", WidthInChars.ToString());
                r             = r + "(.{1,XXX}[\\s:;,.-?!…]+)(?=\\w+)".Replace("XXX", (WidthInChars - 1).ToString());
                WrappingRegEx = new Regex(r, RegexOptions.Multiline);
            }
            WriteVerbose(string.Format("Any text will be printed in {0} {1}-point. Print area is {2:N2} inches tall X {3:N2} inches wide = {4:N0} characters.", new object[] { PrintFont.Name, PrintFont.Size, (HeightInHundreths / 100), (WidthInHundreths / 100), WidthInChars }));
            #endregion
        }