private void OnActiveTopicChanged(object sender, EventArgs e) { HelpTopic topic = viewModel.ActiveTopic; if (topic == null) { return; } // ---- lstTopics ---- foreach (HelpTopicViewItem item in lstTopics.Items) { if (item.Topic == topic) { lstTopics.SelectedItem = item; break; } } // ---- Right-hand side panel ---- HtmlFormatter formatter = new EmbeddedHtmlFormatter(); formatter.FixLinks = true; string html = formatter.FormatTopic(topic); string text = TextFormatter.FormatTopic(topic); txtNoFormat.Text = text; webBrowser1.DocumentText = html; txtTopicTitle.Text = HelpTopicViewItem.GetTopicDisplayTitle(topic); if (topic.Source is string) { txtSource.Text = (string)topic.Source; } else if (topic.Source is byte[]) { txtSource.Text = FormatHexData((byte[])topic.Source); } else { txtSource.Text = ""; } // Special handling for commands. if (topic.IsHidden && !string.IsNullOrEmpty(topic.ExecuteCommand)) { if (topic.ExecuteCommand[0] == 'P') { // TODO: parse mark string redirectTarget = topic.ExecuteCommand.Substring(2); if (MessageBox.Show(this, "Redirect to " + redirectTarget + "?", "Redirect", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes) { viewModel.NavigateTo(new HelpUri(redirectTarget)); } } } }
private void lstTopics_SelectedIndexChanged(object sender, EventArgs e) { HelpTopicViewItem item = lstTopics.SelectedItem as HelpTopicViewItem; if (item == null) { return; } HelpTopic topic = item.Topic; viewModel.ActiveTopic = topic; }
private void OnActiveDatabaseChanged(object sender, EventArgs e) { for (int i = 0; i < cbDatabases.Items.Count; i++) { var item = cbDatabases.Items[i] as HelpDatabaseViewItem; if (item.Database == viewModel.ActiveDatabase) { cbDatabases.SelectedIndex = i; break; } } lstTopics.Items.Clear(); lstContexts.Items.Clear(); lstErrors.Items.Clear(); if (viewModel.ActiveDatabase == null) { tabTopics.Text = "Topics"; tabContexts.Text = "Contexts"; tabErrors.Text = "Errors"; return; } lstTopics.Visible = false; int topicIndex = 0; foreach (HelpTopic topic in viewModel.ActiveDatabase.Topics) { HelpTopicViewItem item = new HelpTopicViewItem(topicIndex, topic); lstTopics.Items.Add(item); topicIndex++; } lstTopics.Visible = true; tabTopics.Text = string.Format("Topics ({0})", lstTopics.Items.Count); foreach (string contextString in viewModel.ActiveDatabase.ContextStrings) { lstContexts.Items.Add(contextString); } tabContexts.Text = string.Format("Contexts ({0})", lstContexts.Items.Count); foreach (InvalidTopicDataEventArgs error in viewModel.DeserializationErrors) { if (error.Topic.Database == viewModel.ActiveDatabase) { lstErrors.Items.Add(new HelpTopicErrorViewItem(error)); } } tabErrors.Text = string.Format("Errors ({0})", lstErrors.Items.Count); }