SettingsDialog.st
changeset 16313 6abedc9963c0
parent 16201 639512eafece
child 16315 73c4f82ca456
child 16318 c63c5afa0cc9
equal deleted inserted replaced
16312:e4480574be19 16313:6abedc9963c0
     1 "{ Encoding: utf8 }"
       
     2 
       
     3 "
     1 "
     4  COPYRIGHT (c) 2002 by eXept Software AG
     2  COPYRIGHT (c) 2002 by eXept Software AG
     5               All Rights Reserved
     3               All Rights Reserved
     6 
     4 
     7  This software is furnished under a license and may be used
     5  This software is furnished under a license and may be used
    16 "{ NameSpace: Smalltalk }"
    14 "{ NameSpace: Smalltalk }"
    17 
    15 
    18 ApplicationModel subclass:#SettingsDialog
    16 ApplicationModel subclass:#SettingsDialog
    19 	instanceVariableNames:'requestor subCanvasApplicationHolder help doReload doSave
    17 	instanceVariableNames:'requestor subCanvasApplicationHolder help doReload doSave
    20 		enableReload enableHelp enableOK selectedItem applicationList
    18 		enableReload enableHelp enableOK selectedItem applicationList
    21 		categoryIcons lastSelection whyDisabledInfoHolder'
    19 		categoryIcons lastSelection whyDisabledInfoHolder
       
    20 		quickSearchStringHolder quickSearchFieldShownHolder
       
    21 		highlightedWidgetsOriginalAttributes'
    22 	classVariableNames:'ApplicationList IconList'
    22 	classVariableNames:'ApplicationList IconList'
    23 	poolDictionaries:''
    23 	poolDictionaries:''
    24 	category:'Interface-Smalltalk'
    24 	category:'Interface-Smalltalk'
    25 !
    25 !
    26 
    26 
   388                 (ViewSpec
   388                 (ViewSpec
   389                    name: 'Box1'
   389                    name: 'Box1'
   390                    component: 
   390                    component: 
   391                   (SpecCollection
   391                   (SpecCollection
   392                      collection: (
   392                      collection: (
   393                       (HierarchicalListViewSpec
   393                       (VerticalPanelViewSpec
   394                          name: 'HierarchicalListView1'
   394                          name: 'VerticalPanel1'
   395                          layout: (LayoutFrame 0 0.0 0 0.0 0 1.0 -34 1)
   395                          layout: (LayoutFrame 0 0 0 0 0 1 -34 1)
   396                          model: selectedItem
   396                          horizontalLayout: fit
   397                          hasHorizontalScrollBar: true
   397                          verticalLayout: topFit
   398                          hasVerticalScrollBar: true
   398                          horizontalSpace: 3
   399                          listModel: applicationList
   399                          verticalSpace: 3
   400                          useIndex: false
   400                          component: 
   401                          highlightMode: label
   401                         (SpecCollection
   402                          showLeftIndicators: false
   402                            collection: (
   403                          indicatorSelector: doIndicatorClick:
   403                             (ViewSpec
       
   404                                name: 'QuickSearchBox'
       
   405                                visibilityChannel: quickSearchFieldShownHolder
       
   406                                component: 
       
   407                               (SpecCollection
       
   408                                  collection: (
       
   409                                   (LabelSpec
       
   410                                      label: 'Quick Search:'
       
   411                                      name: 'Label1'
       
   412                                      layout: (LayoutFrame 0 0 0 0 150 0 0 1)
       
   413                                      translateLabel: true
       
   414                                      adjust: left
       
   415                                    )
       
   416                                   (InputFieldSpec
       
   417                                      name: 'QuickSeachEntryField'
       
   418                                      layout: (LayoutFrame 150 0 0 0 0 1 0 1)
       
   419                                      model: quickSearchStringHolder
       
   420                                      immediateAccept: true
       
   421                                      acceptOnReturn: true
       
   422                                      acceptOnTab: true
       
   423                                      acceptOnPointerLeave: true
       
   424                                    )
       
   425                                   )
       
   426                                 
       
   427                                )
       
   428                                extent: (Point 260 30)
       
   429                              )
       
   430                             (HierarchicalListViewSpec
       
   431                                name: 'HierarchicalListView1'
       
   432                                model: selectedItem
       
   433                                hasHorizontalScrollBar: true
       
   434                                hasVerticalScrollBar: true
       
   435                                listModel: applicationList
       
   436                                useIndex: false
       
   437                                highlightMode: label
       
   438                                showLeftIndicators: false
       
   439                                indicatorSelector: doIndicatorClick:
       
   440                                extent: (Point 260 575)
       
   441                              )
       
   442                             )
       
   443                           
       
   444                          )
   404                        )
   445                        )
   405                       (HorizontalPanelViewSpec
   446                       (HorizontalPanelViewSpec
   406                          name: 'HorizontalPanel2'
   447                          name: 'HorizontalPanel2'
   407                          layout: (LayoutFrame 0 0.0 -34 1 0 1.0 0 1)
   448                          layout: (LayoutFrame 0 0.0 -34 1 0 1.0 0 1)
   408                          visibilityChannel: loadAndSaveSettingsItemVisible
   449                          visibilityChannel: loadAndSaveSettingsItemVisible
   418                                name: 'Button3'
   459                                name: 'Button3'
   419                                activeHelpKey: saveSettingsToFile
   460                                activeHelpKey: saveSettingsToFile
   420                                translateLabel: true
   461                                translateLabel: true
   421                                tabable: true
   462                                tabable: true
   422                                model: saveSettingsWithoutAskingForFile
   463                                model: saveSettingsWithoutAskingForFile
   423                                extent: (Point 126 22)
   464                                extent: (Point 124 22)
   424                              )
   465                              )
   425                             (ActionButtonSpec
   466                             (ActionButtonSpec
   426                                label: 'Load From...'
   467                                label: 'Load From...'
   427                                name: 'Button2'
   468                                name: 'Button2'
   428                                activeHelpKey: loadSettingsFromFile
   469                                activeHelpKey: loadSettingsFromFile
   429                                translateLabel: true
   470                                translateLabel: true
   430                                tabable: true
   471                                tabable: true
   431                                model: loadSettingsFromFile
   472                                model: loadSettingsFromFile
   432                                extent: (Point 126 22)
   473                                extent: (Point 124 22)
   433                              )
   474                              )
   434                             )
   475                             )
   435                           
   476                           
   436                          )
   477                          )
   437                        )
   478                        )
   491                                activeHelpKey: helpOnSettings
   532                                activeHelpKey: helpOnSettings
   492                                translateLabel: true
   533                                translateLabel: true
   493                                tabable: true
   534                                tabable: true
   494                                model: help
   535                                model: help
   495                                enableChannel: enableHelp
   536                                enableChannel: enableHelp
   496                                extent: (Point 163 22)
   537                                extent: (Point 161 22)
   497                              )
   538                              )
   498                             (ActionButtonSpec
   539                             (ActionButtonSpec
   499                                label: 'Discard'
   540                                label: 'Discard'
   500                                name: 'Reload'
   541                                name: 'Reload'
   501                                activeHelpKey: discardChangedSettings
   542                                activeHelpKey: discardChangedSettings
   502                                translateLabel: true
   543                                translateLabel: true
   503                                tabable: true
   544                                tabable: true
   504                                model: doReload
   545                                model: doReload
   505                                enableChannel: enableReload
   546                                enableChannel: enableReload
   506                                extent: (Point 163 22)
   547                                extent: (Point 162 22)
   507                              )
   548                              )
   508                             (ActionButtonSpec
   549                             (ActionButtonSpec
   509                                label: 'Apply'
   550                                label: 'Apply'
   510                                name: 'Apply'
   551                                name: 'Apply'
   511                                activeHelpKey: acceptChangedSettings
   552                                activeHelpKey: acceptChangedSettings
   512                                translateLabel: true
   553                                translateLabel: true
   513                                tabable: true
   554                                tabable: true
   514                                model: doSave
   555                                model: doSave
   515                                enableChannel: enableOK
   556                                enableChannel: enableOK
   516                                extent: (Point 164 22)
   557                                extent: (Point 162 22)
   517                              )
   558                              )
   518                             )
   559                             )
   519                           
   560                           
   520                          )
   561                          )
   521                          keepSpaceForOSXResizeHandleH: true
   562                          keepSpaceForOSXResizeHandleH: true
   525                    )
   566                    )
   526                  )
   567                  )
   527                 )
   568                 )
   528               
   569               
   529              )
   570              )
   530              handles: (Any 0.33750000000000002 1.0)
   571              handles: (Any 0.33750000000000036 1.0)
   531            )
   572            )
   532           )
   573           )
   533         
   574         
   534        )
   575        )
   535      )
   576      )
   661                 )
   702                 )
   662                (MenuItem
   703                (MenuItem
   663                   label: 'Collapse All'
   704                   label: 'Collapse All'
   664                   itemValue: menuCollapseAll
   705                   itemValue: menuCollapseAll
   665                 )
   706                 )
       
   707                (MenuItem
       
   708                   label: '-'
       
   709                 )
       
   710                (MenuItem
       
   711                   label: 'Show Search Field'
       
   712                   indication: quickSearchFieldShownHolder
       
   713                 )
   666                )
   714                )
   667               nil
   715               nil
   668               nil
   716               nil
   669             )
   717             )
   670           )
   718           )
  1437      settingsDialog. I think this has to be reworked..."
  1485      settingsDialog. I think this has to be reworked..."
  1438 
  1486 
  1439     ^ requestor notNil "/ loadAndSaveSettingsItemVisible
  1487     ^ requestor notNil "/ loadAndSaveSettingsItemVisible
  1440 !
  1488 !
  1441 
  1489 
       
  1490 quickSearchFieldShownHolder
       
  1491     quickSearchFieldShownHolder isNil ifTrue:[
       
  1492         quickSearchFieldShownHolder := false asValue
       
  1493     ].
       
  1494     ^ quickSearchFieldShownHolder.
       
  1495 !
       
  1496 
       
  1497 quickSearchStringHolder
       
  1498     <resource: #uiAspect>
       
  1499 
       
  1500     quickSearchStringHolder isNil ifTrue:[
       
  1501         quickSearchStringHolder := ValueHolder new.
       
  1502        quickSearchStringHolder onChangeSend:#quickSearchStringHolderChanged to:self.
       
  1503     ].
       
  1504     ^ quickSearchStringHolder.
       
  1505 !
       
  1506 
  1442 selectedItem
  1507 selectedItem
  1443     selectedItem isNil ifTrue:[
  1508     selectedItem isNil ifTrue:[
  1444         selectedItem := ValueHolder new.
  1509         selectedItem := ValueHolder new.
  1445         selectedItem addDependent:self.
  1510         selectedItem addDependent:self.
  1446     ].
  1511     ].
  1488                 arguments:#().
  1553                 arguments:#().
  1489             ].
  1554             ].
  1490             ^ self
  1555             ^ self
  1491         ].
  1556         ].
  1492         oldAppl modifiedChannel removeDependent:self.
  1557         oldAppl modifiedChannel removeDependent:self.
       
  1558         self unhighlightWidgets.
  1493     ].
  1559     ].
  1494 
  1560 
  1495     item := self selectedItem value.
  1561     item := self selectedItem value.
  1496 
  1562 
  1497     item isNil ifTrue:[ item := applicationList root ].
  1563     item isNil ifTrue:[ item := applicationList root ].
  1553         app readSettings.
  1619         app readSettings.
  1554     ].
  1620     ].
  1555     app modifiedChannel addDependent:self.
  1621     app modifiedChannel addDependent:self.
  1556     self subCanvasApplicationHolder value:app.
  1622     self subCanvasApplicationHolder value:app.
  1557     self modifiedChanged.
  1623     self modifiedChanged.
       
  1624     
       
  1625     self highlightWidgetsWithMatchingSearchString
  1558 
  1626 
  1559     "Modified: / 29-10-2010 / 11:51:13 / cg"
  1627     "Modified: / 29-10-2010 / 11:51:13 / cg"
  1560     "Modified: / 17-02-2012 / 10:24:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1628     "Modified: / 17-02-2012 / 10:24:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1561 !
  1629 !
  1562 
  1630 
  1717 saveSettingsWithoutAskingForFile
  1785 saveSettingsWithoutAskingForFile
  1718     self class saveSettingsWithoutAskingForFile.
  1786     self class saveSettingsWithoutAskingForFile.
  1719     self realApplicationsDo:[:app | app clearDidModifySettings].
  1787     self realApplicationsDo:[:app | app clearDidModifySettings].
  1720 ! !
  1788 ! !
  1721 
  1789 
       
  1790 !SettingsDialog methodsFor:'quick search support'!
       
  1791 
       
  1792 highlightWidgets:aSetOfWidget
       
  1793     "highlight a matching widget"
       
  1794 
       
  1795     highlightedWidgetsOriginalAttributes := Dictionary new.
       
  1796     aSetOfWidget do:[:w |
       
  1797         |perWidget|
       
  1798         
       
  1799         highlightedWidgetsOriginalAttributes at:w put:(perWidget := Dictionary new).
       
  1800         perWidget at:#borderWidth: put:w borderWidth.
       
  1801         perWidget at:#borderColor: put:w borderColor.
       
  1802         
       
  1803         w borderWidth:2.
       
  1804         w borderColor:Color red.
       
  1805     ].
       
  1806 !
       
  1807 
       
  1808 highlightWidgetsWithMatchingSearchString
       
  1809     "whenever an app is selected AND a quick search string is present,
       
  1810      go through the widgets and highlight those which match.
       
  1811      This is done by looking at the helpkey and model aspects for a match"
       
  1812 
       
  1813     |app searchString pattern words widgetsToHighlight|
       
  1814     
       
  1815     highlightedWidgetsOriginalAttributes notNil ifTrue:[
       
  1816         self unhighlightWidgets.
       
  1817     ].
       
  1818     
       
  1819     searchString := self quickSearchStringHolder value.
       
  1820     searchString isEmptyOrNil ifTrue:[^ self].
       
  1821     
       
  1822     pattern := '*',searchString,'*'.
       
  1823 
       
  1824     (app := subCanvasApplicationHolder value) isNil ifTrue:[^ self].
       
  1825 
       
  1826     widgetsToHighlight := Set new.
       
  1827     words := app quickSearchStrings.
       
  1828     
       
  1829     (words contains:[:word | pattern match:word]) ifTrue:[
       
  1830         "/ ok - there is a match
       
  1831         app window withAllSubViewsDo:[:v |
       
  1832             v helpKey notNil ifTrue:[
       
  1833                 (pattern match:v helpKey caseSensitive:false) ifTrue:[
       
  1834                     |alreadyIn|
       
  1835                     
       
  1836                     alreadyIn := false.
       
  1837                     v allSuperViewsDo:[:sv | (widgetsToHighlight includes:sv) ifTrue:[ alreadyIn := true]].
       
  1838                     alreadyIn ifFalse:[ widgetsToHighlight add:v ].
       
  1839                 ].   
       
  1840             ].   
       
  1841         ].   
       
  1842     ].
       
  1843     self highlightWidgets:widgetsToHighlight.
       
  1844 !
       
  1845 
       
  1846 quickSearchStringHolderChanged
       
  1847     |oldSelection searchString pattern matches|
       
  1848     
       
  1849     oldSelection := self selectedItem value.
       
  1850     
       
  1851     "/ make all labels normal
       
  1852     applicationList root recursiveDo:[:eachSettingsAppItem |
       
  1853         eachSettingsAppItem label:(eachSettingsAppItem label string).
       
  1854     ]. 
       
  1855 
       
  1856     searchString := self quickSearchStringHolder value.
       
  1857     searchString isEmptyOrNil ifTrue:[^ self].
       
  1858     pattern := '*',searchString,'*'.
       
  1859 
       
  1860     applicationList root recursiveExpand.
       
  1861 "/    applicationList root recursiveDo:[:eachSettingsAppItem |
       
  1862 "/        eachSettingsAppItem expand.
       
  1863 "/    ]. 
       
  1864     matches := OrderedCollection new.
       
  1865     "/ now search all specs for this word
       
  1866     applicationList root recursiveDo:[:eachSettingsAppItem |
       
  1867         |app words|
       
  1868         
       
  1869         eachSettingsAppItem applicationClass notNil ifTrue:[
       
  1870             (app := eachSettingsAppItem application) isNil ifTrue:[
       
  1871                 eachSettingsAppItem application:(app := eachSettingsAppItem applicationClass new).
       
  1872             ].    
       
  1873             words := app quickSearchStrings.
       
  1874             (words contains:[:word | pattern match:word caseSensitive:false ]) ifTrue:[
       
  1875                 matches add:eachSettingsAppItem.
       
  1876             ].   
       
  1877         ].
       
  1878     ]. 
       
  1879     applicationList root children do:[:c | c recursiveCollapse].
       
  1880     "/ now expand all matches
       
  1881     matches do:[:eachMatchingItem |
       
  1882         eachMatchingItem label:(eachMatchingItem label string allBold).
       
  1883         eachMatchingItem makeVisible
       
  1884     ]. 
       
  1885     
       
  1886     oldSelection notNil ifTrue:[
       
  1887         oldSelection makeVisible.
       
  1888         self selectedItem value:oldSelection.
       
  1889     ].    
       
  1890 !
       
  1891 
       
  1892 unhighlightWidget:aWidget
       
  1893     "unhighlight a matching widget"
       
  1894 
       
  1895     highlightedWidgetsOriginalAttributes notNil ifTrue:[
       
  1896         highlightedWidgetsOriginalAttributes keysAndValuesDo:[:widget :oldValues |
       
  1897             oldValues keysAndValuesDo:[:sel :oldValue |
       
  1898                 widget perform:sel with:oldValue
       
  1899             ].    
       
  1900         ].    
       
  1901         highlightedWidgetsOriginalAttributes := nil.
       
  1902     ].  
       
  1903 !
       
  1904 
       
  1905 unhighlightWidgets
       
  1906     "unhighlight a matching widget"
       
  1907 
       
  1908     highlightedWidgetsOriginalAttributes notNil ifTrue:[
       
  1909         highlightedWidgetsOriginalAttributes keysAndValuesDo:[:widget :oldValues |
       
  1910             oldValues keysAndValuesDo:[:sel :oldValue |
       
  1911                 widget perform:sel with:oldValue
       
  1912             ].    
       
  1913         ].    
       
  1914         highlightedWidgetsOriginalAttributes := nil.
       
  1915     ].  
       
  1916 ! !
       
  1917 
  1722 !SettingsDialog methodsFor:'selection'!
  1918 !SettingsDialog methodsFor:'selection'!
  1723 
  1919 
  1724 selectItemWithClass:aClass
  1920 selectItemWithClass:aClass
  1725     "select an item based on the sub-settings application class"
  1921     "select an item based on the sub-settings application class"
  1726 
  1922 
  1832 ! !
  2028 ! !
  1833 
  2029 
  1834 !SettingsDialog::HierarchicalApplicationList::ApplicationItem methodsFor:'queries'!
  2030 !SettingsDialog::HierarchicalApplicationList::ApplicationItem methodsFor:'queries'!
  1835 
  2031 
  1836 canCollapse
  2032 canCollapse
  1837     "the rootItem is cannot be collapsed"
  2033     "the rootItem cannot be collapsed"
  1838 
  2034 
  1839     "/ first check if we are expanded, if not answer false
  2035     "/ first check if we are expanded, if not answer false
  1840     ^ (self isExpanded and:[self isRootItem not])
  2036     ^ (self isExpanded and:[self isRootItem not])
  1841 !
  2037 !
  1842 
  2038