private void InternalExecute(object arg, IEnumerable <ITabularNamedObject> alternateSelection = null)
        {
            ui.Actions.LastActionExecuted = this;
            EditObjectName = null;
            ExpandObject   = null;
            var selection = alternateSelection == null ? ui.Selection : new UITreeSelection(alternateSelection);

            // Check if the context is valid before executing the actino:
            if (!ValidContexts.HasX(selection.Context | Context.Model | Context.Tool))
            {
                return;
            }

            ui.Handler.BeginUpdate(Name);
            _execute(selection, ui.Handler.Model);
            ui.Handler.EndUpdate();

            if (ExpandObject != null)
            {
                ui.ExpandItem(ExpandObject);
            }
            if (EditObjectName != null)
            {
                ui.EditName(EditObjectName);
            }
        }
Beispiel #2
0
        private void InternalExecute(object arg, IEnumerable <ITabularNamedObject> alternateSelection = null)
        {
            TabularModelHandler handler;

            if (ui != null)
            {
                ui.Actions.SelectObjects.Clear();
                ui.Actions.LastActionExecuted = this;
                handler = ui.Handler;
            }
            else
            {
                handler = TabularModelHandler.Singleton;
            }

            EditObjectName = null;
            ExpandObject   = null;
            var selection = alternateSelection == null ? (ui == null ? UITreeSelection.Empty : ui.Selection) : new UITreeSelection(alternateSelection);

            // Check if the context is valid before executing the action:
            if (!ValidContexts.HasX(selection.Context | Context.Model | Context.Tool))
            {
                return;
            }

            handler.BeginUpdate(Name);
            _execute(selection, handler.Model);
            handler.EndUpdate();


            if (ui == null)
            {
                return;
            }

            // Actions can trigger certain UI actions after execution (for example, tree expansion, name editing, tree selection):
            if (ExpandObject != null)
            {
                ui.ExpandItem(ExpandObject);
            }
            if (EditObjectName != null)
            {
                ui.EditName(EditObjectName);
            }
            if (ui.Actions.SelectObjects.Count > 0)
            {
                var tree = ui.Elements.TreeView;
                tree.ClearSelection();
                foreach (var obj in ui.Actions.SelectObjects)
                {
                    tree.FindNodeByTag(obj).IsSelected = true;
                }
                tree.EnsureVisible(tree.FindNodeByTag(ui.Actions.SelectObjects[0]));
            }
        }
Beispiel #3
0
        private void InternalExecute(object arg, IEnumerable <ITabularNamedObject> alternateSelection = null)
        {
            ui.Actions.SelectObjects.Clear();
            ui.Actions.LastActionExecuted = this;
            EditObjectName = null;
            ExpandObject   = null;
            var selection = alternateSelection == null ? ui.Selection : new UITreeSelection(alternateSelection);

            // Check if the context is valid before executing the actino:
            if (!ValidContexts.HasX(selection.Context | Context.Model | Context.Tool))
            {
                return;
            }

            ui.Handler.BeginUpdate(Name);
            _execute(selection, ui.Handler.Model);
            ui.Handler.EndUpdate();

            if (ExpandObject != null)
            {
                ui.ExpandItem(ExpandObject);
            }
            if (EditObjectName != null)
            {
                ui.EditName(EditObjectName);
            }
            if (ui.Actions.SelectObjects.Count > 0)
            {
                var tree = ui.Elements.TreeView;
                tree.ClearSelection();
                foreach (var obj in ui.Actions.SelectObjects)
                {
                    tree.FindNodeByTag(obj).IsSelected = true;
                }
                tree.EnsureVisible(tree.FindNodeByTag(ui.Actions.SelectObjects[0]));
            }
        }
Beispiel #4
0
 public bool Enabled(object arg)
 {
     return(ValidContexts.HasX(ui.Selection.Context) && _enabled(ui.Selection, ui.Handler.Model, arg));
 }
