Create windows right click context menu for SPECIFIC folders - contextmenu

How can I create a context menu that appears for files/folders inside a particular folder.
Say there is a directory "D:\RandomCodes"
How do I create a custom context menu item "Open in MyApp" for any file/folder inside this? This menu item should not appear for any other directory. I know if I add the entry in HKCR/Directory/Shell, it'll work, but then it'll appear for all files and folders everywhere. Please guide me through this.

example:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Folder\shell\NetBeans]
"AppliesTo"="System.ItemPathDisplay:\"NetBeansProjects\""
#="Open with NetBeans"
[HKEY_CLASSES_ROOT\Folder\shell\NetBeans\command]
#="\"C:\\Program Files\\NetBeans 7.2.1\\bin\\netbeans64.exe\" --open \"%1\""
more info here:
http://msdn.microsoft.com/en-us/library/cc144171%28VS.85%29.aspx

I know this is a pretty old question, but to anyone who comes across this in the future, I found the simplest way was to add a String Value to the key called "AppliesTo" and set its value to "under:{path}"
In my example, I want it to only look in the T Drive, so my String value is "AppliesTo":"under:T:".
In C#, this is easily accomplished with the following:
RegistryKey _key = Registry.ClassesRoot.OpenSubKey("Folder\\Shell", true);
RegistryKey newkey = _key.CreateSubKey("My Menu Item");
newkey.SetValue("AppliesTo", "under:T:");
RegistryKey subNewkey = newkey.CreateSubKey("Command");
subNewkey.SetValue("", "C:\\yourApplication.exe");
subNewkey.Close();
newkey.Close();
_key.Close();

Is possible modifing your code for IShellExtInit:
STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pidl,LPDATAOBJECT pDataObj,HKEY hk)
{
// Initialize can be called more than once
// If Initialize has already been called, release the old
// IDataObject pointer.
if (m_pDataObj)
{
m_pDataObj->Release();
}
// If a data object pointer was passed in, save it and
// extract the file name.
if (pDataObj == NULL)
return E_INVALIDARG;
m_pDataObj = pDataObj;
pDataObj->AddRef();
STGMEDIUM medium;
FORMATETC fe = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
UINT uCount;
HRESULT hr = pDataObj->GetData(&fe, &medium);
if (FAILED(hr))
return E_INVALIDARG;
// save the file name
if (DragQueryFile((HDROP) medium.hGlobal, 0xFFFFFFFF, NULL, 0)==1)
{
DragQueryFile((HDROP) medium.hGlobal, 0, m_szFile,
sizeof(m_szFile));
if (lstrcmpi(m_szFile, "D:\\RandomCodes") == 0)
{
hr = NOERROR;
}
else
hr = E_INVALIDARG;
}
else
hr = E_INVALIDARG;
ReleaseStgMedium(&medium);
return hr;
}

Related

SWT: Integrate clickable link into StyledText

With the help of this question I was able to figure out how I can display a link inside a StyledText widget in SwT. The color is correct and even the cursor changes shape when hovering over the link.
So far so good, but the link is not actually clickable. Although the cursor changes its shape, nothing happens if clicking on the link. Therefore I am asking how I can make clicking the link to actually open it in the browser.
I thought of using a MouseListener, tracking the click-location back to the respective text the click has been performed on and then deciding whether to open the link or not. However that seems way too complicated given that there already is some routine going on for changing the cursor accordingly. I believe that there is some easy way to do this (and assuring that the clicking-behavior is actually consistent to when the cursor changes its shape).
Does anyone have any suggestions?
Here's an MWE demonstrating what I have done so far:
public static void main(String[] args) throws MalformedURLException {
final URL testURL = new URL("https://stackoverflow.com/questions/1494337/can-html-style-links-be-added-to-swt-styledtext");
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1, true));
StyledText sTextWidget = new StyledText(shell, SWT.READ_ONLY);
final String firstPart = "Some text before ";
String msg = firstPart + testURL.toString() + " some text after";
sTextWidget.setText(msg);
sTextWidget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
StyleRange linkStyleRange = new StyleRange(firstPart.length(), testURL.toString().length(), null, null);
linkStyleRange.underline = true;
linkStyleRange.underlineStyle = SWT.UNDERLINE_LINK;
linkStyleRange.data = testURL.toString();
sTextWidget.setStyleRange(linkStyleRange);
shell.open();
while(!shell.isDisposed()) {
display.readAndDispatch();
}
}
Okay I was being a little too fast on posting this question... There's a snippet that deals with exactly this problem and it shows, that one indeed has to use an extra MouseListener in order to get things working.
The snippet can be found here and this is the relevant part setting up the listener:
styledText.addListener(SWT.MouseDown, event -> {
// It is up to the application to determine when and how a link should be activated.
// In this snippet links are activated on mouse down when the control key is held down
if ((event.stateMask & SWT.MOD1) != 0) {
int offset = styledText.getOffsetAtLocation(new Point (event.x, event.y));
if (offset != -1) {
StyleRange style1 = null;
try {
style1 = styledText.getStyleRangeAtOffset(offset);
} catch (IllegalArgumentException e) {
// no character under event.x, event.y
}
if (style1 != null && style1.underline && style1.underlineStyle == SWT.UNDERLINE_LINK) {
System.out.println("Click on a Link");
}
}
}
});

