/// <summary>
        /// Execution de la commande
        /// Si ok, enregistrement du path dans l'historique.
        /// </summary>
        public void Execute()
        {
            //-----------------------------------------------------------------------------------------------
            // Principes d'ouverture.
            //
            // 1. Si il n'y a qu'un seul écran, on ouvre sur place.
            //      On part du principe que l'utilisateur peut se placer en mode DualScreen s'il le souhaite.
            //      Sinon on doit demander si il veut charger sur place ou pas...
            //      Si c'est un écran Capture -> idem.
            //      On offre de plus la possibilité d'annuler l'action au cas où.
            //
            // 2. Si il y a deux players, dont au moins un vide, on ouvre dans le premier vide trouvé.
            //
            // 3. Si il y a deux players plein, on pose à droite.
            //
            // 4+ Variations à définir...
            // 4. Si il y a 1 player plein et un capture vide, on ouvre dans le player.
            //-----------------------------------------------------------------------------------------------
            ICommand       clm;
            CommandManager cm  = CommandManager.Instance();
            ICommand       css = new CommandShowScreens(screenManagerKernel);

            if (ForceScreen != -1)
            {
                // Position d'écran forcée: Vérifier s'il y a des choses à enregistrer.

                PlayerScreen ps    = (PlayerScreen)screenManagerKernel.screenList[ForceScreen - 1];
                bool         bLoad = true;
                if (ps.FrameServer.Metadata.IsDirty)
                {
                    DialogResult dr = ConfirmDirty();
                    if (dr == DialogResult.Yes)
                    {
                        // Launch the save dialog.
                        // Note: if we cancel this one, we will go on without saving...
                        screenManagerKernel.mnuSaveOnClick(null, EventArgs.Empty);
                    }
                    else if (dr == DialogResult.Cancel)
                    {
                        // Cancel the load.
                        bLoad = false;
                        screenManagerKernel.CancelLastCommand = true;
                    }
                    // else (DialogResult.No) => Do nothing.
                }

                if (bLoad)
                {
                    // Utiliser l'écran, qu'il soit vide ou plein.
                    clm = new CommandLoadMovie(ps, filePath);
                    CommandManager.LaunchCommand(clm);

                    //Si on a pu charger la vidéo, sauver dans l'historique
                    if (ps.FrameServer.VideoFile.Loaded)
                    {
                        SaveFileToHistory(filePath);
                    }
                }
            }
            else
            {
                switch (screenManagerKernel.screenList.Count)
                {
                case 0:
                {
                    // Ajouter le premier écran
                    ICommand caps = new CommandAddPlayerScreen(screenManagerKernel, false);
                    CommandManager.LaunchCommand(caps);

                    // Charger la vidéo dedans
                    PlayerScreen ps = screenManagerKernel.screenList[0] as PlayerScreen;
                    if (ps != null)
                    {
                        clm = new CommandLoadMovie(ps, filePath);
                        CommandManager.LaunchCommand(clm);

                        //Si on a pu charger la vidéo, sauver dans l'historique
                        if (ps.FrameServer.VideoFile.Loaded)
                        {
                            SaveFileToHistory(filePath);
                        }

                        //Afficher l'écran qu'on vient de le créer.
                        CommandManager.LaunchCommand(css);
                    }
                    break;
                }

                case 1:
                {
                    PlayerScreen ps = screenManagerKernel.screenList[0] as PlayerScreen;
                    if (ps != null)
                    {
                        bool bLoad = true;
                        if (ps.FrameServer.Metadata.IsDirty)
                        {
                            DialogResult dr = ConfirmDirty();
                            if (dr == DialogResult.Yes)
                            {
                                // Launch the save dialog.
                                // Note: if we cancel this one, we will go on without saving...
                                screenManagerKernel.mnuSaveOnClick(null, EventArgs.Empty);
                            }
                            else if (dr == DialogResult.Cancel)
                            {
                                // Cancel the load.
                                bLoad = false;
                                screenManagerKernel.CancelLastCommand = true;
                            }
                            // else (DialogResult.No) => Do nothing.
                        }

                        if (bLoad)
                        {
                            clm = new CommandLoadMovie(ps, filePath);
                            CommandManager.LaunchCommand(clm);

                            //Si on a pu charger la vidéo, sauver dans l'historique
                            if (ps.FrameServer.VideoFile.Loaded)
                            {
                                SaveFileToHistory(filePath);
                            }
                        }
                    }
                    else
                    {
                        // Only screen is a capture screen and we try to play a video.
                        // In that case we create a new player screen and load the video in it.

                        ICommand caps = new CommandAddPlayerScreen(screenManagerKernel, false);
                        CommandManager.LaunchCommand(caps);

                        // Reset the buffer before the video is loaded.
                        screenManagerKernel.UpdateCaptureBuffers();

                        // load video.
                        PlayerScreen newScreen = (screenManagerKernel.screenList.Count > 0) ? (screenManagerKernel.screenList[1] as PlayerScreen) : null;
                        if (newScreen != null)
                        {
                            clm = new CommandLoadMovie(newScreen, filePath);
                            CommandManager.LaunchCommand(clm);

                            //video loaded finely, save in history.
                            if (newScreen.FrameServer.VideoFile.Loaded)
                            {
                                SaveFileToHistory(filePath);
                            }

                            // Display screens.
                            CommandManager.LaunchCommand(css);
                        }
                    }

                    break;
                }

                case 2:
                {
                    //Chercher un écran vide.
                    int iEmptyScreen = -1;

                    PlayerScreen ps0 = screenManagerKernel.screenList[0] as PlayerScreen;
                    PlayerScreen ps1 = screenManagerKernel.screenList[1] as PlayerScreen;

                    if (ps0 != null && ps0.FrameServer.VideoFile.Loaded == false)
                    {
                        iEmptyScreen = 0;
                    }
                    else if (ps1 != null && ps1.FrameServer.VideoFile.Loaded == false)
                    {
                        iEmptyScreen = 1;
                    }


                    if (iEmptyScreen >= 0)
                    {
                        // On a trouvé un écran vide, charger la vidéo dedans.
                        clm = new CommandLoadMovie((PlayerScreen)screenManagerKernel.screenList[iEmptyScreen], filePath);
                        CommandManager.LaunchCommand(clm);

                        //Si on a pu charger la vidéo, sauver dans l'historique
                        if (((PlayerScreen)screenManagerKernel.screenList[iEmptyScreen]).FrameServer.VideoFile.Loaded)
                        {
                            SaveFileToHistory(filePath);
                        }

                        //--------------------------------------------
                        // Sur échec, on ne modifie pas l'écran actif.
                        // normalement c'est toujours l'autre écran.
                        //--------------------------------------------
                    }
                    else
                    {
                        // On a pas trouvé d'écran vide...
                        // Par défaut : toujours à droite.
                        // (étant donné que l'utilisateur à la possibilité d'annuler l'opération
                        // et de revenir à l'ancienne vidéo facilement, autant éviter une boîte de dialogue.)

                        PlayerScreen ps = screenManagerKernel.screenList[1] as PlayerScreen;
                        if (ps != null)
                        {
                            bool bLoad = true;
                            if (ps.FrameServer.Metadata.IsDirty)
                            {
                                DialogResult dr = ConfirmDirty();
                                if (dr == DialogResult.Yes)
                                {
                                    // Launch the save dialog.
                                    // Note: if we cancel this one, we will go on without saving...
                                    screenManagerKernel.mnuSaveOnClick(null, EventArgs.Empty);
                                }
                                else if (dr == DialogResult.Cancel)
                                {
                                    // Cancel the load.
                                    bLoad = false;
                                    screenManagerKernel.CancelLastCommand = true;
                                }
                                // else (DialogResult.No) => Do nothing.
                            }

                            if (bLoad)
                            {
                                clm = new CommandLoadMovie(ps, filePath);
                                CommandManager.LaunchCommand(clm);

                                //Si on a pu charger la vidéo, sauver dans l'historique
                                if (ps.FrameServer.VideoFile.Loaded)
                                {
                                    SaveFileToHistory(filePath);
                                }
                                else
                                {
                                    //----------------------------------------------------------------------------
                                    // Echec de chargement, vérifier si on ne vient pas d'invalider l'écran actif.
                                    //----------------------------------------------------------------------------
                                    if (screenManagerKernel.m_ActiveScreen == ps)
                                    {
                                        screenManagerKernel.Screen_SetActiveScreen(screenManagerKernel.screenList[0]);
                                    }
                                }
                            }
                        }
                    }

                    // Vérifier qu'on a un écran actif.
                    // sinon, positionner le premier comme actif.
                    break;
                }

                default:
                    break;
                }
            }

            screenManagerKernel.OrganizeCommonControls();
            screenManagerKernel.OrganizeMenus();
            screenManagerKernel.UpdateStatusBar();
        }
