|
|
Class: TextView
Object
|
+--GraphicsContext
|
+--DeviceGraphicsContext
|
+--GraphicsMedium
|
+--DisplaySurface
|
+--SimpleView
|
+--View
|
+--ListView
|
+--TextView
|
+--EditTextView
- Package:
- stx:libwidg
- Category:
- Views-Text
- Version:
- rev:
1.316
date: 2010/03/18 14:56:16
- user: cg
- file: TextView.st directory: libwidg
- module: stx stc-classLibrary: libwidg
- Author:
- Claus Gittinger
a view for readOnly text - this class adds selections to a simple list.
The text is not editable and there is no cursor.
Use TextViews for readonly text, EditTextView for editable text.
Please read the historic notice in the ListView class.
[Instance variables:]
selectionStartLine <Number> the line of the selection start (or nil)
selectionStartCol <Number> the col of the selection start
selectionEndLine <Number> the line of the selection end
selectionEndCol <Number> the col of the selection end
clickStartLine <Number> temporary - remember where select operation started
clickStartCol <Number> temporary
clickLine <Number> temporary
clickCol <Number> temporary
clickCount <Number> temporary
expandingTop <Boolean> temporary - for expandSelection
selectionFgColor <Color> color used to draw selections
selectionBgColor <Color> color used to draw selections
selectStyle <Symbol> how words are selected
directoryForFileDialog <nil|pathName> directory where save dialog should start
contentsWasSaved <Boolean> set to true, whenever saved in a file
externalEncoding <Symbol|nil> external encoding, used when text is saved to
a file. Usually something like
#jis7, #euc, #sjis etc.
(currently only passed down from the
fileBrowser)
dropSource <DropSource> drag operation descriptor or nil (dragging disabled)
dragIsActive <Boolean> true, drag operation is activated
searchAction <Block> an autosearch action; typically set by the browser.
Will be used as default when searchFwd/searchBwd is
pressed. If the searchPattern is changed, no autosearch
action will be executed.
searchBarActionBlock <Block> search action block for embedded search
panel. Used as second chance for searchFwd/bwd
[class variables:]
ST80Selections <Boolean> enables ST80 style doubleclick behavior
(right after opening parenthesis, right before
closing parenthesis, at begin of a line
at begin of text)
[StyleSheet parameters:]
textView.background defaults to viewBackground
textView.ViewFont defaults to textFont
text.st80Selections st80 behavior (click on char after parent or quote)
text.selectionForegroundColor defaults to textBackgroundColor
text.selectionBackgroundColor defaults to textForegroundColor
text.alternativeSelectionForegroundColor pasted text (i.e. paste will not replace)
defaults to selectionForegroundColor
text.alternativeSelectionBackgroundColor pasted text (i.e. paste will not replace)
defaults to selectionBackgroundColor
EditTextView
CodeView
Workspace
class initialization
-
initialize
-
defaults
-
defaultIcon
-
return the default icon if started as a topView
-
defaultMenuMessage
-
This message is the default yo be sent to the menuHolder to get a menu
-
defaultSelectionBackgroundColor
-
return the default selection background color
-
defaultSelectionForegroundColor
-
return the default selection foreground color
-
defaultViewBackgroundColor
-
return the default view background
-
lastSearchIgnoredCase
-
-
lastSearchWasMatch
-
-
st80SelectMode
-
-
st80SelectMode: aBoolean
-
-
updateStyleCache
-
extract values from the styleSheet and cache them in class variables
instance creation
-
on: aModel aspect: aspect change: change menu: menu initialSelection: initial
-
for ST-80 compatibility
-
with: someText
-
interface specs
-
searchDialogSpec
-
This resource specification was automatically generated
by the UIPainter of ST/X.
startup
-
open
-
start an empty TextView
-
openModalOnModel: aModel
-
start a textView on a model; return the textView
-
openModalWith: aString
-
start a textView with aString as initial contents
-
openModalWith: aString title: aTitle
-
start a textView with aString as initial contents. Return the textView.
-
openOn: aFileName
-
start a textView on a file; return the textView
-
openOnModel: aModel
-
start a textView on a model; return the textView
-
openWith: aStringOrStringCollection
-
start a textView with aStringOrStringCollection as initial contents
-
openWith: aStringOrStringCollection selected: selectedBoolean
-
start a textView with aStringOrStringCollection as initial (optionally selected) contents.
Return the textView.
-
openWith: aStringOrStringCollection title: aTitle
-
start a textView with aStringOrStringCollection as initial contents. Return the textView.
-
setupEmpty
-
create a textview in a topview, with horizontal and
vertical scrollbars - a helper for #startWith: and #startOn:
-
setupForFile: aFileName
-
setup a textView on a file; return the textView
-
setupForModel: aModel
-
setup a textView on a model; return the textView
-
setupWith: aStringOrStringCollection title: aTitle
-
setup a textView with aStringOrStringCollection as initial contents in a topView
Compatibility-ST80
-
displaySelection: aBoolean
-
ST-80 compatibility: ignored here.
-
editText: someText
-
ST-80 compatibility: set the edited text.
-
selectAndScroll
-
ST-80 compatibility: ignored here.
-
selectionStartIndex
-
ST-80 compatibility: return the selections start character position.
-
selectionStopIndex
-
ST-80 compatibility: return the character position of
the character right after the selection.
accessing
-
characterEncoding: encodingArg
-
define how the contents is encoded internally.
This should normally never be required, as ST/X now assumes
unicode (of which iso8859-1 is a subset) encoding.
The possibility to change the characterEncoding is provided as
a backward compatibility hook for programs which want to use
another encoding internally.
-
characterPositionOfSelection
-
return the character index of the first character in the selection.
Returns 0 if there is no selection.
-
characterPositionOfSelectionEnd
-
return the character index of the last character in the selection.
Returns 0 if there is no selection.
-
contentsWasSaved
-
return true, if the contents was saved (by a save action),
false if not (or was modified again after the last save).
-
contentsWasSaved: aBoolean
-
-
defaultFileNameForFileDialog
-
return the default fileName to use for the save-box
-
defaultFileNameForFileDialog: aBaseName
-
define the default fileName to use for the save-box
-
directoryForFileDialog: aDirectory
-
define the default directory to use for save-box
-
externalEncoding
-
return the encoding used when the contents is saved via the 'save / save as' dialog.
This is (currently only) passed down from the fileBrowser,
and required when utf8/japanese/chinese/korean text is edited.
(encoding is something like #utf8 #'iso8859-5' #euc, #sjis, #jis7, #gb, #big5 or #ksc).
Notice: this only affects the external representation of the text.
-
externalEncoding: encodingSymOrNil
-
define how the contents should be encoded when saved
via the 'save / save as' dialog.
This is (currently only) passed down from the fileBrowser,
and required when utf8/japanese/chinese/korean text is edited.
(encoding is something like #utf8 #'iso8859-5' #euc, #sjis, #jis7, #gb, #big5 or #ksc).
Notice: this only affects the external representation of the text.
-
parenthesisSpecification
-
return the value of the instance variable 'parenthesisSpecification' (automatically generated)
-
parenthesisSpecification: aDictionary
-
set the dictionary which specifies which characters are opening, which are closing
and which are ignored characters w.r.t. parenthesis matching.
See the classes initialize method for a useful value.
-
saveAction: something
-
-
searchBarActionBlock
-
-
searchBarActionBlock: something
-
accessing-behavior
-
readOnly: aBoolean
-
for protocol compatibility with editTextViews,
but actually ignored
accessing-contents
-
contents: newContents selected: selectedBoolean
-
-
fromFile: aFileName
-
take contents from a named file
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
list: something
-
set the displayed contents (a collection of strings)
with redraw.
Redefined since changing the contents implies deselect
-
loadTextFile: aFileName
-
take contents from a named file
-
setContents: something
-
set the contents (either a string or a Collection of strings)
dont change the position (i.e. do not scroll) or the selection.
-
setList: something
-
set the displayed contents (a collection of strings)
without redraw.
Redefined since changing contents implies deselect
-
setupForFile: aFileName
-
take contents from a named file
-
text
-
for ST80 compatibility
-
wordAtLine: selectLine col: selectCol do: aFiveArgBlock
-
find word boundaries, evaluate the block argument with those.
A helper for nextWord and selectWord functions.
accessing-look
-
selectionBackgroundColor
-
return the selection-background color.
-
selectionForegroundColor
-
return the selection-foreground color.
-
selectionForegroundColor: color1 backgroundColor: color2
-
set both the selection-foreground and cursor background colors.
The default is defined by the styleSheet;
typically black-on-green for color displays and white-on-black for b&w displays.
accessing-mvc
-
on: aModel aspect: aspectSym list: listSym change: changeSym menu: menuSym initialSelection: initial
-
set all of model, aspect, listMessage, changeSymbol, menySymbol
and selection. Added for ST-80 compatibility
drag & drop
-
allowDrag: aBoolean
-
enable/disable dragging support
-
canDrag
-
returns true if dragging is enabled
-
collectionOfDragObjects
-
returns collection of dragable objects assigned to selection
Here, by default, a collection of text-dragObjects is generated;
however, if a dragObjectConverter is defined, that one gets a chance
to convert as appropriate.
-
dropSource
-
returns the dropSource or nil
-
dropSource: aDropSourceOrNil
-
set the dropSource or nil
encoding
-
validateFontEncodingFor: newEncoding ask: ask
-
if required, query user if he/she wants to change to another font,
which is able to display text encoded as specified by newEncoding
event handling
-
buttonMotion: buttonState x: x y: y
-
mouse-move while button was pressed - handle selection changes
-
buttonMultiPress: button x: x y: y
-
multi-mouse-click - select word under pointer
-
buttonPress: button x: x y: y
-
mouse-click - prepare for selection change
-
buttonRelease: button x: x y: y
-
mouse- button release - turn off autoScroll if any
-
doubleClickX: x y: y
-
double-click - select word under pointer
-
extendSelectionToX: x y: y
-
mouse-move while button was pressed - handle selection changes
-
keyPress: key x: x y: y
-
handle some keyboard input (there is not much to be done here)
-
mapped
-
-
quadClickX: x y: y
-
quadrupleClick-click - select all
-
tripleClickX: x y: y
-
triple-click - select line under pointer
initialization & release
-
fetchDeviceResources
-
fetch device colors, to avoid reallocation at redraw time
-
initStyle
-
setup viewStyle specifics
-
initialize
-
-
initializeSaveAction
-
menu actions
-
appendTo: aFileName
-
append contents to a file named fileName
-
changeFont
-
pop up a fontPanel to change font
-
copySelection
-
copy contents into smalltalk copybuffer
-
defaultForGotoLine
-
return a default value to show in the gotoLine box
-
doPrint
-
print the contents on the printer
-
editMenu
-
return my popUpMenu
-
find
-
same as search - for VW compatibility
-
gotoLine
-
show a box to enter lineNumber for positioning;
The entered number may be prefixed by a + or -;
in this case, the linenumber is taken relative to the current position.
-
openSaveDialog
-
Ask user for filename using a fileSelectionBox
and save contents into that file.
-
save
-
save contents into a file
- ask user for filename using a fileSelectionBox.
-
saveAs: fileName
-
save the contents into a file named fileName
-
saveAs: aFilename doAppend: doAppend
-
save the contents into a file named fileName;
if doAppend is true, the views contents is appended to the existing
contents - otherwise, it overwrites any previous file contents.
on error return false otherwise return true
-
search
-
search for a string - show a box to enter searchpattern
- currently no regular expressions are handled.
-
search: patternArg ignoreCase: ign forward: fwd
-
search for a string without matching
-
search: patternArg ignoreCase: ign match: match forward: fwd
-
private
-
currentSelectionBgColor
-
-
currentSelectionFgColor
-
-
fileOutContentsOn: aStream
-
save contents on a stream, replacing leading spaces by tab-characters.
-
fileOutContentsOn: aStream compressTabs: compressTabs
-
save contents on a stream. If compressTabs is true,
leading spaces will be replaced by tab-characters in the output.
-
fileOutContentsOn: aStream compressTabs: compressTabs encoding: encodingSymOrNil
-
save contents on a stream. If compressTabs is true,
leading spaces will be replaced by tab-characters in the output.
-
getFontParameters
-
get some info of the used font. They are cached since we use them often ..
This is redefined here, to use the fonts maxHeight/maxAscent for
line separation. This is required, to allow for proper handling of
national characters, such as A-dieresis ...
-
isClosingParenthesis: ch
-
-
isOpeningParenthesis: ch
-
-
rememberSearchPattern: pattern
-
-
removeTrailingWhitespace
-
-
resetVariablesBeforeNewSearch
-
clear the autosearch action, when the first pattern is searched for
-
scrollSelectDown
-
auto scroll action; scroll and reinstall timed-block
-
scrollSelectLeft
-
auto scroll action; scroll and reinstall timed-block
-
scrollSelectRight
-
auto scroll action; scroll and reinstall timed-block
-
scrollSelectUp
-
auto scroll action; scroll and reinstall timed-block
-
stopScrollSelect
-
stop auto scroll; deinstall timed-block
-
widthForScrollBetween: firstLine and: lastLine
-
return the width in pixels for a scroll between firstLine and lastLine
queries
-
hasSearchActionSelection
-
Here we fake the use of typeOfSelection which is really in EditTextView
-
isTextView
-
I am showing text
-
specClass
-
redefined, since the name of my specClass is nonStandard (i.e. not TextViewSpec)
redrawing
-
clearMarginOfVisibleLine: visLine with: color
-
if there is a margin, clear it - a helper for selection drawing
-
drawSelectedFromVisibleLine: startVisLineNr to: endVisLineNr
-
-
drawVisibleLineSelected: visLineNr
-
-
drawVisibleLineSelected: visLineNr col: col
-
-
drawVisibleLineSelected: visLineNr from: selectionStartCol
-
-
drawVisibleLineSelected: visLineNr from: startCol to: endCol
-
-
redrawFromVisibleLine: startVisLineNr to: endVisLineNr
-
redraw a visible line range
-
redrawMarginOfVisibleLine: visLine
-
draw margin - a helper for selection drawing
-
redrawVisibleLine: visLineNr
-
redraw visible line lineNr
-
redrawVisibleLine: visLine col: col
-
redraw single character at col in visible line lineNr.
-
redrawVisibleLine: visLine from: startCol
-
redraw visible line lineNr from startCol to end of line
-
redrawVisibleLine: visLine from: startCol to: endCol
-
redraw visible line lineNr from startCol to endCol
searching
-
clearSearchAction
-
-
scanFor: aCharacter fromLine: startLine col: startCol forward: forward ifFound: foundBlock ifNotFound: notFoundBlock
-
search for a character in the direction given by forward.
Performs foundBlock with line/col as argument if found, notFoundBlock if not.
-
searchAction
-
-
searchAction: aSearcherOrSearchBlock
-
-
searchAgainInSameDirection
-
search again in the same direction and -if found- position cursor
-
searchBwd
-
search backward and -if found- position cursor
-
searchBwd: pattern
-
do a backward search
-
searchBwd: pattern ifAbsent: aBlock
-
do a backward search
-
searchBwd: pattern ignoreCase: ign
-
do a backward search
-
searchBwd: pattern ignoreCase: ign ifAbsent: aBlock
-
do a backward search
-
searchBwd: pattern ignoreCase: ign match: match
-
do a backward search.
match pattern functionality is not yet available for backward search
-
searchForAndSelectMatchingParenthesisFromLine: startLine col: startCol
-
select characters enclosed by matching parenthesis if one is under startLine/Col
-
searchForMatchingParenthesisFromLine: startLine col: startCol ifFound: foundBlock ifNotFound: notFoundBlock onError: failBlock
-
search for a matching parenthesis; start search with character at startLine/startCol.
Search for the corresponding character is done forward if its an opening,
backwards if its a closing parenthesis.
Evaluate foundBlock with line/col as argument if found, notFoundBlock if not.
If there is a nesting error, evaluate failBlock.
-
searchForMatchingParenthesisFromLine: startLine col: startCol ifFound: foundBlock ifNotFound: notFoundBlock onError: failBlock ignoring: ignoreSet
-
search for a matching parenthesis; start search with character at startLine/startCol.
Search for the corresponding character is done forward if its an opening,
backwards if its a closing parenthesis.
Evaluate foundBlock with line/col as argument if found, notFoundBlock if not.
If there is a nesting error, evaluate failBlock.
-
searchForMatchingParenthesisFromLine: startLine col: startCol ifFound: foundBlock ifNotFound: notFoundBlock onError: failBlock openingCharacters: openingCharacters closingCharacters: closingCharacters
-
search for a matching parenthesis; start search with character at startLine/startCol.
Search for the corresponding character is done forward if its an opening,
backwards if its a closing parenthesis.
Evaluate foundBlock with line/col as argument if found, notFoundBlock if not.
If there is a nesting error, evaluate failBlock.
-
searchForMatchingParenthesisFromLine: startLine col: startCol ifFound: foundBlock ifNotFound: notFoundBlock onError: failBlock openingCharacters: openingCharacters closingCharacters: closingCharacters ignoredCharacters: ignoreSet specialEOLComment: eolCommentSequence
-
search for a matching parenthesis; start search with character at startLine/startCol.
Search for the corresponding character is done forward if its an opening,
backwards if its a closing parenthesis.
Evaluate foundBlock with line/col as argument if found, notFoundBlock if not.
If there is a nesting error, evaluate failBlock.
-
searchFwd
-
search forward for pattern or selection
-
searchFwd: pattern
-
do a forward search
-
searchFwd: pattern ifAbsent: aBlock
-
do a forward search
-
searchFwd: pattern ignoreCase: ign
-
do a forward search
-
searchFwd: pattern ignoreCase: ign ifAbsent: aBlock
-
do a forward search
-
searchFwd: pattern ignoreCase: ign match: match
-
do a forward search
-
searchFwd: pattern ignoreCase: ign match: match ifAbsent: aBlock
-
do a forward search
-
searchFwd: pattern ignoreCase: ign match: match startingAtLine: startLine col: startCol ifAbsent: aBlock
-
do a forward search
-
searchPattern
-
return the last search pattern
-
searchUsingSearchAction: direction
-
-
searchUsingSearchAction: direction ifAbsent: notFoundAction
-
-
setSearchPattern
-
set the searchpattern from the selection if there is one
-
setSearchPattern: aStringOrNil
-
set the searchpattern for future searches
-
setSearchPattern: aString ignoreCase: aBoolean
-
set the searchpattern and caseIgnore for future searches
-
setSearchPatternWithMatchEscapes: match
-
set the searchpattern from the selection if there is one
-
showMatch: pattern atLine: line col: col
-
after a search, highlight the matched pattern.
The code below needs a rewrite to take care of match-characters
(for now, it only highlights simple patterns and '*string*' correctly)
-
showMatch: pattern isMatch: isMatch atLine: line col: col
-
after a search, highlight the matched pattern.
The code below needs a rewrite to take care of match-characters
(for now, it only highlights simple patterns and '*string*' correctly)
-
showNotFound
-
search not found - tell user by beeping and changing
cursor for a while (sometimes I work with a headset :-)
(used to be: tell user by changing cursor for a while)
-
startPositionForSearchBackward
-
-
startPositionForSearchBackwardBasedOnSelection
-
-
startPositionForSearchForward
-
-
startPositionForSearchForwardBasedOnSelection
-
selections
-
changeTypeOfSelectionTo: newType
-
ignored here - but redefined in subclasses which
differentiate between pasted- and user-selections
-
expandSelectionDown
-
-
expandSelectionLeft
-
-
expandSelectionRight
-
-
expandSelectionUp
-
-
hasSelection
-
return true, if there is a selection
-
hasSelectionForCopy
-
return true, if there is a selection which can be copyied
(the same as #hasSelection, except for editfields in password-mode)
-
hasSelectionWithinSingleLine
-
return true, if there is a selection and it is within a line
-
isInSelection: line col: aColNr
-
returns true, if the line, and column is in the selection
-
makeSelectionVisible
-
scroll to make the selection visible
-
selectAll
-
select the whole text
-
selectFromCharacterPosition: pos1
-
compute line/col from the character position and select the text up to the end
-
selectFromCharacterPosition: pos1 to: pos2
-
compute line/col from character positions and select the text
-
selectFromLine: startLine col: startCol toLine: endLine col: endCol
-
select a piece of text and redraw that area
-
selectFromLine: startLine toLine: endLine
-
select a piece of text and redraw that area
-
selectLine: selectLine
-
select one line and redraw it
-
selectLineAtY: y
-
select the line at given y-(view-)coordinate
-
selectLineWhereCharacterPosition: pos
-
select the line, where characterPosition pos is living.
The argument pos starts at 1 from the start of the text
and counts characters (i.e. can be used to convert from
character position within a string to line-position in view).
-
selectWordAtLine: line col: col
-
select the word at given line/col
-
selectWordAtX: x y: y
-
select the word at given x/y-(view-)coordinate
-
selectedInterval
-
return the selection-boundaries as interval
-
selection
-
return the selection as a collection of (line-)strings.
If the selection ends in a full line, the last entry in the returned
collection will be an empty string.
-
selectionAsString
-
return the selection as a String (i.e. without emphasis)
-
selectionChanged
-
can be redefined for notification or special actions
-
selectionEndCol
-
-
selectionEndLine
-
-
selectionStartCol
-
-
selectionStartLine
-
-
st80SelectMode
-
-
st80SelectMode: aBoolean
-
-
unselect
-
unselect - if there was a selection redraw that area
-
unselectWithoutRedraw
-
forget selection but do not redraw the selection area
- can be done when the selected area is redrawn anyway or
known to be invisible (however, redraw knows about that anyway).
-
validateNewSelection
-
make certain that the selection is valid.
This is a dummy here, but subclasses (like single-line editFields)
may redefine it to limit the selection to a single line, or whatever.
although textViews (and instances of subclasses) are mostly used
as components (in the fileBrowser, the browser, the launcher etc.),
they may also be opened as a textEditor;
open a (readonly) textView on some information text:
TextView
openWith:'read this'
title:'demonstration'
|
the same, but open it modal:
TextView
openModalWith:'read this first'
title:'demonstration'
|
open it modal (but editable) on some text:
(must accept before closing)
This is somewhat kludgy - when closed, the view has already
nilled its link to the model. Therefore, the accept must be
done 'manually' below.
However, usually an applicationModel is installed as the
editor-topViews application. This would get a closeRequest,
where it could handle things.
|m textView|
m := 'read this first' asValue.
textView := EditTextView openModalOnModel:m.
textView modified ifTrue:[
(self confirm:'text was not accepted - do it now ?')
ifTrue:[
m value:textView contents
]
].
Transcript showCR:m value.
|
open a textEditor on some file:
EditTextView openOn:'Makefile'
|
|