Example #1
0
        private RecentFileWrapper FindPrevious(bool select)
        {
            RecentFileWrapper previousMatch = FindPrevSetting();

            if (previousMatch != null)
            {
                if (select)
                {
                    previousMatch.IsSelected = true;
                }
                else
                {
                    var listItem = VisualLogicalTreeWalkHelper.FindObjectInVisualTreeWithMatchingType <ListViewItem>(
                        RecentFilesList,
                        child =>
                    {
                        object dc = child.GetValue(FrameworkElement.DataContextProperty);
                        return(dc != null && dc == previousMatch);
                    });
                    if (listItem != null)
                    {
                        listItem.BringIntoView();
                    }
                }
            }
            else
            {
                AudioCues.PlayBeep();
            }
            return(previousMatch);
        }
Example #2
0
        public DescribableTreeNode FindPrevious(bool select)
        {
            DescribableTreeNode previousMatch = FindPrevDescription(m_DescribableTreeNodes);

            if (previousMatch != null)
            {
                var listItem = VisualLogicalTreeWalkHelper.FindObjectInVisualTreeWithMatchingType <ListViewItem>(
                    m_view.ListView,
                    child =>
                {
                    object dc = child.GetValue(FrameworkElement.DataContextProperty);
                    return(dc != null && dc == previousMatch);
                });
                if (select)
                {
                    previousMatch.IsSelected = true;
                    if (listItem != null)
                    {
                        FocusHelper.FocusBeginInvoke(listItem); //m_view.m_LastListItemSelected
                    }
                }
                else
                {
                    if (listItem != null)
                    {
                        listItem.BringIntoView();
                    }
                }
            }
            else
            {
                AudioCues.PlayBeep();
            }
            return(previousMatch);
        }
Example #3
0
        public MarkedTreeNode FindNext(bool select)
        {
            MarkedTreeNode nextMatch = FindNextMarkers(m_MarkedTreeNodes);

            if (nextMatch != null)
            {
                var listItem = VisualLogicalTreeWalkHelper.FindObjectInVisualTreeWithMatchingType <ListViewItem>(
                    m_view.ListView,
                    child =>
                {
                    object dc = child.GetValue(FrameworkElement.DataContextProperty);
                    return(dc != null && dc == nextMatch);
                });
                if (select)
                {
                    nextMatch.IsSelected = true;
                    if (listItem != null)
                    {
                        FocusHelper.FocusBeginInvoke(listItem); //m_view.m_LastListItemSelected
                    }
                }
                else
                {
                    if (listItem != null)
                    {
                        listItem.BringIntoView();
                    }
                }
            }
            else
            {
                AudioCues.PlayBeep();
            }
            return(nextMatch);
        }
Example #4
0
        private SettingWrapper FindNext(bool select)
        {
            SettingWrapper nextMatch = FindNextSetting();

            if (nextMatch != null)
            {
                if (select)
                {
                    nextMatch.IsSelected = true;
                }
                else
                {
                    var listItem = VisualLogicalTreeWalkHelper.FindObjectInVisualTreeWithMatchingType <ListViewItem>(
                        SettingsList,
                        child =>
                    {
                        object dc = child.GetValue(FrameworkElement.DataContextProperty);
                        return(dc != null && dc == nextMatch);
                    });
                    if (listItem != null)
                    {
                        listItem.BringIntoView();
                    }
                }
            }
            else
            {
                AudioCues.PlayBeep();
            }
            return(nextMatch);
        }
        public HeadingTreeNodeWrapper FindPrevious(bool select)
        {
            ExpandAll();

            HeadingTreeNodeWrapper prevMatch = FindPrevMatch(m_roots);

            if (prevMatch != null)
            {
                if (select)
                {
                    //prevMatch.IsSelected = true;
                    ViewModel.View.SelectTreeNodeWrapper(prevMatch, true);
                }
                else
                {
                    var treeViewItem = VisualLogicalTreeWalkHelper.FindObjectInVisualTreeWithMatchingType <TreeViewItem>(
                        ViewModel.View.TreeView,
                        child =>
                    {
                        object dc = child.GetValue(FrameworkElement.DataContextProperty);
                        return(dc != null && dc == prevMatch);
                    });
                    if (treeViewItem != null)
                    {
                        treeViewItem.BringIntoView();
                    }
                }
            }
            else
            {
                AudioCues.PlayBeep();
            }

            return(prevMatch);
        }
