#1587: Updated `ViewHost` after node selection with arrow keys and handled item move...
[hl.git] / sources / HeuristicLab.Core.Views / 3.3 / LogView.cs
blob9b4b11bc93a72e91a77c73ea829ace3d868da469
1 #region License Information
2 /* HeuristicLab
3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
5 * This file is part of HeuristicLab.
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
20 #endregion
22 using System;
23 using System.Linq;
24 using HeuristicLab.Common;
25 using HeuristicLab.MainForm;
27 namespace HeuristicLab.Core.Views {
28 /// <summary>
29 /// Base class for editors of engines.
30 /// </summary>
31 [View("Log View")]
32 [Content(typeof(Log), true)]
33 [Content(typeof(ILog), false)]
34 public partial class LogView : ItemView {
35 /// <summary>
36 /// Gets or sets the current engine.
37 /// </summary>
38 /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="EditorBase"/>.</remarks>
39 public new ILog Content {
40 get { return (ILog)base.Content; }
41 set { base.Content = value; }
44 /// <summary>
45 /// Initializes a new instance of <see cref="EngineBaseEditor"/>.
46 /// </summary>
47 public LogView() {
48 InitializeComponent();
51 /// <summary>
52 /// Removes the event handlers from the underlying <see cref="IEngine"/>.
53 /// </summary>
54 /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
55 protected override void DeregisterContentEvents() {
56 Content.Cleared -= new EventHandler(Content_Cleared);
57 Content.MessageAdded -= new EventHandler<EventArgs<string>>(Content_MessageAdded);
58 base.DeregisterContentEvents();
61 /// <summary>
62 /// Adds event handlers to the underlying <see cref="IEngine"/>.
63 /// </summary>
64 /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
65 protected override void RegisterContentEvents() {
66 base.RegisterContentEvents();
67 Content.Cleared += new EventHandler(Content_Cleared);
68 Content.MessageAdded += new EventHandler<EventArgs<string>>(Content_MessageAdded);
71 /// <summary>
72 /// Updates all controls with the latest data of the model.
73 /// </summary>
74 /// <remarks>Calls <see cref="EditorBase.UpdateControls"/> of base class <see cref="EditorBase"/>.</remarks>
75 protected override void OnContentChanged() {
76 base.OnContentChanged();
77 logTextBox.Clear();
78 if (Content == null) {
79 logTextBox.Enabled = false;
80 } else {
81 logTextBox.Enabled = true;
82 if (Content.Messages.FirstOrDefault() != null)
83 logTextBox.Text = string.Join(Environment.NewLine, Content.Messages.ToArray());
87 protected virtual void Content_MessageAdded(object sender, EventArgs<string> e) {
88 if (InvokeRequired)
89 Invoke(new EventHandler<EventArgs<string>>(Content_MessageAdded), sender, e);
90 else {
91 logTextBox.Text = string.Join(Environment.NewLine, Content.Messages.ToArray());
92 logTextBox.SelectionStart = logTextBox.Text.Length;
93 logTextBox.ScrollToCaret();
97 protected virtual void Content_Cleared(object sender, EventArgs e) {
98 if (InvokeRequired)
99 Invoke(new EventHandler(Content_Cleared), sender, e);
100 else
101 logTextBox.Clear();
104 protected virtual void clearButton_Click(object sender, EventArgs e) {
105 Content.Clear();