#FEATURE by cg
class: EditTextView
added: #compareWithFile
changed: #editMenu
new menu function: compare contents with file
--- a/EditTextView.st Thu Aug 11 18:42:42 2016 +0200
+++ b/EditTextView.st Fri Aug 12 18:16:26 2016 +0200
@@ -6251,6 +6251,36 @@
and:t2 label:'Clipboard'
!
+compareWithFile
+ "compare the selection or the whole text against the contents of a file"
+
+ |fn t1 t2|
+
+ fn := Dialog requestFileName:'Compare against file:' default:defaultFileNameForFileDialog.
+ fn isEmptyOrNil ifTrue:[^ self].
+
+ t2 := fn asFilename contentsOfEntireFile.
+ t2 isEmptyOrNil ifTrue:[
+ Dialog information:'File is empty.'.
+ ^ self.
+ ].
+
+ self hasSelection ifTrue:[
+ t1 := self selectionAsString.
+ ] ifFalse:[
+ t1 := self contents asString
+ ].
+ t1 := t1 string.
+
+ t1 = t2 ifTrue:[
+ Dialog information:'Same contents.'.
+ ^ self.
+ ].
+ DiffTextView
+ openOn:t1 label:'Editor'
+ and:t2 label:'File'
+!
+
copySelection
"copy contents into smalltalk copybuffer.
Redefined to move the (currently hidden cursor) to the selection's end"
@@ -6336,58 +6366,58 @@
"return the views middleButtonMenu"
<resource: #keyboard (#Again #AgainForAll #Copy #Cut #Paste #Accept
- #Find #GotoLine #SaveAs #Print
- #PasteFromHistory #Join #Wrap #Undo #Redo
- #ToggleAutoIndent #ToggleInsertMode
- #LearnKeyboardMacro #ExecuteKeyboardMacro )>
+ #Find #GotoLine #SaveAs #Print
+ #PasteFromHistory #Join #Wrap #Undo #Redo
+ #ToggleAutoIndent #ToggleInsertMode
+ #LearnKeyboardMacro #ExecuteKeyboardMacro )>
<resource: #programMenu>
|items m sub translateItems sortItems miscItems toolItems subSub toolSub
transSub sortSub what undoIdx redoIdx sensor main mainItems|
items := #(
- ('Redo' redo Redo )
- ('Again (for All)' multipleAgain AgainForAll )
- ('-' )
- ('Search...' search Find )
- ('Goto Line...' gotoLine GotoLine )
- ('-' )
- ('Tools' tools )
- ('Font...' changeFont )
- ('Insert Unicode...' insertUnicode )
- ).
+ ('Redo' redo Redo )
+ ('Again (for All)' multipleAgain AgainForAll )
+ ('-' )
+ ('Search...' search Find )
+ ('Goto Line...' gotoLine GotoLine )
+ ('-' )
+ ('Tools' tools )
+ ('Font...' changeFont )
+ ('Insert Unicode...' insertUnicode )
+ ).
CharacterSetView notNil ifTrue:[
- items := items ,
- #(
- ('Special Characters...' specialCharacters OpenSpecialCharacterWindow )
- ).
+ items := items ,
+ #(
+ ('Special Characters...' specialCharacters OpenSpecialCharacterWindow )
+ ).
].
items := items , #(
- ('-' )
- ('Save As...' save SaveAs )
- ('Print' doPrint Print )
- ('=' )
- ('Misc' misc ShiftCtrl) ).
+ ('-' )
+ ('Save As...' save SaveAs )
+ ('Print' doPrint Print )
+ ('=' )
+ ('Misc' misc ShiftCtrl) ).
miscItems := #(
- ('AutoIndent \c' autoIndent: ToggleAutoIndent )
- ('InsertMode \c' insertMode: ToggleInsertMode )
- ('-' )
- ('Paste Previous...' pasteOrReplaceFromHistory PasteFromHistory )
- ('Join Lines' joinLines Join )
- ('Wrap Lines...' wrapLines Wrap )
- ('-' )
- ('Learn Macro' learnMode: LearnKeyboardMacro)
- ('Execute Macro' executeLearnedKeyboardMacro ExecuteKeyboardMacro )
- ('-' )
- ('Insert File...' insertFile )
- ('Insert URL Contents...' insertURL )
- ('Insert new UUID' insertUUID )
- ('Insert Date && Time' insertDateAndTime )
- ('-' )
- ('Insert File as String Literal...' insertFileAsStringLiteral )
- ('Paste as String Literal' pasteAsStringLiteral )
- ).
+ ('AutoIndent \c' autoIndent: ToggleAutoIndent )
+ ('InsertMode \c' insertMode: ToggleInsertMode )
+ ('-' )
+ ('Paste Previous...' pasteOrReplaceFromHistory PasteFromHistory )
+ ('Join Lines' joinLines Join )
+ ('Wrap Lines...' wrapLines Wrap )
+ ('-' )
+ ('Learn Macro' learnMode: LearnKeyboardMacro)
+ ('Execute Macro' executeLearnedKeyboardMacro ExecuteKeyboardMacro )
+ ('-' )
+ ('Insert File...' insertFile )
+ ('Insert URL Contents...' insertURL )
+ ('Insert new UUID' insertUUID )
+ ('Insert Date && Time' insertDateAndTime )
+ ('-' )
+ ('Insert File as String Literal...' insertFileAsStringLiteral )
+ ('Paste as String Literal' pasteAsStringLiteral )
+ ).
"/ CharacterSetView notNil ifTrue:[
"/ miscItems := miscItems ,
"/ #(
@@ -6404,55 +6434,56 @@
"/ ].
translateItems := #(
- ('English -> German' (babelFishTranslate: 'en_de') )
- ('English -> French' (babelFishTranslate: 'en_fr') )
- ('English -> Italian' (babelFishTranslate: 'en_it') )
- ('English -> Spanish' (babelFishTranslate: 'en_es') )
- ('English -> Portuguese' (babelFishTranslate: 'en_pt') )
- ('-' )
- ('German -> English' (babelFishTranslate: 'de_en') )
- ('French -> English' (babelFishTranslate: 'fr_en') )
- ('Italian -> English' (babelFishTranslate: 'it_en') )
- ('Spanish -> English' (babelFishTranslate: 'es_en') )
- ('Portuguese -> English' (babelFishTranslate: 'pt_en') )
- ).
+ ('English -> German' (babelFishTranslate: 'en_de') )
+ ('English -> French' (babelFishTranslate: 'en_fr') )
+ ('English -> Italian' (babelFishTranslate: 'en_it') )
+ ('English -> Spanish' (babelFishTranslate: 'en_es') )
+ ('English -> Portuguese' (babelFishTranslate: 'en_pt') )
+ ('-' )
+ ('German -> English' (babelFishTranslate: 'de_en') )
+ ('French -> English' (babelFishTranslate: 'fr_en') )
+ ('Italian -> English' (babelFishTranslate: 'it_en') )
+ ('Spanish -> English' (babelFishTranslate: 'es_en') )
+ ('Portuguese -> English' (babelFishTranslate: 'pt_en') )
+ ).
sortItems := #(
- ('Lines' (sortSelection:ignoreCase: #lines false) )
- ('Lines by First Word' (sortSelection:ignoreCase: #linesByFirstWord false) )
- ('Lines by n''th Word' (sortSelection:ignoreCase: #linesByNthWord false) )
- ('Lines by n''th Number' (sortSelection:ignoreCase: #linesByNthNumber false) )
- ('Lines by n''th Hex Number' (sortSelection:ignoreCase: #linesByNthHexNumber false) )
- ('Words' (sortSelection:ignoreCase: #words false) )
- ('-' )
- ('Lines (ignore case)' (sortSelection:ignoreCase: #lines true) )
- ('Lines by First Word (ignore case)' (sortSelection:ignoreCase: #linesByFirstWord true) )
- ('Lines by n''th Word (ignore case)' (sortSelection:ignoreCase: #linesByNthWord true) )
- ('Words (ignore case)' (sortSelection:ignoreCase: #words true) )
- ('-' )
- ('By Line Length' (sortSelection:ignoreCase: #linesByLength nil) )
- ('Reverse' (sortSelection:ignoreCase: #reverse nil) )
- ).
+ ('Lines' (sortSelection:ignoreCase: #lines false) )
+ ('Lines by First Word' (sortSelection:ignoreCase: #linesByFirstWord false) )
+ ('Lines by n''th Word' (sortSelection:ignoreCase: #linesByNthWord false) )
+ ('Lines by n''th Number' (sortSelection:ignoreCase: #linesByNthNumber false) )
+ ('Lines by n''th Hex Number' (sortSelection:ignoreCase: #linesByNthHexNumber false) )
+ ('Words' (sortSelection:ignoreCase: #words false) )
+ ('-' )
+ ('Lines (ignore case)' (sortSelection:ignoreCase: #lines true) )
+ ('Lines by First Word (ignore case)' (sortSelection:ignoreCase: #linesByFirstWord true) )
+ ('Lines by n''th Word (ignore case)' (sortSelection:ignoreCase: #linesByNthWord true) )
+ ('Words (ignore case)' (sortSelection:ignoreCase: #words true) )
+ ('-' )
+ ('By Line Length' (sortSelection:ignoreCase: #linesByLength nil) )
+ ('Reverse' (sortSelection:ignoreCase: #reverse nil) )
+ ).
toolItems := #(
- ('Indent' indent )
- ('Toggle Case' convertSelectionToLowercaseOrUppercaseOrUppercaseFirst ConvertSelectionToLowercaseOrUppercaseOrUppercaseFirst)
- ('Sort' sort )
- ('Split...' splitLinesAtCharacterOrString )
- ('-' )
- ('Google Spell Check' googleSpellingSuggestion )
- ('Builtin Spell Check' internalSpellingSuggestion )
- ('Translate' babelFishTranslate )
- ('Compare with Clipboard...' compareWithClipboard )
- ).
+ ('Indent' indent )
+ ('Toggle Case' convertSelectionToLowercaseOrUppercaseOrUppercaseFirst ConvertSelectionToLowercaseOrUppercaseOrUppercaseFirst)
+ ('Sort' sort )
+ ('Split...' splitLinesAtCharacterOrString )
+ ('-' )
+ ('Google Spell Check' googleSpellingSuggestion )
+ ('Builtin Spell Check' internalSpellingSuggestion )
+ ('Translate' babelFishTranslate )
+ ('Compare with Clipboard...' compareWithClipboard )
+ ('Compare with File...' compareWithFile )
+ ).
Smalltalk isStandAloneApp ifFalse:[
- toolItems := toolItems , #(
- ('-' )
- ('Open FileBrowser on It' openFileBrowserOnIt )
- ('Open Workspace with It' openWorkspaceWithIt )
- ('Inspect Selected String' inspectSelectedString )
- ).
+ toolItems := toolItems , #(
+ ('-' )
+ ('Open FileBrowser on It' openFileBrowserOnIt )
+ ('Open Workspace with It' openWorkspaceWithIt )
+ ('Inspect Selected String' inspectSelectedString )
+ ).
].
sub := PopUpMenu itemList:items resources:resources performer:model.
@@ -6479,92 +6510,92 @@
sub subMenuAt:#misc put:subSub.
mainItems := #(
- ('Undo' undo Undo )
- ('Again' again Again )
- ('-' )
- ('Cut' cut Cut )
- ('Copy' copySelection Copy )
- ('Paste' pasteOrReplace Paste )
- ('-' )
- ('Accept' accept Accept )
- ('=' )
- ('More' others Ctrl )
- ).
+ ('Undo' undo Undo )
+ ('Again' again Again )
+ ('-' )
+ ('Cut' cut Cut )
+ ('Copy' copySelection Copy )
+ ('Paste' pasteOrReplace Paste )
+ ('-' )
+ ('Accept' accept Accept )
+ ('=' )
+ ('More' others Ctrl )
+ ).
main := PopUpMenu itemList:mainItems resources:resources.
main subMenuAt:#others put:sub.
sensor := self sensor.
(sensor notNil and:[sensor ctrlDown]) ifTrue:[
sensor shiftDown ifTrue:[
- m := subSub
- ] ifFalse:[
- m := sub
- ]
+ m := subSub
+ ] ifFalse:[
+ m := sub
+ ]
] ifFalse:[
- m := main
+ m := main
].
"/ the 'Smalltalk at:' code is here to
"/ avoid making the SOAP package a prerequisite for this package (libwidg)
(Smalltalk at:#'SOAP::GoogleClient') isNil ifTrue:[
- "/ GoogleClient new spellingSuggestionOf: 'Smmalltlaak and Soaap'.
- m disable:#googleSpellingSuggestion
+ "/ GoogleClient new spellingSuggestionOf: 'Smmalltlaak and Soaap'.
+ m disable:#googleSpellingSuggestion
].
(Smalltalk at:#'RBSpellChecker') isNil ifTrue:[
- m disable:#internalSpellingSuggestion
+ m disable:#internalSpellingSuggestion
].
HTTPInterface isNil ifTrue:[
- m disableAll:#(insertURL)
+ m disableAll:#(insertURL)
].
self isReadOnly ifTrue:[
- m disableAll:#(accept undo again multipleAgain redo
- paste pasteOrReplace pasteOrReplaceFromHistory
- cut indent autoIndent: insertMode:
- insertFile insertFileAsStringLiteral insertURL
- babelFishTranslate googleSpellingSuggestion sort
- convertSelectionToLowercaseOrUppercaseOrUppercaseFirst
- joinLines wrapLines insertUUID insertDateAndTime pasteAsStringLiteral
- insertUnicode specialCharacters)
+ m disableAll:#(accept undo again multipleAgain redo
+ paste pasteOrReplace pasteOrReplaceFromHistory
+ cut indent autoIndent: insertMode:
+ insertFile insertFileAsStringLiteral insertURL
+ babelFishTranslate googleSpellingSuggestion sort
+ convertSelectionToLowercaseOrUppercaseOrUppercaseFirst
+ joinLines wrapLines insertUUID insertDateAndTime pasteAsStringLiteral
+ insertUnicode specialCharacters)
].
self hasSelectionForCopy ifFalse:[
- m disable:#copySelection.
+ m disable:#copySelection.
].
self hasSelection ifFalse:[
- m disableAll:#(cut googleSpellingSuggestion babelFishTranslate openFileBrowserOnIt
- openWorkspaceWithIt sort indent splitLinesAtCharacterOrString inspectSelectedString).
+ m disableAll:#(cut googleSpellingSuggestion babelFishTranslate openFileBrowserOnIt
+ openWorkspaceWithIt sort indent splitLinesAtCharacterOrString inspectSelectedString).
] ifTrue:[
- (Error handle:[:ex |
- ex return:false
- ] do:[
- |fn|
- fn := self selectionAsString.
- fn asFilename exists or:[ fn withoutSeparators withoutQuotes asFilename exists ]
- ]) ifFalse:[
- m disableAll:#(openFileBrowserOnIt).
- ]
+ (Error handle:[:ex |
+ ex return:false
+ ] do:[
+ |fn|
+ fn := self selectionAsString.
+ fn asFilename exists or:[ fn withoutSeparators withoutQuotes asFilename exists ]
+ ]) ifFalse:[
+ m disableAll:#(openFileBrowserOnIt).
+ ]
].
self hasUndoAction ifFalse:[
- m disable:#undo.
+ m disable:#undo.
] ifTrue:[
- what := undoSupport undoActionInfo.
- what notNil ifTrue:[
- undoIdx := m indexOf:#undo.
- m labelAt:undoIdx put:(resources string:'Undo (%1)' with:what).
- ]
+ what := undoSupport undoActionInfo.
+ what notNil ifTrue:[
+ undoIdx := m indexOf:#undo.
+ m labelAt:undoIdx put:(resources string:'Undo (%1)' with:what).
+ ]
].
self hasRedoAction ifFalse:[
- sub disable:#redo.
+ sub disable:#redo.
] ifTrue:[
- what := undoSupport redoActionInfo.
- what notNil ifTrue:[
- redoIdx := sub indexOf:#redo.
- sub labelAt:redoIdx put:(resources string:'Redo (%1)' with:what).
- ]
+ what := undoSupport redoActionInfo.
+ what notNil ifTrue:[
+ redoIdx := sub indexOf:#redo.
+ sub labelAt:redoIdx put:(resources string:'Redo (%1)' with:what).
+ ]
].
self canAccept ifFalse:[
- m disable:#accept
+ m disable:#accept
].
^ m.