Example #6
0
        private void OnWindowClosing(object sender, CancelEventArgs e)
        {
            if (m_ButtonTriggersClose)
            {
                ContentPlaceHolder.Content = null;
                DetailsPlaceHolder.Content = null;

                if (m_whenDoneAction != null)
                {
                    m_whenDoneAction.Invoke();
                    m_whenDoneAction = null;
                }

                return;
            }

            if (!AllowEscapeAndCloseButton)
            {
                AudioCues.PlayAsterisk();
                e.Cancel = true;
                return;
            }

            ContentPlaceHolder.Content = null;
            DetailsPlaceHolder.Content = null;

            if (m_whenDoneAction != null)
            {
                m_whenDoneAction.Invoke();
                m_whenDoneAction = null;
            }
        }
Example #7
0
 protected override void OnKeyUp(KeyEventArgs e)
 {
     if (!IgnoreEscape && e.Key == Key.Escape)
     {
         if (AllowEscapeAndCloseButton)
         {
             m_ButtonTriggersClose = false;
             Close();
         }
         else
         {
             AudioCues.PlayAsterisk();
         }
     }
     base.OnKeyUp(e);
 }
Example #8
0
        private void initializeCommands_Navigation()
        {
            CommandGotoBegining = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioGotoBegin_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioGotoBegin_LongDesc,
                null,    // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("go-first"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandGotoBegining", Category.Debug, Priority.Medium);

                CommandPause.Execute();

                if (PlayBytePosition == 0)
                {
                    AudioCues.PlayBeep();
                }
                else
                {
                    if (IsAutoPlay)
                    {
                        State.Selection.ClearSelection();
                    }

                    PlayBytePosition = 0;
                }
            },
                () => !IsWaveFormLoading &&
                State.Audio.HasContent &&
                !IsRecording &&
                (!IsMonitoring || IsMonitoringAlways),
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_GotoBegin));

            m_ShellView.RegisterRichCommand(CommandGotoBegining);
            //
            CommandGotoEnd = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioGotoEnd_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioGotoEnd_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("go-last"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandGotoEnd", Category.Debug, Priority.Medium);

                CommandPause.Execute();

                if (PlayBytePosition == State.Audio.DataLength)
                {
                    AudioCues.PlayBeep();
                }
                else
                {
                    if (IsAutoPlay)
                    {
                        State.Selection.ClearSelection();
                    }

                    PlayBytePosition = State.Audio.DataLength;
                }
            },
                () => !IsWaveFormLoading &&
                State.Audio.HasContent &&
                !IsRecording &&
                (!IsMonitoring || IsMonitoringAlways),
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_GotoEnd));

            m_ShellView.RegisterRichCommand(CommandGotoEnd);
            //
            CommandStepBack = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioStepBack_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioStepBack_LongDesc,
                null,  // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("media-skip-backward"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandStepBack", Category.Debug, Priority.Medium);

                CommandPause.Execute();

                long bytesLeftPrevious = -1;

                State.Audio.FindInPlayStreamMarkersAndDo(PlayBytePosition,
                                                         (bytesLeft, bytesRight, markerTreeNode, index)
                                                         =>
                {
                    if (bytesLeftPrevious == -1)
                    {
                        if (IsAutoPlay)
                        {
                            State.Selection.ClearSelection();
                        }

                        PlayBytePosition = bytesLeft;
                        AudioCues.PlayBeep();
                        return(-1);
                    }

                    if (IsAutoPlay)
                    {
                        State.Selection.ClearSelection();
                    }

                    PlayBytePosition = bytesLeftPrevious;

                    return(-1);
                }
                                                         ,
                                                         (bytesToMatch_, bytesLeft, bytesRight, markerTreeNode)
                                                         =>
                {
                    bytesLeftPrevious = bytesLeft;
                    return(bytesToMatch_);
                }
                                                         );
            },
                () => !IsWaveFormLoading &&
                !IsRecording &&
                (!IsMonitoring || IsMonitoringAlways) &&
                State.Audio.HasContent && State.Audio.PlayStreamMarkers != null && State.Audio.PlayStreamMarkers.Count > 1,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_StepBack));

            m_ShellView.RegisterRichCommand(CommandStepBack);
            //
            CommandStepForward = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioStepForward_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioStepForward_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("media-skip-forward"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandStepForward", Category.Debug, Priority.Medium);

                CommandPause.Execute();

                long bytesRight;
                long bytesLeft;
                int index;
                TreeNode subTreeNode;
                bool match = State.Audio.FindInPlayStreamMarkers(PlayBytePosition, out subTreeNode, out index, out bytesLeft, out bytesRight);

                if (match)
                {
                    if (index == State.Audio.PlayStreamMarkers.Count - 1)
                    {
                        AudioCues.PlayBeep();
                        return;
                    }

                    if (IsAutoPlay)
                    {
                        State.Selection.ClearSelection();
                    }

                    PlayBytePosition = bytesRight;
                }
                else
                {
                    Debug.Fail("audio chunk not found ??");

                    AudioCues.PlayBeep();
                }
            },
                () => CommandStepBack.CanExecute(),
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_StepForward));

            m_ShellView.RegisterRichCommand(CommandStepForward);
            //
            CommandFastForward = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioFastForward_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioFastForward_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("media-seek-forward"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandFastForward", Category.Debug, Priority.Medium);

                CommandPause.Execute();

                long newBytesPosition = PlayBytePosition + State.Audio.GetCurrentPcmFormat().Data.ConvertTimeToBytes((long)Settings.Default.AudioWaveForm_JumpTimeStep * AudioLibPCMFormat.TIME_UNIT);
                if (newBytesPosition > State.Audio.DataLength)
                {
                    newBytesPosition = State.Audio.DataLength;
                    AudioCues.PlayBeep();
                }

                if (IsAutoPlay)
                {
                    State.Selection.ClearSelection();
                }

                PlayBytePosition = newBytesPosition;
            },
                () => !IsWaveFormLoading &&
                State.Audio.HasContent &&
                (!IsMonitoring || IsMonitoringAlways) &&
                !IsRecording,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_GoForward));

            m_ShellView.RegisterRichCommand(CommandFastForward);
            //
            CommandRewind = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioRewind_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioRewind_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("media-seek-backward"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandRewind", Category.Debug, Priority.Medium);

                CommandPause.Execute();

                long newTimeBytePosition = PlayBytePosition - State.Audio.GetCurrentPcmFormat().Data.ConvertTimeToBytes((long)Settings.Default.AudioWaveForm_JumpTimeStep * AudioLibPCMFormat.TIME_UNIT);
                if (newTimeBytePosition < 0)
                {
                    newTimeBytePosition = 0;
                    AudioCues.PlayBeep();
                }

                if (IsAutoPlay)
                {
                    State.Selection.ClearSelection();
                }

                PlayBytePosition = newTimeBytePosition;
            },
                () => !IsWaveFormLoading &&
                State.Audio.HasContent &&
                !IsRecording &&
                (!IsMonitoring || IsMonitoringAlways),
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_GoBack));

            m_ShellView.RegisterRichCommand(CommandRewind);
            //
            CommandFastForwardX = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioFastForwardX_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioFastForwardX_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("media-seek-forward"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandFastForwardX", Category.Debug, Priority.Medium);

                CommandPause.Execute();

                long newBytesPosition = PlayBytePosition + State.Audio.GetCurrentPcmFormat().Data.ConvertTimeToBytes((long)Settings.Default.AudioWaveForm_JumpTimeStepX * AudioLibPCMFormat.TIME_UNIT);
                if (newBytesPosition > State.Audio.DataLength)
                {
                    newBytesPosition = State.Audio.DataLength;
                    AudioCues.PlayBeep();
                }

                if (IsAutoPlay)
                {
                    State.Selection.ClearSelection();
                }

                PlayBytePosition = newBytesPosition;
            },
                () => CommandFastForward.CanExecute(),
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_GoForwardX));

            m_ShellView.RegisterRichCommand(CommandFastForwardX);
            //
            CommandRewindX = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioRewindX_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioRewindX_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("media-seek-backward"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandRewindX", Category.Debug, Priority.Medium);

                CommandPause.Execute();

                long newTimeBytePosition = PlayBytePosition - State.Audio.GetCurrentPcmFormat().Data.ConvertTimeToBytes((long)Settings.Default.AudioWaveForm_JumpTimeStepX * AudioLibPCMFormat.TIME_UNIT);
                if (newTimeBytePosition < 0)
                {
                    newTimeBytePosition = 0;
                    AudioCues.PlayBeep();
                }

                if (IsAutoPlay)
                {
                    State.Selection.ClearSelection();
                }

                PlayBytePosition = newTimeBytePosition;
            },
                () => CommandRewind.CanExecute(),
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_GoBackX));

            m_ShellView.RegisterRichCommand(CommandRewindX);
        }