IllegalStateException while adding vertical field manager in another manager

I am trying to add a list in a VerticalFieldManager and then that manager to another VerticalFieldManager. I am using it in custom tabs.First time when application starts it runs fine but when I switch to another tab and return to same it gives IllegalStateException.
I tried it in many ways but not getting what is causing the exception in adding that VerticalFieldManager.
I am using the code :
//HEADER
_bitmap = EncodedImage.getEncodedImageResource("Friends.png");
friendsBmp = new BitmapField(Constants.sizePic(_bitmap, _bitmap.getHeight(), _bitmap.getWidth()));
//add(WebBitmapField.getUrlHFM());
SCREEN_FLAG = Constants.FRIENDS_FLAG ;
//FRIENDS' UPPER TAB
friendsTabHFM =new HorizontalFieldManager();
Bitmap ConnectedUser_normal_Bmp =Constants.sizePic(EncodedImage.
getEncodedImageResource("connected_user_normal.png"),40, Display.getWidth()/2); //Bitmap.getBitmapResource("connected_user_normal.png");
Bitmap search_normal_Bmp = Constants.sizePic(EncodedImage.
getEncodedImageResource("search_normal.png"),40, Display.getWidth()/2);//Bitmap.getBitmapResource("search_normal.png");
Bitmap ConnectedUser_tap_Bmp = Constants.sizePic(EncodedImage.
getEncodedImageResource("connected_user_tap.png"),40, Display.getWidth()/2);//Bitmap.getBitmapResource("connected_user_tap.png");
Bitmap search_tap_Bmp = Constants.sizePic(EncodedImage.
getEncodedImageResource("search_tap.png"),40, Display.getWidth()/2);//Bitmap.getBitmapResource("search_tap.png");
connectedUsersTab= new CustomButtonField(ConnectedUser_normal_Bmp.getWidth(), "", ConnectedUser_normal_Bmp, ConnectedUser_tap_Bmp, ButtonField.FIELD_HCENTER );
connectedUsersTab.setChangeListener(this);
searchTab = new CustomButtonField(search_normal_Bmp.getWidth(), "", search_normal_Bmp, search_tap_Bmp, ButtonField.FIELD_RIGHT);
searchTab.setChangeListener(this);
friendsTabHFM.add(connectedUsersTab);
friendsTabHFM.add(searchTab);
if(Constants.isGetConnectedFriends){
Constants.isGetConnectedFriends =false ;
if(friendsVFM.getFieldCount()!= 0){
friendsVFM.deleteAll();
}
//GET CONNECTED FRIENDS WEB SERVICE CALL
GetConnectedFriendsInterMediater getConnectedFriendsInterMediater = new GetConnectedFriendsInterMediater(WebServiceDetails.METHOD_GET_CONNECTED_USER, Jxa.loginUserName);
PleaseWaitPopupScreen.showScreenAndWait(getConnectedFriendsInterMediater, Constants.PLEASE_WAIT_TEXT);
}else if(Constants.isGetUserByUsername){
//Constants.isGetUserByUsername = false ;
GetUserByUsernameIntermediator getUserListIntermediator=new GetUserByUsernameIntermediator(Jxa.loginUserName ,SearchUserScreen.userName);
PleaseWaitPopupScreen.showScreenAndWait(getUserListIntermediator, Constants.PLEASE_WAIT_TEXT);
}else if(Constants.isGetAllUser){
Constants.isGetAllUser = false ;
GetAllUserListIntermediator getAllUserListIntermediator=new GetAllUserListIntermediator(WebServiceDetails.METHOD_FIND_USERS,SearchUserScreen._ageRange,SearchUserScreen._status,SearchUserScreen._religion,String.valueOf(SearchUserScreen._page) ,Jxa.loginUserName);
PleaseWaitPopupScreen.showScreenAndWait(getAllUserListIntermediator, Constants.PLEASE_WAIT_TEXT);
}
if(_mainScreenVFM.getFieldCount()!=0){
_mainScreenVFM.deleteAll();
}
_mainScreenVFM.add(friendsTabHFM);
_mainScreenVFM.add(friendsVFM);
These code is for a tab in which two sub-tabs are there.For sub tabs it is running fine but for not for main tab.
One more scenario is there,when GetConnectedFriendsInterMediater is called in that I am adding the list in friendsVFM which creating the exception.
Code for that is:
GetConnectedFriendsWebService getFriendsWebService = new GetConnectedFriendsWebService(method ,userName);
Vector friendsVecList= getFriendsWebService.getFriends();
Constants.connectedUsersVector = friendsVecList ;
synchronized (UiApplication.getEventLock()) {
if(TabControlScreen.friendsVFM.getFieldCount()!=0){
TabControlScreen.friendsVFM.deleteAll();
}
TabControlScreen.friendsVFM.add(ConnectedFriends.getInstance(KingdomConnectMain.buddyList)); //HERE LIST IS ADDED
}
I have resolved the problem ,when I was switching the tab ,I was not creating new instance for friendsVFM and using the same instance which was causing the exception at that time.Now ,same exception is thrown when I am trying to add buddyList in _listVFM . I know it is due to adding the buddyList again which is already added.Is there any solution so that I can add the list without exception. Code for that:
//CREATING SINGLETON REFERENCE OF THE BUDDYLIST SCREEN
public static ConnectedFriends getInstance(BuddyListField buddyListField){
if(connectedFriends==null){
connectedFriends = new ConnectedFriends(buddyListField);
}
return connectedFriends;
}
public ConnectedFriends(BuddyListField buddyListField) {
if(_listVFM!=null){
_listVFM.deleteAll();
}
_listVFM = new VerticalFieldManager();
_listVFM.add(buddyListField);//HERE IS EXCEPTION ,BUT WANT TO ADD THE LIST //SECOND TIME TOO
}
When I am returning from another tab to sam tab it throws exception or in other words I am not able to add the list.
Illegal state exception occurs when you're trying to add fields twice as suggested by Signare also. I guess you should try this first:
friendsVFM.getManager().delete(friendsVFM);
I solved it by using getManager() on buddyList and removing that.Than again I added it as per requirement and it worked.Code for this :
if(ConnectedFriends.getInstance(KingdomConnectMain.buddyList).getManager()!= null){
ConnectedFriends.getInstance(KingdomConnectMain.buddyList).getManager().delete(ConnectedFriends.getInstance(KingdomConnectMain.buddyList));
}
TabControlScreen.friendsVFM.add(ConnectedFriends.getInstance(KingdomConnectMain.buddyList));
This code is used while calling GetConnectedFriendsWebService in the second part of codes.

