void SetButtonGreyState()
        {
            btnUndo.Enabled = _undoManager != null && _undoManager.HasChanges();
            btnRedo.Enabled = _undoManager != null && _undoManager.CanRedo();

            btnAddVariable.Enabled    = true;
            btnDeleteVariable.Enabled = dgvVariables.SelectedRows.Count > 0;

            btnAddAcronym.Enabled    = treeAcronyms.FocusedNode != null && !AcronymManager.IsTypeNode(treeAcronyms.FocusedNode);
            btnDeleteAcronym.Enabled = AcronymManager.IsAcronymNode(treeAcronyms.FocusedNode);

            btnAddLevel.Enabled    = treeAcronyms.FocusedNode != null;
            btnDeleteLevel.Enabled = AcronymManager.IsLevelNode(treeAcronyms.FocusedNode);

            btnAddType.Enabled    = true;
            btnDeleteType.Enabled = AcronymManager.IsTypeNode(treeAcronyms.FocusedNode);

            btnAddCategory.Enabled      = AcronymManager.IsAcronymNode(treeAcronyms.FocusedNode);
            btnDeleteCategories.Enabled = dgvCategories.SelectedRows.Count > 0;

            btnApplyFilters.Enabled = true;

            btnImportVariables.Enabled = !_isReadOnly && _varConfigFacade != null && _undoManager != null && !_undoManager.HasChanges() && _hasChangedSinceLastSave == false;
            btnCleanVariables.Enabled  = !_isReadOnly && _varConfigFacade != null && _undoManager != null && !_undoManager.HasChanges() && _hasChangedSinceLastSave == false;

            btnSave.Enabled = !_isReadOnly;
        }
Esempio n. 2
0
        internal override bool Perform()
        {
            if (_treeAcronyms.FocusedNode == null || AcronymManager.IsTypeNode(_treeAcronyms.FocusedNode))
            {
                return(false);
            }

            TreeListNode parentNode = null;

            //assess at which level acronym should be inserted with respect to which node is focused
            if (AcronymManager.IsLevelNode(_treeAcronyms.FocusedNode))
            {
                parentNode = _treeAcronyms.FocusedNode;
            }
            else if (AcronymManager.IsAcronymNode(_treeAcronyms.FocusedNode))
            {
                parentNode = _treeAcronyms.FocusedNode.ParentNode;
            }

            //append the new node
            TreeListNode node = _treeAcronyms.AppendNode(null, parentNode);

            node.Tag = _varConfigFacade.AddAcronymRow(parentNode.Tag as VarConfig.AcronymLevelRow);

            parentNode.Expanded            = true;
            parentNode.ParentNode.Expanded = true;

            return(true);
        }
        internal override bool Perform()
        {
            if (_treeAcronyms.FocusedNode == null)
            {
                return(false);
            }

            TreeListNode addAfterNode = null;
            TreeListNode parentNode   = null;

            //assess where level should be inserted with respect to which node is focused ...
            if (AcronymManager.IsTypeNode(_treeAcronyms.FocusedNode))
            {
                parentNode = _treeAcronyms.FocusedNode; //... type node: insert as first level
            }
            else if (AcronymManager.IsLevelNode(_treeAcronyms.FocusedNode))
            {
                addAfterNode = _treeAcronyms.FocusedNode; //... (other) level node: insert after this level
                parentNode   = addAfterNode.ParentNode;
            }

            else if (AcronymManager.IsAcronymNode(_treeAcronyms.FocusedNode))
            {
                addAfterNode = _treeAcronyms.FocusedNode.ParentNode; //... acronym node: insert after the level of the acronym
                parentNode   = addAfterNode.ParentNode;
            }

            //first append the new node ...
            TreeListNode node = _treeAcronyms.AppendNode(null, parentNode);

            VarConfig.AcronymLevelRow addAfterRow = null;
            if (addAfterNode != null)
            {
                addAfterRow = addAfterNode.Tag as VarConfig.AcronymLevelRow;
            }
            node.Tag = _varConfigFacade.AddAcronymLevelRow(parentNode.Tag as VarConfig.AcronymTypeRow, addAfterRow);

            //... then move ...
            int pos = -1;

            if (addAfterNode == null)
            {
                pos = 0;                            //... at front, if type node was selected
            }
            else if (addAfterNode.NextNode != null) //... after the focused node, if level- or acronym-node selected
            {
                pos = addAfterNode.ParentNode.Nodes.IndexOf(addAfterNode.NextNode);
            }

            if (pos >= 0)
            {
                _treeAcronyms.SetNodeIndex(node, pos);
            }

            parentNode.Expanded = true;

            return(true);
        }
        internal override bool Perform()
        {
            if (!AcronymManager.IsTypeNode(_treeAcronyms.FocusedNode))
            {
                return(false);
            }

            VarConfig.AcronymTypeRow typeRow = _treeAcronyms.FocusedNode.Tag as VarConfig.AcronymTypeRow;

            string usage = string.Empty;
            List <VarConfig.AcronymRow> usedAcronymRows = new List <VarConfig.AcronymRow>();

            foreach (VarConfig.AcronymRow acronymRow in _varConfigFacade.GetAcronymsOfType(typeRow.ShortName))
            {
                string usingVariables = _acronymManager.GetVariablesUsingAcronym(acronymRow.Name, typeRow.ShortName);
                if (usingVariables != string.Empty)
                {
                    usedAcronymRows.Add(acronymRow);
                    usage += acronymRow.Name + " used by " + usingVariables + Environment.NewLine;
                }
            }

            if (usage != string.Empty)
            {
                if (usage.Length > 2000) //probably this will happen only per accident, if a user tries to delete types like tax or benefit/pension (MessageBox is then too large for the screen)
                {
                    usage = usage.Substring(0, 2000) + Environment.NewLine + Environment.NewLine + "etc., etc., etc.";
                }

                if (Tools.UserInfoHandler.GetInfo("The following acronyms of this type are used:" + Environment.NewLine + usage +
                                                  Environment.NewLine + Environment.NewLine + "Cancel delete?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    return(false);
                }

                foreach (VarConfig.AcronymRow usedAcronymRow in usedAcronymRows)
                {
                    usedAcronymRow.Description = VariablesManager.DESCRIPTION_UNKNOWN; //temporarily rename, to allow for updating automatic labels
                }
                typeRow.LongName = VariablesManager.DESCRIPTION_UNKNOWN;
                _acronymManager.UpdateAutomaticLabelForSpecificAcronyms(usedAcronymRows);
            }

            typeRow.Delete();

            return(true);
        }