Lines 17-22
Link Here
|
17 |
import java.util.Iterator; |
17 |
import java.util.Iterator; |
18 |
|
18 |
|
19 |
import org.eclipse.core.runtime.Assert; |
19 |
import org.eclipse.core.runtime.Assert; |
|
|
20 |
import org.eclipse.core.runtime.ListenerList; |
20 |
import org.eclipse.jface.action.Action; |
21 |
import org.eclipse.jface.action.Action; |
21 |
import org.eclipse.jface.action.IAction; |
22 |
import org.eclipse.jface.action.IAction; |
22 |
import org.eclipse.jface.resource.JFaceResources; |
23 |
import org.eclipse.jface.resource.JFaceResources; |
Lines 44-49
Link Here
|
44 |
import org.eclipse.swt.events.FocusListener; |
45 |
import org.eclipse.swt.events.FocusListener; |
45 |
import org.eclipse.swt.events.MouseAdapter; |
46 |
import org.eclipse.swt.events.MouseAdapter; |
46 |
import org.eclipse.swt.events.MouseEvent; |
47 |
import org.eclipse.swt.events.MouseEvent; |
|
|
48 |
import org.eclipse.swt.graphics.Color; |
47 |
import org.eclipse.swt.graphics.Font; |
49 |
import org.eclipse.swt.graphics.Font; |
48 |
import org.eclipse.swt.graphics.Point; |
50 |
import org.eclipse.swt.graphics.Point; |
49 |
import org.eclipse.swt.widgets.Composite; |
51 |
import org.eclipse.swt.widgets.Composite; |
Lines 71-76
Link Here
|
71 |
*/ |
73 |
*/ |
72 |
public class RichTextEditor { |
74 |
public class RichTextEditor { |
73 |
|
75 |
|
|
|
76 |
public enum State { |
77 |
DEFAULT, BROWSER, EDITOR, PREVIEW; |
78 |
}; |
79 |
|
80 |
public static class StateChangedEvent { |
81 |
|
82 |
public State state; |
83 |
|
84 |
} |
85 |
|
86 |
public interface StateChangedListener { |
87 |
|
88 |
public void stateChanged(StateChangedEvent event); |
89 |
|
90 |
} |
91 |
|
74 |
public class ViewSourceAction extends Action { |
92 |
public class ViewSourceAction extends Action { |
75 |
|
93 |
|
76 |
public ViewSourceAction() { |
94 |
public ViewSourceAction() { |
Lines 141-146
Link Here
|
141 |
|
159 |
|
142 |
private boolean stickyPreview = false; |
160 |
private boolean stickyPreview = false; |
143 |
|
161 |
|
|
|
162 |
private final ListenerList stateChangedListeners = new ListenerList(ListenerList.IDENTITY); |
163 |
|
144 |
public RichTextEditor(TaskRepository repository, int style) { |
164 |
public RichTextEditor(TaskRepository repository, int style) { |
145 |
this(repository, style, null, null); |
165 |
this(repository, style, null, null); |
146 |
} |
166 |
} |
Lines 338-343
Link Here
|
338 |
return mode; |
358 |
return mode; |
339 |
} |
359 |
} |
340 |
|
360 |
|
|
|
361 |
/** |
362 |
* @return The preview source viewer or null if there is no extension available or the attribute is read only |
363 |
*/ |
341 |
private SourceViewer getPreviewViewer() { |
364 |
private SourceViewer getPreviewViewer() { |
342 |
if (extension == null) { |
365 |
if (extension == null) { |
343 |
return null; |
366 |
return null; |
Lines 356-361
Link Here
|
356 |
previewViewer.getControl().setData(EditorUtil.KEY_TOGGLE_TO_MAXIMIZE_ACTION, |
379 |
previewViewer.getControl().setData(EditorUtil.KEY_TOGGLE_TO_MAXIMIZE_ACTION, |
357 |
editorViewer.getControl().getData(EditorUtil.KEY_TOGGLE_TO_MAXIMIZE_ACTION)); |
380 |
editorViewer.getControl().getData(EditorUtil.KEY_TOGGLE_TO_MAXIMIZE_ACTION)); |
358 |
installMenu(previewViewer.getControl(), editorViewer.getControl().getMenu()); |
381 |
installMenu(previewViewer.getControl(), editorViewer.getControl().getMenu()); |
|
|
382 |
//set the background color in case there is an incoming to show |
383 |
previewViewer.getTextWidget().setBackground(editorComposite.getBackground()); |
359 |
} |
384 |
} |
360 |
return previewViewer; |
385 |
return previewViewer; |
361 |
} |
386 |
} |
Lines 527-532
Link Here
|
527 |
} |
552 |
} |
528 |
editorComposite.layout(); |
553 |
editorComposite.layout(); |
529 |
control.setFocus(); |
554 |
control.setFocus(); |
|
|
555 |
fireStateChangedEvent(); |
556 |
} |
557 |
|
558 |
protected void fireStateChangedEvent() { |
559 |
if (stateChangedListeners.isEmpty()) { |
560 |
return; |
561 |
} |
562 |
StateChangedEvent event = new StateChangedEvent(); |
563 |
if (defaultViewer != null && defaultViewer.getControl() == editorLayout.topControl) { |
564 |
event.state = State.DEFAULT; |
565 |
} else if (defaultViewer != null && editorViewer.getControl() == editorLayout.topControl) { |
566 |
event.state = State.EDITOR; |
567 |
} else if (previewViewer != null && previewViewer.getControl() == editorLayout.topControl) { |
568 |
event.state = State.PREVIEW; |
569 |
} else if (browserViewer != null && browserViewer.getControl() == editorLayout.topControl) { |
570 |
event.state = State.BROWSER; |
571 |
} |
572 |
Object[] listeners = stateChangedListeners.getListeners(); |
573 |
for (Object listener : listeners) { |
574 |
((StateChangedListener) listener).stateChanged(event); |
575 |
} |
530 |
} |
576 |
} |
531 |
|
577 |
|
532 |
/** |
578 |
/** |
Lines 561-567
Link Here
|
561 |
} |
607 |
} |
562 |
|
608 |
|
563 |
private void showPreview(boolean sticky) { |
609 |
private void showPreview(boolean sticky) { |
564 |
if (!isReadOnly()) { |
610 |
if (!isReadOnly() && getPreviewViewer() != null) { |
565 |
show(getPreviewViewer()); |
611 |
show(getPreviewViewer()); |
566 |
stickyPreview = sticky; |
612 |
stickyPreview = sticky; |
567 |
} |
613 |
} |
Lines 585-596
Link Here
|
585 |
} |
631 |
} |
586 |
|
632 |
|
587 |
public void enableAutoTogglePreview() { |
633 |
public void enableAutoTogglePreview() { |
588 |
if (getPreviewViewer() != null) { |
634 |
if (!isReadOnly() && getPreviewViewer() != null) { |
589 |
show(getPreviewViewer()); |
635 |
show(getPreviewViewer()); |
590 |
previewViewer.getTextWidget().addMouseListener(new MouseAdapter() { |
636 |
previewViewer.getTextWidget().addMouseListener(new MouseAdapter() { |
591 |
@Override |
637 |
@Override |
592 |
public void mouseUp(MouseEvent e) { |
638 |
public void mouseUp(MouseEvent e) { |
593 |
if (!stickyPreview) { |
639 |
if (e.count == 2 && !stickyPreview) { |
594 |
int offset = previewViewer.getTextWidget().getCaretOffset(); |
640 |
int offset = previewViewer.getTextWidget().getCaretOffset(); |
595 |
showEditor(); |
641 |
showEditor(); |
596 |
editorViewer.getTextWidget().setCaretOffset(offset); |
642 |
editorViewer.getTextWidget().setCaretOffset(offset); |
Lines 609-612
Link Here
|
609 |
} |
655 |
} |
610 |
} |
656 |
} |
611 |
|
657 |
|
|
|
658 |
/** |
659 |
* Sets the background color for all instantiated viewers |
660 |
* |
661 |
* @param color |
662 |
*/ |
663 |
public void setBackground(Color color) { |
664 |
if (editorComposite != null && !editorComposite.isDisposed()) { |
665 |
editorComposite.setBackground(color); |
666 |
for (Control child : editorComposite.getChildren()) { |
667 |
child.setBackground(color); |
668 |
} |
669 |
} |
670 |
} |
671 |
|
672 |
public void addStateChangedListener(StateChangedListener listener) { |
673 |
stateChangedListeners.add(listener); |
674 |
} |
675 |
|
676 |
public void removeStateChangedListener(StateChangedListener listener) { |
677 |
stateChangedListeners.remove(listener); |
678 |
} |
679 |
|
612 |
} |
680 |
} |