/// <summary>
 /// Default contructor.
 /// </summary>
 internal ActionResponse(ActionRequest initialActionRequest, Addon targetAddon)
 {
     this.initialActionRequest = initialActionRequest;
     this.targetAddon = targetAddon;
 }
        /// <summary>
        /// Selects the proper addon that can handle the action request.
        /// </summary>
        public static ActionResponse DispatchAction(ActionRequest request)
        {
            ActionResponse response = null;

            switch (request.ActionType)
            {
            case ActionType.ActionSaveProperties:
                if (propertyAddon != null)
                {
                    PropBaseCtl propCtl = (propertyAddon.AddonPanel as PropBaseCtl);
                    if (propCtl != null)
                    {
                        propCtl.SaveProperties();
                    }
                }
                break;

            case ActionType.ActionBeginEdit:
            {
                // Stop editing properties if it's the case.
                if (propertyAddon != null)
                {
                    PropBaseCtl propCtl = (propertyAddon.AddonPanel as PropBaseCtl);
                    if (propCtl != null)
                    {
                        propCtl.EndEdit();
                        propertyAddon = null;
                    }
                }

                propertyAddon = SelectPropertyAddon(request.Items);
                response      = new ActionResponse(request, propertyAddon);
            }
            break;

            case ActionType.ActionBeginPreview:
            {
                // Stop previewing if it's the case.
                if (request.ActionType == ActionType.ActionBeginPreview &&
                    previewAddon != null)
                {
                    PreviewBaseCtl previewCtl = (previewAddon.AddonPanel as PreviewBaseCtl);
                    if (previewCtl != null)
                    {
                        previewCtl.EndPreview();
                        AddonsCore.Instance.FirePreviewEnded();
                        previewAddon = null;
                    }
                }

                previewAddon = SelectPreviewAddon(request.Items);
                response     = new ActionResponse(request, previewAddon);
            }
            break;

            default:
                response = null;
                break;
            }

            return(response);
        }
        /// <summary>
        /// Selects the proper addon that can handle the action request.
        /// </summary>
        public static ActionResponse DispatchAction(ActionRequest request)
        {
            ActionResponse response = null;

            switch (request.ActionType)
            {
                case ActionType.ActionSaveProperties:
                    if (propertyAddon != null)
                    {
                        PropBaseCtl propCtl = (propertyAddon.AddonPanel as PropBaseCtl);
                        if (propCtl != null)
                        {
                            propCtl.SaveProperties();
                        }
                    }
                    break;

                case ActionType.ActionBeginEdit:
                    {
                        // Stop editing properties if it's the case.
                        if (propertyAddon != null)
                        {
                            PropBaseCtl propCtl = (propertyAddon.AddonPanel as PropBaseCtl);
                            if (propCtl != null)
                            {
                                propCtl.EndEdit();
                                propertyAddon = null;
                            }
                        }

                        propertyAddon = SelectPropertyAddon(request.Items);
                        response = new ActionResponse(request, propertyAddon);
                    }
                    break;

                case ActionType.ActionBeginPreview:
                    {
                        // Stop previewing if it's the case.
                        if (request.ActionType == ActionType.ActionBeginPreview &&
                            previewAddon != null)
                        {
                            PreviewBaseCtl previewCtl = (previewAddon.AddonPanel as PreviewBaseCtl);
                            if (previewCtl != null)
                            {
                                previewCtl.EndPreview();
                                AddonsCore.Instance.FirePreviewEnded();
                                previewAddon = null;
                            }
                        }

                        previewAddon = SelectPreviewAddon(request.Items);
                        response = new ActionResponse(request, previewAddon);
                    }
                    break;

                default:
                    response = null;
                    break;
            }

            return response;
        }
        /// <summary>
        /// Check whether there is an addon that can handle the given action
        /// having the actual addon configuration.
        /// </summary>
        public static bool CanDispatchAction(ActionRequest request, ref bool automatic)
        {
            if (request != null)
            {
                switch (request.ActionType)
                {
                    case ActionType.ActionSaveProperties:
                        return (propertyAddon != null);

                    case ActionType.ActionBeginEdit:
                        return (SelectPropertyAddon(request.Items) != null);

                    case ActionType.ActionBeginPreview:
                        PreviewAddon addon = SelectPreviewAddon(request.Items);

                        if (addon != null)
                        {
                            PreviewBaseCtl previewCtl = addon.AddonPanel as PreviewBaseCtl;
                            if (previewCtl != null)
                            {
                                automatic = previewCtl.SupportAutoPreview;
                                return true;
                            }
                        }
                        
                        return false;
                }
            }

            return false;
        }
