--- a/SmallSense__PO.st Wed Oct 16 15:44:43 2013 +0100
+++ b/SmallSense__PO.st Thu Oct 17 01:41:47 2013 +0100
@@ -3,7 +3,7 @@
"{ NameSpace: SmallSense }"
HierarchicalItem subclass:#PO
- instanceVariableNames:'subject icon label name description'
+ instanceVariableNames:'subject icon label name context'
classVariableNames:'IconWidth'
poolDictionaries:''
category:'SmallSense-Core-Interface-PO'
@@ -22,15 +22,6 @@
"Modified: / 18-09-2013 / 00:13:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
-!PO class methodsFor:'Instance Creation'!
-
-name: name description:description
-
- ^ self new name:name; description:description.
-
- "Created: / 04-04-2011 / 13:46:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
!PO class methodsFor:'Instance creation'!
subject: anObject
@@ -42,15 +33,16 @@
!PO methodsFor:'accessing'!
-cursorColumnAfterComplete
-
- "Answers a cursor column after completion. The number returned
- is relative to the start of the text being replaced"
+context
+ ^ context
+!
- ^self stringToComplete size + 1
+context:something
+ something notNil ifTrue:[
+ context := something.
+ ].
- "Created: / 05-04-2011 / 17:05:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 03-10-2013 / 16:50:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 17-10-2013 / 01:16:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
cursorColumnAfterCompleteForLanguage: language
@@ -63,14 +55,6 @@
"Modified: / 04-10-2013 / 07:48:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-description
- ^ description
-!
-
-description:something
- description := something.
-!
-
icon
^nil
@@ -121,6 +105,37 @@
subject := something.
! !
+!PO methodsFor:'completion'!
+
+insert
+ "Insert given completion item at cursor position"
+
+ | po stringToComplete stringAlreadyWritten stringToInsert textView |
+
+ po := self.
+ textView := context codeView.
+ stringToComplete := po stringToCompleteForLanguage: context language.
+ stringAlreadyWritten := context wordBeforeCursor.
+ stringToInsert := stringToComplete copyFrom: (stringAlreadyWritten size + 1).
+ textView isCodeView2 ifTrue:[textView := textView textView].
+ textView undoableDo:[
+ (stringToComplete startsWith: stringAlreadyWritten) ifTrue:[
+ textView insertStringAtCursor: stringToInsert.
+ ] ifFalse:[
+ | startCol endCol |
+
+ endCol := textView cursorCol - 1.
+ startCol := textView cursorCol - stringAlreadyWritten size.
+ textView insertStringAtCursor: stringToComplete.
+ textView deleteFromLine:textView cursorLine col: startCol toLine:textView cursorLine col:endCol.
+ textView cursorCol: startCol + stringToComplete size.
+ ].
+ ].
+ textView setCursorCol: textView cursorCol - stringToComplete size + (po cursorColumnAfterCompleteForLanguage: context language).
+
+ "Created: / 17-10-2013 / 01:08:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
!PO methodsFor:'displaying'!
displayLabel:aLabel h:lH on:aGC x:x y:y h:h
@@ -141,15 +156,6 @@
"Modified: / 18-09-2013 / 00:13:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
-!PO methodsFor:'new'!
-
-name:nam description:desc
- name := nam.
- description := desc.
-
- "Created: / 16-03-2011 / 16:31:13 / Jakub <zelenja7@fel.cvut.cz>"
-! !
-
!PO methodsFor:'printing & storing'!
printOn:aStream