Simple way to decorate editor title image in Eclipse editor? - eclipse

JDT and other plugins for Eclipse decorate the editor title image with problem status (compilation errors etc.). In my plugin I want to mimic that behaviour.
However, looking at the sources, JDT seems to do a lot of extra handling to do the decoration.
Decorators, especially lightweight ditto, is a handy way of doing decorations on icons, but I can find no way to programatically enable them for the title image of an editor. (And I don't want to pull in all of JDT UI in my plugin...)
Is there such a way or do I need to implement my own ILabelProvider and then
public void updatedTitleImage(Image image) {
setTitleImage(image);
}
like the JavaEditor does?

There seems to be no way to use decorators with the editor title image (as of 3.7 at least).
I ended up creating a EditorLabelUpdator which implemented the IResourceChangeListener interface (to find out when markers changed), basically the resourceChanged() method. It then uses a simple decorator-type class built from the pattern of OverlayImageIcon (of which you can find a lot of examples on Google).
The constructor is called from the initalization of the editor, sending the editor as a parameter which is saved for getting at the resource and its title icon.
The editor also had to be amended with a callback method triggering the title icon updating (updatedTitleImage(Image image)).
This is the core of the code I got:
public void resourceChanged(IResourceChangeEvent event) {
if (isMarkerChangeForResource(event, editor)) {
/* Changes in markers on this resource, so re-decorate title image */
decorate();
}
}
private boolean isMarkerChangeForResource(IResourceChangeEvent event, AlanEditor editor) {
boolean isMarkerChangeForThisResource;
final IResource resource = ResourceUtil.getResource(editor.getEditorInput());
final IPath path = resource.getFullPath();
IResourceDelta delta = event.getDelta().findMember(path);
isMarkerChangeForThisResource = (delta != null) && ((delta.getFlags() & IResourceDelta.MARKERS) != 0);
return isMarkerChangeForThisResource;
}
public void decorate() {
Shell shell = editor.getEditorSite().getShell();
if (shell != null && !shell.isDisposed()) {
shell.getDisplay().syncExec(new Runnable() {
public void run() {
Image decoratedImage = decorateImage(editor.getTitleImage(), getSeverity());
editor.updatedTitleImage(decoratedImage);
}
});
}
}
private Image decorateImage(Image titleImage, int severity) {
final ImageRegistry registry = AlanIDEPlugin.getDefault().getImageRegistry();
String key = createKey(severity);
ImageDescriptor descriptor = AlanIDEPlugin.getImageDescriptor(key);
if (descriptor != null)
return descriptor.createImage();
OverlayImageDescriptor overlayImageDescriptor = buildDecoratedImage(severity, key);
registry.put(key, overlayImageDescriptor);
return overlayImageDescriptor.createImage();
}
private String createKey(int severity) {
String key;
switch (severity) {
case IMarker.SEVERITY_ERROR: key = EDITOR_TITLE_ICON + ".error"; break;
case IMarker.SEVERITY_WARNING: key = EDITOR_TITLE_ICON + ".warning"; break;
default: key = EDITOR_TITLE_ICON; break;
}
return key;
}
private OverlayImageDescriptor buildDecoratedImage(int severity, String key) {
ImageDescriptor overlay = null;
if (severity >= IMarker.SEVERITY_ERROR)
overlay = AlanIDEPlugin.getImageDescriptor("ovr16.error_ovr");
else if (severity == IMarker.SEVERITY_WARNING)
overlay = AlanIDEPlugin.getImageDescriptor("ovr16.warning_ovr");
ImageDescriptor baseImage = AlanIDEPlugin.getImageDescriptor(EDITOR_TITLE_ICON);
OverlayImageDescriptor overlayIcon = new OverlayImageDescriptor(baseImage);
if (overlay != null)
overlayIcon.addOverlay(overlay, IDecoration.BOTTOM_LEFT);
return overlayIcon;
}
private int getSeverity() {
int severity = 0;
try {
final IResource resource = ResourceUtil.getResource(editor.getEditorInput());
severity = resource.findMaxProblemSeverity(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
} catch (CoreException e) {
// Might be a project that is not open
}
return severity;
}
This was the simplest solution I could come up with.

Yes, there is an extension point which you can use to achieve that. See the code below:
<!--define the decorator -->
<extension point="org.eclipse.ui.decorators">
<decorator
adaptable="true"
class="org.example.PackageExplorerDecorator"
id="org.example.PackageExplorerDecorator"
label="File Decorator"
lightweight="true"
state="true">
<enablement>
<or>
<objectClass
name="org.eclipse.jdt.core.IMethod">
</objectClass>
<objectClass
name="org.eclipse.core.resources.IResource">
</objectClass>
</or>
</enablement>
For the PackageExplorerDecorator: extends LabelProvider implements ILightweightLabelDecorator

Related

How can i store or read a animation clip data in runtime?

I'm working on a small program that can modify the animation at run time(Such as when you run faster the animation not only play faster but also with larger movement). So i need to get the existing animation, change its value, then send it back.
I found it is interesting that i can set a new curve to the animation, but i can't get access to what i already have. So I either write a file to store my animation curve (as text file for example), or i find someway to read the animation on start up.
I tried to use
AnimationUtility.GetCurveBindings(AnimationCurve);
It worked in my testing, but in some page it says this is a "Editor code", that if i build the project into a standalone program it will not work anymore. Is that true? If so, is there any way to get the curve at run time?
Thanks to the clearify from Benjamin Zach and suggestion from TehMightyPotato
I'd like to keep the idea about modifying the animation at runtime. Because it could adapt to more situations imo.
My idea for now is to write a piece of editor code that can read from the curve in Editor and output all necesseary information about the curve (keyframes) into a text file. Then read that file at runtime and create new curve to overwrite the existing one. I will leave this question open for a few days and check it to see if anyone has a better idea about it.
As said already AnimationUtility belongs to the UnityEditor namespace. This entire namespace is completely stripped of in a build and nothing in it will be available in the final app but only within the Unity Editor.
Store AnimationCurves to file
In order to store all needed information to a file you could have a script for once serializing your specific animation curve(s) in the editor before building using e.g. BinaryFormatter.Serialize. Then later on runtime you can use BinaryFormatter.Deserialize for returning the info list again.
If you wanted it more editable you could as well use e.g. JSON or XML of course
UPDATE: In general Stop using BinaryFormatter!
In the newest Unity versions the Newtonsoft Json.NET package comes already preinstalled so simply rather use JSON
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Unity.Plastic.Newtonsoft.Json;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
public class AnimationCurveManager : MonoBehaviour
{
[Serializable]
public sealed class ClipInfo
{
public int ClipInstanceID;
public List<CurveInfo> CurveInfos = new List<CurveInfo>();
// default constructor is sometimes required for (de)serialization
public ClipInfo() { }
public ClipInfo(Object clip, List<CurveInfo> curveInfos)
{
ClipInstanceID = clip.GetInstanceID();
CurveInfos = curveInfos;
}
}
[Serializable]
public sealed class CurveInfo
{
public string PathKey;
public List<KeyFrameInfo> Keys = new List<KeyFrameInfo>();
public WrapMode PreWrapMode;
public WrapMode PostWrapMode;
// default constructor is sometimes required for (de)serialization
public CurveInfo() { }
public CurveInfo(string pathKey, AnimationCurve curve)
{
PathKey = pathKey;
foreach (var keyframe in curve.keys)
{
Keys.Add(new KeyFrameInfo(keyframe));
}
PreWrapMode = curve.preWrapMode;
PostWrapMode = curve.postWrapMode;
}
}
[Serializable]
public sealed class KeyFrameInfo
{
public float Value;
public float InTangent;
public float InWeight;
public float OutTangent;
public float OutWeight;
public float Time;
public WeightedMode WeightedMode;
// default constructor is sometimes required for (de)serialization
public KeyFrameInfo() { }
public KeyFrameInfo(Keyframe keyframe)
{
Value = keyframe.value;
InTangent = keyframe.inTangent;
InWeight = keyframe.inWeight;
OutTangent = keyframe.outTangent;
OutWeight = keyframe.outWeight;
Time = keyframe.time;
WeightedMode = keyframe.weightedMode;
}
}
// I know ... singleton .. but what choices do we have? ;)
private static AnimationCurveManager _instance;
public static AnimationCurveManager Instance
{
get
{
// lazy initialization/instantiation
if (_instance) return _instance;
_instance = FindObjectOfType<AnimationCurveManager>();
if (_instance) return _instance;
_instance = new GameObject("AnimationCurveManager").AddComponent<AnimationCurveManager>();
return _instance;
}
}
// Clips to manage e.g. reference these via the Inspector
public List<AnimationClip> clips = new List<AnimationClip>();
// every animation curve belongs to a specific clip and
// a specific property of a specific component on a specific object
// for making this easier lets simply use a combined string as key
private string CurveKey(string pathToObject, Type type, string propertyName)
{
return $"{pathToObject}:{type.FullName}:{propertyName}";
}
public List<ClipInfo> ClipCurves = new List<ClipInfo>();
private string filePath = Path.Combine(Application.streamingAssetsPath, "AnimationCurves.dat");
private void Awake()
{
if (_instance && _instance != this)
{
Debug.LogWarning("Multiple Instances of AnimationCurveManager! Will ignore this one!", this);
return;
}
_instance = this;
DontDestroyOnLoad(gameObject);
// load infos on runtime
LoadClipCurves();
}
#if UNITY_EDITOR
// Call this from the ContextMenu (or later via editor script)
[ContextMenu("Save Animation Curves")]
private void SaveAnimationCurves()
{
ClipCurves.Clear();
foreach (var clip in clips)
{
var curveInfos = new List<CurveInfo>();
ClipCurves.Add(new ClipInfo(clip, curveInfos));
foreach (var binding in AnimationUtility.GetCurveBindings(clip))
{
var key = CurveKey(binding.path, binding.type, binding.propertyName);
var curve = AnimationUtility.GetEditorCurve(clip, binding);
curveInfos.Add(new CurveInfo(key, curve));
}
}
// create the StreamingAssets folder if it does not exist
try
{
if (!Directory.Exists(Application.streamingAssetsPath))
{
Directory.CreateDirectory(Application.streamingAssetsPath);
}
}
catch (IOException ex)
{
Debug.LogError(ex.Message);
}
// create a new file e.g. AnimationCurves.dat in the StreamingAssets folder
var json = JsonConvert.SerializeObject(ClipCurves);
File.WriteAllText(filePath, json);
AssetDatabase.Refresh();
}
#endif
private void LoadClipCurves()
{
if (!File.Exists(filePath))
{
Debug.LogErrorFormat(this, "File \"{0}\" not found!", filePath);
return;
}
var fileStream = new FileStream(filePath, FileMode.Open);
var json = File.ReadAllText(filePath);
ClipCurves = JsonConvert.DeserializeObject<List<ClipInfo>>(json);
}
// now for getting a specific clip's curves
public AnimationCurve GetCurve(AnimationClip clip, string pathToObject, Type type, string propertyName)
{
// either not loaded yet or error -> try again
if (ClipCurves == null || ClipCurves.Count == 0) LoadClipCurves();
// still null? -> error
if (ClipCurves == null || ClipCurves.Count == 0)
{
Debug.LogError("Apparantly no clipCurves loaded!");
return null;
}
var clipInfo = ClipCurves.FirstOrDefault(ci => ci.ClipInstanceID == clip.GetInstanceID());
// does this clip exist in the dictionary?
if (clipInfo == null)
{
Debug.LogErrorFormat(this, "The clip \"{0}\" was not found in clipCurves!", clip.name);
return null;
}
var key = CurveKey(pathToObject, type, propertyName);
var curveInfo = clipInfo.CurveInfos.FirstOrDefault(c => string.Equals(c.PathKey, key));
// does the curve key exist for the clip?
if (curveInfo == null)
{
Debug.LogErrorFormat(this, "The key \"{0}\" was not found for clip \"{1}\"", key, clip.name);
return null;
}
var keyframes = new Keyframe[curveInfo.Keys.Count];
for (var i = 0; i < curveInfo.Keys.Count; i++)
{
var keyframe = curveInfo.Keys[i];
keyframes[i] = new Keyframe(keyframe.Time, keyframe.Value, keyframe.InTangent, keyframe.OutTangent, keyframe.InWeight, keyframe.OutWeight)
{
weightedMode = keyframe.WeightedMode
};
}
var curve = new AnimationCurve(keyframes)
{
postWrapMode = curveInfo.PostWrapMode,
preWrapMode = curveInfo.PreWrapMode
};
// otherwise finally return the AnimationCurve
return curve;
}
}
Then you can do something like e.e.
AnimationCurve originalCurve = AnimationCurvesManager.Instance.GetCurve(
clip,
"some/relative/GameObject",
typeof<SomeComponnet>,
"somePropertyName"
);
the second parameter pathToObject is an empty string if the property/component is attached to the root object itself. Otherwise it is given in the hierachy path as usual for Unity like e.g. "ChildName/FurtherChildName".
Now you can change the values and assign a new curve on runtime.
Assigning new curve on runtime
On runtime you can use animator.runtimeanimatorController in order to retrieve a RuntimeAnimatorController reference.
It has a property animationClips which returns all AnimationClips assigned to this controller.
You could then use e.g. Linq FirstOrDefault in order to find a specific AnimationClip by name and finally use AnimationClip.SetCurve to assign a new animation curve to a certain component and property.
E.g. something like
// you need those of course
string clipName;
AnimationCurve originalCurve = AnimationCurvesManager.Instance.GetCurve(
clip,
"some/relative/GameObject",
typeof<SomeComponnet>,
"somePropertyName"
);
// TODO
AnimationCurve newCurve = SomeMagic(originalCurve);
// get the animator reference
var animator = animatorObject.GetComponent<Animator>();
// get the runtime Animation controller
var controller = animator.runtimeAnimatorController;
// get all clips
var clips = controller.animationClips;
// find the specific clip by name
// alternatively you could also get this as before using a field and
// reference the according script via the Inspector
var someClip = clips.FirstOrDefault(clip => string.Equals(clipName, clip.name));
// was found?
if(!someClip)
{
Debug.LogWarningFormat(this, "There is no clip called {0}!", clipName);
return;
}
// assign a new curve
someClip.SetCurve("relative/path/to/some/GameObject", typeof(SomeComponnet), "somePropertyName", newCurve);
Note: Typed on smartphone so no warranty! But I hope the idea gets clear...
Also checkout the example in AnimationClip.SetCurve → You might want to use the Animation component instead of an Animator in your specific use case.

Execute Pick Point from Windows Form in ArcGIS

I have a windows form which is launched with an ESRI AddIn button (ArcGIS 10.2 and Windows 7). On my form I have a button to pick a point from the Map. I have added an ESRI BaseTool class to the project, which has an OnMouseDown event.
The problem is that I cannot get the Tool to run. Note that the tool is not on the ArcGIS Command Bar (like the button is) but the tool is still found by the Find(uid) process.
When the Tool was added to the project (using the ArcGIS Add BaseTool process) it didn't update the .esriaddinx file. I had to do that manually.
My Addin file is:
<AddIn language="CLR4.0" library="HVLR_Processing.dll" namespace="HVLR_Processing">
<ArcMap>
<Commands>
<Button id="RMS_HVLR_Processing_clsHVLR_Processing" class="clsHVLR_Processing" ...
<Tool id="HVLR_PickTool" class="clsMapPick" category="Add-In Controls" caption="" message="" tip="" image="" />
</Commands>
</ArcMap>
The clsMapClick code contains the OnMouseDown event.
To start the process I have tried many methods. I can retrieve the Tool but when I execute it (or assign it to the CurrentTool) nothing happens.
UID pUID;
ICommandItem pCmdItem;
ICommand pCmd;
clsMapPick pPick;
ITool pTool;
try
{
this.WindowState = FormWindowState.Minimized;
m_pApp.CurrentTool = null;
pUID = new UIDClass();
pUID.Value = "HVLR_PickTool";
pCmdItem = m_pApp.Document.CommandBars.Find(pUID, false, false);
if (pCmdItem != null)
{
m_pApp.CurrentTool = pCmdItem; // Nothing happens
m_pApp.CurrentTool.Execute(); // Nothing happens
m_pApp.CurrentTool.Refresh();
}
}
catch (Exception ex)
Can anyone tell me how to get this tool to execute?
OK. Big stuff-up. You can't add a BaseTool to an ESRI AddIn; it's a COM object. What has to be done is:
Create a new ESRI Tool class.
Add a boolean variable to the class to indicate the mousedown event has fired.
In the OnUpdate method put some code to continue until the mousedown event has fired.
Create an OnMouseDown event handler by starting to type protected void On... and itellisense will allow you to select the event you want to track.
Put the code you want to run in the OnMouseDown event handler and also set the boolean value to true.
Code:
public class clsMapPick : ESRI.ArcGIS.Desktop.AddIns.Tool
{
private bool m_bIsFinished = false;
private int m_iXPixel = -1;
private int m_iYPixel = -1;
//private string m_sError = "";
//private bool m_bSuccess = true;
public clsMapPick()
{
}
protected override void OnActivate()
{
base.OnActivate();
return;
}
protected override void OnUpdate()
{
if (m_bIsFinished)
{
m_bIsFinished = false;
frmHVLR.m_dX = m_iXPixel;
frmHVLR.m_dX = m_iYPixel;
}
}
protected override void OnMouseDown(MouseEventArgs arg)
{
base.OnMouseDown(arg);
m_iXPixel = arg.X;
m_iYPixel = arg.Y;
m_bIsFinished = true;
}
}
In the form where the button for clicking on the map is fired:
string sError = "";
dPickedX = 0;
dPickedY = 0;
UID pUID;
ICommandItem pCmdItem;
ICommandBars pCmdBars;
ICommand pCmd;
ITool pTool;
try
{
this.WindowState = FormWindowState.Minimized;
pCmdBars = m_pApp.Document.CommandBars;
pUID = new UIDClass();
pUID.Value = HVLR_Processing.ThisAddIn.IDs.clsMapPick;
pCmdItem = pCmdBars.Find(pUID);
if (pCmdItem != null)
{
m_pApp.CurrentTool = pCmdItem;
//pCmdItem.Execute();
dPickedX = m_pMxDoc.CurrentLocation.X;
dPickedY = m_pMxDoc.CurrentLocation.Y;
}
return sError;
}
This is working fine for me now, the Tool class is being called but the OnMouseDown event isn't being fired.
If you know why I'd appreciate it.

Deleting values from Project Preference store

In my custom plugin I am creating some folders on a new Wizard and adding paths of those created folders in project preferences. Now while deleting the folder I need to remove that path from the store. For that I extended org.eclipse.ltk.core.refactoring.deleteParticipants extension. I also created a class extending Change class and inside it in the perform method I wrote following to remove the key-value from preferences.
public Change perform(IProgressMonitor pm) throws CoreException {
System.out.println("called");
IPath deletedFolderPath = deletedFolder.getProjectRelativePath().makeAbsolute();
IResource[] roots = {deletedFolder.getProject()};
String[] fileSearchPatterns = {"*.properties", "*.prefs"};
FileTextSearchScope searchScope = FileTextSearchScope.newSearchScope(roots, fileSearchPatterns, false);
String regex = deletedFolderPath.addTrailingSeparator().toString();
Pattern searchPattern = Pattern.compile(regex);
TextSearchRequestor requestor = new TextSearchRequestor() {
public boolean acceptPatternMatch(TextSearchMatchAccess matchAccess) throws CoreException {
IFile matchedFile = matchAccess.getFile();
if("prefs".equals(matchedFile.getFileExtension())){
String prefKey = "";
try {
prefKey = ProjectPreferences.getKeyForValue(regex, deletedFolder.getProject());
ProjectPreferences.removeKeyFromStore(prefKey, deletedFolder.getProject());
System.out.println("after");
}
catch (BackingStoreException e) {
throw new CoreException(null);
}
}
else if(".properties".equals(matchedFile.getFileExtension())) {
}
return true;
}
};
TextSearchEngine.create().search(searchScope, requestor, searchPattern, pm);
return null;
}
but it get stuck on the line after pressing "OK" on the delete wizard.
ProjectPreferences.removeKeyFromStore(prefKey, deletedFolder.getProject())
or more specifically on the flush statement written in the removeKeyFromStore method
public static void removeKeyFromStore(String key, IProject project) throws BackingStoreException {
IEclipsePreferences projPref = getPreferences(project);
projPref.remove(key);
projPref.flush();
}
What am I doing wrong here or any other better way to achieve the same functionality.
Thanks!!

How to enable content proposal in NatTable TextCellEditor?

I am currently looking for content assist feature in Nattable TextCellEditor.I have found the way to attach the ContentProposalAdapter and IContentProposalProvider by extending the Nattable TextCellEditor. but ,The selected value from the proposed list is not updating in the text control.
Snippet :
#Override
protected Text createEditorControl(final Composite parent, final int Style) {
this.textControl = super.createEditorControl(parent, style);
contentProposalAdapter =
new ContentProposalAdapter(this.textControl, new TextContentAdapter(), contentProposalProvider, keyStroke,
null);
contentProposalAdapter.addContentProposalListener(new IContentProposalListener() {
#Override
public void proposalAccepted(IContentProposal proposal) {
System.out.println(proposal.getContent());
}
});
}
The problem you have is the internal FocusListener that is triggered while selecting a value in the popup. To add the support you also need to override the internal FocusListener with a listener that doesn't fire if the content proposal popup is open.
An example would be to add a boolean flag that indicates that the popup is open and add a listener that sets the flag accordingly.
private boolean popupOpen = false;
...
contentProposalAdapter.addContentProposalListener(new IContentProposalListener2() {
#Override
public void proposalPopupClosed(ContentProposalAdapter adapter) {
this.popupOpen = false;
}
#Override
public void proposalPopupOpened(ContentProposalAdapter adapter) {
this.popupOpen = true;
}
});
And then implement and set a FocusListener in the constructor that takes care of that flag.
this.focusListener = new FocusAdapter() {
#Override
public void focusLost(FocusEvent e) {
if (!TextCellEditor.this.popupOpen) {
if (!commit(MoveDirectionEnum.NONE, true)) {
if (e.widget instanceof Control && !e.widget.isDisposed()) {
((Control) e.widget).forceFocus();
}
} else {
if (!TextCellEditor.this.parent.isDisposed())
TextCellEditor.this.parent.forceFocus();
}
}
}
};
In case the value should be immediately committed after it is selected, you need to add a listener that performs the commit after selection.
contentProposalAdapter.addContentProposalListener(new IContentProposalListener() {
#Override
public void proposalAccepted(IContentProposal proposal) {
commit(MoveDirectionEnum.NONE);
}
});
Unfortunately the AbstractCellEditor#InlineFocusListener is private and can therefore not be extended.
Feel free to file an enhancement ticket for NatTable to introduce the ability to easily add content proposals to a text cell editor.
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=NatTable

Disabling a button in page editor (ribbon) for field-type image

I have used a custom image component which has image field-type ribbon when editing in page editor.
In core db, there are 3 webedit buttons for image which I need to hide/disable:
path: /sitecore/system/Field types/Simple Types/Image/WebEdit Buttons/
buttons:
1. Choose Image
2. Image Properties
3. Clear Image
Also, i am aware that this is possible by overriding Querystate() method but im unsure of its implementation as I am new to CommandState handling.
Instead of going through QueryState , I am trying this
I have set the property "DisableEdit" of image as:
<myImage:PictureFillImage Field="<%# MyImage.Constants.FieldNames.Image %>" DisableEdit="true" ID="UIImage" runat="server"/>
I am using a custom class as:
public class PictureFillImage : Sitecore.Web.UI.WebControls.FieldControl
And i am trying to disable web editing for the image as:
public bool DisableEdit { get; set; }
private Sitecore.Web.UI.WebControls.Image _smlImage;
private Sitecore.Data.Fields.ImageField _smlImageField;
private Sitecore.Web.UI.WebControls.FieldControl _fieldControl;
protected override void OnLoad(EventArgs e)
{
this.DataBind();
}
public override void DataBind()
{
// base.OnLoad(e);
this.Item = this.GetItem();
if ((this.Item != null) && (this.Field != null))
{
Sitecore.Data.Fields.Field field = this.Item.Fields[this.Field];
if (field != null)
{
this._smlImageField = (Sitecore.Data.Fields.ImageField)field;
this._smlImage = new Sitecore.Web.UI.WebControls.Image();
this._smlImage.Field = this.Field;
this._fieldControl = this._smlImage as Sitecore.Web.UI.WebControls.FieldControl;
this._smlImage.ID = this.ID;
this._smlImage.CssClass = this.CssClass;
this._smlImage.Parameters = "all=all";
this._fieldControl.Item = this.Item;
this._smlImage.DisableWebEditing = DisableEdit;
this._fieldControl.DisableWebEditing = DisableEdit;
}
}
base.DataBind();
}
I was hoping that the code would hide the three buttons: "Choose Image", "Image Properties" and "Clear Image" that appear in the floating ribbon in the page editor but I had negative result.
Please help.
You should override the query state method and return hidden or enabled
public override CommandState QueryState(CommandContext context)
{
// your logic here
//access current item
var item = context.Items[0];
// return either Commandstate.Hidden or Commandstate.Enabled
}
For each button you will have a command class declared so you can customize the behaviour for each button.
You can get access to the current item as well.
There's a good example here on how to overrride the querystate to affect the state of the buttons
https://briancaos.wordpress.com/2010/09/10/unlock-sitecore-items/