editactions.monkey2 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. Namespace ted2
  2. Class EditActions
  3. Field undo:Action
  4. Field redo:Action
  5. Field cut:Action
  6. Field copy:Action
  7. Field paste:Action
  8. Field selectAll:Action
  9. Field wordWrap:Action
  10. Field gotoLine:Action
  11. Method New( docs:DocumentManager )
  12. _docs=docs
  13. undo=New Action( "Undo" )
  14. undo.Triggered=OnUndo
  15. undo.HotKey=Key.Z
  16. undo.HotKeyModifiers=Modifier.Menu|Modifier.Ignore
  17. redo=New Action( "Redo" )
  18. redo.Triggered=OnRedo
  19. redo.HotKey=Key.Y
  20. redo.HotKeyModifiers=Modifier.Menu|Modifier.Ignore
  21. cut=New Action( "Cut" )
  22. cut.Triggered=OnCut
  23. cut.HotKey=Key.X
  24. cut.HotKeyModifiers=Modifier.Menu|Modifier.Ignore
  25. copy=New Action( "Copy" )
  26. copy.Triggered=OnCopy
  27. copy.HotKey=Key.C
  28. copy.HotKeyModifiers=Modifier.Menu|Modifier.Ignore
  29. paste=New Action( "Paste" )
  30. paste.Triggered=OnPaste
  31. paste.HotKey=Key.V
  32. paste.HotKeyModifiers=Modifier.Menu|Modifier.Ignore
  33. selectAll=New Action( "Select all" )
  34. selectAll.Triggered=OnSelectAll
  35. selectAll.HotKey=Key.A
  36. selectAll.HotKeyModifiers=Modifier.Menu|Modifier.Ignore
  37. wordWrap=New Action( "Toggle word wrap" )
  38. wordWrap.Triggered=OnWordWrap
  39. wordWrap.HotKey=Key.W
  40. wordWrap.HotKeyModifiers=Modifier.Menu
  41. gotoLine=New Action( "Goto line" )
  42. gotoLine.Triggered=OnGotoLine
  43. gotoLine.HotKey=Key.G
  44. gotoLine.HotKeyModifiers=Modifier.Menu
  45. End
  46. Method Update()
  47. Local tv:=Cast<TextView>( App.KeyView )
  48. undo.Enabled=tv And tv.CanUndo
  49. redo.Enabled=tv And tv.CanRedo
  50. cut.Enabled=tv And tv.CanCut
  51. copy.Enabled=tv And tv.CanCopy
  52. paste.Enabled=tv And tv.CanPaste
  53. selectAll.Enabled=tv
  54. End
  55. Private
  56. Field _docs:DocumentManager
  57. Method OnUndo()
  58. Local tv:=Cast<TextView>( App.KeyView )
  59. If tv tv.Undo()
  60. End
  61. Method OnRedo()
  62. Local tv:=Cast<TextView>( App.KeyView )
  63. If tv tv.Redo()
  64. End
  65. Method OnCut()
  66. Local tv:=Cast<TextView>( App.KeyView )
  67. If tv tv.Cut()
  68. End
  69. Method OnCopy()
  70. Local tv:=Cast<TextView>( App.KeyView )
  71. If tv tv.Copy()
  72. End
  73. Method OnPaste()
  74. Local tv:=Cast<TextView>( App.KeyView )
  75. If tv tv.Paste()
  76. End
  77. Method OnSelectAll()
  78. Local tv:=Cast<TextView>( App.KeyView )
  79. If tv tv.SelectAll()
  80. End
  81. Method OnWordWrap()
  82. Local tv:=Cast<TextView>( App.KeyView )
  83. If tv tv.WordWrap=Not tv.WordWrap
  84. End
  85. Method OnGotoLine()
  86. Local tv:=Cast<TextView>( App.KeyView )
  87. If Not tv Return
  88. Local line:=RequestInt( "Goto line:","Goto line",tv.CursorLine+1,0,1,tv.Document.NumLines )
  89. If Not line Return
  90. tv.GotoLine( line-1 )
  91. tv.MakeKeyView()
  92. End
  93. End