Changing the environment

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Changing the environment

Sean Malloy-2
Annoying lack-of-feature time.

Is it possible to modify the environment, so when the home key is hit, the
cursor goes to the beginning of text, and not the beginning of the line? (or
have it alternate between the two.)

One strike goes to start of line, next strike goes to start of text, and
back again.

If it is possible, can someone point me in the direction I might take to
make this change myself?


Reply | Threaded
Open this post in threaded view
|

Re: Changing the environment

Ian Bartholomew-18
Sean,

> Is it possible to modify the environment, so when the home key is
> hit, the cursor goes to the beginning of text, and not the beginning
> of the line? (or have it alternate between the two.)

Dolphin uses the Windows RichEdit control to do all it's editing and the
key definitions (Home - beginning of line, Ctrl-Home beginning of page)
are the ones that the control uses.  The next version of Dolphin (coming
shortly(ish)) uses a different editor (ScITE) and may have different or
configurable key assignments (?Andy/Blair)..

> If it is possible, can someone point me in the direction I might take
> to make this change myself?

This whole area is a bit confusing, there are a number of different
events that can be intercepted, but on the basis that "is it works then
it's OK" adding the following method to the TextEdit class seems to work
(all standard disclaimers apply)

onKeyPressed: aKeyEvent
    aKeyEvent code == VK_HOME
        ifTrue:
            [self caretPosition: 1.
            ^0].
    ^super onKeyPressed: aKeyEvent

--
Ian

Use the Reply-To address to contact me.
Mail sent to the From address is ignored.


Reply | Threaded
Open this post in threaded view
|

Re: Changing the environment

Blair McGlashan
"Ian Bartholomew" <[hidden email]> wrote in message
news:RuC5c.20153$[hidden email]...

> Sean,
>
> > Is it possible to modify the environment, so when the home key is
> > hit, the cursor goes to the beginning of text, and not the beginning
> > of the line? (or have it alternate between the two.)
>
> Dolphin uses the Windows RichEdit control to do all it's editing and the
> key definitions (Home - beginning of line, Ctrl-Home beginning of page)
> are the ones that the control uses.  The next version of Dolphin (coming
> shortly(ish)) uses a different editor (ScITE) and may have different or
> configurable key assignments (?Andy/Blair)..

Scintilla has various "home" commands that can be mapped to the Home key:
See http://scintilla.sourceforge.net/ScintillaDoc.html. By default though it
homes first to the start of the text in the line (i.e. the first character
after any indentation) and then to the start of the line. This makes sense
for a programmers' editor. I haven't explored the other "home" commands.

Scintilla also has its own custom key binding mechanism, but at present we
have chosen not to use that since it is redundant in Dolphin. You may be
wondering why I am mentioning this, but see below:

>
> > If it is possible, can someone point me in the direction I might take
> > to make this change myself?
>
> This whole area is a bit confusing, there are a number of different
> events that can be intercepted, but on the basis that "is it works then
> it's OK" adding the following method to the TextEdit class seems to work
> (all standard disclaimers apply)
>
> onKeyPressed: aKeyEvent
>     aKeyEvent code == VK_HOME
>         ifTrue:
>             [self caretPosition: 1.
>             ^0].
>     ^super onKeyPressed: aKeyEvent
>

I imagine this suggestion will work (thanks Ian), but you may want to make
use of Dolphin's standard accelerator key mechanism to make your
modification - assuming that pressing Ctrl+Home is not acceptable to you.

Sean: What you need to do is add an "additional accelerator" key that maps
to a command implementation that will allow you to do what you want. I've
knocked together an example below that makes the Home key go first to the
start of line, and if already there to the start of the text. This may not
be exactly what you want, but its purpose is to demonstrate how to implement
custom key bindings in add-on packages.

To convert the text to a package that can be loaded into Dolphin cut & paste
the text below into a file with a .pac extension. Then install this using
the package browser. Note that only newly opened browsers and workspaces
will pick up the new key binding.

Regards

Blair McGlashan
Object Arts Ltd
----------------------------
| package |
package := Package name: 'Dolphin Custom Key Binding Example'.
package paxVersion: 0;
 basicComment: 'This package illustrates extending the IDE by adding a
custom key binding.'.

package basicScriptAt: #postinstall put: '| bindings |
bindings := SmalltalkWorkspace acceleratorKeyBindings.
bindings at: ''Home'' put: #indecisiveHome.
SmalltalkWorkspace acceleratorKeyBindings: bindings!!'.
package basicScriptAt: #postuninstall put: '| bindings |
bindings := SmalltalkWorkspace acceleratorKeyBindings.
bindings removeKey: ''Home'' ifAbsent: [].
SmalltalkWorkspace acceleratorKeyBindings: bindings!!'.

package methodNames
 add: #SmalltalkWorkspace -> #indecisiveHome;
 yourself.

package binaryGlobalNames: (Set new
 yourself).

package globalAliases: (Set new
 yourself).

package allResourceNames: (Set new
 yourself).

package setPrerequisites: (IdentitySet new
 add: '..\..\Dolphin\IDE\Base\Development System';
 add: '..\..\Dolphin\Base\Dolphin';
 yourself).

package!

"Class Definitions"!


"Global Aliases"!


"Loose Methods"!

!SmalltalkWorkspace methodsFor!

indecisiveHome
 | caret line startOfLine |
 caret := self view caretPosition.
 caret = 1
  ifTrue:
   [Sound beep.
   ^self].
 line := self view lineFromPosition: caret.
 startOfLine := self view positionAtLine: line.
 self view caretPosition: (caret = startOfLine ifTrue: [1] ifFalse:
[startOfLine])! !
!SmalltalkWorkspace categoriesFor: #indecisiveHome!commands!public! !

"End of package definition"!

"Source Globals"!

"Classes"!

"Binary Globals"!

"Resources"!


Reply | Threaded
Open this post in threaded view
|

Re: Changing the environment

Sean Malloy-2
Blair,

wow you've gone above and beyond!

Thankyou.


Reply | Threaded
Open this post in threaded view
|

Re: Changing the environment

Sean Malloy-2
In reply to this post by Blair McGlashan
Blair,

How would you go about being able to move the caret between the start of the
line, and the start of text on the same line.

Right now you hit home, and it takes you to the start of the line. Hit home
again, and it takes you to the start of the entire block of text.

I'm trying to change it so it switches between startOfLine, and startOfText
(On the same line). I can't seem to find a way to check the amount of
whitespaces in between the start of the line and the text. Checking for
tabs, etc etc.

Any ideas?

Thanks.



"Blair McGlashan" <[hidden email]> wrote in message
news:c373qu$2318ej$[hidden email]...

> "Ian Bartholomew" <[hidden email]> wrote in message
> news:RuC5c.20153$[hidden email]...
> > Sean,
> >
> > > Is it possible to modify the environment, so when the home key is
> > > hit, the cursor goes to the beginning of text, and not the beginning
> > > of the line? (or have it alternate between the two.)
> >
> > Dolphin uses the Windows RichEdit control to do all it's editing and the
> > key definitions (Home - beginning of line, Ctrl-Home beginning of page)
> > are the ones that the control uses.  The next version of Dolphin (coming
> > shortly(ish)) uses a different editor (ScITE) and may have different or
> > configurable key assignments (?Andy/Blair)..
>
> Scintilla has various "home" commands that can be mapped to the Home key:
> See http://scintilla.sourceforge.net/ScintillaDoc.html. By default though
it

> homes first to the start of the text in the line (i.e. the first character
> after any indentation) and then to the start of the line. This makes sense
> for a programmers' editor. I haven't explored the other "home" commands.
>
> Scintilla also has its own custom key binding mechanism, but at present we
> have chosen not to use that since it is redundant in Dolphin. You may be
> wondering why I am mentioning this, but see below:
>
> >
> > > If it is possible, can someone point me in the direction I might take
> > > to make this change myself?
> >
> > This whole area is a bit confusing, there are a number of different
> > events that can be intercepted, but on the basis that "is it works then
> > it's OK" adding the following method to the TextEdit class seems to work
> > (all standard disclaimers apply)
> >
> > onKeyPressed: aKeyEvent
> >     aKeyEvent code == VK_HOME
> >         ifTrue:
> >             [self caretPosition: 1.
> >             ^0].
> >     ^super onKeyPressed: aKeyEvent
> >
>
> I imagine this suggestion will work (thanks Ian), but you may want to make
> use of Dolphin's standard accelerator key mechanism to make your
> modification - assuming that pressing Ctrl+Home is not acceptable to you.
>
> Sean: What you need to do is add an "additional accelerator" key that maps
> to a command implementation that will allow you to do what you want. I've
> knocked together an example below that makes the Home key go first to the
> start of line, and if already there to the start of the text. This may not
> be exactly what you want, but its purpose is to demonstrate how to
implement
> custom key bindings in add-on packages.
>
> To convert the text to a package that can be loaded into Dolphin cut &
paste

