首页 > 代码库 > 5.27save
5.27save
public void doSave(IProgressMonitor monitor) { // TODO Auto-generated method stub performSave(monitor, getEditorInput()); 自定义的一个save函数,作用是? getCommandStack().markSaveLocation();
Marks the last executed or redone Command as the point at which the changes were saved. Calculation of isDirty()
will be based on this checkpoint.
}
public void doSaveAs() { // TODO Auto-generated method stub Shell shell = getSite().getShell(); final IEditorInput input = getEditorInput();IEditorInput是什么? SaveAsDialog dialog = new SaveAsDialog(shell);建立一个save as的dialog IFile original = (input instanceof IFileEditorInput) ? ((IFileEditorInput) input).getFile(): null; if (original != null){ dialog.setOriginalFile(original);} dialog.create(); 这个是用来做什么?
creates this window‘s widgetry in a new top-level shell.
The default implementation of this framework method creates this window‘s shell (by calling createShell
),
and its controls (by calling createContents
),
then initializes this window‘s shell bounds (by calling initializeBounds
).
int result = dialog.open();返回值是ok或者cancel if (result == Window.CANCEL) { return;这个return到哪里去? }
IPath filePath = dialog.getResult();the path, ornull
if Cancel was pressed IFile file = null;
if (filePath == null) { return; } else { file = ResourcesPlugin.getWorkspace().getRoot().getFile(filePath);通过路径找到文件。 } if (input.exists()) { } else { dialog.setErrorMessage(null); dialog.setMessage(WARN_FILEEXIST, IMessageProvider.WARNING); return; } if(file.exists()){ }else{ try { file.create(ResourceURLHelper.getNullInputStream(), true, null); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } } DiagramEditorInput newInput = new DiagramEditorInput(file.getLocation()); performSave(getProgressMonitor(),newInput); }
public boolean isSaveAsAllowed() { // TODO Auto-generated method stub return true; }
private void performSave(IProgressMonitor monitor, IEditorInput input) { if (diagram == null) return; 同样的问题,return到哪里去? diagram.doSaveXML();自定义save函数 Document xmlTree = diagram.getDiagramDoc();自定义函数 if (xmlTree == null) return; IFile file = ResourceUtil.getFile(getEditorInput()); OutputFormat format = OutputFormat.createPrettyPrint(); try { FileWriter fileWriter; fileWriter = new FileWriter((String) input.getAdapter(Path.class)); XMLWriter writer = new XMLWriter(fileWriter, format); writer.write(xmlTree); writer.close(); if (file != null) { file.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor()); } } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。