Exemple #5
0
        private void OnSelectFile(object sender, SelectFileEventArgs args)
        {
            CancelAutoPreview();

            if (args != null)
            {
                List<string> paths = new List<string>();
                paths.Add(args.m_strPath);
                RaiseNavigationAction(NavActionType.ActionSelectFile, paths);

                if (paths != null && 
                    paths.Count == 1 &&
                    !string.IsNullOrEmpty(paths[0]))
                {
                    ActionRequest req = new ActionRequest();
                    req.ActionType = ActionType.ActionBeginPreview;
                    req.Items = paths;

                    bool autoPreviewAvailable = false;
                    if (AddonsCore.Instance.CanDispatchAction(req, ref autoPreviewAvailable))
                    {
                        if (autoPreviewAvailable && BuiltinAddonConfig.FEPreviewTimer > 0)
                        {
                            previewTimer.Interval = (int)(BuiltinAddonConfig.FEPreviewTimer * 1000);
                            previewTimer.Start();
                            RaiseNavigationAction(NavActionType.ActionPrepareAutoPreview, null, null);
                        }
                        else
                        {
                            RaiseNavigationAction(NavActionType.ActionNotifyPreviewableItem, null, null);
                        }
                    }
                    else
                    {
                        RaiseNavigationAction(NavActionType.ActionNotifyNonPreviewableItem, null, null);
                    }
                }
            }
        }
 /// <summary>
 /// Default contructor.
 /// </summary>
 internal ActionResponse(ActionRequest initialActionRequest, Addon targetAddon)
 {
     this.initialActionRequest = initialActionRequest;
     this.targetAddon          = targetAddon;
 }
Exemple #7
0
        public bool CanDispatchAction(ActionRequest request, ref bool automatic)
        {
            Logger.LogHeavyTrace("CanDispatchAction() called ...");

            bool retVal = false;
            try
            {
                if (request.Items != null)
                {
                    retVal = ActionManagement.ActionDispatcher.CanDispatchAction(request, ref automatic);
                }
            }
            catch
            {
                retVal = false;
            }

            Logger.LogHeavyTrace("CanDispatchAction() done .. returning " + retVal);
            return retVal;
        }
