예제 #1
0
        public ChangeTimeView()
        {
            InitializeComponent();

            ChangeTimeViewModel vm = (ChangeTimeViewModel)DataContext;

            vm.PropertyChanged += (_, args) => {
                if (args.PropertyName == nameof(vm.Title))
                {
                    InlineExpression.SetInlineExpression(TitleBlock, vm.Title);
                }
            };
            Loaded += (_, _) => {
                // Window Setup
                _window = Window.GetWindow(this);
                Debug.Assert(_window != null, nameof(_window) + " != null");
                _window.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));

                (double dpiWidthFactor, double dpiHeightFactor) = WindowHelpers.GetDpiFactors(_window);
                _window.CenterOnScreen(dpiWidthFactor, dpiHeightFactor);
            };

            MouseDown += (_, e) => {
                if (e.ChangedButton == MouseButton.Left)
                {
                    DependencyObject scope = FocusManager.GetFocusScope(Root);
                    FocusManager.SetFocusedElement(scope, _window);
                    _window.DragMove();
                }
            };
        }
예제 #2
0
        public AboutControl(MainWindow mainWindow)
        {
            InitializeComponent();

            AboutBox.Text = mainWindow.AssemblyInfo.Description;

            AboutArea.Header       = LanguageLibrary.Language.Default.group_about_area;
            AuthorsGroupBox.Header = LanguageLibrary.Language.Default.group_authors_area;

            var authors = Properties.Resources.Authors;

            var sp = new StackPanel {
                Orientation = Orientation.Vertical
            };

            using (var reader = new StringReader(authors))
            {
                var line = string.Empty;
                do
                {
                    line = reader.ReadLine();
                    if (line != null)
                    {
                        var tb = new TextBlock
                        {
                            Text    = line,
                            Padding = new Thickness(5)
                        };

                        var l = line.Split('|');

                        if (l.Length > 0)
                        {
                            var inlineExpression =
                                string.Format(
                                    "<bold>{0}</bold> | <hyperlink NavigateUri='{1}' Click='Url_Click'>{1}</hyperlink>",
                                    l[0], l[1]);
                            InlineExpression.SetInlineExpression(tb, inlineExpression);
                        }

                        sp.Children.Add(tb);
                    }
                } while (line != null);
            }

            AuthorsGroupBox.Content = sp;
        }
