终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

95 line
2.8 KiB

  1. using BeDesignerSCADA.Common;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Shapes;
  15. namespace BeDesignerSCADA.View
  16. {
  17. /// <summary>
  18. /// JsEditWindow.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class JsEditWindow : Window
  21. {
  22. public JsEditWindow()
  23. {
  24. InitializeComponent();
  25. Owner = Application.Current.MainWindow;
  26. Closing += (s, e) => { e.Cancel = true; Hide(); };
  27. }
  28. public static JsEditWindow Instance { get; } = new JsEditWindow();
  29. public static string ShowEdit(string script, List<FrameworkElement> selectItems)
  30. {
  31. // 获取所有控件的可用属性
  32. var pros = PropertyHelper.GetCustomerControlProperty(selectItems);
  33. Instance.Tree.ItemsSource = pros;
  34. Instance.txtBox.Text = script;
  35. Instance.ShowDialog();
  36. if (Instance.IsOk)
  37. {
  38. return Instance.txtBox.Text;
  39. }
  40. else
  41. {
  42. return script;
  43. }
  44. }
  45. public bool IsOk { get; set; }
  46. private void CancelBtn_Click(object sender, RoutedEventArgs e)
  47. {
  48. IsOk = false;
  49. Close();
  50. }
  51. private void ConfirmBtn_Click(object sender, RoutedEventArgs e)
  52. {
  53. IsOk = true;
  54. Close();
  55. }
  56. private void Tree_MouseMove(object sender, MouseEventArgs e)
  57. {
  58. if (Tree.SelectedItem != null && e.LeftButton == MouseButtonState.Pressed)
  59. {
  60. DragDrop.DoDragDrop(Tree, Tree.SelectedItem, System.Windows.DragDropEffects.Copy);
  61. }
  62. }
  63. private void txtBox_Drop(object sender, DragEventArgs e)
  64. {
  65. e.Effects = DragDropEffects.Copy;
  66. var data = ((ControlName)e.Data.GetData("BeDesignerSCADA.Common.ControlName"));
  67. var str = $"{(data.Parent == null ? string.Empty : (data.Parent.Name + "."))}{data.Name}";
  68. var position = txtBox.GetPositionFromPoint(e.GetPosition(txtBox));
  69. if (position == null)
  70. {
  71. txtBox.Text += str;
  72. return;
  73. }
  74. var offset = txtBox.Document.GetOffset(position.Value.Location);
  75. txtBox.SelectionStart = offset;
  76. txtBox.Document.Insert(offset, str);
  77. }
  78. private void txtBox_DragOver(object sender, DragEventArgs e)
  79. {
  80. e.Effects = DragDropEffects.Copy;
  81. }
  82. }
  83. }