Exemple #8
0
        /// <summary>
        /// Forwards an ActionRequest send by an addon to the Action Dispatcher.
        /// This one is the only object able to decide which addon can handle
        /// this request.
        /// </summary>
        public ActionResponse DispatchAction(ActionRequest request)
        {
            ActionResponse retVal = null;

            Logger.LogHeavyTrace("DispatchAction() called ...");

            try
            {
                if (request.Items != null)
                {
                    retVal = ActionManagement.ActionDispatcher.DispatchAction(request);
                }
            }
            catch
            {
                retVal = null;
            }

            Logger.LogHeavyTrace("DispatchAction() done.");
            return retVal;
        }
        /// <summary>
        /// Handles the NavigationAction event of the navigation addon.
        /// </summary>
        void OnNavigationAction(object sender, NavigationActionEventArgs args)
        {
            try
            {
                Logger.LogHeavyTrace("MainForm handling OnNavigationAction ...");

                Application.UseWaitCursor = true;
                this.SuspendLayoutEx();

                bool isVoidAction = false;
                bool isPreviewAction = false;
                ActionRequest request = new ActionRequest();
                ActionResponse response = null;

                Logger.LogHeavyTrace("Action is of type: " + args.ActionType.ToString());

                pnlPreview.SuspendLayoutEx();
                pnlProperties.SuspendLayoutEx();

                lblNoPreview.Text = Translator.Translate("TXT_THEREARENOITEMS");

                prepareAutoPreview = 
                    (args.ActionType == NavActionType.ActionPrepareAutoPreview &&
                     args.ActionType != NavActionType.ActionCancelAutoPreview);

                switch (args.ActionType)
                {
                    case NavActionType.ActionSaveProperties:
                        // It is a save property request.
                        request.ActionType = ActionManagement.ActionType.ActionSaveProperties;
                        request.Items = args.Paths; // don't matter any way
                        break;

                    case NavActionType.ActionSelectDirectory:
                    case NavActionType.ActionSelectFile:
                    case NavActionType.ActionSelectMultipleItems:
                        // It is a property request.
                        request.ActionType = ActionManagement.ActionType.ActionBeginEdit;
                        request.Items = args.Paths;
                        break;

                    case NavActionType.ActionDoubleClickFile:
                        // It is a regular preview request.
                        request.ActionType = ActionManagement.ActionType.ActionBeginPreview;
                        request.Items = args.Paths;
                        isPreviewAction = true;
                        break;

                    case NavActionType.ActionNotifyNonPreviewableItem:
                        lblNoPreview.Text = Translator.Translate("TXT_NOTIFY_NON_PREVIEW");
                        isPreviewAction = true;
                        break;

                    case NavActionType.ActionNotifyPreviewableItem:
                        lblNoPreview.Text = Translator.Translate("TXT_NOTIFY_PREVIEW");
                        isPreviewAction = true;
                        break;

                    case NavActionType.ActionPrepareAutoPreview:
                        lblNoPreview.Text = Translator.Translate("TXT_PREPARE_PREVIEW");
                        prepareAutoPreview = true;
                        isPreviewAction = true;
                        break;

                    case NavActionType.ActionCancelAutoPreview:
                        if (args.AdditionalData == null && prepareAutoPreview)
                        {
                            lblNoPreview.Text = Translator.Translate("TXT_PREVIEW_CANCELED");
                        }
                        else
                        {
                            lblNoPreview.Text = Translator.Translate("TXT_NOTIFY_PREVIEW");
                        }
                        isPreviewAction = true;
                        break;

                    case NavActionType.ActionReloadNavigation:
                        {
                            // Don't reselct addons, send command to the ones already selected.
                            isVoidAction = true;

                            NavBaseCtl ctl = GetNavigationControl();
                            if (ctl != null)
                            {
                                ctl.Reload(args.AdditionalData);
                            }
                        }
                        break;

                    case NavActionType.ActionReloadPreview:
                        {
                            // Don't reselct addons, send command to the ones already selected.
                            isVoidAction = true;

                            PreviewBaseCtl ctl = GetPreviewControl();
                            if (ctl != null)
                            {
                                ctl.Reload(args.AdditionalData);
                            }
                        }
                        break;

                    case NavActionType.ActionReloadProperties:
                        {
                            // Don't reselct addons, send command to the ones already selected.
                            isVoidAction = true;

                            PropBaseCtl ctl = GetPropertiesControl();
                            if (ctl != null)
                            {
                                ctl.Reload(args.AdditionalData);
                            }
                        }
                        break;

                    case NavActionType.ActionDoubleClickDirectory:
                    default:
                        // No actions currently taken in this situation.
                        isVoidAction = true;
                        break;
                }

                if (!isVoidAction)
                {
                    response = AddonsCore.Instance.DispatchAction(request);
                    bool failed = ActionResponse.IsFailedAction(response);

                    if (isPreviewAction)
                    {
                        PreviewBaseCtl previewCtl = GetPreviewControl();
                        if (previewCtl != null)
                        {
                            previewCtl.EndPreview();
                            previewCtl.NavigationAction -= 
                                new BaseAddonCtl.NavigationActionEventHandler(OnNavigationAction);
                        }

                        if (failed)
                        {
                            Logger.LogHeavyTrace("Preview action has failed.");
                            if (!pnlPreview.Controls.Contains(lblNoPreview))
                            {
                                pnlPreview.Controls.Clear();
                                pnlPreview.Controls.Add(lblNoPreview);
                            }
                        }
                        else
                        {
                            // Note that only a single item can be previewed.
                            PreviewAddon addon = response.TargetAddon as PreviewAddon;
                            if (!pnlPreview.Controls.Contains(addon.AddonPanel))
                            {
                                pnlPreview.Controls.Clear();
                                addon.AddonPanel.Dock = DockStyle.Fill;
                                addon.AddonPanel.Location = new System.Drawing.Point(10, 10);
                                addon.AddonPanel.TabIndex = 0;
                                pnlPreview.Controls.Add(addon.AddonPanel);
                            }

                            previewCtl = GetPreviewControl();
                            if (previewCtl != null)
                            {
                                previewCtl.NavigationAction +=
                                    new BaseAddonCtl.NavigationActionEventHandler(OnNavigationAction);

                                previewCtl.BeginPreview(args.Paths[0], args.AdditionalData);
                            }
                        }
                    }
                    else
                    {
                        PropBaseCtl propCtl = GetPropertiesControl();
                        if (propCtl != null)
                        {
                            propCtl.NavigationAction -=
                                new BaseAddonCtl.NavigationActionEventHandler(OnNavigationAction);
                        }

                        if (failed)
                        {
                            Logger.LogHeavyTrace("View Properties Action has failed.");
                            pnlProperties.Controls.Clear();
                            pnlProperties.Controls.Add(lblNoProperties);
                        }
                        else
                        {
                            PropertyAddon addon = response.TargetAddon as PropertyAddon;
                            if (!pnlProperties.Controls.Contains(addon.AddonPanel))
                            {
                                pnlProperties.Controls.Clear();
                                addon.AddonPanel.Dock = DockStyle.Fill;
                                pnlProperties.Controls.Add(addon.AddonPanel);
                            }

                            propCtl = GetPropertiesControl();
                            if (propCtl != null)
                            {
                                propCtl.NavigationAction +=
                                    new BaseAddonCtl.NavigationActionEventHandler(OnNavigationAction);

                                propCtl.BeginEdit(args.Paths, args.AdditionalData);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorDispatcher.DispatchError(ex);
            }
            finally
            {
                pnlPreview.ResumeLayoutEx();
                pnlProperties.ResumeLayoutEx();
                this.ResumeLayoutEx();
                Application.UseWaitCursor = false;

                Logger.LogHeavyTrace("MainForm handled OnNavigationAction.");
            }
        }