private void miCopyFile_Click(object sender, RoutedEventArgs e)
 {
     WClipbroad.SetFileDropList(new System.Collections.Specialized.StringCollection()
     {
         SelectedFile.FullName
     });
 }
Esempio n. 2
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            var cancelButton     = Template.FindName("CancelButton", this) as ImageButton;
            var fileButton       = Template.FindName("FileButton", this) as ImageButton;
            var folderButton     = Template.FindName("FolderButton", this) as ImageButton;
            var detailsButton    = Template.FindName("DetailsButton", this) as ImageButton;
            var copyMenu         = Template.FindName("CopyMenuItem", this) as ImageMenuItem;
            var copyImageMenu    = Template.FindName("CopyImageMenuItem", this) as ImageMenuItem;
            var copyFilenameMenu = Template.FindName("CopyFilenameMenuItem", this) as ImageMenuItem;
            var copyFolderMenu   = Template.FindName("CopyFolderMenuItem", this) as ImageMenuItem;

            if (cancelButton != null)
            {
                cancelButton.Click += (s, a) => RaiseCancelClickedEvent();
            }

            if (fileButton != null)
            {
                fileButton.Click += (s, a) =>
                {
                    RaiseOpenFileClickedEvent();

                    try
                    {
                        if (!string.IsNullOrWhiteSpace(OutputFilename) && File.Exists(OutputFilename))
                        {
                            Process.Start(OutputFilename);
                        }
                    }
                    catch (Exception ex)
                    {
                        Dialog.Ok("Open File", "Error while openning the file", ex.Message);
                    }
                }
            }
            ;

            if (folderButton != null)
            {
                folderButton.Click += (s, a) =>
                {
                    RaiseExploreFolderClickedEvent();

                    try
                    {
                        if (!string.IsNullOrWhiteSpace(OutputFilename) && Directory.Exists(OutputPath))
                        {
                            Process.Start("explorer.exe", $"/select,\"{OutputFilename}\"");
                        }
                    }
                    catch (Exception ex)
                    {
                        Dialog.Ok("Explore Folder", "Error while openning the folder", ex.Message);
                    }
                }
            }
            ;

            if (detailsButton != null)
            {
                detailsButton.Click += (s, a) =>
                {
                    if (Exception != null)
                    {
                        var viewer = new ExceptionViewer(Exception);
                        viewer.ShowDialog();
                    }
                }
            }
            ;

            if (copyMenu != null)
            {
                copyMenu.Click += (s, a) =>
                {
                    if (!string.IsNullOrWhiteSpace(OutputFilename))
                    {
                        Clipboard.SetFileDropList(new StringCollection {
                            OutputFilename
                        });
                    }
                }
            }
            ;

            if (copyImageMenu != null)
            {
                copyImageMenu.Click += (s, a) =>
                {
                    if (!string.IsNullOrWhiteSpace(OutputFilename))
                    {
                        Clipboard.SetImage(OutputFilename.SourceFrom());
                    }
                }
            }
            ;

            if (copyFilenameMenu != null)
            {
                copyFilenameMenu.Click += (s, a) =>
                {
                    if (!string.IsNullOrWhiteSpace(OutputFilename))
                    {
                        Clipboard.SetText(OutputFilename);
                    }
                }
            }
            ;

            if (copyFolderMenu != null)
            {
                copyFolderMenu.Click += (s, a) =>
                {
                    if (!string.IsNullOrWhiteSpace(OutputPath))
                    {
                        Clipboard.SetText(OutputPath);
                    }
                }
            }
            ;
        }