示例#2
0
        /// <summary>
        /// Execution de la commande
        /// </summary>
        public void Execute()
        {
            // When there is only one screen, we don't want it to have the "active" screen look.
            // Since we have 2 screens at most, we first clean up all of them,
            // and we'll display the active screen look afterwards, only if needed.
            foreach (AbstractScreen screen in screenManagerKernel.screenList)
            {
                screen.DisplayAsActiveScreen(false);
            }

            // There are two types of closing demands: explicit and implicit.
            // explicit-close ask for a specific screen to be closed.
            // implicit-close just ask for a close, we choose which one here.

            if (iScreenToRemove >= 0 && iScreenToRemove < screenManagerKernel.screenList.Count)
            {
                // Explicit. Make the other one the "active" screen if necessary.
                // For now, we do different actions based on screen type. (fixme?)

                if (screenManagerKernel.screenList[iScreenToRemove] is PlayerScreen)
                {
                    // PlayerScreen, check if dirty and ask for saving if so.

                    PlayerScreen ps      = (PlayerScreen)screenManagerKernel.screenList[iScreenToRemove];
                    bool         bRemove = true;
                    if (ps.FrameServer.Metadata.IsDirty)
                    {
                        DialogResult dr = MessageBox.Show(m_ResManager.GetString("InfoBox_MetadataIsDirty_Text", Thread.CurrentThread.CurrentUICulture).Replace("\\n", "\n"),
                                                          m_ResManager.GetString("InfoBox_MetadataIsDirty_Title", Thread.CurrentThread.CurrentUICulture),
                                                          MessageBoxButtons.YesNoCancel,
                                                          MessageBoxIcon.Question);

                        if (dr == DialogResult.Yes)
                        {
                            // Launch the save dialog.
                            // Note: if user cancels this one, we will not save anything...
                            screenManagerKernel.mnuSaveOnClick(null, EventArgs.Empty);
                        }
                        else if (dr == DialogResult.Cancel)
                        {
                            // Cancel the close.
                            bRemove = false;
                            screenManagerKernel.CancelLastCommand = true;
                        }
                    }

                    if (bRemove)
                    {
                        // We store the current state now.
                        // (We don't store it at construction time to handle the redo case better)
                        if (m_bStoreState)
                        {
                            screenManagerKernel.StoreCurrentState();
                        }

                        ps.m_PlayerScreenUI.ResetToEmptyState();
                        screenManagerKernel.screenList.RemoveAt(iScreenToRemove);

                        // TODO: Remove all commands that were executed during this screen life from the command history.
                        // But to do that we'll need a way to tell apart commands based on their parent screen...
                    }
                }
                else if (screenManagerKernel.screenList[iScreenToRemove] is CaptureScreen)
                {
                    // Capture.
                    // We store the current state now.
                    // (We don't store it at construction time to handle the redo case better)
                    if (m_bStoreState)
                    {
                        screenManagerKernel.StoreCurrentState();
                    }

                    screenManagerKernel.screenList[iScreenToRemove].BeforeClose();
                    screenManagerKernel.screenList.RemoveAt(iScreenToRemove);

                    // TODO: Remove all commands that were executed during this screen life from the command history.
                    // But to do that we'll need a way to tell apart commands based on their parent screen...
                }
            }
            else
            {
                // Implicit close. Find the empty screen.
                // (We actually know for sure that there is indeed an empty screen).
                for (int i = 0; i < screenManagerKernel.screenList.Count; i++)
                {
                    if (!screenManagerKernel.screenList[i].Full)
                    {
                        // We store the current state now.
                        // (We don't store it at construction time to handle the redo case better)
                        if (m_bStoreState)
                        {
                            screenManagerKernel.StoreCurrentState();
                        }
                        screenManagerKernel.screenList.RemoveAt(i);
                        // TODO: Remove all commands that were executed during this screen life from the command history.
                        // But to do that we'll need a way to tell apart commands based on their parent screen...
                        break;
                    }
                }
            }

            // Handle the remaining screen.
            if (screenManagerKernel.screenList.Count > 0)
            {
                screenManagerKernel.Screen_SetActiveScreen(screenManagerKernel.screenList[0]);
            }
            else
            {
                // Show back the Thumbnails...
            }
        }