Importing content to XNA program using code?

Is it possible that a XNA program able to import the resource (etc: image, sound) into the content of the program via code? For example, the user want to add an new image into the program, the XNA program will behave like the Window's Add File or Copy File. If possible WinForm shall avoid.
OpenFileDialog f = new OpenFileDialog();
f.Filter = "PNG files (*.png)|*.png|All files (*.*)|*.*";
f.Title = "Import Image";
DialogResult result = f.ShowDialog(); // Show the dialog.
string file = "";
if (result == DialogResult.OK) // Test result.
{
file = f.FileName;
}
else //If cancels, handle here
Application.Exit();
using (FileStream SourceStream = File.Open(file, FileMode.Open))
{
//Load the Texture here
YourTexture = Texture2D.FromStream(GraphicsDevice, SourceStream);
}
That uses a simple WinForms OpenDialog Window, but if you don't want winforms, you can make your own and use this part just to load.
using (FileStream SourceStream = File.Open(file, FileMode.Open))
{
//Load the Texture here
YourTexture = Texture2D.FromStream(GraphicsDevice, SourceStream);
}
You can save the Texture2D Back by doing
using(Stream stream = File.Create(file));
{
texture.SaveAsPng(stream, texture.Width, texture.Height);
}

How to get images from cache using a XPCOM Component in Firefox

I need to get the cache file path for ever image loaded in a document, I am wondering what are the Interfaces I need to use in order to do that
https://developer.mozilla.org/en/XPCOM_Interface_Reference
This is what I used to evict cache entry:
function removeItem(url){
let cacheService = Components.classes["#mozilla.org/network/cache-service;1"]
.getService(Components.interfaces.nsICacheService);
var Ci = Components.interfaces;
var session = cacheService.createSession("image", Ci.nsICache.STORE_ANYWHERE, false);
if(!session){
return;
}
var entry;
try{
entry = session.openCacheEntry(url, Ci.nsICache.ACCESS_READ, false);
if(!entry){
return;
}
}catch(ex){
return;
}
entry.doom();
entry.close();
}
}
Once you have entry you should be able to open a stream to it - possibly getting the content or even replacing it - I haven't tried it though.

How to copy attachments from a List into a document library via workflow activity

I currently have a task list, some of them contain file attachments. As part of a new workflow I'm creating in MOSS Designer I need to copy the attachments to files in a document library. What is the best way to do this? Is there an activity already made for this? Thanks!
I know it is an old question but for someone out there..
private void MoveAppraisalSupportDocs(SPListItemCollection sourceDocsList, SPList destinationDocsLib)
{
int sourceDocCnt = sourceDocsList.Count;
if (sourceDocCnt > 0)
{
for (int sd = 0; sd < sourceDocCnt; sd++)
{
SPListItem sourceItem = sourceDocsList[sd];
byte[] fileBytes = sourceItem.File.OpenBinary();
string destUrl = destinationDocsLib.RootFolder.Url + "/" + sourceItem.File.Name;
SPFile destFile = destinationDocsLib.RootFolder.Files.Add(destUrl, fileBytes, true /*true means overwrite */);
}
}
}

Resources