pocorall.SCM_Notifier.MainForm.UpdateTray C# (CSharp) Method

UpdateTray() private method

private UpdateTray ( bool newNonUpdatedFoldersChanged ) : void
newNonUpdatedFoldersChanged bool
return void
        private void UpdateTray(bool newNonUpdatedFoldersChanged)
        {
            // Update tray ToolTip

            const int MaxTrayTextLen = 63 - 4;			// "\n...".Length == 4
            string updateTrayText = "";
            string errorTrayText = "";

            foreach (ScmRepository folder in folders)
            {
                if (!folder.Disable && (folder.Status == ScmRepositoryStatus.Error))
                {
                    if (errorTrayText == "")
                        errorTrayText = "Failed:";

                    if ((MaxTrayTextLen - errorTrayText.Length) > (1 + folder.VisiblePath.Length))
                    {
                        errorTrayText += "\n" + folder.VisiblePath;
                    }
                    else if (errorTrayText != "")
                    {
                        errorTrayText += "\n...";
                        break;
                    }
                }
            }

            foreach (ScmRepository folder in folders)
            {
                if ((folder.Status == ScmRepositoryStatus.NeedUpdate) || (folder.Status == ScmRepositoryStatus.NeedUpdate_Modified))
                {
                    if (updateTrayText == "")
                    {
                        if ((MaxTrayTextLen - errorTrayText.Length) > 15)	// "\nUpdate needed:".Length == 15
                            updateTrayText = (errorTrayText != "" ? "\n" : "") + "Update needed:";
                        else
                            break;
                    }

                    if ((MaxTrayTextLen - (updateTrayText.Length + errorTrayText.Length)) > (1 + folder.VisiblePath.Length))
                    {
                        updateTrayText += "\n" + folder.VisiblePath;
                    }
                    else if (updateTrayText != "")
                    {
                        updateTrayText += "\n...";
                        break;
                    }
                }
            }

            notifyIcon.Text = errorTrayText + updateTrayText;

            if (notifyIcon.Text == "")
                notifyIcon.Text = Application.ProductName;

            // Update tray icon

            Icon icon;
            if (folders.ContainsStatus (ScmRepositoryStatus.Error))
            {
                icon = trayIcon_Error;
            }
            else if ((folders.ContainsStatus (ScmRepositoryStatus.NeedUpdate)) ||
                (folders.ContainsStatus (ScmRepositoryStatus.NeedUpdate_Modified)))
            {
                icon = trayIcon_NeedUpdate;
            }
            else if (folders.ContainsStatus (ScmRepositoryStatus.Unknown))
            {
                icon = trayIcon_Unknown;
            }
            else if ((folders.ContainsStatus (ScmRepositoryStatus.UpToDate)) ||
                (folders.ContainsStatus (ScmRepositoryStatus.UpToDate_Modified)))
            {
                icon = trayIcon_UpToDate;
            }
            else
                icon = trayIcon_Unknown;

            if (icon != Icon)
                Icon = notifyIcon.Icon = icon;

            // Update menu

            if ((folders.ContainsStatus (ScmRepositoryStatus.NeedUpdate)
                || folders.ContainsStatus (ScmRepositoryStatus.NeedUpdate_Modified))
                && !Config.ChangeLogBeforeUpdate)
            {
                updateAllToolStripMenuItem.Enabled = true;
                menuItem_UpdateAll.Enabled = true;
            }
            else
            {
                updateAllToolStripMenuItem.Enabled = false;
                menuItem_UpdateAll.Enabled = false;
            }

            if (newNonUpdatedFoldersChanged)
            {
                // Update tray balloon

                if (newNonUpdatedFolders.Count > 0)
                {
                    string[] nonUpdatedFolders = new string[newNonUpdatedFolders.Count];
                    for (int i = 0; i < newNonUpdatedFolders.Count; i++)
                        nonUpdatedFolders[i] = listViewFolders.Items[folders.IndexOf (newNonUpdatedFolders[i])].Text;

                    firstBalloonPath = nonUpdatedFolders[0];

                    string balloonMessage = String.Join (Environment.NewLine, nonUpdatedFolders);
                    notifyIcon.ShowBalloonTip (Config.ShowBalloonInterval, "Update needed", balloonMessage, ToolTipIcon.Info);
                }
            }
        }
MainForm