use of com.twinsoft.convertigo.beans.core.ISharedComponent in project convertigo by convertigo.
the class NgxUIComponentTreeObject method editCompTsFile.
public void editCompTsFile() {
if (!(getObject() instanceof ISharedComponent)) {
return;
}
final UISharedComponent comp = (UISharedComponent) getObject();
try {
// Refresh project resource
String projectName = comp.getProject().getName();
IProject project = ConvertigoPlugin.getDefault().getProjectPluginResource(projectName);
project.refreshLocal(IResource.DEPTH_INFINITE, null);
// Close editor
String filePath = comp.getProject().getMobileBuilder().getTempTsRelativePath((ISharedComponent) comp);
IFile file = project.getFile(filePath);
closeComponentFileEditor(file);
// Write temporary file
comp.getProject().getMobileBuilder().writeCompTempTs((ISharedComponent) comp);
file.refreshLocal(IResource.DEPTH_ZERO, null);
// Open file in editor
if (file.exists()) {
IEditorInput input = new ComponentFileEditorInput(file, comp);
if (input != null) {
IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
String editorId = desc.getId();
IEditorPart editorPart = activePage.openEditor(input, editorId);
addMarkers(file, editorPart);
editorPart.addPropertyListener(new IPropertyListener() {
boolean isFirstChange = false;
@Override
public void propertyChanged(Object source, int propId) {
if (source instanceof ITextEditor) {
if (propId == IEditorPart.PROP_DIRTY) {
if (!isFirstChange) {
isFirstChange = true;
return;
}
isFirstChange = false;
ITextEditor editor = (ITextEditor) source;
IDocumentProvider dp = editor.getDocumentProvider();
IDocument doc = dp.getDocument(editor.getEditorInput());
FormatedContent scriptContent = new FormatedContent(MobileBuilder.getMarkers(doc.get()));
NgxUIComponentTreeObject.this.setPropertyValue("scriptContent", scriptContent);
}
}
}
});
}
}
} catch (Exception e) {
ConvertigoPlugin.logException(e, "Unable to open typescript file for component '" + comp.getName() + "'!");
}
}
Aggregations