extensions.st
changeset 396 015297b155fe
parent 395 25ed27eaeaae
parent 392 94ab746c648a
child 421 0d146090b05a
--- a/extensions.st	Thu Feb 12 00:30:40 2015 +0000
+++ b/extensions.st	Fri Feb 13 08:44:44 2015 +0000
@@ -54,6 +54,60 @@
     "Created: / 27-11-2011 / 17:22:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!DebugView methodsFor:'event handling'!
+
+processShortcut:aKeyPressEvent
+    "a shortcut key event as forwarded from the keyboardProcessor - if there is the
+     shortcut key defined, process the shortcut and return true - otherwise false."
+
+    UserPreferences current smallSenseEnabled ifTrue:[   
+        (aKeyPressEvent key == #OpenNavigator or:[aKeyPressEvent rawKey == #CtrlT and:[(aKeyPressEvent targetView keyboardMap hasBindingFor: #OpenNavigator) not]]) ifTrue:[ 
+            SmallSense::Navigator open.                                                                      
+            ^ true
+        ].    
+    ].
+    ^ super processShortcut:aKeyPressEvent
+
+    "Created: / 25-01-2015 / 12:18:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 11-02-2015 / 21:34:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!DialogBox class methodsFor:'smalltalk dialogs-SmallSense'!
+
+stx_goodies_smallsense_requestProject:title from:listOfProjects initialAnswer:initialTextOrNil suggestions:suggestions
+    "Ask for a project (package-id)"
+
+    <swizzle: #requestProject:from:initialAnswer:suggestions:>
+    "
+    stx_goodies_smallsense swizzle: (DialogBox class >> #stx_goodies_smallsense_requestProject:from:initialAnswer:suggestions:)
+    "
+
+    | dialog |
+
+    UserPreferences current smallSenseNewDialogsEnabled ifFalse:[ 
+        ^ self stx_libwidg_requestProject:title from:listOfProjects initialAnswer:initialTextOrNil suggestions:suggestions
+    ].
+    dialog := SmallSense::PackageSelectDialog new.
+    dialog title: title.
+    dialog filter: [ :pkg | listOfProjects includes: pkg ].
+    dialog updateMatching.
+    (initialTextOrNil notNil and:[initialTextOrNil ~~ PackageId noProjectID]) ifTrue:[
+        initialTextOrNil isEmpty ifTrue:[
+            suggestions size == 1 ifTrue:[
+                dialog pattern:   suggestions anElement. 
+                dialog selection: suggestions anElement. 
+            ].
+        ] ifFalse:[ 
+            dialog pattern: initialTextOrNil.
+            dialog selection: initialTextOrNil.
+        ]
+    ].
+    ^ dialog open.
+
+    "Created: / 25-11-2014 / 13:20:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 13-12-2014 / 08:49:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !EditTextView methodsFor:'accessing-behavior'!
 
 autoIndent
@@ -502,6 +556,24 @@
     "Modified: / 23-09-2013 / 14:32:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!Tools::Inspector2 methodsFor:'event handling'!
+
+processShortcut:aKeyPressEvent
+    "a shortcut key event as forwarded from the keyboardProcessor - if there is the
+     shortcut key defined, process the shortcut and return true - otherwise false."
+
+    UserPreferences current smallSenseEnabled ifTrue:[   
+        (aKeyPressEvent key == #OpenNavigator or:[aKeyPressEvent rawKey == #CtrlT and:[(aKeyPressEvent targetView keyboardMap hasBindingFor: #OpenNavigator) not]]) ifTrue:[ 
+            SmallSense::Navigator open.
+            ^ true
+        ].    
+    ].
+    ^ super processShortcut:aKeyPressEvent
+
+    "Created: / 25-01-2015 / 12:18:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 11-02-2015 / 21:34:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !Tools::LintService methodsFor:'event handling'!
 
 buttonPress:button x:x y:y in:view 
@@ -562,6 +634,23 @@
     "Created: / 24-08-2013 / 21:53:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!Tools::NewSystemBrowser methodsFor:'user actions-events'!
+
+processShortcut: aKeyPressEvent
+    UserPreferences current smallSenseEnabled ifTrue:[
+        aKeyPressEvent isKeyPressEvent ifTrue:[
+            (aKeyPressEvent key == #OpenNavigator or:[aKeyPressEvent rawKey == #CtrlT and:[(aKeyPressEvent targetView keyboardMap hasBindingFor: #OpenNavigator) not]]) ifTrue:[ 
+                self searchMenuOpenNavigatorOnDeclarations.
+                ^ true
+            ].
+        ].
+    ].
+    ^ super processShortcut: aKeyPressEvent
+
+    "Created: / 01-02-2015 / 07:22:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 11-02-2015 / 21:34:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !Tools::NewSystemBrowser methodsFor:'private-searching-smallsense'!
 
 searchCompletionBlock_SmallSense
@@ -573,6 +662,40 @@
     "Created: / 25-11-2013 / 12:27:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!Tools::NewSystemBrowser methodsFor:'menu actions-searching-SmallSense'!
+
+searchMenuOpenNavigatorOnDeclarations
+    "Open a SmallSense navigator on definitions (i.e.,
+     navugating to a class or or method implementor)"
+
+    | result |    
+
+    result := SmallSense::Navigator new open.
+    result isBehavior ifTrue:[
+        self createBuffer.
+        self switchToClass: result.
+        ^ self
+    ].
+    result isMethod ifTrue:[ 
+        self createBuffer.
+        self switchToClass: result mclass selector: result selector.
+        ^ self
+    ].
+    result isCollection ifTrue:[ 
+        (result allSatisfy:[:e|e isMethod]) ifTrue:[ 
+            self  spawnMethodBrowserForSearch:[ result ] 
+                  sortBy:#class 
+                  in:#newBuffer 
+                  label:(resources string: 'Implementors of %1' with: result anElement selector storeString)
+        ].
+        ^ self
+    ].
+    ^ self
+
+    "Created: / 23-01-2015 / 20:31:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 08-02-2015 / 08:21:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !Tools::NewSystemBrowser methodsFor:'private-searching-smallsense'!
 
 smallSenseSearchCompletion:patternString
