/// <summary> /// Set the enabled status of the given item. If the item is disabled, a /// tooltip string is set to explain why the command is unavailable. /// </summary> private void SetKwsToolsStripItemStatus(ToolStripItem item, KwsAction action, Workspace kws) { Debug.Assert(item != null && kws != null); String denyReason = ""; item.Enabled = true; bool can = m_uiBroker.CanPerformKwsAction(action, kws, ref denyReason); if (can) { item.ForeColor = Color.Black; } else { item.ForeColor = Color.Gray; } item.Tag = can; item.ToolTipText = denyReason; }
/// <summary> /// Return true if the user is allowed to perform the requested action on /// the given user in the given workspace. If the user is not allowed, false is returned and denyReason /// is set with a user-friendly string. /// </summary> public bool CanPerformKwsAction(KwsAction action, Workspace targetKws, ref String denyReason) { String featureNotAvailable = "Feature not available yet."; String cantPerformNow = "This action cannot be performed at the moment."; // FIXME: when implementing this, don't forget to enforce // some limitations when dealing with a public workspace. // We don't want users to rename their public workspace, or to // change it between secure and standard. I don't even know what // that would do. denyReason = ""; switch (action) { case KwsAction.ChangeKwsType: { denyReason = featureNotAvailable; return false; } case KwsAction.ChangeLockFlag: { denyReason = featureNotAvailable; return false; } case KwsAction.ChangeModerationFlag: { denyReason = featureNotAvailable; return false; } case KwsAction.Connect: { if (targetKws.Sm.CanWorkOnline()) return true; else { denyReason = cantPerformNow; return false; } } case KwsAction.DeleteFromServer: { denyReason = featureNotAvailable; return false; } case KwsAction.Disable: { if (targetKws.Sm.CanStop()) return true; else { denyReason = cantPerformNow; return false; } } case KwsAction.Disconnect: { if (targetKws.Sm.CanWorkOffline()) return true; else { denyReason = cantPerformNow; return false; } } case KwsAction.Export: { if( targetKws.Sm.CanExport()) return true; else { denyReason = cantPerformNow; return false; } } case KwsAction.ChangePreserveDeletedFlag: { denyReason = featureNotAvailable; return false; } case KwsAction.Rename: { denyReason = featureNotAvailable; return false; } case KwsAction.Rebuild: { if (targetKws.Sm.CanRebuild()) return true; else { denyReason = cantPerformNow; return false; } } case KwsAction.RemoveFromList: { if (targetKws.Sm.CanDelete()) return true; else { denyReason = cantPerformNow; return false; } } default: { denyReason = "unknown action"; return false; } } }