PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/src/lextm/wiseeditor/feature/EditorAidFeature.cs

http://lextudio.googlecode.com/
C# | 953 lines | 613 code | 125 blank | 215 comment | 127 complexity | 55f5aa807fc2f30ae0864665737f0d6c MD5 | raw file
Possible License(s): CPL-1.0, Apache-2.0, GPL-2.0, LGPL-2.1
  1. using System;
  2. using System.CodeDom;
  3. using System.Collections.Generic;
  4. using System.Windows.Forms;
  5. using BeWise.Common.Utils;
  6. using BeWise.SharpBuilderTools.Gui;
  7. using BeWise.SharpBuilderTools.Helpers;
  8. using Borland.Studio.ToolsAPI;
  9. using Lextm.OpenTools;
  10. namespace Lextm.WiseEditor.Feature {
  11. public class EditorAidFeature : Lextm.OpenTools.CustomFeature {
  12. const string Name = "Editor Aid";
  13. /**************************************************************/
  14. /* Private
  15. /**************************************************************/
  16. private static void HyperMove(bool aBack) {
  17. if (!ValidationHelpers.ValidateCurrentSourceEditorNotNull()) {
  18. return;
  19. }
  20. IOTASourceEditor _SourceEditor = OtaUtils.GetCurrentSourceEditor();
  21. IOTAEditView _EditView = _SourceEditor.GetEditView(0);
  22. string _Source = OtaUtils.GetSourceEditorText(_SourceEditor);
  23. int _StartPos = OtaUtils.GetSourceEditorTextPos(_SourceEditor);
  24. int _Pos = -1;
  25. bool _Found = false;
  26. if (aBack) {
  27. int i = _StartPos - 1;
  28. while (i > 0) {
  29. if (// 'zA'
  30. (Char.IsLower(_Source, i-1) && Char.IsUpper(_Source, i)) ||
  31. // '.R' or '_T' or ' P'
  32. (Char.IsLetterOrDigit(_Source, i-1) && !Char.IsLetterOrDigit(_Source,i)) ||
  33. // '8y' or '7P'
  34. (Char.IsDigit(_Source, i-1) && Char.IsLetter(_Source, i)) ||
  35. // 'A3' or 'd6'
  36. (Char.IsLetter(_Source, i-1) && Char.IsDigit(_Source, i)) ||
  37. // 'RGx'
  38. (Char.IsUpper(_Source, i) && Char.IsUpper(_Source, i-1) && i + 1 < _Source.Length && Char.IsLower(_Source, i+1))
  39. ) {
  40. _Pos = i;
  41. _Found = true;
  42. break;
  43. }
  44. i--;
  45. }
  46. if (!_Found) {
  47. _Pos = 0;
  48. _Found = true;
  49. }
  50. } else {
  51. int i = _StartPos;
  52. while (i < _Source.Length - 1) {
  53. if (// 'aZ'
  54. (Char.IsLower(_Source, i) && Char.IsUpper(_Source, i+1)) ||
  55. // '8a' or '8A'
  56. (Char.IsLetter(_Source, i) && Char.IsDigit(_Source, i+1)) ||
  57. // 'a8' or 'A8'
  58. (Char.IsDigit(_Source, i) && Char.IsLetter(_Source, i+1)) ||
  59. // '.R' or '_T' or ' P'
  60. (!Char.IsLetterOrDigit(_Source,i) && Char.IsLetterOrDigit(_Source, i+1)) ||
  61. // 'RGx'
  62. (Char.IsUpper(_Source, i) && Char.IsUpper(_Source, i+1) && i+2 < _Source.Length - 1 && Char.IsLower(_Source, i+2))
  63. ) {
  64. _Pos = i + 1;
  65. _Found = true;
  66. break;
  67. }
  68. i++;
  69. }
  70. if (!_Found) {
  71. _Pos = _Source.Length;
  72. _Found = true;
  73. }
  74. }
  75. if (_Found) {
  76. if ((_EditView.Block.Style == OTABlockType.btNonInclusive) ||
  77. (_EditView.Block.Size > 0)) {
  78. int _SelStart = OtaUtils.CharPosToBufferPos(_SourceEditor, _SourceEditor.BlockStart);
  79. int _SelEnd = OtaUtils.CharPosToBufferPos(_SourceEditor, _SourceEditor.BlockAfter);
  80. _EditView.Block.Reset();
  81. if (_SelStart == _StartPos) {
  82. _EditView.CursorPos = OtaUtils.BufferPosToEditPos(_SourceEditor, _Pos);
  83. _EditView.Block.BeginBlock();
  84. _EditView.CursorPos = OtaUtils.BufferPosToEditPos(_SourceEditor, _SelEnd);
  85. } else if (_SelEnd == _StartPos) {
  86. _EditView.CursorPos = OtaUtils.BufferPosToEditPos(_SourceEditor, _SelStart);
  87. _EditView.Block.BeginBlock();
  88. _EditView.CursorPos = OtaUtils.BufferPosToEditPos(_SourceEditor, _Pos);
  89. }
  90. _EditView.Block.EndBlock();
  91. }
  92. _EditView.CursorPos = OtaUtils.BufferPosToEditPos(_SourceEditor, _Pos);
  93. _EditView.MoveViewToCursor();
  94. _EditView.Paint();
  95. }
  96. }
  97. private static void SortSelectedText(bool aAscending, bool aCaseSensitive) {
  98. IOTASourceEditor _SourceEditor = OtaUtils.GetCurrentSourceEditor();
  99. if (_SourceEditor == null)
  100. {
  101. return;
  102. }
  103. string _Text = OtaUtils.GetSelectedText(OtaUtils.GetCurrentModule());
  104. if (_Text == null || _Text.Length == 0) {
  105. OtaUtils.SelectLine(OtaUtils.GetCurrentSourceEditor());
  106. _Text = OtaUtils.GetSelectedText(OtaUtils.GetCurrentModule());
  107. }
  108. List<string> _Lines = new List<string>(Lextm.StringHelper.GetLinesFromString(_Text));
  109. // Do the sorting
  110. SortHelper _SortHelper = new SortHelper();
  111. _SortHelper.Ascending = aAscending;
  112. _SortHelper.CaseSensitive = aCaseSensitive;
  113. _Lines.Sort(_SortHelper);
  114. _Text = OtaUtils.BuildLines(_Lines, true);
  115. OtaUtils.ReplaceSelectedText(_SourceEditor, _Text);
  116. _SourceEditor.GetEditView(0).Paint();
  117. }
  118. /**************************************************************/
  119. /* Protected
  120. /**************************************************************/
  121. //private void DoBackHistory(object aSender, EventArgs e) {
  122. // bool result = OTAUtils.ExecuteMenu("BackMenuItem");
  123. //}
  124. /*
  125. private void DoComment(object aSender, EventArgs e) {
  126. if (!ValidationHelpers.ValidateCurrentModuleIsCSOrXmlOrDelphiFile()) {
  127. return;
  128. }
  129. IOTASourceEditor _SourceEditor = OTAUtils.GetCurrentSourceEditor();
  130. if (_SourceEditor != null) {
  131. string _Text = OTAUtils.GetSelectedText(OTAUtils.GetCurrentModule());
  132. bool _NoTextSelected = (_Text == null || _Text.Length == 0);
  133. if (_NoTextSelected) {
  134. OTAUtils.SelectLine(OTAUtils.GetCurrentSourceEditor());
  135. _Text = OTAUtils.GetSelectedText(OTAUtils.GetCurrentModule());
  136. }
  137. string[] _Lines = ShareUtils.GetLinesFromString(_Text);
  138. if (_Lines.Length > 0) {
  139. BaseLanguageCodeHelper _LanguageCodeHelper = LanguageCodeHelperFactory.GetLanguageCodeHelper(OTAUtils.GetCurrentEditorFileName());
  140. _Lines = _LanguageCodeHelper.CommentLines(_Lines);
  141. _Text = OTAUtils.BuildLines(_Lines, _Text.EndsWith("\n"));
  142. OTAUtils.ReplaceSelectedText(_SourceEditor, _Text);
  143. _SourceEditor.GetEditView(0).Paint();
  144. }
  145. }
  146. }
  147. */
  148. private void DoConvertSpaceToTab(object aSender, EventArgs AEventArgs) {
  149. if (!ValidationHelpers.ValidateCurrentSourceEditorNotNull()) {
  150. return;
  151. }
  152. IOTASourceEditor _SourceEditor = OtaUtils.GetCurrentSourceEditor();
  153. IOTAEditView _EditView = _SourceEditor.GetEditView(0);
  154. int _Error;
  155. // Replace All
  156. while (_EditView.Buffer.EditPosition.Replace(new string(' ', OtaUtils.GetCSIndentationFromOptions()),
  157. "\t",
  158. false,
  159. false,
  160. true,
  161. OTASearchDirection.sdForward,
  162. out _Error) > 0)
  163. ;
  164. _EditView.Paint();
  165. }
  166. private void DoConvertTabToSpace(object aSender, EventArgs AEventArgs) {
  167. if (!ValidationHelpers.ValidateCurrentSourceEditorNotNull()) {
  168. return;
  169. }
  170. IOTASourceEditor _SourceEditor = OtaUtils.GetCurrentSourceEditor();
  171. IOTAEditView _EditView = _SourceEditor.GetEditView(0);
  172. int _Error;
  173. // Replace All
  174. while (_EditView.Buffer.EditPosition.Replace("\t",
  175. new string(' ', OtaUtils.GetCSIndentationFromOptions()),
  176. false,
  177. false,
  178. true,
  179. OTASearchDirection.sdForward,
  180. out _Error) > 0)
  181. ;
  182. _EditView.Paint();
  183. }
  184. //private void DoCreateRegion(object aSender, EventArgs e) {
  185. // if (!ValidationHelpers.ValidateCurrentModuleIsSourceFile()) {
  186. // return;
  187. // }
  188. // IOTASourceEditor _SourceEditor = OtaUtils.GetCurrentSourceEditor();
  189. // if (_SourceEditor != null) {
  190. // IOTAEditView _EditView = _SourceEditor.GetEditView(0);
  191. // if (_EditView != null) {
  192. // FrmCreateRegion _Frm = new FrmCreateRegion();
  193. // if (_Frm.ShowDialog() == DialogResult.OK) {
  194. // string _Text = OtaUtils.GetSelectedText(OtaUtils.GetCurrentModule());
  195. // bool _NoTextSelected = (_Text == null || _Text.Length == 0);
  196. // if (_NoTextSelected) {
  197. // OtaUtils.SelectLine(OtaUtils.GetCurrentSourceEditor());
  198. // _Text = OtaUtils.GetSelectedText(OtaUtils.GetCurrentModule());
  199. // }
  200. // IList<string> _Lines = MiscUtils.GetLinesFromString(_Text);
  201. // string[] _NewLines = new string[_Lines.Count + 2];
  202. // BaseLanguageCodeHelper _LanguageCodeHelper = LanguageCodeHelperFactory.GetLanguageCodeHelper(OtaUtils.GetCurrentEditorFileName());
  203. // if (_EditView.CursorPos.Col > 1 && !_NoTextSelected) {
  204. // _NewLines[0] = new String(' ', _EditView.CursorPos.Col) + _LanguageCodeHelper.CreateRegionHeader(_Frm.RegionText);
  205. // } else {
  206. // _NewLines[0] = OtaUtils.GetStringBeforeFirstWord() + _LanguageCodeHelper.CreateRegionHeader(_Frm.RegionText);
  207. // }
  208. // for (int i = 0; i < _Lines.Count; i++) {
  209. // _NewLines[i+1] = _Lines[i];
  210. // }
  211. // if (_EditView.CursorPos.Col > 1 && !_NoTextSelected) {
  212. // _NewLines[_NewLines.Length -1] = new String(' ', _EditView.CursorPos.Col) + _LanguageCodeHelper.CreateRegionFooter(_Frm.RegionText);
  213. // } else {
  214. // _NewLines[_NewLines.Length -1] = OtaUtils.GetStringBeforeFirstWord() + _LanguageCodeHelper.CreateRegionFooter(_Frm.RegionText);
  215. // }
  216. // _Text = OtaUtils.BuildLines(_NewLines, true);
  217. // OtaUtils.ReplaceSelectedText(_SourceEditor, _Text);
  218. // _EditView.Paint();
  219. // }
  220. // }
  221. // }
  222. //}
  223. private void DoDefaultSort(object aSender, EventArgs AEventArgs) {
  224. if (!ValidationHelpers.ValidateCurrentSourceEditorNotNull()) {
  225. return;
  226. }
  227. SortSelectedText(true, true);
  228. }
  229. private void DoElideToDefinitions(object sender, EventArgs e) {
  230. if (!ValidationHelpers.ValidateCurrentModuleNotNull()) {
  231. return;
  232. }
  233. OtaUtils.GetCurrentEditor().Show();
  234. IOTAEditView _EditView = OtaUtils.GetCurrentEditView();
  235. _EditView.Paint();
  236. int Line = _EditView.CursorPos.Line;
  237. short Col = _EditView.CursorPos.Col;
  238. int _count = 0;
  239. InteriorElideToDefinitions(null , null, ref _count);
  240. //OTAUtils.ElideNearestBlock(_EditView, false);
  241. _EditView.Paint();
  242. OtaUtils.GoToPosition(OtaUtils.GetCurrentSourceEditor(), Line, Col);
  243. _EditView.MoveViewToCursor();
  244. _EditView.Paint();
  245. }
  246. private void DoElideNearestBlock(object aSender, EventArgs AEventArgs) {
  247. IOTAEditView _EditView = OtaUtils.GetCurrentEditView();
  248. if (_EditView != null) {
  249. OtaUtils.ElideNearestBlock(_EditView, false);
  250. _EditView.Paint();
  251. }
  252. }
  253. //private void DoForwardHistory(object aSender, EventArgs e) {
  254. // OTAUtils.ExecuteMenu("ForwardMenuItem");
  255. //}
  256. private void DoGetNextOccurence(object aSender, EventArgs AEventArgs) {
  257. DoGetNextPriorOccurence(false);
  258. }
  259. private static void DoGetNextPriorOccurence(bool aPrev) {
  260. if (!ValidationHelpers.ValidateCurrentSourceEditorNotNull()) {
  261. return;
  262. }
  263. IOTASourceEditor _SourceEditor = OtaUtils.GetCurrentSourceEditor();
  264. IOTAEditView _EditView = _SourceEditor.GetEditView(0);
  265. string _Word = OtaUtils.GetCurrentSelectedText();
  266. bool _Found = false;
  267. int _Pos = 0;
  268. // Find with the Current Word
  269. if (String.IsNullOrEmpty(OtaUtils.GetCurrentSelectedText())) {
  270. _Word = OtaUtils.GetCurrentWord(_SourceEditor);
  271. _Found = OtaUtils.FindTextIdent(_Word,
  272. OtaUtils.GetSourceEditorText(_SourceEditor),
  273. OtaUtils.GetSourceEditorTextPos(_SourceEditor),
  274. aPrev,
  275. out _Pos);
  276. if (_Found) {
  277. _EditView.CursorPos = OtaUtils.BufferPosToEditPos(_SourceEditor, _Pos);
  278. OtaUtils.ElideNearestBlock(_EditView, true);
  279. // clear selected block
  280. _EditView.Block.Reset();
  281. _EditView.CursorPos = OtaUtils.BufferPosToEditPos(_SourceEditor, _Pos);
  282. }
  283. // Find with the SelectedText
  284. } else {
  285. _Found = OtaUtils.FindSelectionText(_Word,
  286. OtaUtils.GetSourceEditorText(_SourceEditor),
  287. OtaUtils.GetSourceEditorTextPos(_SourceEditor),
  288. aPrev,
  289. out _Pos);
  290. if (_Found) {
  291. _EditView.CursorPos = OtaUtils.BufferPosToEditPos(_SourceEditor, _Pos);
  292. OtaUtils.ElideNearestBlock(_EditView, true);
  293. // clear selected block
  294. _EditView.Block.Reset();
  295. _EditView.CursorPos = OtaUtils.BufferPosToEditPos(_SourceEditor, _Pos);
  296. _EditView.Block.BeginBlock();
  297. _EditView.CursorPos = OtaUtils.BufferPosToEditPos(_SourceEditor, _Pos + _Word.Length);
  298. _EditView.Block.EndBlock();
  299. }
  300. }
  301. if (_Found) {
  302. _EditView.MoveViewToCursor();
  303. _EditView.Paint();
  304. }
  305. }
  306. private void DoGetPriorOccurence(object aSender, EventArgs AEventArgs) {
  307. DoGetNextPriorOccurence(true);
  308. }
  309. //private void DoGoToNextError(object aSender, EventArgs e) {
  310. // IOTAMessageService _MessageService = OTAUtils.GetMessageService();
  311. // _MessageService.NextErrorMessage(true, true);
  312. //}
  313. //private void DoGoToPreviousError(object aSender, EventArgs e) {
  314. // IOTAMessageService _MessageService = OTAUtils.GetMessageService();
  315. // _MessageService.NextErrorMessage(false, true);
  316. //}
  317. private void DoHyperBack(object aSender, EventArgs AEventArgs) {
  318. HyperMove(true);
  319. }
  320. private void DoHyperForward(object aSender, EventArgs AEventArgs) {
  321. HyperMove(false);
  322. }
  323. private void DoIndent(object aSender, EventArgs AEventArgs) {
  324. if (!ValidationHelpers.ValidateCurrentSourceEditorNotNull()) {
  325. return;
  326. }
  327. IOTASourceEditor _SourceEditor = OtaUtils.GetCurrentSourceEditor();
  328. IOTAEditView _EditView = _SourceEditor.GetEditView(0);
  329. BaseLanguageCodeHelper _LanguageCodeHelper = LanguageCodeHelperFactory.GetLanguageCodeHelper(OtaUtils.GetCurrentEditorFileName());
  330. _EditView.Buffer.EditBlock.Indent(_LanguageCodeHelper.GetIndentation());
  331. _EditView.Paint();
  332. }
  333. //private void DoInsertCodeTemplate(object aSender, EventArgs e) {
  334. // IOTAEditView _EditView = OTAUtils.GetCurrentEditView();
  335. // if (_EditView != null) {
  336. // IOTAEditActions _EditActions = _EditView as IOTAEditActions;
  337. // if (_EditActions != null) {
  338. // _EditActions.CodeTemplate();
  339. // }
  340. // }
  341. //}
  342. private void DoInsertFileAsText(object aSender, EventArgs AEventArgs) {
  343. if (!ValidationHelpers.ValidateCurrentSourceEditorNotNull()) {
  344. return;
  345. }
  346. IOTAEditView _EditView = OtaUtils.GetCurrentEditView();
  347. if (_EditView != null) {
  348. Vista_Api.OpenFileDialog _OpenFileDialog = new Vista_Api.OpenFileDialog();
  349. _OpenFileDialog.Title = "Sharp Builder Tools - Select the file to insert";
  350. _OpenFileDialog.Filter += "Any file (*.*)|*.*";
  351. _OpenFileDialog.CheckFileExists = true;
  352. if (_OpenFileDialog.ShowDialog() == DialogResult.OK) {
  353. _EditView.Position.InsertFile(_OpenFileDialog.FileName);
  354. }
  355. }
  356. }
  357. private void DoLowerCase(object aSender, EventArgs AEventArgs) {
  358. if (!ValidationHelpers.ValidateCurrentSourceEditorNotNull()) {
  359. return;
  360. }
  361. IOTASourceEditor _SourceEditor = OtaUtils.GetCurrentSourceEditor();
  362. IOTAEditView _EditView = _SourceEditor.GetEditView(0);
  363. _EditView.Buffer.EditBlock.LowerCase();
  364. _EditView.Paint();
  365. }
  366. //private void DoShowCodeComplete(object aSender, EventArgs e) {
  367. // IOTAEditView _EditView = OTAUtils.GetCurrentEditView();
  368. // if (_EditView != null) {
  369. // IOTAEditActions _EditActions = _EditView as IOTAEditActions;
  370. // if (_EditActions != null) {
  371. // _EditActions.CodeCompletion(OTACodeCompleteStyle.csCodelist);
  372. // }
  373. // }
  374. //}
  375. //private void DoShowCodeCompleteParams(object aSender, EventArgs e) {
  376. // IOTAEditView _EditView = OTAUtils.GetCurrentEditView();
  377. // if (_EditView != null) {
  378. // IOTAEditActions _EditActions = _EditView as IOTAEditActions;
  379. // if (_EditActions != null) {
  380. // _EditActions.CodeCompletion(OTACodeCompleteStyle.csParamList);
  381. // }
  382. // }
  383. //}
  384. private void DoSort(object aSender, EventArgs AEventArgs) {
  385. if (!ValidationHelpers.ValidateCurrentSourceEditorNotNull()) {
  386. return;
  387. }
  388. FrmSortOptions _Frm = new FrmSortOptions();
  389. if (_Frm.ShowDialog() == DialogResult.OK) {
  390. SortSelectedText(_Frm.Ascending, _Frm.CaseSensitive);
  391. }
  392. }
  393. private void DoToggleCase(object aSender, EventArgs AEventArgs) {
  394. if (!ValidationHelpers.ValidateCurrentSourceEditorNotNull()) {
  395. return;
  396. }
  397. IOTASourceEditor _SourceEditor = OtaUtils.GetCurrentSourceEditor();
  398. IOTAEditView _EditView = _SourceEditor.GetEditView(0);
  399. _EditView.Buffer.EditBlock.ToggleCase();
  400. _EditView.Paint();
  401. }
  402. private void DoToggleComment(object aSender, EventArgs AEventArgs) {
  403. if (!ValidationHelpers.ValidateCurrentModuleIsSourceFile()) {
  404. return;
  405. }
  406. IOTASourceEditor _SourceEditor = OtaUtils.GetCurrentSourceEditor();
  407. if (_SourceEditor != null) {
  408. string _Text = OtaUtils.GetSelectedText(OtaUtils.GetCurrentModule());
  409. bool _NoTextSelected = string.IsNullOrEmpty(_Text);
  410. if (_NoTextSelected) {
  411. OtaUtils.SelectLine(OtaUtils.GetCurrentSourceEditor());
  412. _Text = OtaUtils.GetSelectedText(OtaUtils.GetCurrentModule());
  413. }
  414. IList<string> _Lines = Lextm.StringHelper.GetLinesFromString(_Text);
  415. if (_Lines.Count > 0) {
  416. BaseLanguageCodeHelper _LanguageCodeHelper = LanguageCodeHelperFactory.GetLanguageCodeHelper(OtaUtils.GetCurrentEditorFileName());
  417. for (int i = 0; i < _Lines.Count; i++) {
  418. if (_LanguageCodeHelper.IsCommented(_Lines[i])) {
  419. _Lines[i] = _LanguageCodeHelper.UncommentLine(_Lines[i]);
  420. } else {
  421. _Lines[i] = _LanguageCodeHelper.CommentLine(_Lines[i]);
  422. }
  423. }
  424. _Text = OtaUtils.BuildLines(_Lines, _Text.EndsWith(Environment.NewLine, StringComparison.Ordinal));
  425. OtaUtils.ReplaceSelectedText(_SourceEditor, _Text);
  426. _SourceEditor.GetEditView(0).Paint();
  427. }
  428. }
  429. }
  430. /*
  431. protected void DoViewUsing(object aSender, EventArgs e) {
  432. IOTAModule _Module = OTAUtils.GetCurrentModule();
  433. IOTACodeDomProvider _CodeDomProvider = (IOTACodeDomProvider) _Module.GetService(typeof(IOTACodeDomProvider));
  434. if (_CodeDomProvider != null) {
  435. IOTACodeDomFile _CodeDomFile = _CodeDomProvider.CodeDomFile;
  436. CodeObject _CodeObject = _CodeDomFile.GetDom();
  437. if (_CodeObject != null) {
  438. CodeCompileUnit _CodeCompileUnit = (CodeCompileUnit) _CodeObject;
  439. ArrayList result = new ArrayList(_CodeCompileUnit.UserData.Keys);
  440. for (int i = 0; i < result.Count; i++) {
  441. ValidationHelpers.ShowDebug(result[i].ToString());
  442. ValidationHelpers.ShowDebug(_CodeCompileUnit.UserData[result[i]].ToString());
  443. }
  444. }
  445. }
  446. }
  447. */
  448. /*
  449. private void DoUnComment(object aSender, EventArgs e) {
  450. if (!ValidationHelpers.ValidateCurrentModuleIsCSOrXmlOrDelphiFile()) {
  451. return;
  452. }
  453. IOTASourceEditor _SourceEditor = OTAUtils.GetCurrentSourceEditor();
  454. if (_SourceEditor != null) {
  455. string _Text = OTAUtils.GetSelectedText(OTAUtils.GetCurrentModule());
  456. bool _NoTextSelected = (_Text == null || _Text.Length == 0);
  457. if (_NoTextSelected) {
  458. OTAUtils.SelectLine(OTAUtils.GetCurrentSourceEditor());
  459. _Text = OTAUtils.GetSelectedText(OTAUtils.GetCurrentModule());
  460. }
  461. string[] _Lines = ShareUtils.GetLinesFromString(_Text);
  462. if (_Lines.Length > 0) {
  463. BaseLanguageCodeHelper _LanguageCodeHelper = LanguageCodeHelperFactory.GetLanguageCodeHelper(OTAUtils.GetCurrentEditorFileName());
  464. if (_LanguageCodeHelper.IsCommented(_Lines)) {
  465. _Lines = _LanguageCodeHelper.UnCommentLines(_Lines);
  466. _Text = OTAUtils.BuildLines(_Lines, _Text.EndsWith("\n"));
  467. OTAUtils.ReplaceSelectedText(_SourceEditor, _Text);
  468. _SourceEditor.GetEditView(0).Paint();
  469. }
  470. }
  471. }
  472. }
  473. */
  474. private void DoUnElideNearestBlock(object aSender, EventArgs AEventArgs) {
  475. IOTAEditView _EditView = OtaUtils.GetCurrentEditView();
  476. if (_EditView != null) {
  477. OtaUtils.ElideNearestBlock(_EditView, true);
  478. _EditView.Paint();
  479. }
  480. }
  481. private void DoUnElideAllBlocks(object aSender, EventArgs AEventArgs) {
  482. IOTAEditView _EditView = OtaUtils.GetCurrentEditView();
  483. if (_EditView != null) {
  484. IOTAElideActions _ElideActions = _EditView as IOTAElideActions;
  485. if (_ElideActions != null) {
  486. _ElideActions.UnElideAllBlocks();
  487. _EditView.Paint();
  488. }
  489. }
  490. }
  491. private void DoUnindent(object aSender, EventArgs AEventArgs) {
  492. if (!ValidationHelpers.ValidateCurrentSourceEditorNotNull()) {
  493. return;
  494. }
  495. IOTASourceEditor _SourceEditor = OtaUtils.GetCurrentSourceEditor();
  496. IOTAEditView _EditView = _SourceEditor.GetEditView(0);
  497. BaseLanguageCodeHelper _LanguageCodeHelper = LanguageCodeHelperFactory.GetLanguageCodeHelper(OtaUtils.GetCurrentEditorFileName());
  498. _EditView.Buffer.EditBlock.Indent(0 - _LanguageCodeHelper.GetIndentation());
  499. _EditView.Paint();
  500. }
  501. private void DoUpperCase(object aSender, EventArgs AEventArgs) {
  502. if (!ValidationHelpers.ValidateCurrentSourceEditorNotNull()) {
  503. return;
  504. }
  505. IOTASourceEditor _SourceEditor = OtaUtils.GetCurrentSourceEditor();
  506. IOTAEditView _EditView = _SourceEditor.GetEditView(0);
  507. _EditView.Buffer.EditBlock.UpperCase();
  508. _EditView.Paint();
  509. }
  510. /**************************************************************/
  511. /* Public
  512. /**************************************************************/
  513. private const string MenuEdit = "CBCEditMenu";
  514. private const string MenuTextEdit = "Editor Aid";
  515. protected override void IdeRegisterMenus() {
  516. RegisterEditMenu();
  517. RegisterSearchMenu();
  518. }
  519. private static void InteriorElideToDefinitions(IOTACodeDomProvider _CodeDomProvider,
  520. CodeObject _CodeObject, ref int _count)
  521. {
  522. _count++;
  523. if (_count > 100000){
  524. Lextm.Windows.Forms.MessageBoxFactory.Warn(Name, "Terminated", "Too large elide operation.");
  525. return;
  526. }
  527. if (_CodeDomProvider == null) {
  528. _CodeDomProvider = (IOTACodeDomProvider) OtaUtils.GetCurrentModule().GetService(typeof(IOTACodeDomProvider));
  529. }
  530. if (_CodeDomProvider == null) {
  531. return;
  532. }
  533. if (_CodeObject == null){
  534. IOTACodeDomFile _CodeDomFile = _CodeDomProvider.CodeDomFile;
  535. _CodeObject = _CodeDomFile.GetDom();
  536. }
  537. if (_CodeObject == null) {
  538. return;
  539. }
  540. if (_CodeObject is CodeCompileUnit){
  541. for (int i = 0; i < ((CodeCompileUnit)_CodeObject).Namespaces.Count; i++){
  542. InteriorElideToDefinitions(_CodeDomProvider, ((CodeCompileUnit)_CodeObject).Namespaces[i], ref _count);
  543. }
  544. return;
  545. }
  546. //..............................
  547. if (_CodeObject is CodeNamespace){
  548. for (int i = 0; i < ((CodeNamespace)_CodeObject).Types.Count; i++){
  549. InteriorElideToDefinitions(_CodeDomProvider, ((CodeNamespace)_CodeObject).Types[i], ref _count);
  550. }
  551. return;
  552. }
  553. //..............................
  554. if (!(_CodeObject is CodeTypeMember)) {
  555. return;
  556. }
  557. //...................
  558. if (_CodeObject is CodeMemberEvent){
  559. return;
  560. }
  561. //...................
  562. if (_CodeObject is CodeMemberField){
  563. return;
  564. }
  565. //...................
  566. if (_CodeObject is CodeMemberMethod){
  567. int Line = -1;
  568. int StatementsLine = -1;
  569. try{
  570. if ( ((CodeTypeMember)_CodeObject).LinePragma != null){
  571. Line = ((CodeTypeMember)_CodeObject).LinePragma.LineNumber;
  572. }
  573. }catch{
  574. Line = -1;
  575. }
  576. try{
  577. if (((CodeMemberMethod)_CodeObject).Statements[0] != null){
  578. if (((CodeMemberMethod)_CodeObject).Statements[0].LinePragma != null){
  579. StatementsLine = ((CodeMemberMethod)_CodeObject).Statements[0].LinePragma.LineNumber;
  580. }
  581. }
  582. }catch{
  583. StatementsLine = -1;
  584. }
  585. /*************************************/
  586. if (StatementsLine == -1){
  587. if (Line != -1){
  588. ElideAt(Line+1);
  589. }
  590. }else{
  591. if (Line == -1){
  592. ElideAt(StatementsLine);
  593. }else{
  594. if ( Line == StatementsLine ){
  595. ElideAt(Line);
  596. }else{
  597. ElideAt(StatementsLine);
  598. }
  599. }
  600. }
  601. /*************************************/
  602. return;
  603. }
  604. //...................
  605. if (_CodeObject is CodeMemberProperty){
  606. int Line;
  607. CodeStatementCollection csc;
  608. try{
  609. csc = ((CodeMemberProperty)_CodeObject).GetStatements;
  610. if (csc != null){
  611. if (csc[0].LinePragma != null){
  612. Line = csc[0].LinePragma.LineNumber;
  613. if (Line >0){
  614. /*************************************/
  615. ElideAt(Line);
  616. /*************************************/
  617. }
  618. }
  619. }
  620. }catch{}
  621. try{
  622. csc = ((CodeMemberProperty)_CodeObject).SetStatements;
  623. if (csc != null){
  624. if (csc[0].LinePragma != null){
  625. Line = csc[0].LinePragma.LineNumber;
  626. if (Line >0){
  627. /*************************************/
  628. ElideAt(Line);
  629. /*************************************/
  630. }
  631. }
  632. }
  633. }catch{}
  634. return;
  635. }
  636. //...................
  637. if (_CodeObject is CodeTypeDeclaration){
  638. if (_CodeObject is CodeTypeDelegate){
  639. }else{
  640. if ( ((CodeTypeDeclaration)_CodeObject).IsClass ){
  641. }
  642. if ( ((CodeTypeDeclaration)_CodeObject).IsEnum ){
  643. }
  644. if ( ((CodeTypeDeclaration)_CodeObject).IsInterface ){
  645. }
  646. if ( ((CodeTypeDeclaration)_CodeObject).IsStruct ){
  647. }
  648. for (int i=0; i < ((CodeTypeDeclaration)_CodeObject).Members.Count; i++){
  649. InteriorElideToDefinitions(_CodeDomProvider, ((CodeTypeDeclaration)_CodeObject).Members[i], ref _count);
  650. }
  651. }
  652. return;
  653. }
  654. }
  655. private static void ElideAt(int Line){
  656. //System.Windows.Forms.Messag/eBox.Show("ElideAt");
  657. OtaUtils.GoToPosition(OtaUtils.GetCurrentSourceEditor(), Line, 1);
  658. //SelectCurrentLine();
  659. //Utils_OTAPI.CurrentEditView.Paint();
  660. //Utils_WinAPI.Beep(5000,1000);
  661. OtaUtils.GetCurrentElideActions().ElideNearestBlock();
  662. OtaUtils.GetCurrentEditView().Paint();
  663. }
  664. private void RegisterEditMenu( ) {
  665. RegisterAction(CreateEmptyMenu(Lextm.OpenTools.MenuItemLocation.Child,
  666. ShareUtils.MenuRootDefault,
  667. MenuEdit,
  668. MenuTextEdit)
  669. );
  670. RegisterAction(CreateActionMenu(MenuItemLocation.Child,
  671. MenuEdit,
  672. "ToggleCaseMenu",
  673. 0,
  674. "Toggle Case",
  675. new EventHandler(DoToggleCase)));
  676. RegisterAction(CreateActionMenu(MenuItemLocation.Child,
  677. MenuEdit,
  678. "UpCaseCaseMenu",
  679. 0,
  680. "Up Case Ctrl+K+N",
  681. new EventHandler(DoUpperCase)));
  682. RegisterAction(CreateActionMenu(MenuItemLocation.Child,
  683. MenuEdit,
  684. "LowCaseMenu",
  685. 0,
  686. "Low Case Ctrl+K+O",
  687. new EventHandler(DoLowerCase)));
  688. RegisterAction(CreateSeparatorMenu(MenuItemLocation.Child,
  689. MenuEdit));
  690. RegisterAction(CreateActionMenu(MenuItemLocation.Child,
  691. MenuEdit,
  692. "ToggleCommentMenu",
  693. ShareUtils.Shift + ShareUtils.Ctrl + (int)Keys.Delete, // Ctrl /
  694. "ToggleComment",
  695. new EventHandler(DoToggleComment)));
  696. RegisterAction(CreateSeparatorMenu(MenuItemLocation.Child,
  697. MenuEdit));
  698. RegisterAction(CreateActionMenu(MenuItemLocation.Child,
  699. MenuEdit,
  700. "SortMenu",
  701. 0,
  702. "Sort...",
  703. new EventHandler(DoSort)));
  704. RegisterAction(CreateActionMenu(MenuItemLocation.Child,
  705. MenuEdit,
  706. "DefaultSortMenu",
  707. OtaUtils.Ctrl + OtaUtils.Shift + OtaUtils.Alt + (int)Keys.S,
  708. "Default Sort (Ascending / Case Sensitive)",
  709. new EventHandler(DoDefaultSort)));
  710. //RegisterAction(CreateActionMenu(MenuItemLocation.Child,
  711. // MenuEdit,
  712. // "CreateRegionMenu",
  713. // 49234, // Alt Ctrl C
  714. // "Create Region...",
  715. // new EventHandler(DoCreateRegion)));
  716. RegisterAction(CreateActionMenu(MenuItemLocation.Child,
  717. MenuEdit,
  718. "SpaceToTabMenu",
  719. 0,
  720. "Convert Space to Tab",
  721. new EventHandler(DoConvertSpaceToTab)));
  722. RegisterAction(CreateActionMenu(MenuItemLocation.Child,
  723. MenuEdit,
  724. "TabToSpaceMenu",
  725. 0,
  726. "Convert Tab to Space",
  727. new EventHandler(DoConvertTabToSpace)));
  728. RegisterAction(CreateSeparatorMenu(MenuItemLocation.Child,
  729. MenuEdit));
  730. RegisterAction(CreateActionMenu(MenuItemLocation.Child,
  731. MenuEdit,
  732. "UnindentMenu",
  733. ShareUtils.Alt + (int)Keys.U, // Alt U
  734. "Unindent",
  735. new EventHandler(DoUnindent)));
  736. RegisterAction(CreateActionMenu(MenuItemLocation.Child,
  737. MenuEdit,
  738. "IndentMenu",
  739. ShareUtils.Alt + (int)Keys.I, // Alt I
  740. "Indent",
  741. new EventHandler(DoIndent)));
  742. RegisterAction(CreateSeparatorMenu(MenuItemLocation.Child,
  743. MenuEdit));
  744. RegisterAction(CreateActionMenu(MenuItemLocation.Child,
  745. MenuEdit,
  746. "InsertTextFileMenu",
  747. 0,
  748. "Insert Text File...",
  749. new EventHandler(DoInsertFileAsText)));
  750. }
  751. private void RegisterSearchMenu( ) {
  752. RegisterAction(CreateEmptyMenu(MenuItemLocation.Child,
  753. ShareUtils.MenuRootDefault,
  754. "CBCSearchMenu",
  755. "Search")
  756. );
  757. //TODO: create a outline item
  758. RegisterAction(CreateActionMenu(MenuItemLocation.Child,
  759. "CBCSearchMenu",
  760. "UnElideAllBlocksMenu",
  761. 0,
  762. "Unfold All Blocks Shift+Ctrl+K+A",
  763. new EventHandler(DoUnElideAllBlocks)));
  764. RegisterAction(CreateActionMenu(MenuItemLocation.Child,
  765. "CBCSearchMenu",
  766. "UnElideNearestBlockMenu",
  767. 0,
  768. "Unfold Nearest Block Shift+Ctrl+K+U",
  769. new EventHandler(DoUnElideNearestBlock)));
  770. RegisterAction(CreateActionMenu(MenuItemLocation.Child,
  771. "CBCSearchMenu",
  772. "ElideNearestBlockMenu",
  773. 0,
  774. "Fold Nearest Block Shift+Ctrl+K+E",
  775. new EventHandler(DoElideNearestBlock)));
  776. RegisterAction(CreateActionMenu(MenuItemLocation.Child,
  777. "CBCSearchMenu",
  778. "ElideToDefinitionMenu",
  779. 0,
  780. "Fold to Definition",
  781. new EventHandler(DoElideToDefinitions)));
  782. RegisterAction(CreateSeparatorMenu(MenuItemLocation.Child,
  783. "CBCSearchMenu"));
  784. RegisterAction(CreateActionMenu(MenuItemLocation.Child,
  785. "CBCSearchMenu",
  786. "GotoNextOccurenceMenu",
  787. OtaUtils.Ctrl + OtaUtils.Alt + (int)Keys.Down,
  788. "Go to Next Occurence",
  789. new EventHandler(DoGetNextOccurence)));
  790. RegisterAction(CreateActionMenu(MenuItemLocation.Child,
  791. "CBCSearchMenu",
  792. "GotoPriorOccurenceMenu",
  793. OtaUtils.Ctrl + OtaUtils.Alt + (int)Keys.Up,
  794. "Go to Prior Occurence",
  795. new EventHandler(DoGetPriorOccurence)));
  796. RegisterAction(CreateActionMenu(MenuItemLocation.Child,
  797. "CBCSearchMenu",
  798. "HyperForwardMenu",
  799. OtaUtils.Ctrl + OtaUtils.Alt + (int)Keys.Right,
  800. "Hyper Forward",
  801. new EventHandler(DoHyperForward)));
  802. RegisterAction(CreateActionMenu(MenuItemLocation.Child,
  803. "CBCSearchMenu",
  804. "HyperBackwardMenu",
  805. OtaUtils.Ctrl + OtaUtils.Alt + (int)Keys.Left,
  806. "Hyper Backward",
  807. new EventHandler(DoHyperBack)));
  808. }
  809. }
  810. }