@@ -671,6 +794,132 @@
     "Modified: / 07-08-2014 / 13:10:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!Tools::NewSystemBrowser methodsFor:'private-dialogs-SmallSense'!
+
+stx_goodies_smallsense_askForMethodCategory:question title:boxTitle okLabel:okLabel list:someCategories recentList:recentListOrNil initialAnswer:initialText
+    "convenient helper method: setup a box asking for a method category"
+
+    <swizzle: #askForMethodCategory:title:okLabel:list:recentList:initialAnswer:>
+
+    | dialog |
+
+    UserPreferences current smallSenseNewDialogsEnabled ifFalse:[ 
+        ^ self stx_libtool_askForMethodCategory:question title:boxTitle okLabel:okLabel list:someCategories recentList:recentListOrNil initialAnswer:initialText     
+    ].
+    dialog := SmallSense::ProtocolSelectDialog new.   
+    dialog title: (resources string: question).
+    dialog updateMatching.
+    dialog addButtonCancel.   
+    dialog addButtonAcceptWithLabel: (resources string: okLabel).  
+    initialText notNil ifTrue:[ 
+        dialog pattern: initialText.
+        dialog selection: initialText. 
+    ].
+    ^ dialog open
+    "
+    stx_goodies_smallsense swizzle: (Tools::NewSystemBrowser >> #stx_goodies_smallsense_askForMethodCategory:title:okLabel:list:recentList:initialAnswer:)
+    "
+
+    "Created: / 09-01-2015 / 10:44:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 29-01-2015 / 07:10:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!Tools::NewSystemBrowser class methodsFor:'utilities'!
+
+stx_goodies_smallsense_askForClassToSearch:doWhatByDefault single:singleClass msgTail:msgTail resources:resourcesOrNil filter:filterOrNil forBrowser:aBrowserOrNil thenDo:aBlock
+    "utility common code for both opening a new browser on a class and
+     to search for a class in an existing browser.
+     If singleClass is true, a single class will be asked for and browsed,
+     otherwise, a match pattern is allowed and a multi-class browser is opened.
+     Moved from instance protocol for better reusability."
+
+    <swizzle: #askForClassToSearch:single:msgTail:resources:filter:forBrowser:thenDo:>
+
+    |classes box boxLabel title okText okText2 okText3 className canFind doWhat doWhat2 doWhat3 resources showFullNameHolder onlyShowJavaClassesHolder|
+
+    UserPreferences current smallSenseNewDialogsEnabled ifFalse:[ 
+        ^ self stx_libtool_askForClassToSearch:doWhatByDefault single:singleClass msgTail:msgTail resources:resourcesOrNil filter:filterOrNil forBrowser:aBrowserOrNil thenDo:aBlock
+    ].
+
+    resources := resourcesOrNil ? self classResources.
+    showFullNameHolder := (LastClassSearchBoxShowedFullName ? false) asValue.
+    onlyShowJavaClassesHolder := (LastClassSearchBoxShowedJavaOnly ? false) asValue.
+
+    doWhat := doWhatByDefault.
+    canFind := aBrowserOrNil notNil
+               and:[aBrowserOrNil navigationState notNil and:[ aBrowserOrNil navigationState isFullBrowser ]].
+
+    (doWhat isNil or:[aBrowserOrNil isNil]) ifTrue:[
+        title := 'Select a class'.
+        boxLabel := (resources string:'Select a class').
+        okText := 'OK'.
+        okText2 := nil. doWhat2 := nil.
+        okText3 := nil. doWhat3 := nil.
+    ] ifFalse:[
+        title := (singleClass ifTrue:[ 'Class to browse' ] ifFalse:[ 'Class(es) to browse' ]).
+        boxLabel := (resources string:'Browse or Search').
+
+        (doWhat isNil and:[canFind not]) ifTrue:[
+            doWhat := #newBuffer.
+        ].
+
+        doWhat == #newBrowser ifTrue:[
+            okText := 'Open New Window'.
+            okText2 := 'Open New Buffer'. doWhat2 := #newBuffer.
+            okText3 := 'Open'.       doWhat3 := nil.
+        ] ifFalse:[ doWhat == #newBuffer ifTrue:[
+            okText := 'Open New Buffer'.
+            okText2 := 'Open New Window'.   doWhat2 := #newBrowser.
+            okText3 := 'Open'.       doWhat3 := nil.
+        ] ifFalse:[
+            title := (singleClass ifTrue:[ 'Class to find' ] ifFalse:[ 'Class(es) to find' ]).
+            okText := 'Open'.
+            okText2 := 'Open New Window'.   doWhat2 := #newBrowser.
+            okText3 := 'Open New Buffer'. doWhat3 := #newBuffer.
+        ]].
+    ].
+
+    box := SmallSense::ClassSearchDialog new.
+    box multiselect: true.
+
+    "button3" "okButton" "button2" "cancel"
+
+    box addButtonCancel.
+    doWhat notNil ifTrue:[
+        box addButtonWithLabel: (resources string:okText) action: [ box doAccept ] enablement: box acceptEnabledHolder.
+        (aBrowserOrNil notNil and:[aBrowserOrNil navigationState isFullBrowser]) "singleClass" ifTrue:[
+            box addButtonWithLabel: (resources string:okText3) action: [ doWhat := doWhat3. box doAccept ] enablement: box acceptEnabledHolder.
+        ].
+        box addButtonWithLabel: (resources string:okText2) action: [ doWhat := doWhat2. box doAccept ] enablement: box acceptEnabledHolder.
+    ] ifFalse:[
+        box addButtonAccept.
+    ].
+
+
+
+    classes := box open.
+    classes isEmptyOrNil ifTrue:[ ^ nil ].
+    self assert: classes size == 1.
+    className := classes anElement name.
+
+
+    LastClassSearchBoxShowedFullName := showFullNameHolder value.
+    LastClassSearchBoxShowedJavaOnly := onlyShowJavaClassesHolder value.
+
+    (doWhat isNil or:[aBrowserOrNil isNil]) ifTrue:[
+        aBlock notNil ifTrue:[aBlock value:className optionalArgument:singleClass and:doWhat].
+        ^ className
+    ].
+
+    aBrowserOrNil withSearchCursorDo:[
+        aBlock value:className value:singleClass value:doWhat.
+    ].
+    ^ className
+
+    "Created: / 28-04-2014 / 23:41:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 25-11-2014 / 13:08:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !UserPreferences methodsFor:'accessing-SmallSense'!
 
 smallSenseBackgroundLintEnabled
