This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #59: codefolding persistence on large files
- Loading branch information
Showing
4 changed files
with
68 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...se.cfml/src/org/cfeclipse/cfml/editors/codefolding/CodeFoldingResourceChangeReporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.cfeclipse.cfml.editors.codefolding; | ||
|
||
import java.io.File; | ||
|
||
import org.eclipse.core.resources.IFile; | ||
import org.eclipse.core.resources.IResource; | ||
import org.eclipse.core.resources.IResourceChangeEvent; | ||
import org.eclipse.core.resources.IResourceChangeListener; | ||
import org.eclipse.core.resources.IResourceDelta; | ||
import org.eclipse.core.resources.IResourceDeltaVisitor; | ||
import org.eclipse.core.runtime.CoreException; | ||
|
||
public class CodeFoldingResourceChangeReporter implements IResourceChangeListener { | ||
|
||
public void resourceChanged(IResourceChangeEvent event) { | ||
try { | ||
if (event.getType() == IResourceChangeEvent.POST_CHANGE) { | ||
IResourceDelta changes = event.getDelta(); | ||
changes.accept(new IResourceDeltaVisitor() { | ||
public boolean visit(IResourceDelta change) { | ||
if (change.getResource().getType() == IResource.FILE) { | ||
// rename the fold state file | ||
if (change.getMovedToPath() != null) { | ||
File foldFile = CodeFoldingSetter.getFoldStateFile((IFile) change.getResource()); | ||
if (foldFile.exists()) { | ||
String newName = change.getMovedToPath().toFile().getName() + "_folds"; | ||
String oldName = foldFile.toPath().toFile().getName(); | ||
String oldPath = foldFile.toPath().toFile().toString(); | ||
String newPath = oldPath.replace(oldName, newName); | ||
foldFile.toPath().toFile().renameTo(new File(newPath)); | ||
} | ||
} | ||
if (change.getKind() == IResourceDelta.REMOVED && change.getMovedToPath() == null | ||
&& change.getMovedFromPath() == null) { | ||
File foldFile = CodeFoldingSetter.getFoldStateFile((IFile) change.getResource()); | ||
if (foldFile.exists()) { | ||
foldFile.delete(); | ||
} | ||
} | ||
} | ||
; | ||
return true; | ||
} | ||
}); | ||
} | ||
|
||
} catch (CoreException temp) { | ||
System.err.println("Caught a CoreException"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters