[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.tools] Re: MultpageEditor Accelerator problem
|
- From: rr.cm@xxxxxxx (Ron)
- Date: Thu, 17 Apr 2003 17:40:30 +0000 (UTC)
- Newsgroups: eclipse.tools
- Organization: http://www.eclipse.org
- User-agent: NewsPortal 0.23
Hi Tobias,
Many, many thanks. This works perfectly (so far). I had tried this very
approach but didn't know about updateActionBars().
The only tricky part was figuring out how to get the menu 'set' at
startup. Calling pageChange() from createPages() fixed this. I
implemented the following in my MultipageEditorPart extension:
/**
* Creates the pages of the multi-page editor.
*/
protected void createPages()
{
createGraphPage();
getGraphEditor().setPageIndex(0);
createTextEditorPage();
getGraphEditor().setTextEditor( getTextEditor() );
pageChange(0); // <-- looks obvious now, took a while to figure out
}
My graph editor now has the setAccelerators() code that is called by
pageChange():
/**
* Set the accelerators as active for the correct editor page.
*
* @param aPageIndex Index of the current page.
*/
public void setAccelerators( int aPageIndex )
{
IKeyBindingService bind = getEditorSite().getKeyBindingService();
if (aPageIndex == mPageIndex)
{
// Stop actions from being sent to the embedded text editor.
bind.unregisterAction(
mTextEditor.getAction(ITextEditorActionConstants.CUT));
bind.unregisterAction(
mTextEditor.getAction(ITextEditorActionConstants.COPY));
bind.unregisterAction(
mTextEditor.getAction(ITextEditorActionConstants.PASTE));
bind.unregisterAction(
mTextEditor.getAction(ITextEditorActionConstants.UNDO));
bind.unregisterAction(
mTextEditor.getAction(ITextEditorActionConstants.REDO));
}
else
{
// Reconnect actions with text editor on page 1.
bind.registerAction(mTextEditor.getAction(ITextEditorActionConstants.CUT));
bind.registerAction(mTextEditor.getAction(ITextEditorActionConstants.COPY));
bind.registerAction(mTextEditor.getAction(ITextEditorActionConstants.PASTE));
bind.registerAction(mTextEditor.getAction(ITextEditorActionConstants.UNDO));
bind.registerAction(mTextEditor.getAction(ITextEditorActionConstants.REDO));
}
// Propagate changes.
getEditorSite().getActionBars().updateActionBars();
}
thanks again!
Ron
Tobias wrote:
> Hi Ron,
> I run into quite the same problem earlier this week. I don't know if the
> described behaviour is a bug or if it is intended and we just do not
> understand how to handle it correctly. Whatsoever, I finally implemented
> the following work-around:
> private void setCopyPasteBinding(boolean routeToEditor) {
> IKeyBindingService bind = getEditorSite().getKeyBindingService();
> if (!routeToEditor) {
> // Stop actions from being sent to the embedded text editor.
> bind.unregisterAction(
> editor.getAction(ITextEditorActionConstants.CUT));
> bind.unregisterAction(
> editor.getAction(ITextEditorActionConstants.COPY));
> bind.unregisterAction(
> editor.getAction(ITextEditorActionConstants.PASTE));
> bind.unregisterAction(
> editor.getAction(ITextEditorActionConstants.SELECT_ALL));
> bind.unregisterAction(
> editor.getAction(ITextEditorActionConstants.DELETE));
> } else {
> // Reconnect actions with text editor on page 0.
> bind.registerAction(
> editor.getAction(ITextEditorActionConstants.CUT));
> bind.registerAction(
> editor.getAction(ITextEditorActionConstants.COPY));
> bind.registerAction(
> editor.getAction(ITextEditorActionConstants.PASTE));
> bind.registerAction(
> editor.getAction(ITextEditorActionConstants.SELECT_ALL));
> bind.registerAction(
> editor.getAction(ITextEditorActionConstants.DELETE));
> }
> // Propagate changes.
> getActionBars().updateActionBars();
> }
> Call this whenever the displayed page changes, and COPY/PASTE should work
> again. At least for me it does..
> Good luck,
> Tobias