WorkspaceApplication.st
changeset 11496 6d48914856b8
parent 11483 5f545a7d153a
child 11612 445864161db9
equal deleted inserted replaced
11495:2624c6cdb934 11496:6d48914856b8
   759             itemValue: processText
   759             itemValue: processText
   760             translateLabel: true
   760             translateLabel: true
   761             isVisible: thisIsASmalltalkWorkspace
   761             isVisible: thisIsASmalltalkWorkspace
   762           )
   762           )
   763          (MenuItem
   763          (MenuItem
       
   764             label: 'Compare Text Against...'
       
   765             itemValue: compareTextAgainst
       
   766             translateLabel: true
       
   767           )
       
   768          (MenuItem
   764             label: '-'
   769             label: '-'
   765           )
   770           )
   766          (MenuItem
   771          (MenuItem
   767             label: 'Services'
   772             label: 'Services'
   768             translateLabel: true
   773             translateLabel: true
   877           )
   882           )
   878          )
   883          )
   879         nil
   884         nil
   880         nil
   885         nil
   881       )
   886       )
       
   887 
       
   888     "Modified: / 04-05-2012 / 15:43:09 / cg"
   882 !
   889 !
   883 
   890 
   884 editModeInfoLabelMenu
   891 editModeInfoLabelMenu
   885     "This resource specification was automatically generated
   892     "This resource specification was automatically generated
   886      by the MenuEditor of ST/X."
   893      by the MenuEditor of ST/X."
  2465 
  2472 
  2466 clearHistory
  2473 clearHistory
  2467     Workspace clearDoItHistory
  2474     Workspace clearDoItHistory
  2468 !
  2475 !
  2469 
  2476 
       
  2477 compareTextAgainst
       
  2478     |ws otherText thisText|
       
  2479 
       
  2480     ws := self selectedWorkspace scrolledView.
       
  2481     ws isTextView ifFalse:[
       
  2482         ^ self 
       
  2483     ].
       
  2484 
       
  2485     ws hasSelection ifTrue:[
       
  2486         thisText := ws selectionAsString.
       
  2487     ] ifFalse:[
       
  2488         thisText := ws contents asString.
       
  2489     ].
       
  2490 
       
  2491     otherText := Dialog requestText:'Paste other text below:'.
       
  2492     otherText isEmptyOrNil ifTrue:[^ self ].
       
  2493 
       
  2494     DiffTextView 
       
  2495         openOn: thisText label: 'Workspace' 
       
  2496         and: otherText label: 'Other Text' 
       
  2497         title: 'Comparing Workspace Contents'
       
  2498 
       
  2499     "Created: / 04-05-2012 / 15:35:32 / cg"
       
  2500 !
       
  2501 
  2470 doIt
  2502 doIt
  2471     |ws|
  2503     |ws|
  2472 
  2504 
  2473     ws := self selectedWorkspacesTextView.
  2505     ws := self selectedWorkspacesTextView.
  2474     ws notNil ifTrue:[
  2506     ws notNil ifTrue:[
  3396 fileInText
  3428 fileInText
  3397     self selectedWorkspacesTextView contentsAsString readStream fileIn
  3429     self selectedWorkspacesTextView contentsAsString readStream fileIn
  3398 !
  3430 !
  3399 
  3431 
  3400 filterText
  3432 filterText
  3401     |template filterBlock newList oldList answer nDeleted deletedLines|
  3433     |template filterBlock newList oldList answer nDeleted deletedLines
       
  3434      prevLine nextLine line|
  3402 
  3435 
  3403     template :=
  3436     template :=
  3404 '"/ general text filter;
  3437 '"/ general text filter;
  3405 "/ the following block should evaluate to true for all lines
  3438 "/ the following block should evaluate to true for all lines
  3406 "/ you want to keep - lines for which the block returns false will be removed.
  3439 "/ you want to KEEP.
       
  3440 "/ Lines for which the block returns false, will be removed.
  3407 "/ Beginner warning: Smalltalk know-how is useful here.
  3441 "/ Beginner warning: Smalltalk know-how is useful here.
  3408 
  3442 
  3409 [:line |
  3443 [:line :lineNr :previousLine :nextLine|
  3410      "/ any condition on line.
  3444      "/ any condition on line.
  3411      "/ Notice, that line might be a Text object (i.e. non-string),
  3445      "/ Notice, that line might be a Text object (i.e. non-string),
  3412      "/ so you may want to use line string.
  3446      "/ so you may want to use ''line string''.
  3413      "/ 
  3447      "/ 
  3414      "/ Useful queries on the line are:
  3448      "/ Useful queries on the line are:
  3415      "/     - size                   the length of the line
  3449      "/     - size                   the length of the line
  3416      "/     - hasChangeOfEmphasis    any bold, italic etc.
  3450      "/     - hasChangeOfEmphasis    any bold, italic etc.
  3417      "/     - startsWith:someString
  3451      "/     - startsWith:someString
  3418      "/     - endsWith:someString
  3452      "/     - endsWith:someString
  3419 
  3453      "/     - includesString:someString
  3420      "/ example filter (removes all empty lines)
  3454      "/     - pattern match: 
       
  3455 
       
  3456      "/ example filters
       
  3457      "/
       
  3458      "/ -------- removes all empty lines ---------------
  3421      "/
  3459      "/
  3422      "/ line size > 0
  3460      "/ line size > 0
  3423 
  3461 
  3424      "/ example filter (removes all lines which do not end with some suffix)
  3462      "/ -------- removes all lines which do not end with some suffix ----------
  3425      "/
  3463      "/
  3426      "/ (line asLowercase endsWith:''foo'') not
  3464      "/ (line asLowercase endsWith:''foo'') not
       
  3465 
       
  3466      "/ -------- removes duplicates ----------
       
  3467      "/
       
  3468      "/ (line = nextLine) not
  3427 
  3469 
  3428      "/ dummy filter (keeps all lines)
  3470      "/ dummy filter (keeps all lines)
  3429      "/
  3471      "/
  3430      true
  3472      true
  3431 ]
  3473 ]
  3432 '.
  3474 '.
  3433 
  3475 
  3434     filterBlock := self askForFilterBlock:'Filter block:'
  3476     filterBlock := self askForFilterBlock:'Filter block (to remove lines):'
  3435                         template:template
  3477                         template:template
  3436                         rememberIn:#LastFilterBlockString.
  3478                         rememberIn:#LastFilterBlockString.
  3437     filterBlock isNil ifTrue:[^ self].
  3479     filterBlock isNil ifTrue:[^ self].
  3438 
  3480 
  3439     oldList := self selectedWorkspacesTextView list.
  3481     oldList := self selectedWorkspacesTextView list.
  3440     oldList := oldList collect:[:lineOrNil | lineOrNil ? ''].
  3482     newList := StringCollection new.
  3441     newList := oldList select:filterBlock.
  3483     deletedLines := OrderedCollection new.
  3442     newList := newList collect:[:line | (line isString and:[line size == 0]) ifTrue:[nil] ifFalse:[line]].
  3484 
  3443     nDeleted := oldList size - newList size.
  3485     oldList notEmptyOrNil ifTrue:[
       
  3486         line := nil.
       
  3487         nextLine := oldList at: 1.
       
  3488         1 to: oldList size do:[:lineNr |
       
  3489             prevLine := line.
       
  3490             line := nextLine.
       
  3491             nextLine := oldList at: lineNr + 1 ifAbsent: nil.
       
  3492 
       
  3493             (filterBlock 
       
  3494                 value:(line ? '') 
       
  3495                 value: lineNr 
       
  3496                 value: (prevLine ? '')  
       
  3497                 value: (nextLine ? '') 
       
  3498             ) ifTrue: [
       
  3499                 newList add: line
       
  3500             ] ifFalse:[
       
  3501                 deletedLines add: line.
       
  3502             ]
       
  3503         ].
       
  3504 
       
  3505         newList := newList collect:[:line | (line isString and:[line size == 0]) ifTrue:[nil] ifFalse:[line]].
       
  3506     ].
       
  3507 
       
  3508     nDeleted := deletedLines size.
  3444     nDeleted == 0 ifTrue:[
  3509     nDeleted == 0 ifTrue:[
  3445         self information:'No lines were deleted.'.
  3510         self information:'No lines were deleted.'.
  3446         ^ self
  3511         ^ self
  3447     ].
  3512     ].
  3448 
  3513 
  3449     answer := Dialog confirmWithCancel:(resources 
  3514     answer := OptionBox 
       
  3515                 request:(resources 
  3450                         string:'%1 lines remain (%2 deleted). Change text ?'
  3516                         string:'%1 lines remain (%2 deleted). Change text ?'
  3451                         with:newList size
  3517                         with:newList size
  3452                         with:nDeleted)
  3518                         with:nDeleted)
  3453                 labels:#( 'Cancel' 'No, Show Deleted' 'Yes').
  3519                 buttonLabels:#( 'Cancel' 'No, Show Deleted' 'Yes, but Show Deleted' 'Yes')
       
  3520                 values:#(nil false yesAndShow true)
       
  3521                 default:true.
  3454     answer isNil ifTrue:[^ self].
  3522     answer isNil ifTrue:[^ self].
  3455     answer ifFalse:[
  3523     (answer ~~ true) ifTrue:[
  3456         deletedLines := oldList reject:filterBlock.
       
  3457         TextBox openOn:(deletedLines asStringCollection) title:'Filtered lines'.
  3524         TextBox openOn:(deletedLines asStringCollection) title:'Filtered lines'.
  3458         ^ self.
  3525         (answer == false) ifTrue:[
       
  3526             ^ self.
       
  3527         ].
  3459     ].
  3528     ].
  3460 
  3529 
  3461     self selectedWorkspacesTextView list:newList.
  3530     self selectedWorkspacesTextView list:newList.
       
  3531 
       
  3532     "Modified: / 04-05-2012 / 16:03:32 / cg"
  3462 !
  3533 !
  3463 
  3534 
  3464 googleSpellingSuggestion
  3535 googleSpellingSuggestion
  3465     self selectedWorkspacesTextView googleSpellingSuggestion
  3536     self selectedWorkspacesTextView googleSpellingSuggestion
  3466 !
  3537 !
  3871 ! !
  3942 ! !
  3872 
  3943 
  3873 !WorkspaceApplication class methodsFor:'documentation'!
  3944 !WorkspaceApplication class methodsFor:'documentation'!
  3874 
  3945 
  3875 version
  3946 version
  3876     ^ '$Header: /cvs/stx/stx/libtool/WorkspaceApplication.st,v 1.219 2012-04-26 12:15:48 cg Exp $'
  3947     ^ '$Header: /cvs/stx/stx/libtool/WorkspaceApplication.st,v 1.220 2012-05-04 14:04:21 cg Exp $'
  3877 !
  3948 !
  3878 
  3949 
  3879 version_CVS
  3950 version_CVS
  3880     ^ '$Header: /cvs/stx/stx/libtool/WorkspaceApplication.st,v 1.219 2012-04-26 12:15:48 cg Exp $'
  3951     ^ '$Header: /cvs/stx/stx/libtool/WorkspaceApplication.st,v 1.220 2012-05-04 14:04:21 cg Exp $'
  3881 !
  3952 !
  3882 
  3953 
  3883 version_SVN
  3954 version_SVN
  3884     ^ '§Id: WorkspaceApplication.st 7812 2011-08-17 08:55:59Z vranyj1 §'
  3955     ^ '§Id: WorkspaceApplication.st 7812 2011-08-17 08:55:59Z vranyj1 §'
  3885 ! !
  3956 ! !