private void CreateInvokeMethods()
{
// Icon.
Controller.UpdateIconEvent += delegate(int icon_frame)
{
if (IsHandleCreated)
{
BeginInvoke((Action)delegate
{
if (icon_frame > -1)
this.trayicon.Icon = animationFrames[icon_frame];
else
this.trayicon.Icon = errorIcon;
});
}
};
// Status item.
Controller.UpdateStatusItemEvent += delegate(string state_text)
{
if (IsHandleCreated)
{
BeginInvoke((Action)delegate
{
stateItem.Text = state_text;
string iconText = Utils.Ellipsis(Properties_Resources.CmisSync + "\n" + state_text, 63);
if (!iconText.Equals(trayicon.Text)) // TODO Useful? http://stackoverflow.com/q/34083778
{
trayicon.Text = iconText;
}
});
}
};
// Menu.
Controller.UpdateMenuEvent += delegate(IconState state)
{
if (IsHandleCreated)
{
BeginInvoke((Action)delegate
{
this.trayicon.Text = Utils.Ellipsis(Properties_Resources.CmisSync + "\n" + Controller.StateText, 63);
});
}
};
// Repo Submenu.
Controller.UpdateSuspendSyncFolderEvent += delegate(string reponame)
{
if (IsHandleCreated)
{
BeginInvoke((Action)delegate
{
ToolStripMenuItem repoitem = (ToolStripMenuItem)this.traymenu.Items["tsmi" + reponame];
ToolStripMenuItem pauseitem = (ToolStripMenuItem)repoitem.DropDownItems.Find("pause", false)[0];
ToolStripMenuItem syncitem = (ToolStripMenuItem)repoitem.DropDownItems.Find("sync", false)[0];
foreach (RepoBase aRepo in Program.Controller.Repositories)
{
if (aRepo.Name == reponame)
{
SetEnabledOrDisabled(pauseitem, syncitem, aRepo.Enabled);
break;
}
}
});
}
};
Program.Controller.AlertNotificationRaised += delegate(string title, string message)
{
if (ConfigManager.CurrentConfig.Notifications)
{
//Only show balloon tips when notifications are on
// SystemSounds.Exclamation.Play(); Disabled because annoying.
//trayicon.ShowBalloonTip(25000, title, message, ToolTipIcon.Error);
//System.Windows.Forms.MessageBox.Show(message, title,
// System.Windows.Forms.MessageBoxButtons.OK,
// System.Windows.Forms.MessageBoxIcon.Error);
}
};
}