﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace LogoScriptIDE
{
    /// <summary>
    /// ReplaceWindow.xaml 的交互逻辑
    /// 替换窗口
    /// </summary>
    public partial class ReplaceWindow : Window
    {
        /// <summary>
        /// 替换窗口构造函数
        /// </summary>
        public ReplaceWindow()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 关闭替换窗口时间回调函数
        /// </summary>
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            // 隐藏窗口并取消关闭
            Hide();
            Owner.Activate();
            e.Cancel = true;
        }

        /// <summary>
        /// 搜索回调函数
        /// </summary>
        private void ui_search_Click(object sender, RoutedEventArgs e)
        {
            ((MainWindow)Owner).FindNext(ui_text.Text, (bool)ui_case.IsChecked);
        }

        /// <summary>
        /// 替换回调函数
        /// </summary>
        private void ui_replace_Click(object sender, RoutedEventArgs e)
        {
            ((MainWindow)Owner).Replace(
                ui_text.Text, ui_replaceText.Text, (bool)ui_case.IsChecked);
        }

        /// <summary>
        /// 全部替换回调函数
        /// </summary>
        private void ui_replaceAll_Click(object sender, RoutedEventArgs e)
        {
            ((MainWindow)Owner).ReplaceAll(
                ui_text.Text, ui_replaceText.Text, (bool)ui_case.IsChecked);
        }

        /// <summary>
        /// 取消回调函数
        /// </summary>
        private void ui_cancel_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        /// <summary>
        /// 文本框改变回调函数
        /// 根据文本框中是否有内容设置各个按钮是否可以被点击
        /// </summary>
        private void ui_text_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (ui_text.Text.Length == 0)
            {
                ui_search.IsEnabled = false;
                ui_replace.IsEnabled = false;
                ui_replaceAll.IsEnabled = false;
            }
            else
            {
                ui_search.IsEnabled = true;
                ui_replace.IsEnabled = true;
                ui_replaceAll.IsEnabled = true;
            }
        }
    }
}
