Tools__InternationalLanguageTranslationEditor.st
changeset 3286 1ea9a6fbe2b4
parent 3285 5b8697869e72
child 3312 84084dd13f11
equal deleted inserted replaced
3285:5b8697869e72 3286:1ea9a6fbe2b4
    18 		searchForSimilarTranslationEnableHolder alwaysWriteUTF8Holder
    18 		searchForSimilarTranslationEnableHolder alwaysWriteUTF8Holder
    19 		lastNameSpace pasteOriginalEnableHolder ignoreCaseHolder
    19 		lastNameSpace pasteOriginalEnableHolder ignoreCaseHolder
    20 		closeSearchBar searchTextModifiedHolder searchNextText
    20 		closeSearchBar searchTextModifiedHolder searchNextText
    21 		searchBarImageInfoLabelHolder searchPreviousText searchBoxVisible
    21 		searchBarImageInfoLabelHolder searchPreviousText searchBoxVisible
    22 		searchBarInfoLabelHolder searchTextHolder searchTextView
    22 		searchBarInfoLabelHolder searchTextHolder searchTextView
    23 		searchBoxView translationsPanel lastPackage'
    23 		searchBoxView translationsPanel lastPackage methodsUsingKey'
    24 	classVariableNames:'LastExtractedClass LastExtractedApplicationClass
    24 	classVariableNames:'LastExtractedClass LastExtractedApplicationClass
    25 		LastExtractedProject LastProject'
    25 		LastExtractedProject LastProject'
    26 	poolDictionaries:''
    26 	poolDictionaries:''
    27 	category:'Interface-UIPainter'
    27 	category:'Interface-UIPainter'
    28 !
    28 !
    29 
    29 
    30 Object subclass:#AccessCollectingPseudoResourcePack
    30 Object subclass:#AccessCollectingPseudoResourcePack
    31 	instanceVariableNames:'collectedKeys realResourcePack'
    31 	instanceVariableNames:'collectedKeys realResourcePack watchingTranslationEditor'
    32 	classVariableNames:''
    32 	classVariableNames:''
    33 	poolDictionaries:''
    33 	poolDictionaries:''
    34 	privateIn:InternationalLanguageTranslationEditor
    34 	privateIn:InternationalLanguageTranslationEditor
    35 !
    35 !
    36 
    36 
    90 "
    90 "
    91 !
    91 !
    92 
    92 
    93 history
    93 history
    94     "Created: / 04-03-2006 / 09:07:19 / cg"
    94     "Created: / 04-03-2006 / 09:07:19 / cg"
       
    95 ! !
       
    96 
       
    97 !InternationalLanguageTranslationEditor class methodsFor:'help spec'!
       
    98 
       
    99 flyByHelpSpec
       
   100     <resource: #help>
       
   101 
       
   102     ^ super flyByHelpSpec addPairsFrom:#(
       
   103 
       
   104 #searchBox
       
   105 'Show a search box at the bottom to search for substrings in the string keys'
       
   106 
       
   107 #browseReferringMethods
       
   108 'Browse methods which refer to this string'
       
   109 
       
   110 )
       
   111 ! !
       
   112 
       
   113 !InternationalLanguageTranslationEditor class methodsFor:'help specs'!
       
   114 
       
   115 helpSpec
       
   116     "This resource specification was automatically generated
       
   117      by the UIHelpTool of ST/X."
       
   118 
       
   119     "Do not manually edit this!! If it is corrupted,
       
   120      the UIHelpTool may not be able to read the specification."
       
   121 
       
   122     "
       
   123      UIHelpTool openOnClass:Tools::InternationalLanguageTranslationEditor    
       
   124     "
       
   125 
       
   126     <resource: #help>
       
   127 
       
   128     ^ super helpSpec addPairsFrom:#(
       
   129 
       
   130 #searchBox
       
   131 ''
       
   132 
       
   133 )
    95 ! !
   134 ! !
    96 
   135 
    97 !InternationalLanguageTranslationEditor class methodsFor:'image specs'!
   136 !InternationalLanguageTranslationEditor class methodsFor:'image specs'!
    98 
   137 
    99 closeSearchBarIcon
   138 closeSearchBarIcon
   450                          )
   489                          )
   451                        )
   490                        )
   452                       )
   491                       )
   453                     
   492                     
   454                    )
   493                    )
   455                    handles: (Any 0.33333333333333004 0.66666666666667007 1.0)
   494                    handles: (Any 0.3333333333333301 0.66666666666667018 1.0)
   456                  )
   495                  )
   457                 )
   496                 )
   458               
   497               
   459              )
   498              )
   460              handles: (Any 0.5 1.0)
   499              handles: (Any 0.5 1.0)
   477                    model: closeSearchBar
   516                    model: closeSearchBar
   478                  )
   517                  )
   479                 (LabelSpec
   518                 (LabelSpec
   480                    label: 'Search:'
   519                    label: 'Search:'
   481                    name: 'SearchLabel'
   520                    name: 'SearchLabel'
   482                    layout: (LayoutFrame 30 0 5 0 81 0 27 0)
   521                    layout: (LayoutFrame 30 0 5 0 100 0 27 0)
   483                    translateLabel: true
   522                    translateLabel: true
   484                    adjust: right
   523                    adjust: right
   485                  )
   524                  )
   486                 (InputFieldSpec
   525                 (InputFieldSpec
   487                    name: 'SearchEntryField'
   526                    name: 'SearchEntryField'
   488                    layout: (LayoutFrame 87 0 5 0 244 0 27 0)
   527                    layout: (LayoutFrame 100 0 5 0 257 0 27 0)
   489                    model: searchTextHolder
   528                    model: searchTextHolder
   490                    immediateAccept: true
   529                    immediateAccept: true
   491                    acceptOnReturn: true
   530                    acceptOnReturn: true
   492                    acceptOnTab: true
   531                    acceptOnTab: true
   493                    acceptOnLostFocus: true
   532                    acceptOnLostFocus: true
   496                    postBuildCallback: postBuildSearchTextView:
   535                    postBuildCallback: postBuildSearchTextView:
   497                  )
   536                  )
   498                 (ActionButtonSpec
   537                 (ActionButtonSpec
   499                    label: 'searchNextIcon'
   538                    label: 'searchNextIcon'
   500                    name: 'SearchNextButton'
   539                    name: 'SearchNextButton'
   501                    layout: (LayoutFrame 251 0 5 0 272 0 26 0)
   540                    layout: (LayoutFrame 264 0 5 0 285 0 26 0)
   502                    hasCharacterOrientedLabel: false
   541                    hasCharacterOrientedLabel: false
   503                    translateLabel: true
   542                    translateLabel: true
   504                    model: searchNextText
   543                    model: searchNextText
   505                  )
   544                  )
   506                 (ActionButtonSpec
   545                 (ActionButtonSpec
   507                    label: 'searchPreviousIcon'
   546                    label: 'searchPreviousIcon'
   508                    name: 'searchPreviousButton'
   547                    name: 'searchPreviousButton'
   509                    layout: (LayoutFrame 279 0 5 0 300 0 26 0)
   548                    layout: (LayoutFrame 292 0 5 0 313 0 26 0)
   510                    hasCharacterOrientedLabel: false
   549                    hasCharacterOrientedLabel: false
   511                    translateLabel: true
   550                    translateLabel: true
   512                    model: searchPreviousText
   551                    model: searchPreviousText
   513                  )
   552                  )
   514                 (CheckBoxSpec
   553                 (CheckBoxSpec
   515                    label: 'Ignore case'
   554                    label: 'Ignore case'
   516                    name: 'IgnoreCaseCheckBox'
   555                    name: 'IgnoreCaseCheckBox'
   517                    layout: (LayoutFrame 309 0 5 0 505 0 27 0)
   556                    layout: (LayoutFrame 322 0 5 0 518 0 27 0)
   518                    model: ignoreCaseHolder
   557                    model: ignoreCaseHolder
   519                    translateLabel: true
   558                    translateLabel: true
   520                  )
   559                  )
   521                 (LabelSpec
   560                 (LabelSpec
   522                    label: 'SearchBarImageInfoLabel'
   561                    label: 'SearchBarImageInfoLabel'
   523                    name: 'SearchBarImageInfoLabel'
   562                    name: 'SearchBarImageInfoLabel'
   524                    layout: (LayoutFrame 511 0 5 0 535 0 27 0)
   563                    layout: (LayoutFrame 524 0 5 0 548 0 27 0)
   525                    hasCharacterOrientedLabel: false
   564                    hasCharacterOrientedLabel: false
   526                    translateLabel: true
   565                    translateLabel: true
   527                    labelChannel: searchBarImageInfoLabelHolder
   566                    labelChannel: searchBarImageInfoLabelHolder
   528                  )
   567                  )
   529                 (LabelSpec
   568                 (LabelSpec
   530                    label: 'SearchBarInfoLabel'
   569                    label: 'SearchBarInfoLabel'
   531                    name: 'SearchBarInfoLabel'
   570                    name: 'SearchBarInfoLabel'
   532                    layout: (LayoutFrame 538 0 5 0 816 0 27 0)
   571                    layout: (LayoutFrame 551 0 5 0 829 0 27 0)
   533                    translateLabel: true
   572                    translateLabel: true
   534                    labelChannel: searchBarInfoLabelHolder
   573                    labelChannel: searchBarInfoLabelHolder
   535                    adjust: left
   574                    adjust: left
   536                  )
   575                  )
   537                 )
   576                 )
   561 
   600 
   562     <resource: #menu>
   601     <resource: #menu>
   563 
   602 
   564     ^
   603     ^
   565      #(Menu
   604      #(Menu
   566 	(
   605         (
   567 	 (MenuItem
   606          (MenuItem
   568 	    label: 'Set Current NameSpace'
   607             label: 'Browse Methods Containing this String'
   569 	    itemValue: changeLastNameSpace
   608             itemValue: browseReferringMethods
   570 	    translateLabel: true
   609             translateLabel: true
   571 	  )
   610           )
   572 	 (MenuItem
   611          (MenuItem
   573 	    label: 'Search String in Current NameSpace'
   612             label: '-'
   574 	    itemValue: searchStringInLastNameSpace
   613             isVisible: #false
   575 	    translateLabel: true
   614           )
   576 	  )
   615          (MenuItem
   577 	 (MenuItem
   616             label: 'Set Current NameSpace...'
   578 	    label: '-'
   617             itemValue: changeLastNameSpace
   579 	    isVisible: #false
   618             translateLabel: true
   580 	  )
   619           )
   581 	 (MenuItem
   620          (MenuItem
   582 	    label: 'Set Current Package'
   621             label: 'Search String in Current NameSpace'
   583 	    itemValue: changeLastPackage
   622             itemValue: searchStringInLastNameSpace
   584 	    translateLabel: true
   623             translateLabel: true
   585 	    isVisible: #false
   624           )
   586 	  )
   625          (MenuItem
   587 	 (MenuItem
   626             label: '-'
   588 	    label: 'Search String in Current Package'
   627             isVisible: #false
   589 	    itemValue: searchStringInLastPackage
   628           )
   590 	    translateLabel: true
   629          (MenuItem
   591 	    isVisible: #false
   630             label: 'Set Current Package...'
   592 	  )
   631             itemValue: changeLastPackage
   593 	 )
   632             translateLabel: true
   594 	nil
   633             isVisible: #false
   595 	nil
   634           )
       
   635          (MenuItem
       
   636             label: 'Search String in Current Package'
       
   637             itemValue: searchStringInLastPackage
       
   638             translateLabel: true
       
   639             isVisible: #false
       
   640           )
       
   641          )
       
   642         nil
       
   643         nil
   596       )
   644       )
   597 !
   645 !
   598 
   646 
   599 mainMenu
   647 mainMenu
   600     "This resource specification was automatically generated
   648     "This resource specification was automatically generated
   686            (Menu
   734            (Menu
   687               (
   735               (
   688                (MenuItem
   736                (MenuItem
   689                   label: 'Show Missing Translations Only'
   737                   label: 'Show Missing Translations Only'
   690                   indication: showMissingTranslationsOnly
   738                   indication: showMissingTranslationsOnly
       
   739                 )
       
   740                (MenuItem
       
   741                   label: 'Show Search Box'
       
   742                   indication: searchBoxVisible
   691                 )
   743                 )
   692                (MenuItem
   744                (MenuItem
   693                   label: '-'
   745                   label: '-'
   694                 )
   746                 )
   695                (MenuItem
   747                (MenuItem
   822      #(Menu
   874      #(Menu
   823         (
   875         (
   824          (MenuItem
   876          (MenuItem
   825             label: 'Save'
   877             label: 'Save'
   826             itemValue: menuSave
   878             itemValue: menuSave
   827             translateLabel: true
       
   828             isButton: true
   879             isButton: true
   829             labelImage: (ResourceRetriever XPToolbarIconLibrary saveImageIcon)
   880             labelImage: (ResourceRetriever XPToolbarIconLibrary saveImageIcon)
   830           )
   881           )
   831          (MenuItem
   882          (MenuItem
   832             label: '-'
   883             label: '-'
   833           )
   884           )
   834          (MenuItem
   885          (MenuItem
   835             label: 'Add Translation'
   886             label: 'Add Translation'
   836             itemValue: addTranslation
   887             itemValue: addTranslation
   837             translateLabel: true
       
   838             isButton: true
   888             isButton: true
   839             labelImage: (ResourceRetriever XPToolbarIconLibrary newRowIcon)
   889             labelImage: (ResourceRetriever XPToolbarIconLibrary newRowIcon)
   840           )
   890           )
   841          (MenuItem
   891          (MenuItem
   842             label: 'Remove Translation'
   892             label: 'Remove Translation'
   843             itemValue: removeTranslation
   893             itemValue: removeTranslation
   844             translateLabel: true
       
   845             isButton: true
   894             isButton: true
   846             labelImage: (ResourceRetriever XPToolbarIconLibrary removeRowIcon)
   895             labelImage: (ResourceRetriever XPToolbarIconLibrary removeRowIcon)
   847           )
   896           )
   848          (MenuItem
   897          (MenuItem
   849             label: '-'
   898             label: '-'
   850           )
   899           )
   851          (MenuItem
   900          (MenuItem
   852             label: 'Search'
   901             activeHelpKey: browseReferringMethods
   853             itemValue: search
   902             label: 'Browse'
   854             translateLabel: true
   903             itemValue: browseReferringMethods
   855             isButton: true
   904             labelImage: (ResourceRetriever ToolbarIconLibrary systemBrowserIcon)
   856             shortcutKey: Ctrlf
       
   857             labelImage: (ResourceRetriever #'Tools::InternationalLanguageTranslationEditor' searchToolBarIcon)
       
   858           )
   905           )
   859          (MenuItem
   906          (MenuItem
   860             label: ''
   907             label: ''
   861           )
   908           )
   862          (MenuItem
   909          (MenuItem
   863             label: 'Stop Application'
   910             label: 'Stop Application'
   864             itemValue: stopApplication
   911             itemValue: stopApplication
   865             translateLabel: true
       
   866             isButton: true
   912             isButton: true
   867             isVisible: stopApplicationIconVisibleHolder
   913             isVisible: stopApplicationIconVisibleHolder
   868             labelImage: (ResourceRetriever XPToolbarIconLibrary stop16x16Icon)
   914             labelImage: (ResourceRetriever XPToolbarIconLibrary stop16x16Icon)
       
   915           )
       
   916          (MenuItem
       
   917             activeHelpKey: searchBox
       
   918             label: 'Search'
       
   919             isButton: true
       
   920             startGroup: right
       
   921             hideMenuOnActivated: false
       
   922             indication: searchBoxVisible
       
   923             shortcutKey: Ctrlf
       
   924             labelImage: (ResourceRetriever #'Tools::InternationalLanguageTranslationEditor' searchToolBarIcon)
   869           )
   925           )
   870          )
   926          )
   871         nil
   927         nil
   872         nil
   928         nil
   873       )
   929       )
   901           )
   957           )
   902          (MenuItem
   958          (MenuItem
   903             label: '-'
   959             label: '-'
   904           )
   960           )
   905          (MenuItem
   961          (MenuItem
       
   962             label: 'Extract from Package...'
       
   963             itemValue: extractTranslationsFromProject
       
   964           )
       
   965          (MenuItem
   906             label: 'Extract from Class...'
   966             label: 'Extract from Class...'
   907             itemValue: extractTranslationsFromClass
   967             itemValue: extractTranslationsFromClass
   908           )
       
   909          (MenuItem
       
   910             label: 'Extract from Project...'
       
   911             itemValue: extractTranslationsFromProject
       
   912           )
   968           )
   913          (MenuItem
   969          (MenuItem
   914             label: 'Extract from NameSpace...'
   970             label: 'Extract from NameSpace...'
   915             itemValue: extractTranslationsFromNameSpace
   971             itemValue: extractTranslationsFromNameSpace
   916           )
   972           )
  1263 !
  1319 !
  1264 
  1320 
  1265 searchBoxVisible
  1321 searchBoxVisible
  1266 
  1322 
  1267     searchBoxVisible isNil ifTrue:[
  1323     searchBoxVisible isNil ifTrue:[
  1268 	searchBoxVisible := false asValue.
  1324         searchBoxVisible := false asValue.
       
  1325         searchBoxVisible 
       
  1326             onChangeEvaluate:[ 
       
  1327                 self updateToolVisibility.
       
  1328                 searchBoxVisible value ifTrue:[
       
  1329                     searchTextView takeFocus.
       
  1330                 ].
       
  1331             ].
  1269     ].
  1332     ].
  1270     ^ searchBoxVisible.
  1333     ^ searchBoxVisible.
  1271 
  1334 
  1272     "Created: / 15-06-2007 / 18:15:52 / Administrador"
  1335     "Created: / 15-06-2007 / 18:15:52 / Administrador"
  1273 !
  1336 !
  1551 !
  1614 !
  1552 
  1615 
  1553 initialize
  1616 initialize
  1554     modified := false.
  1617     modified := false.
  1555     inSingleFileMode := false.
  1618     inSingleFileMode := false.
       
  1619     methodsUsingKey := Dictionary new.
  1556     super initialize
  1620     super initialize
  1557 !
  1621 !
  1558 
  1622 
  1559 languageEditorBuilt:aView
  1623 languageEditorBuilt:aView
  1560     languageEditor := aView.
  1624     languageEditor := aView.
  1623 	keyStringsToLanguageMappings addKey:key.
  1687 	keyStringsToLanguageMappings addKey:key.
  1624 	modified := true.
  1688 	modified := true.
  1625     ].
  1689     ].
  1626    index := keyStringsToLanguageMappings indexOfKey:key.
  1690    index := keyStringsToLanguageMappings indexOfKey:key.
  1627    self selectedKeyRow value:index
  1691    self selectedKeyRow value:index
       
  1692 !
       
  1693 
       
  1694 browseReferringMethods
       
  1695     |selectedKey methods browser|
       
  1696 
       
  1697     selectedKey := self selectedKey.
       
  1698     selectedKey isNil ifTrue:[^ Dialog information: 'No selected key'].
       
  1699 
       
  1700     methods := methodsUsingKey at:selectedKey ifAbsent:nil.
       
  1701     methods isEmptyOrNil ifTrue:[
       
  1702         Dialog information:(resources stringWithCRs:'oops - no method remembered.\Please rerun the extract from XXX menu operation').
       
  1703         ^ self.
       
  1704     ].    
       
  1705     browser := UserPreferences systemBrowserClass browseMethods:methods.
       
  1706     browser autoSearch:selectedKey ignoreCase:true.
  1628 !
  1707 !
  1629 
  1708 
  1630 changeLastNameSpace
  1709 changeLastNameSpace
  1631 
  1710 
  1632     |nameSpace defaultNameSpace|
  1711     |nameSpace defaultNameSpace|
  1937 
  2016 
  1938 runApplicationAndCollectTranslations
  2017 runApplicationAndCollectTranslations
  1939     |applicationClass newTranslations pseudoPack app startSelector|
  2018     |applicationClass newTranslations pseudoPack app startSelector|
  1940 
  2019 
  1941     monitoredApplication notNil ifTrue:[
  2020     monitoredApplication notNil ifTrue:[
  1942 	monitoredApplication terminate.
  2021         monitoredApplication terminate.
  1943 	[monitoredApplication notNil] whileTrue:[
  2022         [monitoredApplication notNil] whileTrue:[
  1944 	    Delay waitForSeconds:0.1
  2023             Delay waitForSeconds:0.1
  1945 	].
  2024         ].
  1946     ].
  2025     ].
  1947 
  2026 
  1948     applicationClass := Dialog
  2027     applicationClass := Dialog
  1949 		requestClass:'Application class to start and collect translations from:'
  2028                 requestClass:'Application class to start and collect translations from:'
  1950 		okLabel:'OK'
  2029                 okLabel:'OK'
  1951 		initialAnswer:(lastExtractedApplicationClass ? LastExtractedApplicationClass ).
  2030                 initialAnswer:(lastExtractedApplicationClass ? LastExtractedApplicationClass ).
  1952     applicationClass isNil ifTrue:[^ self ].
  2031     applicationClass isNil ifTrue:[^ self ].
  1953     applicationClass isNamespace ifTrue:[
  2032     applicationClass isNameSpace ifTrue:[
  1954 	Dialog warn:'Entered class is a NameSpace'.
  2033         Dialog warn:'Entered class is a NameSpace'.
  1955 	^ self.
  2034         ^ self.
  1956     ].
  2035     ].
  1957 
  2036 
  1958     applicationClass isVisualStartable ifTrue:[
  2037     applicationClass isVisualStartable ifTrue:[
  1959 	startSelector := #open
  2038         startSelector := #open
  1960     ] ifFalse:[
  2039     ] ifFalse:[
  1961 	startSelector := Dialog
  2040         startSelector := Dialog
  1962 		    request:'Entered class seems to be no application class. Ok to start using selector:'
  2041                     request:'Entered class seems to be no application class. Ok to start using selector:'
  1963 		    initialAnswer:((applicationClass respondsTo:#'start')
  2042                     initialAnswer:((applicationClass respondsTo:#'start')
  1964 					ifTrue:#'start'
  2043                                         ifTrue:#'start'
  1965 					ifFalse:#'new')
  2044                                         ifFalse:#'new')
  1966 		    okLabel:'START'
  2045                     okLabel:'START'
  1967 		    title:'Start Application'.
  2046                     title:'Start Application'.
  1968 	startSelector isNil ifTrue:[
  2047         startSelector isNil ifTrue:[
  1969 	    ^ self
  2048             ^ self
  1970 	].
  2049         ].
  1971 	startSelector := startSelector asSymbol.
  2050         startSelector := startSelector asSymbol.
  1972     ].
  2051     ].
  1973 
  2052 
  1974     lastExtractedApplicationClass := LastExtractedApplicationClass := applicationClass.
  2053     lastExtractedApplicationClass := LastExtractedApplicationClass := applicationClass.
  1975 
  2054 
  1976     newTranslations := Set new.
  2055     newTranslations := Set new.
  1977 
  2056 
  1978     pseudoPack := AccessCollectingPseudoResourcePack new.
  2057     pseudoPack := AccessCollectingPseudoResourcePack new.
  1979     pseudoPack realResourcePack:(applicationClass classResources).
  2058     pseudoPack realResourcePack:(applicationClass classResources).
       
  2059     pseudoPack watchingTranslationEditor:self.
  1980 
  2060 
  1981     self stopApplicationIconVisibleHolder value:true.
  2061     self stopApplicationIconVisibleHolder value:true.
  1982 
  2062 
  1983     monitoredApplication := [
  2063     monitoredApplication := 
  1984 	[
  2064         [
  1985 	    app := applicationClass new.
  2065             [
  1986 	    app perform:startSelector.
  2066                 app := applicationClass new.
  1987 	    app window waitUntilVisible.
  2067                 app resources:pseudoPack.
  1988 	    app window waitUntilClosed.
  2068                 
  1989 	] ensure:[
  2069                 app perform:startSelector.
  1990 	    app closeRequest.
  2070                 app window waitUntilVisible.
  1991 	    self stopApplicationIconVisibleHolder value:false.
  2071                 app window waitUntilClosed.
  1992 	    monitoredApplication := nil.
  2072             ] ensure:[
  1993 	].
  2073                 app closeRequest.
  1994     ] fork.
  2074                 self stopApplicationIconVisibleHolder value:false.
       
  2075                 monitoredApplication := nil.
       
  2076             ].
       
  2077         ] fork.
  1995 !
  2078 !
  1996 
  2079 
  1997 searchStringInLastNameSpace
  2080 searchStringInLastNameSpace
  1998 
  2081 
  1999     |selectedKey browser lastSearchPatterns|
  2082     |selectedKey browser lastSearchPatterns|
  2023 searchStringInLastPackage
  2106 searchStringInLastPackage
  2024 
  2107 
  2025     | selectedKey browser lastSearchPatterns|
  2108     | selectedKey browser lastSearchPatterns|
  2026 
  2109 
  2027     selectedKey := self selectedKey.
  2110     selectedKey := self selectedKey.
  2028     selectedKey isNil ifTrue:[^Dialog information: 'No selected key'].
  2111     selectedKey isNil ifTrue:[^ Dialog information: 'No selected key'].
       
  2112 
  2029     browser := NewSystemBrowser new "open".
  2113     browser := NewSystemBrowser new "open".
  2030     browser allButOpen.
  2114     browser allButOpen.
       
  2115     
  2031     lastSearchPatterns := browser lastSearchPatterns.
  2116     lastSearchPatterns := browser lastSearchPatterns.
  2032     (lastSearchPatterns notNil and:[lastSearchPatterns first ~= selectedKey]) ifTrue:[
  2117     (lastSearchPatterns notNil and:[lastSearchPatterns first ~= selectedKey]) ifTrue:[
  2033 	browser lastSearchPatterns addFirst: selectedKey
  2118         browser lastSearchPatterns addFirst: selectedKey
  2034     ].
  2119     ].
  2035     SearchDialog lastStringSearchArea: #currentPackage.
  2120     SearchDialog lastStringSearchArea: #currentPackage.
  2036     lastPackage isNil ifTrue:[
  2121     lastPackage isNil ifTrue:[
  2037 	self changeLastPackage.
  2122         self changeLastPackage.
  2038     ].
  2123     ].
  2039     lastPackage notNil ifTrue:[
  2124     lastPackage notNil ifTrue:[
  2040 "/        browser navigationState selectedClasses value: lastNameSpace allClasses.
  2125 "/        browser navigationState selectedClasses value: lastNameSpace allClasses.
  2041 	browser navigationState packageFilter value: (OrderedCollection with:lastPackage).
  2126         browser navigationState packageFilter value: (OrderedCollection with:lastPackage).
  2042 	browser navigationState selectedProjects value: (OrderedCollection with:lastPackage).
  2127         browser navigationState selectedProjects value: (OrderedCollection with:lastPackage).
  2043     ].
  2128     ].
  2044     self withWaitCursorDo:[
  2129     self withWaitCursorDo:[
  2045 	browser browseMenuMethodsWithString
  2130         browser 
       
  2131             askForMethodAndSpawnSearchTitle:'String to Search for in Sources:'
       
  2132             browserLabel:'Methods containing "%1"'
       
  2133             searchWith:#( #'findString:in:ignoreCase:match:' #'findString:inMethods:ignoreCase:match:' )
       
  2134             searchWhat:#string
       
  2135             searchArea:#currentPackage
       
  2136             withCaseIgnore:false
       
  2137             withTextEntry:false
       
  2138             withMatch:true
       
  2139             withMethodList:false
       
  2140             setSearchPattern:[:brwsr :string :ignoreCase :doMatch|
       
  2141                                 brwsr autoSearchPattern:string ignoreCase:ignoreCase.
       
  2142                              ]
       
  2143             initialText:selectedKey "/ does not work: ('''*',selectedKey,'*''') check match!!               
  2046     ].
  2144     ].
  2047 ! !
  2145 ! !
  2048 
  2146 
  2049 !InternationalLanguageTranslationEditor methodsFor:'menus dynamic'!
  2147 !InternationalLanguageTranslationEditor methodsFor:'menus dynamic'!
  2050 
  2148 
  2114 ! !
  2212 ! !
  2115 
  2213 
  2116 !InternationalLanguageTranslationEditor methodsFor:'private-key extraction'!
  2214 !InternationalLanguageTranslationEditor methodsFor:'private-key extraction'!
  2117 
  2215 
  2118 addAllTranslations:newTranslations
  2216 addAllTranslations:newTranslations
       
  2217     "merge found xlations into the list of already present xlations"
       
  2218     
  2119     |newTranslationKeys stringKeys nonStringKeys|
  2219     |newTranslationKeys stringKeys nonStringKeys|
  2120 
  2220 
  2121     newTranslationKeys := newTranslations select:[:k | k notEmptyOrNil and:[k isString not or:[k isBlank not]]].
  2221     newTranslationKeys := newTranslations select:[:k | k notEmptyOrNil and:[k isString not or:[k isBlank not]]].
  2122     newTranslationKeys := newTranslationKeys select:[:k | (keyStringsToLanguageMappings includesKey:k) not].
  2222     newTranslationKeys := newTranslationKeys select:[:k | (keyStringsToLanguageMappings includesKey:k) not].
  2123     newTranslationKeys := newTranslationKeys
  2223     "/ follow the common-xlations algrithm of ResourcePack
  2124                                 collect:[:k |
  2224     "/ (which knows how to xlate strings with additional special chars.)
  2125                                         (k endsWith:' ...') ifTrue:[
  2225     newTranslationKeys := 
  2126                                             k copyButLast:4.
  2226         newTranslationKeys collect:[:oldKey |
  2127                                         ] ifFalse:[(k endsWith:'...') ifTrue:[
  2227             |newKey methods|
  2128                                             k copyButLast:3.
  2228             
  2129                                         ] ifFalse:[
  2229             (oldKey endsWith:' ...') ifTrue:[
  2130                                             ('\.:?=,!! ' includes:k last) ifTrue:[
  2230                 newKey := oldKey copyButLast:4.
  2131                                                 k copyButLast:1.
  2231             ] ifFalse:[ (oldKey endsWith:'...') ifTrue:[
  2132                                             ] ifFalse:[
  2232                 newKey := oldKey copyButLast:3.
  2133                                                 k
  2233             ] ifFalse:[ ('\.:?=,!! ' includes:oldKey last) ifTrue:[
  2134                                         ]]]].
  2234                 newKey := oldKey copyButLast:1.
       
  2235             ] ifFalse:[ ((oldKey first == $() and:[ oldKey last == $) ]) ifTrue:[
       
  2236                 newKey := oldKey copyFrom:2 to:oldKey size - 1
       
  2237             ] ifFalse:[ ((oldKey first == $[) and:[ oldKey last == $] ]) ifTrue:[
       
  2238                 newKey := oldKey copyFrom:2 to:oldKey size - 1
       
  2239             ] ifFalse:[
       
  2240                 newKey :=oldKey
       
  2241             ]]]]].
       
  2242             "/ must attach oldKey-methods to newKey
       
  2243             methods := methodsUsingKey at:oldKey ifAbsent:nil.
       
  2244             methods notNil ifTrue:[
       
  2245                 (methodsUsingKey at:newKey ifAbsentPut:[Set new]) addAll:methods
       
  2246             ].    
       
  2247             newKey
       
  2248         ].
       
  2249         
  2135     newTranslationKeys := newTranslationKeys asSet.
  2250     newTranslationKeys := newTranslationKeys asSet.
  2136     newTranslationKeys := newTranslationKeys select:[:k | (keyStringsToLanguageMappings includesKey:k) not].
  2251     newTranslationKeys := newTranslationKeys select:[:k | (keyStringsToLanguageMappings includesKey:k) not].
  2137 
  2252 
  2138     newTranslationKeys notEmpty ifTrue:[
  2253     newTranslationKeys notEmpty ifTrue:[
  2139         stringKeys := newTranslationKeys select:[:k | k isString].
  2254         stringKeys := newTranslationKeys select:[:k | k isString].
  2157         "/ and all arguments to (resources string:) messages.
  2272         "/ and all arguments to (resources string:) messages.
  2158         aClass instAndClassMethodsDo:[:eachMethod |
  2273         aClass instAndClassMethodsDo:[:eachMethod |
  2159             newTranslations addAll:( self extractTranslationsFromMethod:eachMethod ).
  2274             newTranslations addAll:( self extractTranslationsFromMethod:eachMethod ).
  2160         ].
  2275         ].
  2161     ].
  2276     ].
  2162     newTranslations := newTranslations select:[:eachTranslation|
  2277     
  2163         (aClass resources at:eachTranslation ifAbsent:nil) isNil
  2278     newTranslations := 
  2164     ].
  2279         newTranslations select:[:eachTranslation|
       
  2280             (aClass resources at:eachTranslation ifAbsent:nil) isNil
       
  2281         ].
  2165     ^ newTranslations
  2282     ^ newTranslations
  2166 !
  2283 !
  2167 
  2284 
  2168 extractTranslationsFromHelpSpecMethod:aMethod
  2285 extractTranslationsFromHelpSpecMethod:aMethod
       
  2286     "return strings which need translation from a help-spec method"
       
  2287 
  2169     |codeStrings matcher parseTree resourceKeys|
  2288     |codeStrings matcher parseTree resourceKeys|
  2170 
  2289 
  2171     parseTree := RBParser
  2290     parseTree := RBParser
  2172             parseMethod:aMethod source
  2291             parseMethod:aMethod source
  2173             onError: [:str :pos | Transcript showCR:str. Transcript showCR:pos.
  2292             onError: [:str :pos | Transcript showCR:str. Transcript showCR:pos.
  2190 
  2309 
  2191                 aNode isReturn ifTrue:[
  2310                 aNode isReturn ifTrue:[
  2192                     "/ a ^ #(...)
  2311                     "/ a ^ #(...)
  2193                     aNode value isLiteralArray ifTrue:[
  2312                     aNode value isLiteralArray ifTrue:[
  2194                         aNode value value pairWiseDo:[:helpKey :helpString |
  2313                         aNode value value pairWiseDo:[:helpKey :helpString |
       
  2314                             self rememberMethod:aMethod usingKey:helpString.
  2195                             resourceKeys add:helpString.
  2315                             resourceKeys add:helpString.
  2196                         ].
  2316                         ].
  2197                     ].    
  2317                     ].    
  2198                 ] ifFalse:[    
  2318                 ] ifFalse:[    
  2199                     sel := aNode selector.
  2319                     sel := aNode selector.
  2200                     (sel startsWith:'addPairsFrom:') ifTrue:[
  2320                     (sel startsWith:'addPairsFrom:') ifTrue:[
  2201                         argNode := aNode arguments at:1.
  2321                         argNode := aNode arguments at:1.
  2202                         argNode isLiteral ifTrue:[
  2322                         argNode isLiteralArray ifTrue:[
  2203                             arg := argNode value.
  2323                             arg := argNode value.
  2204                             arg isArray ifTrue:[
  2324                             arg doWithIndex:[:el :index |
  2205                                 arg doWithIndex:[:el :index |
  2325                                 index even ifTrue:[
  2206                                     index even ifTrue:[
  2326                                     el isString ifTrue:[
  2207                                         el isString ifTrue:[
  2327                                         self rememberMethod:aMethod usingKey:el.
  2208                                             resourceKeys add:el.
  2328                                         resourceKeys add:el.
  2209                                         ]
  2329                                     ]
  2210                                     ].
       
  2211                                 ].
  2330                                 ].
  2212                             ] ifFalse:[
       
  2213                                 Transcript
       
  2214                                     showCR:(resources
       
  2215                                             string:'Cannot derive resourceKey from non-array in %1 in %2'
       
  2216                                             with:argNode formattedCode
       
  2217                                             with:aMethod selector).
       
  2218                             ].
  2331                             ].
  2219                         ] ifFalse:[
  2332                         ] ifFalse:[
  2220                             Transcript halt
  2333                             Transcript halt
  2221                                 showCR:(resources
  2334                                 showCR:(resources
  2222                                             string:'Cannot derive resourceKey from non-literal: %1 in %2'
  2335                                             string:'Cannot derive resourceKey from non-literal array: %1 in %2'
  2223                                             with:argNode formattedCode
  2336                                             with:argNode formattedCode
  2224                                             with:aMethod selector).
  2337                                             with:aMethod selector).
  2225                         ].
  2338                         ].
  2226                     ].
  2339                     ].
  2227                 ].
  2340                 ].
  2231     matcher executeTree: parseTree initialAnswer: nil.
  2344     matcher executeTree: parseTree initialAnswer: nil.
  2232     ^ resourceKeys
  2345     ^ resourceKeys
  2233 !
  2346 !
  2234 
  2347 
  2235 extractTranslationsFromMenuSpecMethod:aMethod
  2348 extractTranslationsFromMenuSpecMethod:aMethod
       
  2349     "return strings which need translation from a menu-spec method"
       
  2350 
  2236     |menu resourceKeys|
  2351     |menu resourceKeys|
  2237 
  2352 
  2238     menu := aMethod mclass theNonMetaclass perform:aMethod selector.
  2353     menu := aMethod mclass theNonMetaclass perform:aMethod selector.
  2239     menu isNil ifTrue:[ ^ #() ].
  2354     menu isNil ifTrue:[ ^ #() ].
  2240 
  2355 
  2244 
  2359 
  2245     resourceKeys := Set new.
  2360     resourceKeys := Set new.
  2246     menu allItemsDo:[:aMenuItem |
  2361     menu allItemsDo:[:aMenuItem |
  2247         aMenuItem translateLabel ifTrue:[
  2362         aMenuItem translateLabel ifTrue:[
  2248             (aMenuItem isSeparatorItem or:[aMenuItem isMenuSlice])  ifFalse:[
  2363             (aMenuItem isSeparatorItem or:[aMenuItem isMenuSlice])  ifFalse:[
       
  2364                 self rememberMethod:aMethod usingKey:aMenuItem label.
  2249                 resourceKeys add:aMenuItem label.
  2365                 resourceKeys add:aMenuItem label.
  2250             ]
  2366             ]
  2251         ]
  2367         ]
  2252     ].
  2368     ].
  2253     ^ resourceKeys
  2369     ^ resourceKeys
  2254 !
  2370 !
  2255 
  2371 
  2256 extractTranslationsFromMethod:aMethod
  2372 extractTranslationsFromMethod:aMethod
       
  2373     "return strings which need translation from a method."
       
  2374     
  2257     |mResources|
  2375     |mResources|
  2258 
  2376 
  2259     mResources := aMethod resources.
  2377     mResources := aMethod resources.
  2260     mResources notNil ifTrue:[
  2378     mResources notNil ifTrue:[
  2261         (mResources includesKey:#menu) ifTrue:[
  2379         (mResources includesKey:#menu) ifTrue:[
  2275     ].
  2393     ].
  2276     ^ self extractTranslationsFromMethodsCode:aMethod
  2394     ^ self extractTranslationsFromMethodsCode:aMethod
  2277 !
  2395 !
  2278 
  2396 
  2279 extractTranslationsFromMethodsCode:aMethod
  2397 extractTranslationsFromMethodsCode:aMethod
  2280 "/method:mthd selector:sel inClass:cls matchesParseTreeMatcher:aMatcher
  2398     "return strings which need translation from a normal method.
       
  2399      detects messages to the resource translation mechanism"
       
  2400 
  2281     |codeStrings matcher parseTree resourceKeys|
  2401     |codeStrings matcher parseTree resourceKeys|
  2282 
  2402 
  2283     parseTree := RBParser
  2403     parseTree := RBParser
  2284             parseMethod:aMethod source
  2404             parseMethod:aMethod source
  2285             onError: [:str :pos | Transcript showCR:str. Transcript showCR:pos.
  2405             onError: [:str :pos | Transcript showCR:str. Transcript showCR:pos.
  2306 
  2426 
  2307                 sel := aNode selector.
  2427                 sel := aNode selector.
  2308                 ((sel startsWith:'string:') or:[(sel startsWith:'at:') or:[sel startsWith:'stringWithCRs:']]) ifTrue:[
  2428                 ((sel startsWith:'string:') or:[(sel startsWith:'at:') or:[sel startsWith:'stringWithCRs:']]) ifTrue:[
  2309                     keyStringArgNode := aNode arguments at:1.
  2429                     keyStringArgNode := aNode arguments at:1.
  2310                     (keyStringArg := self literalStringOrStringConcatenation:keyStringArgNode) notNil ifTrue:[
  2430                     (keyStringArg := self literalStringOrStringConcatenation:keyStringArgNode) notNil ifTrue:[
       
  2431                         self rememberMethod:aMethod usingKey:keyStringArg.
  2311                         resourceKeys add:keyStringArg.
  2432                         resourceKeys add:keyStringArg.
  2312                     ] ifFalse:[
  2433                     ] ifFalse:[
  2313                         Transcript
  2434                         Transcript
  2314                             showCR:(resources
  2435                             showCR:(resources
  2315                                     string:'[LanguageTranslator] warning: Cannot derive resourceKey from non-string: %1 in %2'
  2436                                     string:'[LanguageTranslator] warning: Cannot derive resourceKey from non-string: %1 in %2'
  2329 extractTranslationsFromSpecMethod:aMethod
  2450 extractTranslationsFromSpecMethod:aMethod
  2330     ^ #()
  2451     ^ #()
  2331 !
  2452 !
  2332 
  2453 
  2333 extractTranslationsFromTableColumnsSpecMethod:aMethod
  2454 extractTranslationsFromTableColumnsSpecMethod:aMethod
       
  2455     "return strings which need translation from a table-spec method"
       
  2456 
  2334     |columnDescription resourceKeys|
  2457     |columnDescription resourceKeys|
  2335 
  2458 
  2336     columnDescription := aMethod mclass theNonMetaclass perform:aMethod selector.
  2459     columnDescription := aMethod mclass theNonMetaclass perform:aMethod selector.
  2337     columnDescription isNil ifTrue:[ ^ #() ].
  2460     columnDescription isNil ifTrue:[ ^ #() ].
  2338 
  2461 
  2339     (columnDescription first isKindOf:DataSetColumnSpec) ifFalse:[
  2462     (columnDescription first isKindOf:DataSetColumnSpec) ifFalse:[
  2340 	columnDescription := columnDescription collect:[:el | DataSetColumnSpec new fromLiteralArrayEncoding:el].
  2463         columnDescription := columnDescription collect:[:el | DataSetColumnSpec new fromLiteralArrayEncoding:el].
  2341     ].
  2464     ].
  2342 
  2465 
  2343     resourceKeys := Set new.
  2466     resourceKeys := Set new.
  2344     columnDescription do:[:aColumnSpec |
  2467     columnDescription do:[:aColumnSpec |
  2345 	aColumnSpec translateLabel ifTrue:[
  2468         aColumnSpec translateLabel ifTrue:[
  2346 	    resourceKeys add:aColumnSpec label.
  2469             self rememberMethod:aMethod usingKey:aColumnSpec label.
  2347 	]
  2470             resourceKeys add:aColumnSpec label.
       
  2471         ]
  2348     ].
  2472     ].
  2349     ^ resourceKeys
  2473     ^ resourceKeys
  2350 !
  2474 !
  2351 
  2475 
  2352 extractTranslationsFromUISpecMethod:aMethod
  2476 extractTranslationsFromUISpecMethod:aMethod
       
  2477     "return strings which need translation from a UI-spec method"
       
  2478     
  2353     |spec resourceKeys visitor|
  2479     |spec resourceKeys visitor|
  2354 
  2480 
  2355     spec := aMethod mclass theNonMetaclass perform:aMethod selector.
  2481     spec := aMethod mclass theNonMetaclass perform:aMethod selector.
  2356     spec isNil ifTrue:[ ^ #() ].
  2482     spec isNil ifTrue:[ ^ #() ].
  2357 
  2483 
  2358     (spec isKindOf:UISpecification) ifFalse:[
  2484     (spec isKindOf:UISpecification) ifFalse:[
  2359 	spec := UISpecification from:spec
  2485         spec := UISpecification from:spec
  2360     ].
  2486     ].
  2361 
  2487 
  2362     resourceKeys := Set new.
  2488     resourceKeys := Set new.
  2363 
  2489 
  2364     visitor := UISpecVisitor new.
  2490     visitor := UISpecVisitor new.
  2365     spec acceptVisitor:visitor.
  2491     spec acceptVisitor:visitor.
  2366 
  2492     visitor translatedLabels do:[:each |
       
  2493         self rememberMethod:aMethod usingKey:each.
       
  2494     ].
  2367     ^ visitor translatedLabels
  2495     ^ visitor translatedLabels
  2368 !
  2496 !
  2369 
  2497 
  2370 literalStringOrStringConcatenation:aParseNode
  2498 literalStringOrStringConcatenation:aParseNode
  2371     "nil if not a literal or a string concatenation"
  2499     "nil if not a literal or a string concatenation"
  2387         (leftString notNil and:[rightString notNil]) ifTrue:[
  2515         (leftString notNil and:[rightString notNil]) ifTrue:[
  2388             ^ leftString , rightString
  2516             ^ leftString , rightString
  2389         ].
  2517         ].
  2390     ].
  2518     ].
  2391     ^ nil
  2519     ^ nil
       
  2520 !
       
  2521 
       
  2522 recordNewTranslation:aString
       
  2523     "called from recorder, when the monitored application does a translation"
       
  2524     
       
  2525     self addAllTranslations:{ aString }
       
  2526 !
       
  2527 
       
  2528 rememberMethod:aMethod usingKey:aKey
       
  2529     (methodsUsingKey at:aKey ifAbsentPut:[Set new]) add:aMethod
  2392 ! !
  2530 ! !
  2393 
  2531 
  2394 !InternationalLanguageTranslationEditor methodsFor:'queries'!
  2532 !InternationalLanguageTranslationEditor methodsFor:'queries'!
  2395 
  2533 
  2396 autoAccept
  2534 autoAccept
  2924     languageEditor pasteOrReplace:previousLanguageText.
  3062     languageEditor pasteOrReplace:previousLanguageText.
  2925     self languageTextModifiedHolder value:true.
  3063     self languageTextModifiedHolder value:true.
  2926 !
  3064 !
  2927 
  3065 
  2928 search
  3066 search
  2929 
  3067     "make the searchbox visible"
       
  3068     
  2930     self searchBoxVisible value: true.
  3069     self searchBoxVisible value: true.
  2931     self updateToolVisibility.
  3070     self updateToolVisibility.
  2932     searchTextView takeFocus.
  3071     searchTextView takeFocus.
  2933 
  3072 
  2934     "Modified: / 16-06-2007 / 11:58:44 / Administrador"
  3073     "Modified: / 16-06-2007 / 11:58:44 / Administrador"
  2968 
  3107 
  2969 !InternationalLanguageTranslationEditor::AccessCollectingPseudoResourcePack methodsFor:'accessing'!
  3108 !InternationalLanguageTranslationEditor::AccessCollectingPseudoResourcePack methodsFor:'accessing'!
  2970 
  3109 
  2971 realResourcePack:something
  3110 realResourcePack:something
  2972     realResourcePack := something.
  3111     realResourcePack := something.
       
  3112 !
       
  3113 
       
  3114 watchingTranslationEditor:something
       
  3115     watchingTranslationEditor := something.
       
  3116 ! !
       
  3117 
       
  3118 !InternationalLanguageTranslationEditor::AccessCollectingPseudoResourcePack methodsFor:'resource pack protocol'!
       
  3119 
       
  3120 forwardFor:aString
       
  3121     collectedKeys isNil ifTrue:[
       
  3122         collectedKeys := Set new.
       
  3123     ].
       
  3124     collectedKeys add:aString.
       
  3125     watchingTranslationEditor notNil ifTrue:[
       
  3126         watchingTranslationEditor recordNewTranslation:aString.
       
  3127     ].
       
  3128     ^ realResourcePack perform:(thisContext sender selector) withArguments:(thisContext sender args).
       
  3129 !
       
  3130 
       
  3131 string:aString
       
  3132     ^ self forwardFor:aString
  2973 ! !
  3133 ! !
  2974 
  3134 
  2975 !InternationalLanguageTranslationEditor::KeyStringsToLanguageMappings class methodsFor:'instance creation'!
  3135 !InternationalLanguageTranslationEditor::KeyStringsToLanguageMappings class methodsFor:'instance creation'!
  2976 
  3136 
  2977 new
  3137 new