Example #9
0
        private void initializeCommands_Selection()
        {
            CommandSelectPreviousChunk = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioSelectPreviousChunk_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioSelectPreviousChunk_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("go-previous"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandSelectPreviousChunk", Category.Debug, Priority.Medium);

                CommandStepBack.Execute();

                SelectChunk(PlayBytePosition);
            },
                () => CommandStepBack.CanExecute(),
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_SelectPreviousChunk));

            m_ShellView.RegisterRichCommand(CommandSelectPreviousChunk);
            //
            CommandSelectNextChunk = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioSelectNextChunk_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioSelectNextChunk_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("go-next"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandSelectNextChunk", Category.Debug, Priority.Medium);

                CommandStepForward.Execute();

                SelectChunk(PlayBytePosition);
            },
                () => CommandStepForward.CanExecute(),
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_SelectNextChunk));

            m_ShellView.RegisterRichCommand(CommandSelectNextChunk);
            //
            //
            CommandEndSelection = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioEndSelection_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioEndSelection_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                ScalableGreyableImageProvider.ConvertIconFormat((DrawingImage)Application.Current.FindResource("Horizon_Image_Right1")),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandEndSelection", Category.Debug, Priority.Medium);

                if (m_SelectionBeginTmpBytePosition < 0)
                {
                    return;
                }

                CommandPause.Execute();

                long begin = m_SelectionBeginTmpBytePosition;
                long end   = PlayBytePosition;

                AudioCues.PlayTockTock();

                if (begin == end)
                {
                    CommandClearSelection.Execute();
                    return;
                }

                if (begin > end)
                {
                    long tmp = begin;
                    begin    = end;
                    end      = tmp;
                }

                State.Selection.SetSelectionBytes(begin, end);

                if (IsAutoPlay)
                {
                    CommandPlay.Execute();
                }

                //if (IsAutoPlay)
                //{
                //    //if (!State.Audio.HasContent)
                //    //{
                //    //    return;
                //    //}

                //    //IsAutoPlay = false;
                //    //LastPlayHeadTime = begin;
                //    //IsAutoPlay = true;

                //    //long bytesFrom = State.Audio.ConvertMillisecondsToBytes(begin);
                //    //long bytesTo = State.Audio.ConvertMillisecondsToBytes(end);

                //    //AudioPlayer_PlayFromTo(bytesFrom, bytesTo);
                //}
            },
                () => CommandSelectAll.CanExecute()
                //CanManipulateWaveForm
                // //&& !IsWaveFormLoading && !IsRecording && !IsMonitoring
                // && State.Audio.HasContent
                && m_SelectionBeginTmpBytePosition >= 0,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_EndSelection));

            m_ShellView.RegisterRichCommand(CommandEndSelection);
            //
            CommandBeginSelection = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioBeginSelection_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioBeginSelection_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                ScalableGreyableImageProvider.ConvertIconFormat((DrawingImage)Application.Current.FindResource("Horizon_Image_Left1")),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandBeginSelection", Category.Debug, Priority.Medium);

                //CommandPause.Execute();
                CommandClearSelection.Execute();

                m_SelectionBeginTmpBytePosition = PlayBytePosition;

                AudioCues.PlayTock();
            },
                () => CommandSelectLeft.CanExecute(),
                //CommandSelectAll.CanExecute()
                //         //CanManipulateWaveForm
                //         ////&& !IsWaveFormLoading && !IsRecording && !IsMonitorin
                //         //&& State.Audio.HasContent,
                //         && PlayBytePosition >= 0,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_BeginSelection));

            m_ShellView.RegisterRichCommand(CommandBeginSelection);
            //
            CommandSelectLeft = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioSelectLeft_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioSelectLeft_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("format-indent-less"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandSelectLeft", Category.Debug, Priority.Medium);

                if (PlayBytePosition <= 0)
                {
                    AudioCues.PlayBeep();
                    return;
                }

                State.Selection.SetSelectionBytes(0, PlayBytePosition);

                PlayBytePosition = State.Selection.SelectionEndBytePosition;

                //AudioCues.PlayTock();
            },
                () => CommandSelectAll.CanExecute()
                //CanManipulateWaveForm
                // //&& !IsWaveFormLoading && !IsRecording && !IsMonitoring
                // && State.Audio.HasContent
                && PlayBytePosition >= 0,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_SelectLeft));

            m_ShellView.RegisterRichCommand(CommandSelectLeft);
            //
            CommandSelectRight = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioSelectRight_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioSelectRight_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("format-indent-more"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandSelectRight", Category.Debug, Priority.Medium);

                if (PlayBytePosition >= State.Audio.DataLength)
                {
                    AudioCues.PlayBeep();
                    return;
                }

                State.Selection.SetSelectionBytes(PlayBytePosition, State.Audio.DataLength);
                //AudioCues.PlayTock();
            },
                () => CommandSelectLeft.CanExecute(),
                //CanManipulateWaveForm
                // //&& !IsWaveFormLoading && !IsRecording && !IsMonitoring
                // && State.Audio.HasContent && PlayBytePosition >= 0,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_SelectRight));

            m_ShellView.RegisterRichCommand(CommandSelectRight);
            //
            CommandSelectAll = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdSelectAll_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdSelectAll_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("view-fullscreen"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandSelectAll", Category.Debug, Priority.Medium);

                //if (!State.Audio.HasContent)
                //{
                //    if (View != null)
                //    {
                //        View.SelectAll();
                //    }
                //    return;
                //}

                State.Selection.SetSelectionBytes(0, State.Audio.DataLength);

                //AudioCues.PlayTockTock();
            },
                () => CanManipulateWaveForm
                //&& !IsWaveFormLoading && !IsRecording && !IsMonitoring
                && State.Audio.HasContent,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_SelectAll));

            m_ShellView.RegisterRichCommand(CommandSelectAll);
            //
            CommandClearSelection = new RichDelegateCommand(Tobi_Plugin_AudioPane_Lang.CmdAudioClearSelection_ShortDesc,
                                                            Tobi_Plugin_AudioPane_Lang.CmdAudioClearSelection_LongDesc,
                                                            null, // KeyGesture obtained from settings (see last parameters below)
                                                            m_ShellView.LoadTangoIcon("edit-clear"),
                                                            () =>
            {
                //Logger.Log("AudioPaneViewModel.CommandClearSelection", Category.Debug, Priority.Medium);

                State.Selection.ClearSelection();
            },
                                                            () => CommandSelectAll.CanExecute()
                                                            //CanManipulateWaveForm
                                                            // //&& !IsWaveFormLoading && !IsRecording && !IsMonitoring
                                                            // && State.Audio.HasContent
                                                            && IsSelectionSet,
                                                            Settings_KeyGestures.Default,
                                                            PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_ClearSelection));

            m_ShellView.RegisterRichCommand(CommandClearSelection);
            //
        }
