eclipse plugin: add proper code for showing wml macro definition code
This commit is contained in:
parent
de8cf79285
commit
985285e8dc
5 changed files with 178 additions and 33 deletions
|
@ -0,0 +1,39 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 by Timotei Dolean <timotei21@gmail.com>
|
||||
*
|
||||
* This program and the accompanying materials are made available
|
||||
* under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.wesnoth.ui.labeling.wmldoc;
|
||||
|
||||
import org.eclipse.swt.custom.StyleRange;
|
||||
|
||||
/**
|
||||
* An interface used to provide WML documentation
|
||||
*/
|
||||
public interface IWMLDocProvider
|
||||
{
|
||||
/**
|
||||
* Gets the title of the wmldoc dialog
|
||||
* @return
|
||||
*/
|
||||
public String getTitle();
|
||||
/**
|
||||
* Gets the text to be written in the info statusbar
|
||||
* @return
|
||||
*/
|
||||
public String getInfoText();
|
||||
/**
|
||||
* Gets the contents to be written into the
|
||||
* styledtext control of the wmldoc dialog
|
||||
* @return
|
||||
*/
|
||||
public String getContents();
|
||||
/**
|
||||
* Gets an array of StyleRange used to style the contents
|
||||
* @return
|
||||
*/
|
||||
public StyleRange[] getStyleRanges();
|
||||
}
|
|
@ -25,6 +25,7 @@ import org.wesnoth.ui.WMLUtil;
|
|||
import org.wesnoth.wML.WMLMacroCall;
|
||||
|
||||
import wesnoth_eclipse_plugin.Logger;
|
||||
import wesnoth_eclipse_plugin.preprocessor.Define;
|
||||
import wesnoth_eclipse_plugin.utils.ProjectUtils;
|
||||
|
||||
/**
|
||||
|
@ -56,14 +57,15 @@ public class WMLDocHandler extends AbstractHandler
|
|||
CompositeNode container = (CompositeNode)abstractNode.eContainer();
|
||||
if (container.getElement() instanceof WMLMacroCall) {
|
||||
WMLMacroCall macro = (WMLMacroCall)container.getElement();
|
||||
|
||||
if (ProjectUtils.getCacheForProject(WMLUtil.getActiveEditorFile().getProject())
|
||||
.getDefines().containsKey(macro.getName()))
|
||||
Define define = ProjectUtils.getCacheForProject(
|
||||
WMLUtil.getActiveEditorFile().getProject())
|
||||
.getDefines().get(macro.getName());
|
||||
if (define != null)
|
||||
{
|
||||
if (presenter_ == null) {
|
||||
presenter_ = new WMLDocInformationPresenter(editor.getSite().getShell(),
|
||||
macro.getName(),
|
||||
"Macro: " + "", "",
|
||||
presenter_ = new WMLDocInformationPresenter(
|
||||
editor.getSite().getShell(),
|
||||
new WMLDocMacro(define),
|
||||
positionAbsolute);
|
||||
presenter_.create();
|
||||
}
|
||||
|
|
|
@ -23,30 +23,30 @@ import org.eclipse.swt.layout.GridLayout;
|
|||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.wesnoth.ui.WMLUtil;
|
||||
|
||||
import wesnoth_eclipse_plugin.utils.ProjectUtils;
|
||||
|
||||
public class WMLDocInformationPresenter extends PopupDialog implements
|
||||
MouseListener, SelectionListener, MouseTrackListener, MouseMoveListener
|
||||
{
|
||||
private Point bounds_;
|
||||
private String currentMacroName_;
|
||||
private IWMLDocProvider currentDocProvider_;
|
||||
private Composite panel_;
|
||||
|
||||
public WMLDocInformationPresenter(Shell parent, String macroName,
|
||||
String titleText, String infoText, Point bounds)
|
||||
/**
|
||||
* Creates a new WMLDocumentation information presenter
|
||||
*/
|
||||
public WMLDocInformationPresenter(Shell parent, IWMLDocProvider docProvider,
|
||||
Point bounds)
|
||||
{
|
||||
super(parent, PopupDialog.INFOPOPUPRESIZE_SHELLSTYLE, true, true, true,
|
||||
true, false, titleText, infoText);
|
||||
false, false, "", "");
|
||||
bounds_ = bounds;
|
||||
currentMacroName_ = macroName;
|
||||
currentDocProvider_ = docProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Control createInfoTextArea(Composite parent)
|
||||
{
|
||||
//Add back& forward button
|
||||
//TODO: Add back& forward button
|
||||
return super.createInfoTextArea(parent);
|
||||
}
|
||||
|
||||
|
@ -60,12 +60,15 @@ public class WMLDocInformationPresenter extends PopupDialog implements
|
|||
GridLayout grid = new GridLayout();
|
||||
grid.numColumns = 5;
|
||||
panel_.setLayout(grid);
|
||||
StyledText text = new StyledText(panel_, SWT.None);
|
||||
|
||||
text.setText(ProjectUtils.getCacheForProject(WMLUtil.getActiveEditorFile().getProject())
|
||||
.getDefines().get(currentMacroName_).getValue());
|
||||
StyledText text = new StyledText(panel_, SWT.NONE);
|
||||
|
||||
setTitleText(currentDocProvider_.getTitle());
|
||||
setInfoText(currentDocProvider_.getInfoText());
|
||||
|
||||
text.setText(currentDocProvider_.getContents());
|
||||
text.setEditable(false);
|
||||
//text.setStyleRanges(ranges);
|
||||
text.setStyleRanges(currentDocProvider_.getStyleRanges());
|
||||
|
||||
text.setLayoutData(createDefaultGridData(4));
|
||||
text.addMouseListener(this);
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 by Timotei Dolean <timotei21@gmail.com>
|
||||
*
|
||||
* This program and the accompanying materials are made available
|
||||
* under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
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 wesnoth_eclipse_plugin.preprocessor.Define;
|
||||
|
||||
/**
|
||||
* Provides WMLDoc info for a macro
|
||||
*/
|
||||
public class WMLDocMacro implements IWMLDocProvider
|
||||
{
|
||||
private Define macro_;
|
||||
private String title_;
|
||||
private String contents_;
|
||||
private List<StyleRange> styleRanges_;
|
||||
|
||||
public WMLDocMacro(Define macro)
|
||||
{
|
||||
macro_ = macro;
|
||||
}
|
||||
|
||||
/**
|
||||
* A method used for lazly generating the documentation
|
||||
*/
|
||||
private void generateDoc()
|
||||
{
|
||||
if (title_ != null && contents_ != null && styleRanges_ != null)
|
||||
return;
|
||||
|
||||
styleRanges_ = new ArrayList<StyleRange>();
|
||||
title_ = "Macro: " + macro_.getName();
|
||||
StringBuilder content = new StringBuilder();
|
||||
|
||||
content.append("Definition:\n");
|
||||
addStyleRange(0, content.length() - 1, SWT.BOLD);
|
||||
content.append(macro_.getValue());
|
||||
|
||||
content.append('\n');
|
||||
if (macro_.getArguments().isEmpty() == false)
|
||||
{
|
||||
int len = content.length() - 1;
|
||||
content.append("Arguments:\n");
|
||||
|
||||
addStyleRange(len, content.length() - len - 1, SWT.BOLD);
|
||||
|
||||
len = content.length() - 1;
|
||||
for(String arg : macro_.getArguments())
|
||||
{
|
||||
content.append('\t' + arg + '\n');
|
||||
}
|
||||
addStyleRange(len, content.length() - len - 1, SWT.ITALIC);
|
||||
}
|
||||
|
||||
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 getContents()
|
||||
{
|
||||
generateDoc();
|
||||
return contents_;
|
||||
}
|
||||
|
||||
public StyleRange[] getStyleRanges()
|
||||
{
|
||||
generateDoc();
|
||||
return styleRanges_.toArray(new StyleRange[styleRanges_.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the associated macro
|
||||
* @return
|
||||
*/
|
||||
public Define getMacro()
|
||||
{
|
||||
return macro_;
|
||||
}
|
||||
|
||||
public String getInfoText()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 by Timotei Dolean <timotei21@gmail.com>
|
||||
*
|
||||
* This program and the accompanying materials are made available
|
||||
* under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.wesnoth.ui.labeling.wmldoc;
|
||||
|
||||
public class WMLMacroDocProvider
|
||||
{
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue