Skip to content

Commit

Permalink
In the outline page overload methods now have a different decoration …
Browse files Browse the repository at this point in the history
…and it's possible to hide them.
  • Loading branch information
fabioz committed Oct 1, 2023
1 parent 6eb37eb commit 8c4e329
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class UIConstants {
public static final String MAGIC_OBJECT_ICON = "icons/magic_co.gif";
public static final String STATIC_MEMBER_HIDE_ICON = "icons/static_co.gif";
public static final String FIELDS_HIDE_ICON = "icons/fields_co.gif";
public static final String STATIC_MEMBER_HIDE_OVERLOADS = "icons/overload_co.gif";

//Decorations
public static final String PRIVATE_ICON = "icons/private_obj.gif"; //__XXX
Expand All @@ -46,6 +47,7 @@ public class UIConstants {

public static final String DECORATION_CLASS = "icons/decoration_class_obj.png";
public static final String DECORATION_STATIC = "icons/decoration_static_obj.png";
public static final String DECORATION_OVERLOAD = "icons/decoration_overload_obj.png";

// Actions
public static final String SYNC_WITH_EDITOR = "icons/sync_ed.gif";
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Licensed under the terms of the Eclipse Public License (EPL).
* Please see the license.txt included with this distribution for details.
* Any modifications to this file must keep this entire header intact.
*/
package org.python.pydev.outline;

import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.python.pydev.parser.jython.SimpleNode;
import org.python.pydev.parser.jython.ast.FunctionDef;
import org.python.pydev.parser.jython.ast.Name;
import org.python.pydev.parser.jython.ast.decoratorsType;
import org.python.pydev.parser.visitors.scope.ASTEntryWithChildren;
import org.python.pydev.shared_core.image.IImageCache;
import org.python.pydev.shared_core.image.UIConstants;
import org.python.pydev.shared_ui.outline.AbstractOutlineFilterAction;

public class OutlineHideOverloadsAction extends AbstractOutlineFilterAction {

private static final String PREF_HIDE_OVERLOADS = "org.python.pydev.OUTLINE_HIDE_OVERLOADS";

public OutlineHideOverloadsAction(PyOutlinePage page, IImageCache imageCache) {
super("Hide overload Methods", page, imageCache, PREF_HIDE_OVERLOADS,
UIConstants.STATIC_MEMBER_HIDE_OVERLOADS);
}

/**
* @return the filter used to hide comments
*/
@Override
protected ViewerFilter createFilter() {
return new ViewerFilter() {

@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof ParsedItem) {
ParsedItem item = (ParsedItem) element;

ASTEntryWithChildren astThis = item.getAstThis();
if (astThis == null) {
return true;
}
SimpleNode token = astThis.node;

if (token instanceof FunctionDef) {
FunctionDef functionDefToken = (FunctionDef) token;
if (functionDefToken.decs != null) {
for (decoratorsType decorator : functionDefToken.decs) {
if (decorator.func instanceof Name) {
Name decoratorFuncName = (Name) decorator.func;
if (decoratorFuncName.id.equals("overload")) {
return false;
}
}
}
}
}
}
return true;
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ public static Image getImageForNode(IImageCache imageCache, SimpleNode token, AS
decorationIcon = UIConstants.DECORATION_STATIC;
} else if (decoratorFuncName.id.equals("classmethod")) {
decorationIcon = UIConstants.DECORATION_CLASS;
} else if (decoratorFuncName.id.equals("overload")) {
decorationIcon = UIConstants.DECORATION_OVERLOAD;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/*
* Author: atotic
* Author: fabioz
*
*
* Created: Jul 10, 2003
*/
package org.python.pydev.outline;
Expand All @@ -23,14 +23,14 @@
import org.python.pydev.ui.NotifyViewCreated;

/**
* Outline page, displays the structure of the document in the editor window.
* Outline page, displays the structure of the document in the editor window.
*
* Partition outlining:<p>
* PyDocumentProvider already partitions the document into strings/comments/other<p>
* RawPartition is the simplest outline that shows this "raw" document partitioning<p>
* raw partition was only used as an example, not useful in production<p>
*
* @note: tests for the outline page are not directly for the outline page, but for its model,
*
* @note: tests for the outline page are not directly for the outline page, but for its model,
* based on ParsedItems.
**/
public class PyOutlinePage extends BaseOutlinePage implements IViewWithControls {
Expand Down Expand Up @@ -62,6 +62,7 @@ protected void createActions() {
menuManager.add(new OutlineHideFieldsAction(this, imageCache));
menuManager.add(new OutlineHideNonPublicMembersAction(this, imageCache));
menuManager.add(new OutlineHideStaticMethodsAction(this, imageCache));
menuManager.add(new OutlineHideOverloadsAction(this, imageCache));
}

}

0 comments on commit 8c4e329

Please sign in to comment.