Home | History | Annotate | Download | only in manifest
      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      3  *
      4  * Licensed under the Eclipse Public License, Version 1.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.eclipse.org/org/documents/epl-v10.php
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.ide.eclipse.adt.internal.editors.manifest;
     18 
     19 import org.eclipse.jface.action.IAction;
     20 import org.eclipse.ui.IActionBars;
     21 import org.eclipse.ui.IEditorPart;
     22 import org.eclipse.ui.actions.ActionFactory;
     23 import org.eclipse.ui.ide.IDEActionFactory;
     24 import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
     25 import org.eclipse.ui.texteditor.ITextEditor;
     26 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
     27 
     28 /**
     29  * Manages the installation/deinstallation of global actions for multi-page
     30  * editors. Responsible for the redirection of global actions to the active
     31  * editor. Multi-page contributor replaces the contributors for the individual
     32  * editors in the multi-page editor.
     33  *
     34  * TODO: Doesn't look like we need this. Remove it if not needed.
     35  * @deprecated
     36  */
     37 final class ManifestEditorContributor extends MultiPageEditorActionBarContributor {
     38     private IEditorPart mActiveEditorPart;
     39 
     40     /**
     41      * Creates a multi-page contributor.
     42      *
     43      * Marked as Private so it can't be instanciated. This is a cheap way to make sure
     44      * it's not being used. As noted in constructor, should be removed if not used.
     45      * @deprecated
     46      */
     47     private ManifestEditorContributor() {
     48         super();
     49     }
     50 
     51     /**
     52      * Returns the action registed with the given text editor.
     53      *
     54      * @return IAction or null if editor is null.
     55      */
     56     protected IAction getAction(ITextEditor editor, String actionID) {
     57         return (editor == null ? null : editor.getAction(actionID));
     58     }
     59 
     60     /*
     61      * (non-JavaDoc) Method declared in
     62      * AbstractMultiPageEditorActionBarContributor.
     63      */
     64 
     65     @Override
     66     public void setActivePage(IEditorPart part) {
     67         if (mActiveEditorPart == part)
     68             return;
     69 
     70         mActiveEditorPart = part;
     71 
     72         IActionBars actionBars = getActionBars();
     73         if (actionBars != null) {
     74 
     75             ITextEditor editor =
     76                 (part instanceof ITextEditor) ? (ITextEditor)part : null;
     77 
     78             actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(),
     79                     getAction(editor, ITextEditorActionConstants.DELETE));
     80             actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(),
     81                     getAction(editor, ITextEditorActionConstants.UNDO));
     82             actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(),
     83                     getAction(editor, ITextEditorActionConstants.REDO));
     84             actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(),
     85                     getAction(editor, ITextEditorActionConstants.CUT));
     86             actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(),
     87                     getAction(editor, ITextEditorActionConstants.COPY));
     88             actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(),
     89                     getAction(editor, ITextEditorActionConstants.PASTE));
     90             actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(),
     91                     getAction(editor, ITextEditorActionConstants.SELECT_ALL));
     92             actionBars.setGlobalActionHandler(ActionFactory.FIND.getId(),
     93                     getAction(editor, ITextEditorActionConstants.FIND));
     94             actionBars.setGlobalActionHandler(
     95                     IDEActionFactory.BOOKMARK.getId(), getAction(editor,
     96                             IDEActionFactory.BOOKMARK.getId()));
     97             actionBars.updateActionBars();
     98         }
     99     }
    100 }
    101