Example #1
0
        /// <summary>
        /// Starts a find operation using the specified find data.
        /// </summary>
        /// <param name="owner">The dialog owner.</param>
        /// <param name="findData">The data to find.</param>
        /// <param name="findMode">Whether to find next, previous, or display a dialog.</param>
        /// <returns>True if the find text was found and selected.  False otherwise.</returns>
        public bool Find(IWin32Window owner, FindData findData, FindMode findMode)
        {
            this.Data = findData;

            // Use this.Data instead of findData in case the user passed in null.
            using (IFindDialog dlg = this.Data.CreateFindDialog())
            {
                bool result;
                switch (findMode)
                {
                case FindMode.ShowDialog:
                    result = this.Find(owner, dlg);
                    break;

                case FindMode.FindPrevious:
                    result = this.FindPrevious(owner, dlg);
                    break;

                default:
                    result = this.FindNext(owner, dlg);
                    break;
                }

                return(result);
            }
        }
        public MainWindowViewModel(WindowSettingsViewModel windowSettingsViewModel, InputTextBoxViewModel inputTextBoxViewModel, StatusBarViewModel statusBarViewModel, IFontDialog fontDialog,
                                   IFindDialog findDialog, IColorDialog colorDialog, IAboutDialog aboutDialog, IMessageDialog messageDialog, IReplaceDialog replaceDialog, IOpenFileDialog openFileDialog,
                                   ISaveFileDialog saveFileDialog, IGoToLineDialog goToLineDialog, ITextFileWriter textFileWriter, ITextFileReader textFileReader, IDocInfoService docInfoService,
                                   IFindNextAndReplaceConditionsService findNextSearchConditionsService)
        {
            _fontDialog     = fontDialog;
            _findDialog     = findDialog;
            _colorDialog    = colorDialog;
            _aboutDialog    = aboutDialog;
            _messageDialog  = messageDialog;
            _replaceDialog  = replaceDialog;
            _openFileDialog = openFileDialog;
            _saveFileDialog = saveFileDialog;
            _goToLineDialog = goToLineDialog;
            _textFileWriter = textFileWriter;
            _textFileReader = textFileReader;
            _docInfoService = docInfoService;
            _findNextSearchConditionsService = findNextSearchConditionsService;

            StatusBarViewModel      = statusBarViewModel;
            InputTextBoxViewModel   = inputTextBoxViewModel;
            WindowSettingsViewModel = windowSettingsViewModel;

            InitMessengerRegistrations();
        }
Example #3
0
        /// <summary>
        /// Handles displaying the find dialog.
        /// </summary>
        /// <param name="findDialog">The dialog to display.</param>
        /// <param name="owner">The dialog owner.</param>
        /// <param name="findData">The find data.</param>
        /// <returns>True if the user pressed OK.</returns>
        protected override bool OnDialogExecute(IFindDialog findDialog, IWin32Window owner, FindData findData)
        {
            // Initialize the find text from the selection.
            string?oldFindText = null;

            if (this.textBox.SelectionLength > 0)
            {
                // Only use the selection if it is one line or less.
                string selectedText = this.textBox.SelectedText;
                if (selectedText.IndexOf('\n') < 0)
                {
                    oldFindText   = findData.Text;
                    findData.Text = this.textBox.SelectedText;
                }
            }

            // Call the base method to display the dialog.
            bool result = base.OnDialogExecute(findDialog, owner, findData);

            // If they canceled, then we may need to restore the old find text.
            if (!result && oldFindText != null)
            {
                findData.Text = oldFindText;
            }

            return(result);
        }
Example #4
0
        private bool FindPrevious(IWin32Window owner, IFindDialog findDialog)
        {
            bool result;

            if (string.IsNullOrEmpty(this.Data.Text))
            {
                this.Data.SearchUp = true;
                result             = this.Find(owner, findDialog);
            }
            else
            {
                using (new WaitCursor(owner as Control))
                {
                    result = this.OnFindPrevious();
                }
            }

            return(result);
        }
Example #5
0
        private bool Find(IWin32Window owner, IFindDialog findDialog)
        {
            Conditions.RequireReference(findDialog, nameof(findDialog));

            bool result = false;

            if (this.OnDialogExecute(findDialog, owner, this.Data))
            {
                if (this.Data.SearchUp)
                {
                    result = this.FindPrevious(owner, findDialog);
                }
                else
                {
                    result = this.FindNext(owner, findDialog);
                }
            }

            return(result);
        }
Example #6
0
        /// <summary>
        /// Called to execute the dialog.  This allows you to do custom actions before
        /// and after the dialog is executed.
        /// </summary>
        /// <param name="findDialog">The dialog to display.</param>
        /// <param name="owner">The dialog owner.</param>
        /// <param name="findData">The find data.</param>
        /// <returns>True if OK was pressed.</returns>
        protected virtual bool OnDialogExecute(IFindDialog findDialog, IWin32Window owner, FindData findData)
        {
            bool result = findDialog.Execute(owner, findData);

            return(result);
        }
 public FindCommand(MainWindowViewModel callerViewModel, IFindDialog findDialog) : base(callerViewModel)
 {
     _findDialog = findDialog;
 }