Example #10
0
        private void initializeCommands_Player()
        {
            CommandPlaybackRateReset = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioPlayRateReset_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioPlayRateReset_LongDesc,
                null,   // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadGnomeGionIcon("Gion_go-previous"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandPlaybackRateReset", Category.Debug, Priority.Medium);

                PlaybackRate = PLAYBACK_RATE_MIN;
            },
                () => true
                //&& !IsWaveFormLoading
                ,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_ResetPlaybackRate));

            m_ShellView.RegisterRichCommand(CommandPlaybackRateReset);
            //
            CommandPlaybackRateDown = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioPlayRateDown_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioPlayRateDown_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadGnomeGionIcon("Gion_go-down"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandPlaybackRateDown", Category.Debug, Priority.Medium);

                if ((PlaybackRate - PLAYBACK_RATE_STEP) >= PLAYBACK_RATE_MIN)
                {
                    PlaybackRate -= PLAYBACK_RATE_STEP;
                }
                else
                {
                    PlaybackRate = PLAYBACK_RATE_MIN;
                    Debug.Fail("This should never happen !");
                }
            },
                () => (PlaybackRate - PLAYBACK_RATE_STEP) >= PLAYBACK_RATE_MIN
                //&& !IsWaveFormLoading
                ,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_PlaybackRateDown));

            m_ShellView.RegisterRichCommand(CommandPlaybackRateDown);
            //
            CommandPlaybackRateUp = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioPlayRateUp_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioPlayRateUp_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadGnomeGionIcon("Gion_go-up"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandPlaybackRateUp", Category.Debug, Priority.Medium);

                if ((PlaybackRate + PLAYBACK_RATE_STEP) <= PLAYBACK_RATE_MAX)
                {
                    PlaybackRate += PLAYBACK_RATE_STEP;
                }
                else
                {
                    PlaybackRate = PLAYBACK_RATE_MAX;
                    Debug.Fail("This should never happen !");
                }
            },
                () => (PlaybackRate + PLAYBACK_RATE_STEP) <= PLAYBACK_RATE_MAX
                //&& !IsWaveFormLoading
                ,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_PlaybackRateUp));

            m_ShellView.RegisterRichCommand(CommandPlaybackRateUp);
            //
            CommandAutoPlay = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioAutoPlay_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioAutoPlay_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("applications-multimedia"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandAutoPlay", Category.Debug, Priority.Medium);

                //if (IsAutoPlay)
                //{
                //    AudioCues.PlayTock();
                //}
                //else
                //{
                //    AudioCues.PlayTockTock();
                //}

                IsAutoPlay = !IsAutoPlay;
            },
                () => true
                //&& !IsWaveFormLoading
                ,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_ToggleAutoPlayMode));

            m_ShellView.RegisterRichCommand(CommandAutoPlay);
            //
            //
            CommandPause = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioPause_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioPause_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("media-playback-pause"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandPause", Category.Debug, Priority.Medium);

                m_PlayAutoAdvance = false;

                SetRecordAfterPlayOverwriteSelection(-1);

                long playBytePosition = PlayBytePosition;

                m_Player.Stop();

                SetPlayHeadTimeBypassAutoPlay(playBytePosition);

                if (EventAggregator != null)
                {
                    EventAggregator.GetEvent <StatusBarMessageUpdateEvent>().Publish(Tobi_Plugin_AudioPane_Lang.PlaybackStopped);
                }

                if (IsMonitoringAlways)
                {
                    CommandStartMonitor.Execute();
                }
            },
                () => State.Audio.HasContent && IsPlaying
                //&& !IsWaveFormLoading
                ,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_PlayPause));

            m_ShellView.RegisterRichCommand(CommandPause);
            //
            CommandPlay = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioPlay_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioPlay_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("media-playback-start"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandPlay", Category.Debug, Priority.Medium);
                CommandPause.Execute();

                if (IsMonitoring)
                {
                    CommandStopMonitor.Execute();
                }

                //#if DEBUG
                //                    Logger.Log("AudioPaneViewModel.CommandPlay (called PAUSE)", Category.Debug, Priority.Medium);
                //#endif


                if (PlayBytePosition < 0)
                {
                    m_LastSetPlayBytePosition = 0;
                }

                if (!IsSelectionSet)
                {
                    //if (LastPlayHeadTime >= State.Audio.ConvertBytesToMilliseconds(State.Audio.DataLength))
                    if (PlayBytePosition >= State.Audio.DataLength)
                    {
                        if (Settings.Default.Audio_DisableAutoJumpToBegin_AtEndOfPlayback)
                        {
                            //m_LastSetPlayBytePosition = State.Audio.DataLength;
                            //PlayBytePosition = State.Audio.DataLength;
                            AudioCues.PlayBeep();
                        }
                        else
                        {
                            //LastPlayHeadTime = 0; infinite loop !
                            AudioPlayer_PlayFromTo(0, -1);
                        }
                    }
                    else
                    {
                        AudioPlayer_PlayFromTo(PlayBytePosition, -1);
                    }
                }
                else
                {
                    if (false &&
                        PlayBytePosition >= State.Selection.SelectionBeginBytePosition &&
                        PlayBytePosition < State.Selection.SelectionEndBytePosition)
                    {
                        //if (verifyBeginEndPlayerValues(byteLastPlayHeadTime, byteSelectionRight))
                        //{
                        //}
                        AudioPlayer_PlayFromTo(PlayBytePosition, State.Selection.SelectionEndBytePosition);
                    }
                    else
                    {
                        //if (verifyBeginEndPlayerValues(byteSelectionLeft, byteSelectionRight))
                        //{
                        //}
                        AudioPlayer_PlayFromTo(State.Selection.SelectionBeginBytePosition, State.Selection.SelectionEndBytePosition);
                    }
                }
            },
                () => State.Audio.HasContent &&
                !IsPlaying &&
                (!IsMonitoring || IsMonitoringAlways) &&
                !IsRecording
                //&& !IsWaveFormLoading
                ,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_PlayPause));

            m_ShellView.RegisterRichCommand(CommandPlay);
            //
            CommandPlayAutoAdvance = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioPlayAutoAdvance_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioPlayAutoAdvance_LongDesc,
                null,                                                     // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadGnomeGionIcon("applications-multimedia"), //emblem-system
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandPlayAutoAdvance", Category.Debug, Priority.Medium);

                m_PlayAutoAdvance = true;
                CommandPlay.Execute();
            },
                () => CommandPlay.CanExecute(),
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_PlayAutoAdvance));

            m_ShellView.RegisterRichCommand(CommandPlayAutoAdvance);
            //
            CommandPlayPreviewLeft = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioPlayPreviewLeft_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioPlayPreviewLeft_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                ScalableGreyableImageProvider.ConvertIconFormat((DrawingImage)Application.Current.FindResource("Horizon_Image_Left")),
                () => PlayPreviewLeftRight(true),
                () => CommandPlay.CanExecute(),
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_PlayLeftPreview));

            m_ShellView.RegisterRichCommand(CommandPlayPreviewLeft);
            //
            CommandPlayPreviewRight = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioPlayPreviewRight_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioPlayPreviewRight_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                ScalableGreyableImageProvider.ConvertIconFormat((DrawingImage)Application.Current.FindResource("Horizon_Image_Right")),
                () => PlayPreviewLeftRight(false),
                () => CommandPlay.CanExecute(),
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_PlayRightPreview));

            m_ShellView.RegisterRichCommand(CommandPlayPreviewRight);
            //
        }
