Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Initial implementation of drag and drop to open files #190

Merged
merged 17 commits into from
Feb 15, 2013

Conversation

gruehle
Copy link
Member

@gruehle gruehle commented Jan 24, 2013

The pull request adds an initial implementation of file association and drag and drop to open files.

Implemented on the Mac:

  • Drag and drop files onto the Brackets icon in Finder or Dock
  • Right-click and select Open With > Brackets.app

These work whether or not Brackets is already running

Missing on Mac: drag and drop onto a Brackets window. Chromium is swallowing all drag events so they never make it to the native shell.

Implemented on Windows:

  • Drag and drop files onto the Brackets icon in Explorer. This will always launch a new instance of Brackets
  • Drag and drop files onto the Brackets window

Missing on Windows: Right click and select Open With > Brackets.exe. This requires registry modifications that would be best to do from the installer.

NOTE: There will be a corresponding brackets pull request that is required to open files at launch time.

@redmunds
Copy link
Contributor

This works great on Windows.

Currently, Brackets always opens to the last opened project. It would be nice if Brackets detected that the file you dropped on it is contained in one of the projects in your recent projects list and automatically switched to that project.

UPDATE: ... only if Brackets is starting up (not when it's already open).

// This should probably be made more robust...

return (str.find_first_of(':') != std::string::npos &&
str.find_first_of('.') != std::string::npos);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not common, but some files don't have an extension, so you shouldn't check for dot.

You should also make sure there are no characters that are not valid in file names. Take a look at the _checkForValidFilename() function in ProjectManager.js for a list of chars to check for.

Copy link
Member Author

Choose a reason for hiding this comment

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

I replaced this code with a call to GetFileAttributes(). If the call succeeds, we can safely assume it is a valid filename :-)

@redmunds
Copy link
Contributor

On Mac, when I right-click, in the Open With sub-menu, the entry I see is "Brackets.app ()". Seems like there should no be any parens if they're empty.

@redmunds
Copy link
Contributor

On Mac, I've seen a few crashes with "Brackets quit unexpectedly" message, but I have not been able to find a reproducible pattern.

@gruehle
Copy link
Member Author

gruehle commented Jan 25, 2013

Currently, Brackets always opens to the last opened project. It would be nice if Brackets detected that the file you dropped on it is contained in one of the projects in your recent projects list and automatically switched to that project.

I'm not sure I agree... many times I want to open a file from a different project without changing the current project. I plan on adding support for dropping folders, which will either switch to that folder or open a new Brackets window showing the dropped folder (haven't figured out which is better yet..).

@gruehle
Copy link
Member Author

gruehle commented Jan 25, 2013

On Mac, when I right-click, in the Open With sub-menu, the entry I see is "Brackets.app ()". Seems like there should no be any parens if they're empty.

Do you know how to control that? I saw the parens at first too, but I no longer see them on my mac.

@redmunds
Copy link
Contributor

It would be nice if Brackets detected that the file you dropped on it is contained in one of the projects
in your recent projects list and automatically switched to that project.

Allow me to qualify that some more. I don't think Brackets should switch projects if it is already open. I would only want Brackets to switch projects in the case where it is starting up to display a particular file.

@gruehle
Copy link
Member Author

gruehle commented Jan 25, 2013

Ah, okay. That makes sense--thanks for clarifying.

I'd rather leave that for a subsequent pull request if that's okay with you.

@redmunds
Copy link
Contributor

Wow, this really sucks trying to have multiple conversations with no threading :)

The empty paren thing seems to happen when right-clicking on a file that has a default app defined which is something other than Brackets. When I right-click on a .html file I see entries for "Safari.app (default)" and "Brackets.app ()". When I right-click on a .css file I see entries for "Brackets.app (default)" and "Safari.app".

@redmunds
Copy link
Contributor

Done with initial review.

@gruehle
Copy link
Member Author

gruehle commented Jan 26, 2013

The parens show up for some file types, but not for others. If I right-click a markdown file, Sublime is the default app, and Brackets shows up without "()". If I right-click a .css file, Brackets shows up with "()". I don't know why.

@gruehle
Copy link
Member Author

gruehle commented Jan 26, 2013

Changes pushed.

<key>LSItemContentTypes</key>
<array>
<string>public.text</string>
<string>public.source-code</string>
Copy link
Contributor

Choose a reason for hiding this comment

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

Indenting in this file is not consistent (mix of spaces and tabs?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@redmunds
Copy link
Contributor

Not sure how important this is, but if you don't have setup_for_hacking setup (which gets cleared every time I do a build on Mac), and you drop a file on icon, Brackets is opened, but the file is forgotten.

@redmunds
Copy link
Contributor

Done with second review.

I sent a crash log with the first review, and saw another crash just now. Any ideas about that?

@gruehle
Copy link
Member Author

gruehle commented Jan 29, 2013

I can consistently reproduce the mac crash now with the following steps:

  1. Launch Brackets
  2. In the Finder, drag a file to the Brackets icon
  3. Click the close button on the Brackets window (note: you must click the close button--pressing Cmd-Q works)

Unfortunately, I haven't been able to determine a fix yet, so this shouldn't be merged until I have time to fix the crash.

@gruehle
Copy link
Member Author

gruehle commented Feb 14, 2013

@redmunds - I finally fixed the crash on quit bug. This pull request is now ready for final review.

@redmunds
Copy link
Contributor

I can no longer reproduce crash.

Last question I have is, what do you think about the "if you don't have setup_for_hacking setup (which gets cleared every time I do a build on Mac), and you drop a file on icon, Brackets is opened, but the file is forgotten" issue?

@gruehle
Copy link
Member Author

gruehle commented Feb 15, 2013

what do you think about the "if you don't have setup_for_hacking setup (which gets cleared every time I do a build on Mac), and you drop a file on icon, Brackets is opened, but the file is forgotten" issue?

I'm not really worried about it. You can drop files onto a running instance of Brackets in that case, so it only affects a minor use case for a small number of users.

@redmunds
Copy link
Contributor

Looks good. Merging.

redmunds added a commit that referenced this pull request Feb 15, 2013
Initial implementation of drag and drop to open files
@redmunds redmunds merged commit 49820e6 into master Feb 15, 2013
@redmunds redmunds deleted the glenn/file-association branch February 15, 2013 19:41
redmunds added a commit that referenced this pull request Dec 8, 2015
Initial implementation of drag and drop to open files
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants