Author: timotei
Date: Sat Aug  6 23:09:11 2011
New Revision: 50627

URL: http://svn.gna.org/viewcvs/wesnoth?rev=50627&view=rev
Log:
eclipse plugin: Rework a bit the WMLDoc and add
information about the Tag if it's created using lua

Modified:
    
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocHandler.java
    
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocInformationPresenter.java
    
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocMacro.java
    
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocTag.java

Modified: 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocHandler.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocHandler.java?rev=50627&r1=50626&r2=50627&view=diff
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocHandler.java
 (original)
+++ 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocHandler.java
 Sat Aug  6 23:09:11 2011
@@ -44,10 +44,11 @@
 
             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 @@
                         {
                             presenter_ = new WMLDocInformationPresenter(
                                     editor.getSite().getShell(),
-                                    new WMLDocTag( installName, ( ( WMLTag ) 
grammarElement ).getName() ),
+                                    new WMLDocTag( editedFile, installName,
+                                            ( ( WMLTag ) grammarElement 
).getName() ),
                                     positionAbsolute);
                             presenter_.create();
                         }

Modified: 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocInformationPresenter.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocInformationPresenter.java?rev=50627&r1=50626&r2=50627&view=diff
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocInformationPresenter.java
 (original)
+++ 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocInformationPresenter.java
 Sat Aug  6 23:09:11 2011
@@ -11,12 +11,6 @@
 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.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,16 +31,11 @@
                                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
@@ -63,17 +51,11 @@
 
                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 @@
                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)
-       {
-       }
 }
 

Modified: 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocMacro.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocMacro.java?rev=50627&r1=50626&r2=50627&view=diff
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocMacro.java
 (original)
+++ 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocMacro.java
 Sat Aug  6 23:09:11 2011
@@ -11,11 +11,12 @@
 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 @@
        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 @@
         */
        private void generateDoc()
        {
-               if (title_ != null && contents_ != null && styleRanges_ != null)
+               if ( docGenerated_ )
                        return;
 
                styleRanges_ = new ArrayList<StyleRange>();
@@ -66,6 +69,8 @@
                }
 
                contents_ = content.toString();
+
+               docGenerated_ = true;
        }
 
        /**
@@ -111,6 +116,8 @@
 
        public String getInfoText()
        {
-               return ""; //$NON-NLS-1$
+           if ( macro_.getLocation( ) == null )
+               return null;
+               return "Defined in: " + macro_.getLocation( ) + " : " + 
macro_.getLineNum( );
        }
 }

Modified: 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocTag.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocTag.java?rev=50627&r1=50626&r2=50627&view=diff
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocTag.java
 (original)
+++ 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocTag.java
 Sat Aug  6 23:09:11 2011
@@ -11,87 +11,112 @@
 import java.util.ArrayList;
 import java.util.List;
 
+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;
-import org.wesnoth.schema.SchemaParser;
-import org.wesnoth.ui.Messages;
-import org.wesnoth.wml.WMLTag;
 
 /**
- * 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( )] );
+    }
 }


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to