Example #11
0
        public static void Handle(Exception rootException, bool doExit, IShellView shellView)
        {
            if (rootException == null)
            {
                return;
            }

            if (!Dispatcher.CurrentDispatcher.CheckAccess())
            {
#if DEBUG
                Debugger.Break();
#endif
                Dispatcher.CurrentDispatcher.Invoke((Action <Exception, bool, IShellView>)Handle, rootException, doExit, shellView);
                return;
            }


            Exception ex = rootException;

            if (rootException is TargetInvocationException)
            {
                if (rootException.InnerException != null)
                {
                    ex = rootException.InnerException.GetRootException();
                }
                else
                {
                    ex = rootException.GetRootException();
                }

                ex = rootException.InnerException;
            }

            LogException(ex);

            var margin = new Thickness(0, 0, 0, 8);

            var panel = new DockPanel {
                LastChildFill = true
            };
            //var panel = new StackPanel { Orientation = Orientation.Vertical };



            var labelMsg = new TextBoxReadOnlyCaretVisible
            {
                TextReadOnly = String.Format(Tobi_Common_Lang.UnhandledException, Environment.NewLine, ApplicationConstants.LOG_FILE_NAME, ApplicationConstants.LOG_FILE_PATH),

                BorderThickness = new Thickness(1),
                Padding         = new Thickness(6),
                FontWeight      = FontWeights.ExtraBlack,
                Margin          = margin,
                BorderBrush     = Brushes.Red
            };


            //var binding = new Binding
            //                  {
            //                      Mode = BindingMode.OneWay,
            //                      Source = UserInterfaceStrings.UnhandledException,
            //                      Path = new PropertyPath(".")
            //                  };
            //var expr = labelMsg.SetBinding(TextBox.TextProperty, binding);

            //labelMsg.PreviewKeyDown += ((sender, e) =>
            //                              {
            //                                  if (!(e.Key == Key.Down || e.Key == Key.Up || e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Home || e.Key == Key.End || e.Key == Key.PageDown || e.Key == Key.PageUp || e.Key == Key.Tab))
            //                                      e.Handled = true;
            //                              });

            labelMsg.SetValue(DockPanel.DockProperty, Dock.Top);
            panel.Children.Add(labelMsg);


            //var exMessage = UserInterfaceStrings.UnhandledException;
            //exMessage += Environment.NewLine;
            //exMessage += @"===============";
            //exMessage += Environment.NewLine;
            var       exMessage = "[" + ex.GetType().FullName + "] " + ex.Message;
            Exception exinnerd  = ex;
            while (exinnerd.InnerException != null)
            {
                if (!String.IsNullOrEmpty(exinnerd.InnerException.Message))
                {
                    exMessage += Environment.NewLine;
                    exMessage += @"======";
                    exMessage += Environment.NewLine;
                    exMessage += "[" + exinnerd.GetType().FullName + "] ";
                    exMessage += exinnerd.InnerException.Message;
                }

                exinnerd = exinnerd.InnerException;
            }

            var compEx = ex as CompositionException;

            if (compEx != null)
            {
                foreach (var error in compEx.Errors)
                {
                    exMessage += Environment.NewLine;
                    exMessage += @"======";
                    exMessage += Environment.NewLine;
                    exMessage += error.Description;

                    if (error.Exception != null)
                    {
                        exMessage += Environment.NewLine;
                        exMessage += @"======";
                        exMessage += Environment.NewLine;
                        exMessage += "[" + error.Exception.GetType().FullName + "] ";
                        exMessage += error.Exception.Message;

                        exinnerd = error.Exception;
                        while (exinnerd.InnerException != null)
                        {
                            if (!String.IsNullOrEmpty(exinnerd.InnerException.Message))
                            {
                                exMessage += Environment.NewLine;
                                exMessage += @"======";
                                exMessage += Environment.NewLine;
                                exMessage += "[" + exinnerd.InnerException.GetType().FullName + "] ";
                                exMessage += exinnerd.InnerException.Message;
                            }

                            exinnerd = exinnerd.InnerException;
                        }
                    }
                }
            }

            var labelSummary = new TextBoxReadOnlyCaretVisible
            {
                TextReadOnly = exMessage,

                Padding    = new Thickness(6),
                FontWeight = FontWeights.ExtraBlack,
                //Margin = margin,

                BorderBrush     = null,
                BorderThickness = new Thickness(0)
            };

            var scroll = new ScrollViewer
            {
                Content = labelSummary,
                //Margin = margin,

                BorderBrush = SystemColors.ControlDarkBrush,
                //BorderBrush = Brushes.Red,

                BorderThickness     = new Thickness(1),
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Stretch
            };
            //scroll.SetValue(DockPanel.DockProperty, Dock.Top);

            panel.Children.Add(scroll);

            // DETAILS:

            var       exStackTrace = ex.StackTrace;
            Exception exinner      = ex;
            while (exinner.InnerException != null)
            {
                if (!String.IsNullOrEmpty(exinner.InnerException.StackTrace))
                {
                    exStackTrace += Environment.NewLine;
                    exStackTrace += "=========================";
                    exStackTrace += Environment.NewLine;
                    exStackTrace += "-------------------------";
                    exStackTrace += Environment.NewLine;
                    exStackTrace += exinner.InnerException.StackTrace;
                }

                exinner = exinner.InnerException;
            }

            if (compEx != null)
            {
                foreach (var error in compEx.Errors)
                {
                    if (error.Exception != null)
                    {
                        exStackTrace += Environment.NewLine;
                        exStackTrace += "=========================";
                        exStackTrace += Environment.NewLine;
                        exStackTrace += "-------------------------";
                        exStackTrace += Environment.NewLine;
                        exStackTrace += error.Exception.StackTrace;

                        exinner = error.Exception;
                        while (exinner.InnerException != null)
                        {
                            if (!String.IsNullOrEmpty(exinner.InnerException.StackTrace))
                            {
                                exStackTrace += Environment.NewLine;
                                exStackTrace += "=========================";
                                exStackTrace += Environment.NewLine;
                                exStackTrace += "-------------------------";
                                exStackTrace += Environment.NewLine;
                                exStackTrace += exinner.InnerException.StackTrace;
                            }

                            exinner = exinner.InnerException;
                        }
                    }
                }
            }

            var stackTrace = new TextBoxReadOnlyCaretVisible
            {
                TextReadOnly = exStackTrace,

                Padding         = new Thickness(6),
                BorderBrush     = null,
                BorderThickness = new Thickness(0)
            };

            var details = new ScrollViewer
            {
                Content             = stackTrace,
                Margin              = margin,
                BorderBrush         = SystemColors.ControlDarkDarkBrush,
                BorderThickness     = new Thickness(1),
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Stretch
            };
            //panel.Children.Add(scroll);

            /*
             * var logStr = String.Format("CANNOT OPEN [{0}] !", logPath);
             *
             * var logFile = File.Open(logPath, FileMode.Open, FileAccess.Read, FileShare.Read);
             * if (logFile.CanRead)
             * {
             *  logFile.Close();
             *  //logFile.Read(bytes, int, int)
             *  logStr = File.ReadAllText(logPath);
             * }
             *
             * var log = new TextBlock
             * {
             *  Text = logStr,
             *  Margin = new Thickness(15),
             *  HorizontalAlignment = HorizontalAlignment.Left,
             *  VerticalAlignment = VerticalAlignment.Top,
             *  TextWrapping = TextWrapping.Wrap,
             * };
             *
             * var scroll2 = new ScrollViewer
             * {
             *  Content = log,
             *  HorizontalAlignment = HorizontalAlignment.Stretch,
             * };
             * panel.Children.Add(scroll2);
             * */

            var windowPopup = new PopupModalWindow(shellView,
                                                   UserInterfaceStrings.EscapeMnemonic(Tobi_Common_Lang.Unexpected),
                                                   panel,
                                                   PopupModalWindow.DialogButtonsSet.Ok,
                                                   PopupModalWindow.DialogButton.Ok,
                                                   !doExit, 500, 250,
                                                   (String.IsNullOrEmpty(exStackTrace) ? null : details), 130, null);

            AudioCues.PlayExclamation();

            try
            {
                windowPopup.ShowModal();
            }
            catch (TargetInvocationException exx1)
            {
                try
                {
                    Dispatcher.CurrentDispatcher.Invoke((Action)(windowPopup.ShowModal));
                }
                catch (TargetInvocationException exx2)
                {
                    throw exx2.InnerException;
                }
            }

            if (windowPopup.ClickedDialogButton == PopupModalWindow.DialogButton.Ok &&
                doExit)
            {
                Application.Current.Shutdown();
                //Environment.Exit(1);
            }
        }