Пример #1
0
        private void WebBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
        {
            if (e.Url.AbsolutePath.StartsWith("page(") && e.Url.AbsolutePath.EndsWith(""))
            {
                e.Cancel = true;

                PageSetup.Load();

                int pageNumber = Int32.Parse(e.Url.AbsolutePath.Replace("page(", "").Replace(")", ""));

                preview.Show();
                preview.ShowPreview(design, pageNumber, design.GetPagefeed(pageNumber).AlbumNumber, PrintMode.ToScreen, ScreenMode.MatchScreenHeight);
                preview.Activate();
            }
            else if (e.Url.AbsolutePath.StartsWith("stamp("))
            {
                string id = e.Url.AbsolutePath;

                int index = Int32.Parse(e.Url.AbsolutePath.Replace("stamp(", "").Replace(")", ""));

                DesignEntry stamp = design[index];

                Design stamps = design.GetStampsFromSeries(pageNumber: stamp.PageNumber, number: stamp.Number);

                Imaging imaging = new Imaging();

                imaging.SetImage(
                    series: stamps,
                    stampNumber: stamp.Number,
                    folder: App.GetSetting("ImagesFolder"),
                    country: design.GetCountry(stamp.PageNumber).Text,
                    section: design.GetSection(stamp.PageNumber).Text
                    );

                if (imaging.ShowDialog() == DialogResult.OK)
                {
                    webBrowser.Refresh();

                    while (webBrowser.ReadyState != WebBrowserReadyState.Complete)
                    {
                        Application.DoEvents();
                    }

                    DesignEntry entry = design.FindPageNumber(stamp.PageNumber);

                    HtmlElement element = webBrowser.Document.GetElementById(string.Format("page({0},{1})", entry.PageNumber, entry.AlbumNumber));

                    if (element != null)
                    {
                        element.ScrollIntoView(true);
                    }
                }

                e.Cancel = true;
            }
        }
Пример #2
0
        private void ImmediatePreviewDesign()
        {
            if (!menuRefresh.Checked)
            {
                return;
            }

            try
            {
                int lineNumber = designMaster.PositionToPlace(designMaster.SelectionStart).iLine;

                if (lineNumber == designMaster.LinesCount - 1)
                {
                    return;
                }

                string end;
                string country = null;
                string series  = null;
                string section = null;

                int lineNumberPageFeedThis;
                int lineNumberPageFeedNext;

                int index;

                //StopwatchHelper.Start("Looking for End");
                index = designMaster.SelectionStart;
                if (!string.IsNullOrEmpty(end = FindLineBefore("End", ref index)))
                {
                    return;
                }
                //StopwatchHelper.Stop();

                //StopwatchHelper.Start("Looking for PageFeed");
                index = designMaster.SelectionStart;
                if (string.IsNullOrEmpty(FindLineBefore("PageFeed", ref index)))
                {
                    return;
                }
                //StopwatchHelper.Stop();

                lineNumberPageFeedThis = designMaster.PositionToPlace(index).iLine;

                //StopwatchHelper.Start("Looking for Series");
                if (string.IsNullOrEmpty(series = FindLineBefore("Series=", ref index)))
                {
                    return;
                }
                //StopwatchHelper.Stop();

                //StopwatchHelper.Start("Looking for Part");
                if (string.IsNullOrEmpty(section = FindLineBefore("Part=", ref index)))
                {
                    return;
                }
                //StopwatchHelper.Stop();

                //StopwatchHelper.Start("Looking for Country");
                if (string.IsNullOrEmpty(country = FindLineBefore("Country=", ref index)))
                {
                    return;
                }
                //StopwatchHelper.Stop();

                //StopwatchHelper.Start("Looking for End or PageFeed");
                index = Math.Min(FindLineAfter("PageFeed", designMaster.SelectionStart), FindLineAfter("End", designMaster.SelectionStart));
                //StopwatchHelper.Stop();

                lineNumberPageFeedNext = designMaster.PositionToPlace(index).iLine;

                StringBuilder pageLines = new StringBuilder();

                pageLines.Append("Album | Pdf=Pdf | Version=Version\r\n");
                pageLines.Append(country).Append("\r\n");
                pageLines.Append(section).Append("\r\n");
                pageLines.Append(series).Append("\r\n");

                //StopwatchHelper.Start("Looking for Comments and Sizes");
                for (int line = lineNumberPageFeedThis; line < lineNumberPageFeedNext; line++)
                {
                    string lineText = designMaster.GetLineText(line).Trim();

                    if (!lineText.StartsWith("'"))
                    {
                        if (lineText.Contains("Comment:"))
                        {
                            string commentValue = lineText.Split("Comment:")[1].Split('|')[0].Replace("!", "").Replace("%", "");

                            if (this.comments.ContainsKey(commentValue))
                            {
                                lineText = lineText.Replace("Comment:" + commentValue, this.comments[commentValue]);
                            }
                            else
                            {
                                index = designMaster.SelectionStart;
                                string commentOrigin = FindLineBefore("Comment=" + commentValue, ref index);

                                if (commentOrigin != null)
                                {
                                    string commentContents = commentOrigin.Split("=")[1].Split('|')[0].Trim();

                                    while (commentContents.StartsWith("!") || commentContents.StartsWith("%"))
                                    {
                                        commentContents = commentContents.Substring(1);
                                    }

                                    this.comments.Add(commentValue, commentContents);

                                    lineText = lineText.Replace("Comment:" + commentValue, commentContents);
                                }
                            }
                        }

                        if (lineText.Contains("Size="))
                        {
                            string sizeValue = lineText.Split("Size=")[1].Split('|')[0].Trim();

                            if (!sizesToSkip.Contains(sizeValue))
                            {
                                if (this.sizes.ContainsKey(sizeValue))
                                {
                                    lineText = lineText.Replace("Size=" + sizeValue, this.sizes[sizeValue]);
                                }
                                else
                                {
                                    index = designMaster.SelectionStart;
                                    string sizeOrigin = FindLineBefore("Design=" + sizeValue, ref index);

                                    if (sizeOrigin == null)
                                    {
                                        this.sizesToSkip.Add(sizeValue);
                                    }
                                    else
                                    {
                                        string sizeContents = sizeOrigin.Split("|", joinAgainExceptFirstOne: true)[1].Trim();

                                        this.sizes.Add(sizeValue, sizeContents + " | Width=+4 | Height=+4");

                                        lineText = lineText.Replace("Size=" + sizeValue, this.sizes[sizeValue]);
                                    }
                                }
                            }
                        }
                    }

                    pageLines.Append(lineText).Append("\r\n");
                }
                //StopwatchHelper.Stop();

                pageLines.Append("End\r\n");

                string pageText = pageLines.ToString();

                //StopwatchHelper.Start("Parsing design");
                Design design = (new DesignParser()).Parse(pageText, null, out string error);
                //StopwatchHelper.Stop();

                if (string.IsNullOrEmpty(error))
                {
                    preview.ShowPreview(design, pageNumber: 1, albumNumber: design.GetPagefeed(1).AlbumNumber, printMode: PrintMode.ToScreen, screenMode: ScreenMode.MatchScreenHeight);
                    preview.Show();
                    preview.Activate();

                    this.Focus();
                }
                else
                {
                    //SetError(error);
                }
            }
            catch (Exception e)
            {
                SetError(e.Message);
            }
        }