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

Add Drop Files #235

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add Drop Files #235

wants to merge 1 commit into from

Conversation

diluculo
Copy link
Contributor

My feature request #231

if (providers.FirstOrDefault(p => p.Handles(newPath)) == null)
continue;

// Check if the document is already open
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this logic should be shared with OpenFileCommandHandler?

@diluculo
Copy link
Contributor Author

diluculo commented Sep 5, 2016

@tgjones Yes, you are right. Please see the #237, where TryActivateDocumentByPath( ) is introduced. If needed, I can add the method into this PR.

OpenFileCommandHandler.cs:

[CommandHandler]
public class OpenFileCommandHandler : CommandHandlerBase<OpenFileCommandDefinition>
{
    ...
    public override async Task Run(Command command)
    {
        ...
        if (dialog.ShowDialog() == true)
        {
            var fullPath = Path.GetFullPath(dialog.FileName);

            if (!_shell.TryActivateDocumentByPath(fullPath))
                _shell.OpenDocument(await GetEditor(fullPath));

            // Add the file to the recent documents list
            _shell.RecentFiles.Update(fullPath);
        }
    }
    ...
}

ShellViewModel.cs:

[Export(typeof(IShell))]
public class ShellViewModel : Conductor<IDocument>.Collection.OneActive, IShell
{
    ...
    public bool TryActivateDocumentByPath(string path)
    {
        foreach (var document in Documents.OfType<PersistedDocument>().Where(d => !d.IsNew))
        {
            if (string.IsNullOrEmpty(document.FilePath))
                continue;

            var docPath = Path.GetFullPath(document.FilePath);
            if (string.Equals(path, docPath, StringComparison.OrdinalIgnoreCase))
            {
                OpenDocument(document);
                return true;
            }
        }

        return false;
    }
    ...
}

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

Successfully merging this pull request may close these issues.

2 participants