Difference between revisions of "Ide/Text Editor"

From wiki.visual-prolog.com

Line 23: Line 23:
=== Create a New Text File ===
=== Create a New Text File ===


Execute the '''File | New...''' command (or '''Ctrl+N''', or click the [[Image:IDE_TE_New.png]] toolbar button) to open the '''Create Project Item''' dialog. In the left pane of this dialog select '''Text File'''. For more detailed description see {{ide|Creating new Project Items#Creating a Text File|New Text File Creation}}.
Execute the '''File | New...''' command (or '''Ctrl+N''', or click the [[Image:Ide_TE_New.png]] toolbar button) to open the '''Create Project Item''' dialog. In the left pane of this dialog select '''Text File'''. For more detailed description see {{ide|Creating new Project Items#Creating a Text File|New Text File Creation}}.


=== Open an Existing File ===
=== Open an Existing File ===

Revision as of 11:42, 25 March 2013

IDE

About the Text Editor

The Visual Prolog Text Editor is used for creating and editing of any text files. However, the Visual Prolog text editor is specially oriented for editing Visual Prolog source code files from the IDE, for example, it supports color highlighting of Visual Prolog language syntax elements (keywords, variables, and other language elements). Also when the text editor is used in the IDE, it supports such Visual Prolog specific functions as Go to Name Declaration, Go to Name Definition, Insert Interface, Insert Class, Insert Predicate, etc.

The text editor supports: undo/redo features (standard restriction is 512 steps), search, replace, changing case of letters, cut, copy, and paste operations with the clipboard, and drag and drop for quick block movements with the mouse, etc.

Programmers can create the Visual Prolog Text Editor in their applications using the pfc\gui\controls\sciLexer package.

The most often used text editor commands have hot keys or can be called with the right mouse button pop-up context menu.

Getting Assistance

Press F1 (or the Ide TE Help.png button in the toolbar or the Help | Visual Prolog Help command) when the input focus is in any text editor window to display this help information.

Set the Editor Options

Text editor options are grouped in the Options dialog.

How to Work with Files

Create a New Text File

Execute the File | New... command (or Ctrl+N, or click the Ide TE New.png toolbar button) to open the Create Project Item dialog. In the left pane of this dialog select Text File. For more detailed description see New Text File Creation.

Open an Existing File

There are several ways to open existing text files:

  • Using the standard File Open dialog box. To activate it you can use the File | Open command, or the Ctrl+O hot key, or clicking the Ide TE Open.png toolbar button.
  • Clicking a text file in the project tree in the Project window.
  • The IDE keeps tracking of text files you last worked on. You can quickly open one of them by selecting it from the list at the bottom of the File menu.

You can have many files opened in text editor windows simultaneously. The Open command does not close any already opened text editor windows. The Visual Prolog IDE is restricted to editing a single version of anyone file; therefore, if you try to open an already edited file, then the IDE simply sets the focus into the editor window with this file.

Notice that the text editor can open both UNICODE and DOS character set text files. When it saves files that had DOS character set (before they were opened), then they are saved with the DOS character set. The same for UNICODE files.

Save an Edited File

There are several ways to save a text file being edited:

  • Using the File | Save command, or the F2 hot key, or clicking the Ide TE Save.png toolbar button.
  • Notice that all modified text files are ALWAYS saved before the IDE compiles them.

Save a File under Different Name

Use the File | Save as ... menu command.

Print an Edited File

Use the File | Print menu command to print the currently edited file. The standard Windows Print dialog appears. In it you can select some printing options.

How to Edit Text

When you open a text file, then the text editor loads the entire file into memory. So the original file is not changed until changes are saved.

Saving changes you can optionally keep the backup copy of an original file.

While you edit a file, the IDE checks whether the file is changed externally. For example, let us open a text file. Then go to a Source code Control System (SCS), for example, like Microsoft Visual SourceSafe. This SCS stores the master copy of the opened project. Let us get the latest version of some project files from the master copy in the SCS. When you return the focus into the IDE, it checks whether any of the opened text (and any other) files differ from their versions updated from the SCS. If the IDE detects such difference, then it display the warning dialog like this:

The file "ExternallyChangedFileName" 
            has been modified outside the IDE text editor. 
            Do you want to reload the file or ignore external changes?

The basic functions for moving around in texts and making simple edits follow the ordinary conventions of other Windows applications. So you can get started immediately. The more powerful editing commands are all on the menus, with their shortcuts shown against them, so you should be able to get up to speed quickly. Most of editing commands are in the pop-up menu, which can be activated with the right mouse button.

Any changes you make can be undone, and you can redo changes that you have undone. You can undo changes even after saving the changed file. However, notice that the undo buffer has the limited length.

Remember that, while loading the text from the selected file, the text editor converts all non-viewable symbols into space characters. Notice that the text editor will also save all such characters like space characters!

Insert Text

Text is entered at the cursor position (the insertion point). The location of the cursor can be set by the keyboard or the mouse.

The cursor (also known as the caret) is the vertical line that indicates the insertion position for text. Contrast this with the mouse cursor that tracks the mouse position.

If any text is selected, it will be deleted before inserting the first character that you type.

To change to the Overwrite mode, where each typed character replaces the one at the cursor position, press the Insert key once. This will also change the Insert indicator on the status bar to Overwrite. Press the Insert key again, to switch back to the Insert mode.

Move in Text

The cursor is constrained to positions within the existing text only, it cannot be free placed anywhere in the document window outside of the existing text.

The following key combinations can be used to move the cursor:

Cursor Moving Operations

To Move the Cursor: Press This Key:
To the mouse cursor position Mouse left button
To the beginning of the file Ctrl+Home
To the end of the file Ctrl+End
From the beginning of the line to the first non-space character in the line Ctrl+Right Arrow
To the left margin Home
To the end of the line End
Forward one character Right Arrow
Back one character Left Arrow
Down one line Down Arrow
Up one line Up Arrow
Forward to the end of the current word Ctrl+Right Arrow
Back to the end of the previous word Ctrl+Left Arrow
Scroll one page (window) up Page Up
Scroll one page (window) down Page Down
Scroll up and down Rotate the Mouse Roll
To a specified line number Ctrl+F2 and fill in the number
To the Declaration of a pointed name (predicate, fact, domain, etc.) Ctrl+F12
To the Definition of a pointed name (to the Clauses of a pointed predicate) F12

You can use the Shift key in conjunction with the keystrokes given in the table (excluding the three last items), to extend the selection.

Move Using Bookmarks

Sometimes you can wish to mark a line with a bookmark in order to be able to find this line quickly. The Visual Prolog text editor does not support this possibility directly. However, when the text editor is used inside the IDE, then it provides some kind of bookmarking on the base of breakpoints implemented in the Debugger.

How to Set Bookmarks

Place the cursor in a line on which you wish to set a bookmark and press the F9 key (you can also use the Breakpoint -> Toggle Breakpoint pop-up menu and the Debug | Toggle Breakpoint menu commands). Then in the beginning of this line the Ide db BreakPoints en.png breakpoint icon appears. In the text editor window status bar find the line number and remember it.

How to Retrieve Bookmarks

Press the Ctrl+Alt+B key (or select the View | Breakpoints menu command). The Breakpoints window appears:
Ide TE Breakpoints.png
In this window you see all breakpoints currently set in all files. Notice that breakpoints (bookmarks) will be seen even in closed files.
To retrieve the desired bookmark in the text editor:
  1. In the Breakpoints window select the correspondent breakpoint (using the breakpoint file name and the line number).
  2. Double-click the breakpoint - the focus will be set into the text editor window with the file in which the breakpoint is set (this file will be opened in the text editor if needed) and the cursor will be positioned on the line on which the breakpoint is set.
    You can also click the right mouse button in the Breakpoints window. In the appeared pop-up menu select the Go to Source command:
Ide TE GoTo.png

How to Remove Bookmarks

There are several ways to remove existing breakpoints (bookmarks):
  1. When you in the text editor and the cursor is in the line marked with the breakpoint, simply press the F12 key (you can also use the Breakpoint -> Toggle Breakpoint pop-up menu and the Debug | Toggle Breakpoint menu commands).
  2. You can remove the selected breakpoint with the pop-up menu Remove command (you can also use the Breakpoints | Remove menu command).
  3. You can remove all existing breakpoint with the pop-up menu Remove All command (you can also use the Breakpoints | Remove All menu command).

Move by "Go to ..." Commands

The Go to IDE menu contains several commands:

"Go to ..." commands

These commands help you to fast navigation inside project text files. The target files can be as already opened in the text editor so still are not opened. Let us discuss these commands:

Go to Declaration

To use this command the cursor should be positioned on some name declared in the project. This name can be any predicate, fact, domain, constant, interface, or class name declared in the project (including declared in PFC packages used in the project).

Press the hot key combination Ctrl+F12 (the Go to Declaration pop-up menu command, or the Go to | Go to Declaration menu command) and the cursor jumps onto declaration of this name. The correspondent source code file will be opened in the text editor (if it was not). If this name is declared in several scopes, then the dialog [..\Dialogs\Resolve_Ambiguity.htm Resolve Ambiguity] displaying these scopes appears:

Ide TE ResolveAmbiguity.png

and you will be able to select the required scope.

Go to Definition

To use this command the cursor should be positioned on a name of some predicate defined in the project.

Now press the key F12 (the Go to Definition pop-up menu command, or the Go to | Go to Definition menu command) and the cursor jumps onto clauses defining this predicate. The correspondent source code file will be opened in the text editor (if it was not). If clauses defining this predicate explicitly exist in several scopes, then the dialog [..\Dialogs\Resolve_Ambiguity.htm Resolve Ambiguity] displaying these scopes appears. Notice that only scopes explicitly containing text of clauses for the predicate are displayed.

Go To Related Files

Press the hot key combination Ctrl+R and the IDE will open the file which relates to the current file and place the cursor at the beginning of the file. If there is more than one file, which relate to the current file, then the dialog Related Files displaying these files appears:

Ide TE RelatedFiles.png

The following file types of the same class relate to each other:

  • Declaration of the class
  • Implementation of the class
  • Interface of the object, which is produced by the class
  • Some resource files (e.g. GUI dialogs, windows and forms) that represent the object, which is produced by the class

Go to Resource Editor

To use this command you should be in a text editor window and the cursor should be placed at the valid resource identifier.

Press the hot key combination Ctrl+Shift+C and the IDE will open the resource file that is associated with the resource identifier at which the cursor is placed. The file would be opened in corresponding editor window.

Go to Line Number

To use this command you should be in a text editor window. Now press the hot key combination Ctrl+F2 (the Go to Line Number pop-up menu command, or the Go to | Go to Line Number menu command) and the small dialog Go to Line appears:

Ide TE LineNumber.png

Type in the desired line number and the cursor jumps onto this line in the current text editor.

Go to Position on Clipboard

When a runtime error occurs in a Visual Prolog program, then the Visual Prolog exception handling system displays the Program Error dialog, which contains information about this runtime error. This information includes the short error description, the filename and the position of the predicate that raises the error.

The Program Error dialog contains the Copy to Clipboard button. Pressing this button you can place the filename and the error position onto the Windows system clipboard.

Now you can load the correspondent project into the IDE and press the Shift+F2 hot key (or execute the IDE menu command Go to | Go to Position on Clipboard). Then the IDE opens the file that name was stored in the clipboard and places the cursor onto the error position stored in the clipboard.

Go to Error (Warning)

Go to Selected Error (Warning)

When errors and/or warnings are generated while compiling project files, then their short descriptions, filenames, and positions are displayed in the Errors (Warnings) window.
In the Errors (Warnings) window you can double-click some error, then the IDE opens the correspondent file and places the cursor onto the position of this error/warning message. The same action is accepted if you first select some error and then press Enter (or execute the Go to Code pop-up menu command).

Go to Next Error (Warning)

In the Errors (Warnings) window you can select one of this error/warning messages. (If you do not make such selection, then the first error/warning message is accepted as the selected.) Then you can go into any other IDE window, make some actions, and then press the F8 hot key (or execute the IDE menu command Go to | Go to Next Error (Warning)). The IDE opens the correspondent file and places the cursor onto the position of the error/warning message next to the current.

Go to Previous Error (Warning)

Similarly, when you press the Shift+F8 hot key (or execute the IDE menu command Go to | Go to Previous Error (Warning)). The IDE opens the correspondent file and place the cursor onto the position of the error/warning message previous to the current.

Select Text

Text is always selected as a stream of consecutive characters.

  • You can select any text with the mouse:
    1. Press and hold the left mouse button at the start of the text you want to select. Then drag the cursor to the end of the selection, and release the button.
    2. Click the left mouse button at the start of the selection. Hold the Shift key down and click the left button at the end of the selection.
  • You can select any text using the keyboard:
    Use any of the cursor motion keys (see the table Cursor Moving Operations above) to move the cursor to the start of the text you want to select. Then press and hold the Shift key down while using the motion keys to move the cursor to the end of the selection.
  • You can select the whole edited text:
    Choose the Edit | Select All menu command or press Ctrl+A.
  • You can cancel a selection pressing Esc.

Drag and Drop

  • To move a selected text:
    Hold the Left mouse button down insider the selection. Drag the mouse cursor to the new location (you will see that the shape of the mouse pointer changes). Release the Left button.
  • To copy a selected text:
    Hold the Ctrl+Left mouse button down in the selection. Drag the mouse cursor to the new location (you will see that the shape of the mouse pointer changes). Release the Left button.

Delete Text

You can delete parts of an edited text with the following actions:

To Delete This: Do This:
Selected piece of text Delete or Backspace
The next character Delete
The previous character Backspace
Till the end of the current word Ctrl+Delete or Delete -> Delete Word Right pop-up menu command
Back to the last start of the word Ctrl+Backspace or Delete -> Delete Word Left pop-up menu command
The current line Ctrl+Y or Delete -> Delete Line pop-up menu command
To the end of the line Delete -> Delete Line pop-up menu command
The current word Double-click a word to select it and Delete or Backspace
The whole document Ctrl+A to select the whole text and Delete or Backspace

Use Clipboard

The Windows clipboard can be used to copy text fragments as inside the text editor so to exchange text fragments with external text editors/viewers.

The following clipboard commands are accessible from the text editor pop-up context menu, from the Edit submenu, and from the toolbar:

  • Cut command
    Hot key: Ctrl+X or Shift+Del.
    Edit | Cut or Cut pop-up menu commands.
    Toolbar: Ide TE Cut.png
    This command is enabled only when some text fragment is selected. Use this command to remove the selected text and place it on the clipboard. Cutting text to the clipboard replaces any text previously stored in the clipboard.
  • Copy command
    Hot key: Ctrl+C or Ctrl+Insert.
    Edit | Copy or Copy pop-up menu commands.
    Toolbar: Ide TE Copy.png
    This command is enabled only when some text fragment is selected. Use this command to copy the selected text on the clipboard. Copying text to the clipboard replaces any text previously stored in the clipboard.
  • Paste command
    Hot key: Ctrl+V or Shift+Ins.
    Edit | Paste or Paste pop-up menu commands.
    Toolbar: Ide TE Paste.png
    This command places a copy of the clipboard contents at the insertion point. It is unavailable if the clipboard is empty. Notice that the editor converts all non-viewable symbols from the clipboard contents into space characters.
    If there is a selected block in an active text editor, then the Paste command replaces the selected block with the contents of the clipboard text buffer.

Remember that the clipboard contents is the same for all windows in all applications opened in the Windows session.

Change Case

You can use the following commands to change case of selected text fragments:

  • Change all selected letters to UPPER case:
    Edit | Upper Case or Ctrl+Shift+U.
  • Change all selected letters to lower case:
    Edit | Lower Case or Ctrl+U.
  • Invert case of each character:
    Edit | Toggle Case or Ctrl+Alt+U.

Find Text

You can use the[Find_Text.htm Find Text] dialog to find each occurrence of any character combination (including uppercase and lowercase characters, whole words or parts of words, using regular expression, etc.) in the file being edited.

You can activate the [Find_Text.htm Find Text] dialog with the Ctrl+F hot key, or the Find pop-up menu command, or the Edit | Find menu command.

When you press the Find button in the [Find_Text.htm Find Text] dialog, the dialog is closed and the text editor starts searching for the specified string (regular expression) with the specified options. If the text editor finds the string, it selects the found string (highlights) and displays the page containing the highlighted string.

If you wish to find the next occurrence of the specified string, then you can use the Find Next command. Just press F3 key (use the Edit | Find Next menu command or the Find Next mouse pop-up menu command).

Replace Text

You can use the [Replace_Text.htm Replace Text] dialog to find and replace some occurrences of a text pattern in the file being edited.

You can activate the [Replace_Text.htm Replace Text] dialog with tthe Ctrl+H hot key, or the Replace pop-up menu command, or the Edit | Replace menu command).

Find Text in Several Files

You can use the [Find_Text_in_Files.htm Find in Files] dialog to find each occurrence of any character combination (including uppercase and lowercase characters, whole words, or parts of words, or using regular expression) in a specified set of files.

You can activate the [Find_Text_in_Files.htm Find in Files] dialog with the Ctrl+Shift+F hot key, or the Find in Files pop-up menu command, or the Edit | Find in Files menu command).

Find Names Containing a Substring

You can use the [..\Code_Experts\Code_Browser_Search.htm Source Browser] to find in the project all Visual Prolog names (of some kind) containing some substring. For example, you can find all predicates, which names contain the "string" sub-part.

Insert Known Names

When used in the IDE, the text editor provides some rather useful [..\Code_Experts\Insert_Facility.htm Insert] menu commands:

Insert menu commands

Using these commands one can easy insert declared in the project predicates, facts, domains, constants, etc. (with scopes in which these names are declared). Most of these commands use [..\Code_Experts\Code_Browser_Search.htm Browse information] generated by the compiler. Therefore, in order to new declared names appear in the dialogs of the [..\Code_Experts\Insert_Facility.htm Insert] menu commands, you need to compile the editing file using the Build | Compile (or Ctrl+F9) or any other compilation command.