eclipse plugin: Rework a bit the WMLDoc and add information...
...about the Tag if it's created using lua
This commit is contained in:
parent
eb8a93c953
commit
35c8f7e3e6
4 changed files with 115 additions and 134 deletions
|
@ -44,10 +44,11 @@ public class WMLDocHandler extends AbstractHandler
|
|||
|
||||
editor.getDocument().readOnly(new IUnitOfWork.Void<XtextResource>()
|
||||
{
|
||||
private WMLDocInformationPresenter presenter_;
|
||||
@Override
|
||||
public void process(XtextResource resource) throws Exception
|
||||
{
|
||||
WMLDocInformationPresenter presenter_ = null;
|
||||
|
||||
ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
|
||||
Point positionRelative = editor.getInternalSourceViewer().getTextWidget().getLocationAtOffset(selection.getOffset());
|
||||
Point positionAbsolute = editor.getInternalSourceViewer().getTextWidget().toDisplay(positionRelative);
|
||||
|
@ -80,7 +81,8 @@ public class WMLDocHandler extends AbstractHandler
|
|||
{
|
||||
presenter_ = new WMLDocInformationPresenter(
|
||||
editor.getSite().getShell(),
|
||||
new WMLDocTag( installName, ( ( WMLTag ) grammarElement ).getName() ),
|
||||
new WMLDocTag( editedFile, installName,
|
||||
( ( WMLTag ) grammarElement ).getName() ),
|
||||
positionAbsolute);
|
||||
presenter_.create();
|
||||
}
|
||||
|
|
|
@ -11,12 +11,6 @@ package org.wesnoth.ui.labeling.wmldoc;
|
|||
import org.eclipse.jface.dialogs.PopupDialog;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.events.MouseEvent;
|
||||
import org.eclipse.swt.events.MouseListener;
|
||||
import org.eclipse.swt.events.MouseMoveListener;
|
||||
import org.eclipse.swt.events.MouseTrackListener;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.events.SelectionListener;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
|
@ -24,8 +18,7 @@ import org.eclipse.swt.widgets.Composite;
|
|||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
public class WMLDocInformationPresenter extends PopupDialog implements
|
||||
MouseListener, SelectionListener, MouseTrackListener, MouseMoveListener
|
||||
public class WMLDocInformationPresenter extends PopupDialog
|
||||
{
|
||||
private Point bounds_;
|
||||
private IWMLDocProvider currentDocProvider_;
|
||||
|
@ -38,18 +31,13 @@ public class WMLDocInformationPresenter extends PopupDialog implements
|
|||
Point bounds)
|
||||
{
|
||||
super(parent, PopupDialog.INFOPOPUPRESIZE_SHELLSTYLE, true, true, true,
|
||||
false, false, "", ""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
false, false, docProvider.getTitle( ),
|
||||
docProvider.getInfoText( ) );
|
||||
|
||||
bounds_ = bounds;
|
||||
currentDocProvider_ = docProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Control createInfoTextArea(Composite parent)
|
||||
{
|
||||
//TODO: Add back& forward button
|
||||
return super.createInfoTextArea(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Control createDialogArea(Composite parent)
|
||||
{
|
||||
|
@ -63,17 +51,11 @@ public class WMLDocInformationPresenter extends PopupDialog implements
|
|||
|
||||
StyledText text = new StyledText(panel_, SWT.NONE);
|
||||
|
||||
setTitleText(currentDocProvider_.getTitle());
|
||||
setInfoText(currentDocProvider_.getInfoText());
|
||||
|
||||
text.setText(currentDocProvider_.getContents());
|
||||
text.setEditable(false);
|
||||
text.setStyleRanges(currentDocProvider_.getStyleRanges());
|
||||
|
||||
text.setLayoutData(createDefaultGridData(4));
|
||||
text.addMouseListener(this);
|
||||
text.addMouseTrackListener(this);
|
||||
text.addMouseMoveListener(this);
|
||||
return panel_;
|
||||
}
|
||||
|
||||
|
@ -85,46 +67,11 @@ public class WMLDocInformationPresenter extends PopupDialog implements
|
|||
gd.horizontalIndent = 5;
|
||||
return gd;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Point getInitialLocation(Point initialSize)
|
||||
{
|
||||
return bounds_;
|
||||
}
|
||||
|
||||
public void mouseMove(MouseEvent e)
|
||||
{
|
||||
}
|
||||
|
||||
public void mouseEnter(MouseEvent e)
|
||||
{
|
||||
}
|
||||
|
||||
public void mouseExit(MouseEvent e)
|
||||
{
|
||||
}
|
||||
|
||||
public void mouseHover(MouseEvent e)
|
||||
{
|
||||
}
|
||||
|
||||
public void widgetSelected(SelectionEvent e)
|
||||
{
|
||||
}
|
||||
|
||||
public void widgetDefaultSelected(SelectionEvent e)
|
||||
{
|
||||
}
|
||||
|
||||
public void mouseDoubleClick(MouseEvent e)
|
||||
{
|
||||
}
|
||||
|
||||
public void mouseDown(MouseEvent e)
|
||||
{
|
||||
}
|
||||
|
||||
public void mouseUp(MouseEvent e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,11 +11,12 @@ package org.wesnoth.ui.labeling.wmldoc;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.wesnoth.preprocessor.Define;
|
||||
import org.wesnoth.ui.Messages;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.StyleRange;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.wesnoth.preprocessor.Define;
|
||||
import org.wesnoth.ui.Messages;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -27,10 +28,12 @@ public class WMLDocMacro implements IWMLDocProvider
|
|||
private String title_;
|
||||
private String contents_;
|
||||
private List<StyleRange> styleRanges_;
|
||||
private boolean docGenerated_;
|
||||
|
||||
public WMLDocMacro(Define macro)
|
||||
{
|
||||
macro_ = macro;
|
||||
docGenerated_ = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,7 +41,7 @@ public class WMLDocMacro implements IWMLDocProvider
|
|||
*/
|
||||
private void generateDoc()
|
||||
{
|
||||
if (title_ != null && contents_ != null && styleRanges_ != null)
|
||||
if ( docGenerated_ )
|
||||
return;
|
||||
|
||||
styleRanges_ = new ArrayList<StyleRange>();
|
||||
|
@ -66,6 +69,8 @@ public class WMLDocMacro implements IWMLDocProvider
|
|||
}
|
||||
|
||||
contents_ = content.toString();
|
||||
|
||||
docGenerated_ = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,6 +116,8 @@ public class WMLDocMacro implements IWMLDocProvider
|
|||
|
||||
public String getInfoText()
|
||||
{
|
||||
return ""; //$NON-NLS-1$
|
||||
if ( macro_.getLocation( ) == null )
|
||||
return null;
|
||||
return "Defined in: " + macro_.getLocation( ) + " : " + macro_.getLineNum( );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,87 +11,112 @@ package org.wesnoth.ui.labeling.wmldoc;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.StyleRange;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.wesnoth.projects.ProjectUtils;
|
||||
import org.wesnoth.schema.SchemaParser;
|
||||
import org.wesnoth.ui.Messages;
|
||||
import org.wesnoth.wml.WMLTag;
|
||||
import org.wesnoth.wml.WmlFactory2;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.StyleRange;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
/**
|
||||
* Displays wml doc for a tag
|
||||
* [tag] or [/tag]
|
||||
* Displays wml doc for a tag [tag] or [/tag]
|
||||
*/
|
||||
public class WMLDocTag implements IWMLDocProvider
|
||||
{
|
||||
private WMLTag tag_;
|
||||
private String title_;
|
||||
private String contents_;
|
||||
private List<StyleRange> styleRanges_;
|
||||
private WMLTag tag_;
|
||||
private String title_;
|
||||
private String contents_;
|
||||
private List<StyleRange> styleRanges_;
|
||||
|
||||
public WMLDocTag( String installName, String name )
|
||||
private boolean docGenerated_;
|
||||
|
||||
public WMLDocTag( IFile currentFile, String installName, String name )
|
||||
{
|
||||
tag_ = SchemaParser.getInstance( installName ).getTags( ).get( name );
|
||||
|
||||
// try to get it from the Project Cache ( lua parsed ones )
|
||||
if ( tag_ == null ) {
|
||||
tag_ = ProjectUtils.getCacheForProject( currentFile.getProject( ) ).
|
||||
getWMLTags( ).get( name );
|
||||
}
|
||||
|
||||
// Create a default one
|
||||
if ( tag_ == null ) {
|
||||
tag_ = WmlFactory2.eINSTANCE.createWMLTag( name );
|
||||
}
|
||||
|
||||
docGenerated_ = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A method used for lazly generating the documentation
|
||||
*/
|
||||
private void generateDoc()
|
||||
{
|
||||
if ( docGenerated_ )
|
||||
return;
|
||||
|
||||
styleRanges_ = new ArrayList<StyleRange>( );
|
||||
|
||||
title_ = Messages.WMLDocTag_0 + tag_.getName( ) + "':"; //$NON-NLS-1$
|
||||
|
||||
contents_ = null;
|
||||
|
||||
if ( !tag_.get_Description( ).isEmpty( ) ) {
|
||||
StringBuilder content = new StringBuilder( );
|
||||
content.append( Messages.WMLDocTag_1 );
|
||||
addStyleRange( 0, content.length( ) - 1, SWT.BOLD );
|
||||
content.append( tag_.get_Description( ) ); //$NON-NLS-1$
|
||||
contents_ = content.toString( );
|
||||
}
|
||||
|
||||
docGenerated_ = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a style range to current list
|
||||
*
|
||||
* @param offset
|
||||
* @param length
|
||||
* @param style
|
||||
*/
|
||||
private void addStyleRange( int offset, int length, int style )
|
||||
{
|
||||
styleRanges_.add( new StyleRange( offset, length, Display.getDefault( ).getSystemColor( SWT.COLOR_INFO_FOREGROUND ), Display.getDefault( ).getSystemColor( SWT.COLOR_INFO_BACKGROUND ), style ) );
|
||||
}
|
||||
|
||||
public String getTitle()
|
||||
{
|
||||
generateDoc( );
|
||||
return title_;
|
||||
}
|
||||
|
||||
public String getInfoText()
|
||||
{
|
||||
tag_ = SchemaParser.getInstance( installName ).getTags().get(name);
|
||||
String infoText = "";
|
||||
if ( tag_.is_LuaBased( ) )
|
||||
infoText += "[Lua tag] ";
|
||||
|
||||
if ( ! tag_.get_DefinitionLocation( ).isEmpty( ) ) {
|
||||
infoText += "Defined in: " + tag_.get_DefinitionLocation( );
|
||||
infoText += " : " + tag_.get_DefinitionOffset( );
|
||||
}
|
||||
return infoText.isEmpty( ) ? null : infoText;
|
||||
}
|
||||
|
||||
/**
|
||||
* A method used for lazly generating the documentation
|
||||
*/
|
||||
private void generateDoc()
|
||||
{
|
||||
if (title_ != null && contents_ != null && styleRanges_ != null)
|
||||
return;
|
||||
public String getContents()
|
||||
{
|
||||
generateDoc( );
|
||||
return contents_;
|
||||
}
|
||||
|
||||
styleRanges_ = new ArrayList<StyleRange>();
|
||||
|
||||
if (tag_ == null)
|
||||
return;
|
||||
|
||||
title_ = Messages.WMLDocTag_0 + tag_.getName() + "':"; //$NON-NLS-1$
|
||||
|
||||
StringBuilder content = new StringBuilder();
|
||||
if ( !tag_.get_Description().isEmpty( ) )
|
||||
{
|
||||
content.append(Messages.WMLDocTag_1);
|
||||
addStyleRange(0, content.length() - 1, SWT.BOLD);
|
||||
content.append( tag_.get_Description() ); //$NON-NLS-1$
|
||||
}
|
||||
contents_ = content.toString();
|
||||
}
|
||||
|
||||
/** Adds a style range to current list
|
||||
*
|
||||
* @param offset
|
||||
* @param length
|
||||
* @param style
|
||||
*/
|
||||
private void addStyleRange(int offset, int length, int style)
|
||||
{
|
||||
styleRanges_.add(new StyleRange(offset, length,
|
||||
Display.getDefault().getSystemColor(SWT.COLOR_INFO_FOREGROUND),
|
||||
Display.getDefault().getSystemColor(SWT.COLOR_INFO_BACKGROUND),
|
||||
style));
|
||||
}
|
||||
|
||||
public String getTitle()
|
||||
{
|
||||
generateDoc();
|
||||
return title_;
|
||||
}
|
||||
|
||||
public String getInfoText()
|
||||
{
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public String getContents()
|
||||
{
|
||||
generateDoc();
|
||||
return contents_;
|
||||
}
|
||||
public StyleRange[] getStyleRanges()
|
||||
{
|
||||
generateDoc();
|
||||
return styleRanges_.toArray(new StyleRange[styleRanges_.size()]);
|
||||
}
|
||||
public StyleRange[] getStyleRanges()
|
||||
{
|
||||
generateDoc( );
|
||||
return styleRanges_.toArray( new StyleRange[styleRanges_.size( )] );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue