private MainAppState GetMainAppState() { MainAppState s = new MainAppState(); s.FileLocked = IsFileLocked(null); s.DatabaseOpened = m_docMgr.ActiveDatabase.IsOpen; s.EntriesCount = (s.DatabaseOpened ? m_lvEntries.Items.Count : 0); s.EntriesSelected = (s.DatabaseOpened ? m_lvEntries.SelectedIndices.Count : 0); s.EnableLockCmd = (s.DatabaseOpened || s.FileLocked); s.NoWindowShown = (GlobalWindowManager.WindowCount == 0); s.SelectedEntry = GetSelectedEntry(true); s.CanCopyUserName = ((s.EntriesSelected == 1) && (s.SelectedEntry != null) && !s.SelectedEntry.Strings.GetSafe(PwDefs.UserNameField).IsEmpty); s.CanCopyPassword = ((s.EntriesSelected == 1) && (s.SelectedEntry != null) && !s.SelectedEntry.Strings.GetSafe(PwDefs.PasswordField).IsEmpty); s.CanOpenUrl = ((s.EntriesSelected > 1) || ((s.SelectedEntry != null) && !s.SelectedEntry.Strings.GetSafe(PwDefs.UrlField).IsEmpty)); s.CanPerformAutoType = ((s.EntriesSelected == 1) && (s.SelectedEntry != null) && s.SelectedEntry.GetAutoTypeEnabled()); s.IsOneTan = (s.EntriesSelected == 1); if(s.SelectedEntry != null) s.IsOneTan &= PwDefs.IsTanEntry(s.SelectedEntry); else s.IsOneTan = false; s.LockUnlock = (s.FileLocked ? KPRes.LockMenuUnlock : KPRes.LockMenuLock); return s; }
private MainAppState UpdateUIEntryCtxState(MainAppState? stOpt) { MainAppState s = (stOpt.HasValue ? stOpt.Value : GetMainAppState()); m_ctxEntryAdd.Enabled = s.DatabaseOpened; m_ctxEntryEdit.Enabled = (s.EntriesSelected == 1); m_ctxEntryDelete.Enabled = (s.EntriesSelected > 0); UIUtil.SetEnabledFast((s.EntriesSelected > 0), m_ctxEntryDuplicate, m_ctxEntryMassSetIcon, m_ctxEntrySelectedPrint, m_ctxEntrySelectedExport); UIUtil.SetEnabledFast(((m_pListSorter.Column < 0) && (s.EntriesSelected > 0)), m_ctxEntryMoveToTop, m_ctxEntryMoveToBottom, m_ctxEntryMoveOneDown, m_ctxEntryMoveOneUp); m_ctxEntrySelectAll.Enabled = (s.DatabaseOpened && (s.EntriesCount > 0)); m_ctxEntryClipCopy.Enabled = (s.EntriesSelected > 0); // For the 'Paste' command, see the menu drop-down opening handler UIUtil.SetEnabledFast((s.EntriesSelected > 0), m_ctxEntryColorStandard, m_ctxEntryColorLightRed, m_ctxEntryColorLightGreen, m_ctxEntryColorLightBlue, m_ctxEntryColorLightYellow, m_ctxEntryColorCustom); m_ctxEntrySelectedNewTag.Enabled = (s.EntriesSelected > 0); PwEntry pe = s.SelectedEntry; m_ctxEntryCopyUserName.Enabled = s.CanCopyUserName; m_ctxEntryCopyPassword.Enabled = s.CanCopyPassword; m_ctxEntryUrlOpenInInternal.Enabled = ((s.EntriesSelected == 1) && (pe != null) && !pe.Strings.GetSafe(PwDefs.UrlField).IsEmpty); UIUtil.SetEnabledFast(s.CanOpenUrl, m_ctxEntryOpenUrl, m_ctxEntryCopyUrl); m_ctxEntryPerformAutoType.Enabled = s.CanPerformAutoType; bool bAttach = ((s.EntriesSelected >= 2) || ((pe != null) && (pe.Binaries.UCount > 0))); m_ctxEntrySaveAttachedFiles.Enabled = bAttach; m_ctxEntrySaveAttachedFiles.Visible = bAttach; m_ctxEntryCopyUserName.Visible = !s.IsOneTan; m_ctxEntryUrl.Visible = !s.IsOneTan; m_ctxEntryCopyPassword.Text = (s.IsOneTan ? KPRes.CopyTanMenu : KPRes.CopyPasswordMenu); return s; }
private bool IsCommandTypeInvokable(MainAppState? sContext, AppCommandType t) { MainAppState s = (sContext.HasValue ? sContext.Value : GetMainAppState()); if(t == AppCommandType.Window) return (s.NoWindowShown && !UIIsInteractionBlocked()); if(t == AppCommandType.Lock) return (s.NoWindowShown && !UIIsInteractionBlocked() && s.EnableLockCmd); return false; }
private MainAppState UpdateUIGroupCtxState(MainAppState? stOpt) { MainAppState s = (stOpt.HasValue ? stOpt.Value : GetMainAppState()); PwGroup pg = GetSelectedGroup(); PwGroup pgParent = ((pg != null) ? pg.ParentGroup : null); PwDatabase pd = m_docMgr.ActiveDatabase; if((pd != null) && !pd.IsOpen) pd = null; // Null if closed PwGroup pgRoot = ((pd != null) ? pd.RootGroup : null); bool bChildOps = (s.DatabaseOpened && (pg != pgRoot)); bool bMoveOps = (bChildOps && (pgParent != null) && (pgParent.Groups.UCount > 1)); uint uSubGroups = 0, uSubEntries = 0; if(pg != null) pg.GetCounts(true, out uSubGroups, out uSubEntries); UIUtil.SetEnabledFast(s.DatabaseOpened, m_ctxGroupAdd, m_ctxGroupEdit, m_ctxGroupFind, m_ctxGroupPrint); UIUtil.SetEnabledFast(bChildOps, m_ctxGroupDuplicate, m_ctxGroupDelete); UIUtil.SetEnabledFast((bMoveOps && (pgParent.Groups.IndexOf(pg) >= 1)), m_ctxGroupMoveToTop, m_ctxGroupMoveOneUp); UIUtil.SetEnabledFast((bMoveOps && (pgParent.Groups.IndexOf(pg) < ((int)pgParent.Groups.UCount - 1))), m_ctxGroupMoveOneDown, m_ctxGroupMoveToBottom); m_ctxGroupSort.Enabled = ((pg != null) && (pg.Groups.UCount > 1)); m_ctxGroupSortRec.Enabled = (uSubGroups > 1); bool bShowEmpty = false, bEnableEmpty = false; if((pd != null) && pd.RecycleBinEnabled) { PwGroup pgRecycleBin = pd.RootGroup.FindGroup(pd.RecycleBinUuid, true); bShowEmpty = ((pgRecycleBin != null) && (pg == pgRecycleBin)); if(bShowEmpty) bEnableEmpty = ((pg.Groups.UCount > 0) || (pg.Entries.UCount > 0)); } m_ctxGroupEmpty.Enabled = bEnableEmpty; m_ctxGroupEmpty.Visible = bShowEmpty; return s; }
private MainAppState UpdateUIGroupCtxState(MainAppState? stOpt) { MainAppState s = (stOpt.HasValue ? stOpt.Value : GetMainAppState()); PwGroup pg = GetSelectedGroup(); PwGroup pgParent = ((pg != null) ? pg.ParentGroup : null); PwDatabase pd = m_docMgr.ActiveDatabase; PwGroup pgRoot = ((pd != null) ? pd.RootGroup : null); bool bChildOps = (s.DatabaseOpened && (pg != pgRoot)); bool bMoveOps = (bChildOps && (pgParent != null) && (pgParent.Groups.UCount > 1)); uint uSubGroups = 0, uSubEntries = 0; if(pg != null) pg.GetCounts(true, out uSubGroups, out uSubEntries); m_ctxGroupAdd.Enabled = m_ctxGroupEdit.Enabled = m_ctxGroupFind.Enabled = m_ctxGroupPrint.Enabled = s.DatabaseOpened; m_ctxGroupDelete.Enabled = bChildOps; m_ctxGroupMoveToTop.Enabled = m_ctxGroupMoveOneUp.Enabled = (bMoveOps && (pgParent.Groups.IndexOf(pg) >= 1)); m_ctxGroupMoveOneDown.Enabled = m_ctxGroupMoveToBottom.Enabled = (bMoveOps && (pgParent.Groups.IndexOf(pg) < ((int)pgParent.Groups.UCount - 1))); m_ctxGroupSort.Enabled = ((pg != null) && (pg.Groups.UCount > 1)); m_ctxGroupSortRec.Enabled = (uSubGroups > 1); return s; }