@@ -791,6 +1040,31 @@
     "Created: / 02-04-2012 / 11:37:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!UserPreferences methodsFor:'accessing-SmallSense'!
+
+smallSenseNewDialogsEnabled
+    ^ self smallSenseEnabled
+        and:[self at:#smallSenseNewDialogsEnabled ifAbsent:[false]]
+
+    "
+    UserPreferences current smallSenseNewDialogsEnabled.
+    UserPreferences current smallSenseNewDialogsEnabled: true.
+    UserPreferences current smallSenseNewDialogsEnabled: false.   
+    "
+
+    "Created: / 10-05-2014 / 00:05:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (comment): / 25-11-2014 / 13:06:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!UserPreferences methodsFor:'accessing-SmallSense'!
+
+smallSenseNewDialogsEnabled: aBoolean
+
+    ^self at:#smallSenseNewDialogsEnabled put: aBoolean
+
+    "Created: / 10-05-2014 / 00:04:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !UserPreferences methodsFor:'accessing-SmallSense-Smalltalk'!
 
 smallSenseSmalltalkIndentOnPasteEnabled
@@ -834,6 +1108,24 @@
     "Created: / 24-09-2013 / 10:04:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!WorkspaceApplication methodsFor:'event handling'!
+
+processShortcut:aKeyPressEvent
+    "a shortcut key event as forwarded from the keyboardProcessor - if there is the
+     shortcut key defined, process the shortcut and return true - otherwise false."
+
+    UserPreferences current smallSenseNewDialogsEnabled ifTrue:[   
+       (aKeyPressEvent key == #OpenNavigator or:[aKeyPressEvent rawKey == #CtrlT and:[(aKeyPressEvent targetView keyboardMap hasBindingFor: #OpenNavigator) not]]) ifTrue:[ 
+            SmallSense::Navigator open.
+            ^ true
+        ].    
+    ].
+    ^ super processShortcut:aKeyPressEvent
+
+    "Created: / 25-01-2015 / 12:18:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 11-02-2015 / 21:33:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !stx_goodies_smallsense class methodsFor:'documentation'!
 
 extensionsVersion_HG