Beispiel #5
0
        /// <summary>
        /// Opens the partner edit screen with the last partner worked on.
        /// Checks if the partner is merged.
        /// </summary>
        public static void OpenLastUsedPartnerEditScreenByContext(Form AParentForm, string AContext = null)
        {
            string ValidContexts;
            string Context;
            long   MergedPartnerKey = 0;
            long   LastPartnerKey;
            string NoPartnerAvailableStr = Catalog.GetString("You have not edited a Partner yet.");

            if (AContext != null)
            {
                ValidContexts = TUserDefaults.USERDEFAULT_LASTPARTNERMAILROOM + ";" + TUserDefaults.USERDEFAULT_LASTPERSONPERSONNEL + ";" +
                                TUserDefaults.USERDEFAULT_LASTUNITPERSONNEL + ";" + TUserDefaults.USERDEFAULT_LASTPERSONCONFERENCE + ";";

                if (!ValidContexts.Contains(AContext + ";"))
                {
                    throw new ArgumentException("AContext \"" + AContext + "\" is not a valid context. Valid contexts: " + ValidContexts);
                }
                else
                {
                    Context = AContext;
                }
            }
            else
            {
                Context = TUserDefaults.USERDEFAULT_LASTPARTNERMAILROOM;
            }

            LastPartnerKey = TUserDefaults.GetInt64Default(Context, 0);

            // we don't need to validate the partner key
            // because it's done in the mnuFile_Popup function.
            // If we don't have a valid partner key, this code can't be called from the file menu.

            // now that this function is called from the main menu, we need to check for LastPartnerKey != 0
            if (LastPartnerKey == 0)
            {
                if (Context == TUserDefaults.USERDEFAULT_LASTPERSONPERSONNEL)
                {
                    NoPartnerAvailableStr = Catalog.GetString("You have not yet worked with a Person in the Personnel Module.");
                }

                MessageBox.Show(Catalog.GetString(NoPartnerAvailableStr),
                                Catalog.GetString("No Last Partner"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }

            if (MergedPartnerHandling(LastPartnerKey, out MergedPartnerKey, AParentForm))
            {
                // work with the merged partner
                LastPartnerKey = MergedPartnerKey;
            }
            else if (MergedPartnerKey > 0)
            {
                // The partner is merged but user cancelled the action
                return;
            }

            // Open the Partner Edit screen
            TFrmPartnerEdit frmPEDS;

            AParentForm.Cursor = Cursors.WaitCursor;

            frmPEDS = new TFrmPartnerEdit(AParentForm);

            if (Context == TUserDefaults.USERDEFAULT_LASTPERSONPERSONNEL)
            {
                frmPEDS.SetParameters(TScreenMode.smEdit, LastPartnerKey, TPartnerEditTabPageEnum.petpPersonnelIndividualData);
            }
            else
            {
                frmPEDS.SetParameters(TScreenMode.smEdit, LastPartnerKey);
            }

            frmPEDS.Show();

            AParentForm.Cursor = Cursors.Default;
        }
Beispiel #6
0
        private void InternalExecute(object arg, IEnumerable <ITabularNamedObject> alternateSelection = null)
        {
            TabularModelHandler handler;

            if (ui != null)
            {
                ui.Actions.SelectObjects.Clear();
                ui.Actions.LastActionExecuted = this;
                handler = ui.Handler;
            }
            else
            {
                handler = TabularModelHandler.Singleton;
            }

            EditObjectName = null;
            ExpandObject   = null;
            var selection = alternateSelection == null ? (ui == null ? UITreeSelection.Empty : ui.Selection) : new UITreeSelection(alternateSelection);

            // Check if the context is valid before executing the action:
            if (!ValidContexts.HasX(selection.Context | Context.Model | Context.Tool))
            {
                return;
            }

            try
            {
                handler.BeginUpdate(Name);
                _execute(selection, handler.Model);
            }
            catch (Exception e)
            {
                MessageBox.Show("The action failed with the following error: " + e.Message, "Unable to perform action", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {
                handler.EndUpdate();
            }


            if (ui == null)
            {
                return;
            }

            // Actions can trigger certain UI actions after execution (for example, tree expansion, name editing, tree selection):
            if (ExpandObject != null)
            {
                ui.ExpandItem(ExpandObject);
            }
            if (EditObjectName != null)
            {
                ui.EditName(EditObjectName);
            }
            if (ui.Actions.SelectObjects.Count > 0)
            {
                var tree = ui.Elements.TreeView;
                tree.ClearSelection();
                TreeNodeAdv firstNode = null;
                foreach (var obj in ui.Actions.SelectObjects)
                {
                    var node = tree.FindNodeByTag(obj);
                    if (firstNode == null)
                    {
                        firstNode = node;
                    }
                    if (node != null)
                    {
                        node.IsSelected = true;
                    }
                }
                if (firstNode != null)
                {
                    tree.EnsureVisible(firstNode);
                }
            }
        }