下面列出了怎么用org.eclipse.ui.ISaveablePart的API类实例代码及写法,或者点击链接到github查看源代码。
public void createDirtyStateTracker() {
dirtyStateTracker = new DirtyStateTracker() {
@Override
public void propertyChanged(final Object source, final int propID) {
IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.getActiveEditor();
if (activeEditor instanceof ISaveablePart && propID == ISaveablePart.PROP_DIRTY) {
update();
if (item != null && !item.isDisposed()) {
item.setEnabled(((ISaveablePart) activeEditor).isDirty());
}
}
}
};
}
@Override
protected EvaluationResult evaluate(IEvaluationContext context) {
IWorkbenchWindow window = InternalHandlerUtil.getActiveWorkbenchWindow(context);
// no window? not active
if (window == null)
return EvaluationResult.FALSE;
WorkbenchPage page = (WorkbenchPage) window.getActivePage();
// no page? not active
if (page == null)
return EvaluationResult.FALSE;
// get saveable part
ISaveablePart saveablePart = getSaveablePart(context);
if (saveablePart == null)
return EvaluationResult.FALSE;
if (saveablePart instanceof ISaveablesSource) {
ISaveablesSource modelSource = (ISaveablesSource) saveablePart;
if (SaveableHelper.needsSave(modelSource))
return EvaluationResult.TRUE;
return EvaluationResult.FALSE;
}
if (saveablePart != null && saveablePart.isDirty())
return EvaluationResult.TRUE;
return EvaluationResult.FALSE;
}
@Override
public void partActivated(IWorkbenchPart part) {
if (part instanceof ISaveablePart) {
final DirtyStateTracker dirtyStateTracker = getDirtyStateTracker();
dirtyStateTracker.partActivated(part);
}
}
@Override
public void partBroughtToTop(IWorkbenchPart part) {
if (part instanceof ISaveablePart) {
final DirtyStateTracker dirtyStateTracker = getDirtyStateTracker();
dirtyStateTracker.partBroughtToTop(part);
}
}
@Override
public void partClosed(IWorkbenchPart part) {
if (part instanceof ISaveablePart) {
final DirtyStateTracker dirtyStateTracker = getDirtyStateTracker();
dirtyStateTracker.partClosed(part);
}
}
@Override
public void partDeactivated(IWorkbenchPart part) {
if (part instanceof ISaveablePart) {
final DirtyStateTracker dirtyStateTracker = getDirtyStateTracker();
dirtyStateTracker.partDeactivated(part);
}
}
@Override
public void partOpened(IWorkbenchPart part) {
if (part instanceof ISaveablePart) {
final DirtyStateTracker dirtyStateTracker = getDirtyStateTracker();
dirtyStateTracker.partOpened(part);
}
}
/**
* Finish save.
*
* @param monitor the monitor
* @param modelOK the model OK
*/
private void finishSave(IProgressMonitor monitor, boolean modelOK) {
if (modelOK) {
if (dirtyTypeNameHash.size() > 0)
jcasGen(monitor);
dirtyTypeNameHash.clear();
}
fileDirty = false;
firePropertyChange(ISaveablePart.PROP_DIRTY);
}
/**
* Sets the file dirty.
*/
public void setFileDirty() {
if (m_bIsInited) {
fileDirty = true;
// next is key
this.firePropertyChange(ISaveablePart.PROP_DIRTY);
}
}
@Override
public void run() {
IPath ignoreThrownExceptionsPath = PyExceptionBreakPointManager
.getInstance().ignoreCaughtExceptionsWhenThrownFrom
.getIgnoreThrownExceptionsPath();
File file = ignoreThrownExceptionsPath.toFile();
IEditorPart openFile = EditorUtils.openFile(file);
if (openFile instanceof ITextEditor) {
final ITextEditor textEditor = (ITextEditor) openFile;
IDocumentProvider documentProvider = textEditor.getDocumentProvider();
final IEditorInput input = openFile.getEditorInput();
if (documentProvider instanceof IStorageDocumentProvider) {
IStorageDocumentProvider storageDocumentProvider = (IStorageDocumentProvider) documentProvider;
// Make sure the file is seen as UTF-8.
storageDocumentProvider.setEncoding(input, "utf-8");
textEditor.doRevertToSaved();
}
if (textEditor instanceof ISaveablePart) {
IPropertyListener listener = new IPropertyListener() {
@Override
public void propertyChanged(Object source, int propId) {
if (propId == IWorkbenchPartConstants.PROP_DIRTY) {
if (source == textEditor) {
if (textEditor.getEditorInput() == input) {
if (!textEditor.isDirty()) {
PyExceptionBreakPointManager.getInstance().ignoreCaughtExceptionsWhenThrownFrom
.updateIgnoreThrownExceptions();
}
}
}
}
}
};
textEditor.addPropertyListener(listener);
}
}
// Code to provide a dialog to edit it (decided on opening the file instead).
// Collection<IgnoredExceptionInfo> ignoreThrownExceptionsForEdition = PyExceptionBreakPointManager.getInstance()
// .getIgnoreThrownExceptionsForEdition();
// HashMap<String, String> map = new HashMap<>();
// for (IgnoredExceptionInfo ignoredExceptionInfo : ignoreThrownExceptionsForEdition) {
// map.put(ignoredExceptionInfo.filename + ": " + ignoredExceptionInfo.line, ignoredExceptionInfo.contents);
// }
//
// EditIgnoredCaughtExceptionsDialog dialog = new EditIgnoredCaughtExceptionsDialog(EditorUtils.getShell(), map);
// int open = dialog.open();
// if (open == dialog.OK) {
// Map<String, String> result = dialog.getResult();
//
// } else {
// System.out.println("Cancel");
// }
}
@Override
protected ISaveablePart getSaveablePart() {
return null;
}
/**
* Creates a new script's document provider with the specified saveable
* part.
*
* @param part
* the saveable part.
*/
public ScriptDocumentProvider( ISaveablePart part )
{
super( part );
}
/**
* Creates a new javascript's document provider with the specified saveable
* part.
*
* @param part
* the saveable part.
*/
public JSDocumentProvider( ISaveablePart part )
{
super( part );
}
/**
* Creates a new document provider with the specified saveable part.
*
* @param part
* the saveable part.
*/
public StorageDocumentProvider( ISaveablePart part )
{
super( part );
}
/**
* Creates a new document provider with the specified saveable part.
*
* @param part
* the saveable part.
*/
public DocumentProvider( ISaveablePart part )
{
super( );
this.part = part;
}