예제 #3
0
        /// <summary>
        /// Sets the body text block.
        /// </summary>
        private void SetBodyTextBlock()
        {
            string body = Article.Article.Body;

            List <bool> whoMatched   = new List <bool>();
            List <bool> whenMatched  = new List <bool>();
            List <bool> whereMatched = new List <bool>();
            bool        whatMatched  = false;
            bool        whyMatched   = false;

            List <string> whoAnnotations   = new List <string>();
            List <string> whenAnnotations  = new List <string>();
            List <string> whereAnnotations = new List <string>();

            List <BodySegment> listBodySegments = new List <BodySegment>();

            // Match annotations to body

            foreach (string who in Article.Annotation.Who.Split(';'))
            {
                if (!string.IsNullOrEmpty(who))
                {
                    bool isFound = body.Contains(who);

                    if (isFound)
                    {
                        whoMatched.Add(true);
                        whoAnnotations.Add(who);

                        int index = body.IndexOf(who);

                        listBodySegments.Add(new BodySegment()
                        {
                            StartIndex = index,
                            EndIndex   = index + who.Length,
                            Label      = "WHO"
                        });
                    }
                    else
                    {
                        whoMatched.Add(false);

                        //Console.WriteLine("\"{0}\" was not found in the article.", who);
                    }
                }
                else
                {
                    break;
                }
            }

            foreach (string when in Article.Annotation.When.Split(';'))
            {
                if (!string.IsNullOrEmpty(when))
                {
                    bool isFound = body.Contains(when);

                    if (isFound)
                    {
                        whenMatched.Add(true);
                        whenAnnotations.Add(when);

                        int index = body.IndexOf(when);

                        listBodySegments.Add(new BodySegment()
                        {
                            StartIndex = index,
                            EndIndex   = index + when.Length,
                            Label      = "WHEN"
                        });
                    }
                    else
                    {
                        whenMatched.Add(false);

                        //Console.WriteLine("\"{0}\" was not found in the article.", when);
                    }
                }
                else
                {
                    break;
                }
            }

            foreach (string where in Article.Annotation.Where.Split(';'))
            {
                if (!string.IsNullOrEmpty(where))
                {
                    bool isFound = body.Contains(where);

                    if (isFound)
                    {
                        whereMatched.Add(true);
                        whereAnnotations.Add(where);

                        int index = body.IndexOf(where);

                        listBodySegments.Add(new BodySegment()
                        {
                            StartIndex = index,
                            EndIndex   = index + where.Length,
                            Label      = "WHERE"
                        });
                    }
                    else
                    {
                        whereMatched.Add(false);

                        //Console.WriteLine("\"{0}\" was not found in the article.", where);
                    }
                }
                else
                {
                    break;
                }
            }

            if (!string.IsNullOrEmpty(Article.Annotation.What))
            {
                string what = Article.Annotation.What;

                what = what.Replace("`` ", "\"");
                what = what.Replace(" ''", "\"");

                whatMatched = body.Contains(what);

                if (whatMatched)
                {
                    int index = body.IndexOf(what);

                    listBodySegments.Add(new BodySegment()
                    {
                        StartIndex = index,
                        EndIndex   = index + what.Length,
                        Label      = "WHAT"
                    });
                }
                else
                {
                    //Console.WriteLine("\"{0}\" was not found in the article.", what);
                }
            }

            if (!string.IsNullOrEmpty(Article.Annotation.Why))
            {
                whyMatched = body.Contains(Article.Annotation.Why);

                if (whyMatched)
                {
                    int index = body.IndexOf(Article.Annotation.Why);

                    listBodySegments.Add(new BodySegment()
                    {
                        StartIndex = index,
                        EndIndex   = index + Article.Annotation.Why.Length,
                        Label      = "WHY"
                    });
                }
                else
                {
                    //Console.WriteLine("\"{0}\" was not found in the article.", Article.Annotation.Why);
                }
            }

            // Check for overlapping ranges

            for (int i = 0; i < listBodySegments.Count; i++)
            {
                for (int j = i + 1; j < listBodySegments.Count; j++)
                {
                    if (listBodySegments[i].Intersects(listBodySegments[j]))
                    {
                        //Console.WriteLine("\"{0}\":{1} intersects with \"{2}\":{3}",
                        //    body.Substring(listBodySegments[i].StartIndex, listBodySegments[i].EndIndex),
                        //    listBodySegments[i].Label,
                        //    body.Substring(listBodySegments[j].StartIndex, listBodySegments[j].EndIndex),
                        //    listBodySegments[j].Label);
                    }
                }
            }

            listBodySegments = listBodySegments.OrderByDescending(s => s.EndIndex).ToList();

            // Set the body text block

            foreach (BodySegment segment in listBodySegments)
            {
                //body = body.Insert(segment.EndIndex, "</bold>");
                //body = body.Insert(segment.StartIndex, "<bold>");
            }

            InlineExpression.SetInlineExpression(BodyTextBlock, body);

            //Console.WriteLine("Who: {0} | When: {1} | Where: {2} | What: {3} | Why: {4}",
            //    whoAnnotations.Count > 0 ? whoMatched.Count(x => x == true) / whoAnnotations.Count : -1,
            //    whenAnnotations.Count > 0 ? whenMatched.Count(x => x == true) / whenAnnotations.Count : -1,
            //    whereAnnotations.Count > 0 ? whereMatched.Count(x => x == true) / whereAnnotations.Count : -1,
            //    whatMatched ? 1 : -1,
            //    whyMatched ? 1 : -1);
        }