using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Autodesk.Connectivity.WebServices;
namespace LinkMaestro
{
public partial class SettingsDialog : Form
{
private bool m_isVaultPro;
private Dictionary<LinkFormat, string> m_linkFormatMap = new Dictionary<LinkFormat, string>()
{
{LinkFormat.VaultExplorer, "Vault Explorer"},
{LinkFormat.VaultPath, "Vault Path"},
{LinkFormat.WebClient, "Web Browser"}
};
public Settings Settings
{
get
{
Settings settings = new Settings()
{
FileLinkFormat = ConvertLinkFormat(m_fileLinkComboBox.Text),
FolderLinkFormat = ConvertLinkFormat(m_folderLinkComboBox.Text),
ItemLinkFormat = ConvertLinkFormat(m_itemLinkComboBox.Text),
ChangeOrderLinkFormat = ConvertLinkFormat(m_coLinkComboBox.Text),
MultiWorkgroups = m_multiCheckBox.Checked,
HTMLFormat = m_htmlFormatCheckBox.Checked
};
return settings;
}
set
{
m_fileLinkComboBox.Text = ConvertLinkFormat(value.FileLinkFormat);
m_folderLinkComboBox.Text = ConvertLinkFormat(value.FolderLinkFormat);
m_itemLinkComboBox.Text = ConvertLinkFormat(value.ItemLinkFormat);
m_coLinkComboBox.Text = ConvertLinkFormat(value.ChangeOrderLinkFormat);
m_multiCheckBox.Checked = value.MultiWorkgroups;
m_htmlFormatCheckBox.Checked = value.HTMLFormat;
}
}
public SettingsDialog(Settings settings, bool isVaultPro)
{
InitializeComponent();
m_isVaultPro = isVaultPro;
if (!m_isVaultPro)
{
m_itemLinkComboBox.Enabled = false;
m_coLinkComboBox.Enabled = false;
}
this.Settings = settings;
m_okButton.Select();
m_descriptionLabel.Text = String.Empty;
}
private string ConvertLinkFormat(LinkFormat format)
{
string debug = m_linkFormatMap[format];
return m_linkFormatMap[format];
}
private LinkFormat ConvertLinkFormat(string format)
{
return m_linkFormatMap.First(n => n.Value == format).Key;
}
private void m_okButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
}
private void m_cancelButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
private void m_siteListButton_Click(object sender, EventArgs e)
{
if (!UserUtil.IsAdmin(GlobalManager.WebServices))
{
MessageBox.Show("This command can only be run by administrators");
return;
}
SiteList sitelist = SiteList.Load();
ConfigSiteListDialog dialog = new ConfigSiteListDialog(sitelist);
DialogResult result = dialog.ShowDialog();
if (result != DialogResult.OK)
return;
sitelist = dialog.SiteList;
sitelist.Save();
}
private void m_ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
ComboBox combo = sender as ComboBox;
SetDescriptionText(combo);
}
private void SetDescriptionText(ComboBox combo)
{
if (combo != null)
{
string value = combo.Text;
LinkFormat linkFormat = ConvertLinkFormat(value);
if (linkFormat == LinkFormat.VaultExplorer)
{
m_descriptionLabel.Text =
"A link to an object inside Vault Explorer. Following the " +
"link will cause Vault Explorer to open and navigate to the " +
"object.";
}
else if (linkFormat == LinkFormat.VaultPath)
{
m_descriptionLabel.Text =
"The full Vault path. Technically this is not a link.";
}
else if (linkFormat == LinkFormat.WebClient)
{
m_descriptionLabel.Text =
"A link to a page inside the Vault web client. Following " +
"the link will cause the default web browser to navigate to " +
"the object in the web browser." + Environment.NewLine +
"NOTE: This will link to a specific version, so the link may go out of date over time.";
}
else
{
m_descriptionLabel.Text = String.Empty;
}
}
}
private void m_ComboBox_Enter(object sender, EventArgs e)
{
ComboBox combo = sender as ComboBox;
SetDescriptionText(combo);
}
}
}