use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.
the class MarkupToEclipseToc method parse.
public String parse(String markupContent) {
if (markupLanguage == null) {
// $NON-NLS-1$
throw new IllegalStateException("Must set markupLanguage");
}
OutlineParser parser = new OutlineParser(markupLanguage);
OutlineItem root = parser.parse(markupContent);
return createToc(root);
}
use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.
the class OutlineDropTargetListener method getDropItems.
/**
* get the outline items being dropped, or null if there are none or if the event does not qualify for a drop.
*/
@SuppressWarnings("unchecked")
private List<OutlineItem> getDropItems(DropTargetEvent event) {
if (event.operations == DND.DROP_NONE || event.item == null) {
return null;
}
Object targetData = event.item.getData();
if (!(targetData instanceof OutlineItem)) {
return null;
}
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
List<?> list = structuredSelection.toList();
if (!list.isEmpty()) {
for (Object i : list) {
if (!(i instanceof OutlineItem)) {
return null;
}
}
return (List<OutlineItem>) list;
}
}
return null;
}
use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.
the class MoveSectionsCommand method doCommand.
@Override
protected void doCommand(IDocument document) throws BadLocationException {
// relocated.
for (int x = 0; x < items.size(); ++x) {
OutlineItem item = items.get(x);
for (int y = 0; y < x; ++y) {
OutlineItem previousItem = items.get(y);
if (previousItem.contains(item)) {
items.remove(x);
--x;
break;
} else if (item.contains(previousItem)) {
items.remove(y);
--x;
--y;
}
}
}
if (items.size() > 1) {
Collections.sort(items, new OffsetComparator());
}
final Section[] sections = new Section[items.size()];
for (int x = 0; x < items.size(); ++x) {
OutlineItem item = items.get(x);
sections[x] = new Section(item.getOffset(), item.getSectionLength());
}
int insertLocation = target.getOffset();
if (location == InsertLocation.WITHIN) {
List<OutlineItem> children = target.getChildren();
if (children.isEmpty()) {
insertLocation += target.getLength();
// insert at the first position found after the header text and any following newlines
while (insertLocation < document.getLength()) {
char c = document.getChar(insertLocation);
if (c == '\r' || c == '\n') {
++insertLocation;
} else {
break;
}
}
} else {
// In this case we handle within as before the first child. Even though this may
// be somewhat non-intuitive, it actually makes sense. Without this we would see
// text content after the target heading but before the first child be magically appended
// to the end of the dropped items -- which in almost all cases is undesirable.
insertLocation = children.get(0).getOffset();
}
} else if (location == InsertLocation.AFTER) {
// insert afte the section denoted by the heading
insertLocation += target.getSectionLength();
}
String twoNewlines = Text.DELIMITER + Text.DELIMITER;
for (int x = 0; x < sections.length; ++x) {
Section section = sections[x];
String text = document.get(section.offset, section.length);
// $NON-NLS-1$
document.replace(section.offset, section.length, "");
// whitespace hack: if the section we're moving doesn't end with a blank line
// then we add one.
int adjustmentFactor = 0;
if (!text.endsWith(twoNewlines)) {
text += twoNewlines;
adjustmentFactor = twoNewlines.length();
section.length += adjustmentFactor;
}
if (section.offset < insertLocation) {
insertLocation -= section.length;
}
final int insertedLocation = insertLocation;
document.replace(insertedLocation, 0, text);
insertLocation += section.length;
// not be adjusted because we first cut and then pasted
for (int y = x + 1; y < sections.length; ++y) {
Section section2 = sections[y];
if (section2.offset < insertedLocation) {
section2.offset -= section.length;
} else if (adjustmentFactor > 0) {
section2.offset += adjustmentFactor;
}
}
}
}
use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.
the class WikiTextSourceEditor method updateOutline.
private void updateOutline() {
if (!outlineDirty) {
return;
}
if (getSourceViewer().getTextWidget().isDisposed()) {
return;
}
// we maintain the outline even if the outline page is not in use, which allows us to use the outline for
// content assist and other things
MarkupLanguage markupLanguage = getMarkupLanguage();
if (markupLanguage == null) {
return;
}
final MarkupLanguage language = markupLanguage.clone();
final Display display = getSourceViewer().getTextWidget().getDisplay();
final String content = document.get();
final int contentGeneration;
synchronized (WikiTextSourceEditor.this) {
contentGeneration = documentGeneration;
initializeOutlineParser();
}
// we parse the outline in another thread so that the UI remains responsive
Job parseOutlineJob = new // $NON-NLS-1$
Job(// $NON-NLS-1$
WikiTextSourceEditor.class.getSimpleName() + "#updateOutline") {
@Override
protected IStatus run(IProgressMonitor monitor) {
outlineParser.setMarkupLanguage(language);
if (shouldCancel()) {
return Status.CANCEL_STATUS;
}
final OutlineItem rootItem = outlineParser.parse(content);
if (shouldCancel()) {
return Status.CANCEL_STATUS;
}
display.asyncExec(new Runnable() {
public void run() {
updateOutline(contentGeneration, rootItem);
}
});
return Status.OK_STATUS;
}
private boolean shouldCancel() {
synchronized (WikiTextSourceEditor.this) {
if (contentGeneration != documentGeneration) {
return true;
}
}
return false;
}
};
parseOutlineJob.setPriority(Job.INTERACTIVE);
parseOutlineJob.setSystem(true);
parseOutlineJob.schedule();
}
use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.
the class WikiTextSourceEditor method updateOutlineNow.
private void updateOutlineNow() {
if (!outlineDirty) {
return;
}
if (getSourceViewer().getTextWidget().isDisposed()) {
return;
}
// we maintain the outline even if the outline page is not in use, which allows us to use the outline for
// content assist and other things
MarkupLanguage markupLanguage = getMarkupLanguage();
if (markupLanguage == null) {
return;
}
final MarkupLanguage language = markupLanguage.clone();
final String content = document.get();
final int contentGeneration;
synchronized (WikiTextSourceEditor.this) {
contentGeneration = documentGeneration;
initializeOutlineParser();
}
outlineParser.setMarkupLanguage(language);
OutlineItem rootItem = outlineParser.parse(content);
updateOutline(contentGeneration, rootItem);
}
Aggregations