home *** CD-ROM | disk | FTP | other *** search
- //----------------------------------------------------------------------------
- // cScript
- // (C) Copyright 1995, 1997 by Borland International, All Rights Reserved
- //
- // ED_DFLT.SPP
- // Script component of IDE's Editor Default emulation.
- // Provides support services for editing environment.
- //
- // $Revision: 1.8 $
- //
- //----------------------------------------------------------------------------
- // Default Editor.
- //----------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------
- // Symbol Imports
- //----------------------------------------------------------------------------
-
- import IDE;
- import editor;
- import scriptEngine;
- import bFileLoading;
-
- //
- // Mark this module as being a library module.
- //
- library;
-
- //----------------------------------------------------------------------------
- // Symbol Defines
- //----------------------------------------------------------------------------
-
- #define BOOKMARK_ID_SYSTEM_ONE 19
- #define BOOKMARK_ID_SYSTEM_TWO 18
- #define BOOKMARK_ID_SYSTEM_THREE 17
- #define FUNCTION_CONTINUE 0
- #define FUNCTION_END 1
-
- //----------------------------------------------------------------------------
- // Menu Vectors.
- //----------------------------------------------------------------------------
-
- DoIDEFileClose() { return FUNCTION_CONTINUE; }
- DoIDEFileOpen() { return FUNCTION_CONTINUE; }
- DoIDEFilePrint() { return FUNCTION_CONTINUE; }
- DoIDEFileSave() { return FUNCTION_CONTINUE; }
- DoIDEFileSaveAs() { return FUNCTION_CONTINUE; }
- DoIDEFileSaveAll() { return FUNCTION_CONTINUE; }
-
- DoIDEEditUndo() { editor.Undo(); return FUNCTION_END; }
- DoIDEEditRedo() { editor.Redo(); return FUNCTION_END; }
- DoIDEEditCut() { editor.InternalCut(); return FUNCTION_END; }
- DoIDEEditCopy() { editor.Copy(); return FUNCTION_END; }
- DoIDEEditPaste() { editor.Paste(); return FUNCTION_END; }
- DoIDEEditClear() { editor.InternalDelete(); return FUNCTION_END; }
- DoIDEEditSelectAll() { editor.SelectAll(); return FUNCTION_END; }
- DoIDEEditBufferList() { return FUNCTION_CONTINUE; }
-
- DoIDESearchFind() { return FUNCTION_CONTINUE;}
- DoIDESearchReplace() { return FUNCTION_CONTINUE; }
- DoIDESearchSearchAgain() { return FUNCTION_CONTINUE; }
-
- DoIDESearchPreviousMessage() { return FUNCTION_CONTINUE; }
- DoIDESearchNextMessage() { return FUNCTION_CONTINUE; }
-
- //----------------------------------------------------------------------------
- // Methods.
- //----------------------------------------------------------------------------
-
- //
- // Used to autoload the Default emulation specific methods.
- //
- defaultEmulation(bUnassign) {
-
- IDE.KeyboardManager.ScriptAbortKey = "<Escape>";
- IDE.KeyboardManager.ProcessKeyboardAssignments(scriptEngine.StartupDirectory+IDE.KeyboardAssignmentFile,bUnassign);
-
- if (bUnassign) {
- print "Default emulation removed.";
- scriptEngine.Unload(typeid(module()));
- } else {
- print "Default emulation enabled.";
- }
- }
-
- //----------------------------------------------------------------------------
- // Methods.
- //----------------------------------------------------------------------------
-
- //
- // Uses Internal specific behavior for deletion of the current block.
- //
- on editor:>InternalBlockStyleChange(declare newStyle) {
- SetBlockStyle(newStyle);
- }
-
- //
- // Delete the current block.
- //
- on editor:>InternalCut() {
- declare eb = .BlockExists();
- if (eb != NULL) {
- declare ev = .TopView;
- ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
- eb.Cut();
- ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
- }
- }
-
- //
- // Uses Internal specific behavior for deletion of the current block.
- //
- on editor:>InternalDelete() {
- declare eb = .BlockExists();
- if (eb != NULL) {
- if (eb.Size != 0) {
- declare ep = .TopView.Position;
- eb.Save();
- ep.Move(eb.StartingRow,eb.StartingColumn);
- eb.Restore();
- declare rv = eb.Delete();
- ResetBlock(EXCLUSIVE_BLOCK);
- IDE.StatusBar = "Block deleted";
- return rv;
- }
- }
- return 0;
- }
-
- on editor:>InternalDeleteWordRight() {
-
- declare nBlocked = FALSE;
- declare eb = .BlockExists();
- declare ev = .TopView;
- declare ep = ev.Position;
-
- if (eb != NULL) {
- eb.Save();
- ep.Save();
- ep.Move(eb.StartingRow,eb.StartingColumn);
- ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
- ep.Move(eb.EndingRow,eb.EndingColumn);
- ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_TWO);
- ep.Restore();
- eb.Restore();
- nBlocked = TRUE;
- }
-
- eb = ResetBlock(EXCLUSIVE_BLOCK);
- eb.Begin();
-
- declare nSpaceAdjust = 0;
- ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_THREE);
-
- if (ep.IsWhiteSpace) {
-
- if (ep.Character == '\t') {
- declare c = ep.Column;
- ep.Delete(1);
- if (ep.Column != c)
- nSpaceAdjust = c - ep.Column;
- }
- ep.MoveCursor(SKIP_RIGHT | SKIP_WHITE);
- } else if (ep.IsWordCharacter) {
- ep.MoveCursor(SKIP_RIGHT | SKIP_WORD);
- ep.MoveCursor(SKIP_RIGHT | SKIP_WHITE);
- } else if (ep.IsSpecialCharacter) {
- ep.Delete(1);
- ep.MoveCursor(SKIP_RIGHT | SKIP_WHITE);
- } else
- ep.Delete(1);
-
- eb.End();
- eb.Delete();
-
- ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_THREE);
-
- while (nSpaceAdjust--) {
- ep.InsertText(' ');
- }
-
- if (nBlocked) {
- SetBlockStyle(EXCLUSIVE_BLOCK);
- ep.Save();
- ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
- eb.Begin();
- ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_TWO);
- eb.End();
- ep.Restore();
- }
- }
-
- //
- // Uses Internal specific behavior for deletion of the current word.
- //
- on editor:>InternalDeleteWordLeft() {
-
- declare eb = .BlockExists();
- eb = ResetBlock(EXCLUSIVE_BLOCK);
- eb.End();
-
- declare ep = .TopView.Position;
-
- ep.MoveCursor(SKIP_LEFT | SKIP_NONWORD);
- ep.MoveCursor(SKIP_LEFT | SKIP_WORD);
-
- eb.Begin();
-
- eb.Cut();
- }
-
- //
- // Uses Internal specific behavior to toggle current character/block.
- //
- on editor:>InternalToggleCase() {
- declare eb = .BlockExists();
- if (eb != NULL) {
- eb.ToggleCase();
- } else {
- declare ep = .TopView.Position;
- ep.Save();
- ep.MoveEOL();
- declare x = ep.Column;
- ep.Restore();
- if (x <= ep.Column) {
- ep.Move(ep.Row+1,1);
- } else {
- eb = .TopView.Block;
- eb.Begin();
- ep.MoveRelative(0,1);
- eb.End();
- eb.ToggleCase();
- eb.Reset();
- }
- }
- }
-
- //
- // Uses Default specific behavior to delete a line.
- //
- on editor:>InternalDeleteLine() {
-
- declare bBlock = FALSE;
- declare eb = .BlockExists();
- declare ev = .TopView;
- declare ep = ev.Position;
-
- if (eb != NULL) {
- eb.Save();
- ep.Save();
- ep.Move(eb.StartingRow,eb.StartingColumn);
- ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
- ep.Move(eb.EndingRow,eb.EndingColumn);
- ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_TWO);
- ep.Restore();
- eb.Restore();
- bBlock = TRUE;
- } else
- eb = .TopView.Block;
-
- ep.MoveBOL();
- ep.Save();
- BeginBlock(EXCLUSIVE_BLOCK);
-
- if (ep.Row == ep.LastRow)
- ep.MoveEOL();
- else
- ep.MoveRelative(1,0);
-
- EndBlock(EXCLUSIVE_BLOCK);
- eb.Delete();
- ep.Restore();
-
- if (bBlock) {
- SetBlockStyle(EXCLUSIVE_BLOCK);
- ep.Save();
- ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
- eb.Begin();
- ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_TWO);
- eb.End();
- ep.Restore();
- }
- }
-
- //
- // Uses Default specific behavior to mark to the begining of the file.
- //
- on editor:>InternalMarkToBOF() {
- declare eb = .TopView.Block;
- declare ep = .TopView.Position;
- if ((eb.StartingRow == ep.Row) && (eb.StartingColumn == ep.Column)) {
- SetBlockStyle(EXCLUSIVE_BLOCK);
- ep.Move(eb.EndingRow,eb.EndingColumn);
- eb.End();
- ep.Move(1,1);
- eb.Begin();
- } else {
- eb.Reset();
- SetBlockStyle(EXCLUSIVE_BLOCK);
- eb.End();
- ep.Move(1,1);
- eb.Begin();
- }
- }
-
- //
- // Uses Default specific behavior to mark to the end of the file.
- //
- on editor:>InternalMarkToEOF() {
- declare eb = .TopView.Block;
- declare ep = .TopView.Position;
- if ((eb.EndingRow == ep.Row) && (eb.EndingColumn == ep.Column)) {
- SetBlockStyle(EXCLUSIVE_BLOCK);
- ep.Move(eb.StartingRow,eb.StartingColumn);
- eb.Begin();
- ep.MoveEOF();
- eb.End();
- } else {
- eb.Reset();
- SetBlockStyle(EXCLUSIVE_BLOCK);
- eb.Begin();
- ep.MoveEOF();
- eb.End();
- }
- }
-
- //
- // Uses Default specific behavior to mark to the begining of the line.
- //
- on editor:>InternalMarkToBOL() {
- declare eb = .BlockExists();
-
- if (eb == NULL)
- ResetBlock();
-
- .MarkToBOL();
- }
-
- //
- // Uses Default specific behavior to mark to the end of the line.
- //
- on editor:>InternalMarkToEOL() {
- declare eb = .BlockExists();
-
- if (eb == NULL)
- ResetBlock();
-
- .MarkToEOL();
- }
-
- //
- // Using Internal behaviour moves block.
- //
- on editor:>InternalMoveBlock() {
- declare eb = .BlockExists();
- if (eb != NULL) {
- declare ev = .TopView;
- declare ep = ev.Position;
- ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
- eb.Save();
- ep.Move(eb.StartingRow, eb.StartingColumn);
- eb.Restore();
- eb.Cut();
- ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
- declare nRow = ep.Row;
- declare nColumn = ep.Column;
- ep.InsertScrap();
- ep.Move(nRow, nColumn);
- eb.Begin();
- ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
- eb.Extend(ep.Row, ep.Column);
- eb.Save();
- ep.Move(nRow, nColumn);
- eb.Restore();
- }
- }
-
- //
- // Using Internal behaviour marks and returns the current word.
- //
- on editor:>InternalMarkWord() {
- declare ep = .TopView.Position;
-
- if (!.TopView.Position.IsWordCharacter) {
- .MoveCursorToWordLeft();
- }
-
- return .MarkWord();
- }
-
- //
- // Using Internal behavior block a line.
- //
- on editor:>InternalMarkLine() {
-
- declare eb = .BlockExists();
- declare ep = .TopView.Position;
-
- SetBlockStyle(EXCLUSIVE_BLOCK);
-
- if (ep.Column == 1) {
- ep.Save();
-
- if (ep.Row < ep.LastRow)
- ep.MoveRelative(1,0);
- else
- ep.MoveEOL();
-
- if (eb == NULL)
- eb = .TopView.Block;
-
- ResetBlock();
- eb.End();
- ep.Restore();
- eb.Begin();
- }
- }
-
- //
- // Using Internal behavior perform lower case operation.
- //
- on editor:>InternalLowerWord() {
- .TopView.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
- if (!.TopView.Position.IsWordCharacter) {
- .MoveCursorToWordLeft();
- }
- .MarkWord().LowerCase();
- .TopView.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
- .TopView.Block.Reset();
- }
-
- //
- // Using Internal behavior perform lower case operation.
- //
- on editor:>InternalUpperWord() {
- .TopView.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
- if (!.TopView.Position.IsWordCharacter) {
- .MoveCursorToWordLeft();
- }
- .MarkWord().UpperCase();
- .TopView.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
- .TopView.Block.Reset();
- }
-
- //
- // Using Internal behavior perform block copy operation.
- //
- on editor:>InternalCopyBlock() {
- declare eb = .BlockExists();
- if (eb != NULL) {
- declare ev = .TopView;
- declare ep = ev.Position;
- if (StartBlockBeforeCursor(eb,ep)) {
- eb.Copy();
- ep.Move(eb.StartingRow,eb.StartingColumn);
- ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
- ep.Move(eb.EndingRow,eb.EndingColumn);
- ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_TWO);
- ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
- .TopView.Position.InsertScrap();
- ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
- eb.Begin();
- ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_TWO);
- eb.End();
- ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
- } else {
- ep.Save();
- eb.Save();
- eb.Copy();
- eb.Reset();
- .TopView.Position.InsertScrap();
- ep.Restore();
- eb.Restore();
- }
- IDE.StatusBar = "Block copied";
-
- } else {
- IDE.ReportError("No marked block");
- }
- }
-