> the text below into a file with a .pac extension. Then install this using
> the package browser. Note that only newly opened browsers and workspaces
> will pick up the new key binding.
>
> Regards
>
> Blair McGlashan
> Object Arts Ltd
> ----------------------------
> | package |
> package := Package name: 'Dolphin Custom Key Binding Example'.
> package paxVersion: 0;
>  basicComment: 'This package illustrates extending the IDE by adding a
> custom key binding.'.
>
> package basicScriptAt: #postinstall put: '| bindings |
> bindings := SmalltalkWorkspace acceleratorKeyBindings.
> bindings at: ''Home'' put: #indecisiveHome.
> SmalltalkWorkspace acceleratorKeyBindings: bindings!!'.
> package basicScriptAt: #postuninstall put: '| bindings |
> bindings := SmalltalkWorkspace acceleratorKeyBindings.
> bindings removeKey: ''Home'' ifAbsent: [].
> SmalltalkWorkspace acceleratorKeyBindings: bindings!!'.
>
> package methodNames
>  add: #SmalltalkWorkspace -> #indecisiveHome;
>  yourself.
>
> package binaryGlobalNames: (Set new
>  yourself).
>
> package globalAliases: (Set new
>  yourself).
>
> package allResourceNames: (Set new
>  yourself).
>
> package setPrerequisites: (IdentitySet new
>  add: '..\..\Dolphin\IDE\Base\Development System';
>  add: '..\..\Dolphin\Base\Dolphin';
>  yourself).
>
> package!
>
> "Class Definitions"!
>
>
> "Global Aliases"!
>
>
> "Loose Methods"!
>
> !SmalltalkWorkspace methodsFor!
>
> indecisiveHome
>  | caret line startOfLine |
>  caret := self view caretPosition.
>  caret = 1
>   ifTrue:
>    [Sound beep.
>    ^self].
>  line := self view lineFromPosition: caret.
>  startOfLine := self view positionAtLine: line.
>  self view caretPosition: (caret = startOfLine ifTrue: [1] ifFalse:
> [startOfLine])! !
> !SmalltalkWorkspace categoriesFor: #indecisiveHome!commands!public! !
>
> "End of package definition"!
>
> "Source Globals"!
>
> "Classes"!
>
> "Binary Globals"!
>
> "Resources"!
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Changing the environment

Blair McGlashan
"Sean Malloy" <[hidden email]> wrote in message
news:40585ad0$0$245$[hidden email]...
> Blair,
>
> How would you go about being able to move the caret between the start of
the
> line, and the start of text on the same line.
>
> Right now you hit home, and it takes you to the start of the line. Hit
home
> again, and it takes you to the start of the entire block of text.
>
> I'm trying to change it so it switches between startOfLine, and
startOfText
> (On the same line). I can't seem to find a way to check the amount of
> whitespaces in between the start of the line and the text. Checking for
> tabs, etc etc.
>
> Any ideas?

You'll have to search for the first non-blank character, something like what
I've pasted below.

Regards

Blair

-----------------------
!SmalltalkWorkspace methodsFor!

indecisiveHome
 | caret line startOfLine firstNonBlank stream |
 caret := self view caretPosition.
 line := self view lineFromPosition: caret.
 startOfLine := self view positionAtLine: line.
 firstNonBlank := startOfLine.
 "#textAtLine is a private method. Note the method comment is wrong, the
index is one-based"
 stream := (self view textAtLine: line) readStream.
 firstNonBlank := stream skipSeparators
  ifTrue: [startOfLine + stream position]
  ifFalse: [startOfLine].
 self view
  caretPosition: (caret = firstNonBlank ifTrue: [startOfLine] ifFalse:
[firstNonBlank])! !
!SmalltalkWorkspace categoriesFor: #indecisiveHome!commands!public! !


Reply | Threaded
Open this post in threaded view
|

Re: Changing the environment

Sean Malloy-2
Awesome. That works _exactly_ how I wanted. Fantastic!


"Blair McGlashan" <[hidden email]> wrote in message
news:c3a29d$25mbsc$[hidden email]...
> "Sean Malloy" <[hidden email]> wrote in message
>
news:40585ad0$0$245$[hidden email]...

> > Blair,
> >
> > How would you go about being able to move the caret between the start of
> the
> > line, and the start of text on the same line.
> >
> > Right now you hit home, and it takes you to the start of the line. Hit
> home
> > again, and it takes you to the start of the entire block of text.
> >
> > I'm trying to change it so it switches between startOfLine, and
> startOfText
> > (On the same line). I can't seem to find a way to check the amount of
> > whitespaces in between the start of the line and the text. Checking for
> > tabs, etc etc.
> >
> > Any ideas?
>
> You'll have to search for the first non-blank character, something like
what

> I've pasted below.
>
> Regards
>
> Blair
>
> -----------------------
> !SmalltalkWorkspace methodsFor!
>
> indecisiveHome
>  | caret line startOfLine firstNonBlank stream |
>  caret := self view caretPosition.
>  line := self view lineFromPosition: caret.
>  startOfLine := self view positionAtLine: line.
>  firstNonBlank := startOfLine.
>  "#textAtLine is a private method. Note the method comment is wrong, the
> index is one-based"
>  stream := (self view textAtLine: line) readStream.
>  firstNonBlank := stream skipSeparators
>   ifTrue: [startOfLine + stream position]
>   ifFalse: [startOfLine].
>  self view
>   caretPosition: (caret = firstNonBlank ifTrue: [startOfLine] ifFalse:
> [firstNonBlank])! !
> !SmalltalkWorkspace categoriesFor: #indecisiveHome!commands!public! !
>
>
>