Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please provide a function that could be used to get/set ShellItems in NativeClipboard #353

Closed
zhuxb711 opened this issue Dec 16, 2022 · 14 comments

Comments

@zhuxb711
Copy link

Is your feature request related to a problem? Please describe.
No

Describe the additions or enhancements you'd like
It would be great if you could provide a way to let us get/set ShellItem(s) through NativeClipboard class easily.
The function like the example below:

public void SetShellItems(IEnumerable<ShellItem> Items)
{
    //Set items to underlying clipboard
}

public IEnumerable<ShellItem> GetShellItems()
{
    //Get items from underlying clipboard
}
@dahall
Copy link
Owner

dahall commented Dec 19, 2022

Does Vanara.Windows.Shell.ShellDataObject have what you want?

@zhuxb711
Copy link
Author

But ShellDataObject rely on System.Windows.Forms which is not friendly to use if someone who do not use WinForms.

@dahall
Copy link
Owner

dahall commented Dec 20, 2022

Got it. Let me see if I can port the ShellDataObject code without the Forms dependencies.

@zhuxb711
Copy link
Author

Thanks, do you have any demo to tell us how to use ShellDataObject with ShellItem (Includes Get/Set ShellItem and Set ShellItem with something custom data which stored in another clipboard id)

dahall added a commit that referenced this issue Dec 20, 2022
@dahall
Copy link
Owner

dahall commented Dec 20, 2022

I added a couple methods to NativeClipboard. Give them a try and let me know your thoughts.

@zhuxb711
Copy link
Author

Due to NativeClipboard not working in my project, I have not be able to test that but I reviewed the code, it looks great. #355 (comment)

@dahall
Copy link
Owner

dahall commented Dec 22, 2022

I'll see if I can troubleshoot #355 over the next few days.

@zhuxb711
Copy link
Author

I found some issues, I could not retrieve the ShellItem which I just set into clipboard

            IEnumerable<ShellItem> Items = Collection.Select((Item) => new ShellItem(Item.Path));

            try
            {
                NativeClipboard.SetShellItems(Items);

                if (NativeClipboard.GetShellItemArray() is ShellItemArray Array)
                {
                    foreach (ShellItem Item in Array)
                    {
                        System.Diagnostics.Debug.WriteLine($"Shell IDList: {Item.FileSystemPath}");
                    }
                }
                else
                {
                    //Runs to here which means no available Shell IDList Array
                    System.Diagnostics.Debug.WriteLine("No available Shell IDList Array");
                }
            }
            catch (Exception)
            {

            }
            finally
            {
                Items.ForEach((Item) => Item.Dispose());
            }

@dahall
Copy link
Owner

dahall commented Dec 27, 2022

The latest AppVeyor package seems to be working. I used this code behind a button in a WinForms project and consistently got what I expected.

string[] fileNames = new[] { @"C:\file1.txt", @"C:\file2.txt" };
NativeClipboard.SetShellItems(fileNames.Select(ShellItem.Open));
MessageBox.Show(string.Join("\n", NativeClipboard.GetShellItemArray().Select(i => i.FileSystemPath)));

@zhuxb711
Copy link
Author

Demo for you. Could set the ShellItem but could not retrieve them back
ClipboardTest.zip

@dahall
Copy link
Owner

dahall commented Jan 15, 2023

I think this is now complete.

@dahall dahall closed this as completed Jan 15, 2023
@dahall
Copy link
Owner

dahall commented Mar 7, 2023

@tajbender What is your last comment regarding?

@tajbender
Copy link
Contributor

@tajbender What is your last comment regarding?

Oups, sorry. That was the wrong topic 🍶

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants