microsoft / PTVS

Python Tools for Visual Studio
https://aka.ms/PTVS
Apache License 2.0
2.53k stars 676 forks source link

New project from existing code enhancements #13

Closed zjturner closed 3 years ago

zjturner commented 9 years ago

1) Create a blank visual studio solution 2) Right click the solution node, choose Add New Project -> Python -> From Existing Python Code 3) Go through the steps.

At the end of the wizard, your project will have been added to a new solution, not the original one.

int19h commented 9 years ago

Good catch! Not sure we can do anything about it, though - that setup is a bit of a hack in the first place (and only exists because File -> New -> Project From Existing Code is not extensible). I'll have a look.

zjturner commented 9 years ago

Another thing that's a little weird, is that the very first dialog when you click Add New Project (the place where you choose the "From Existing Python Code" project template) asks you to enter a project name and project location. Presumably at this point it is fully specified that the project file should be called <location>\<name>.pyproj. Or at least that should be the most reasonable default. But when you click through, you get to another dialog asking you where to save your project, and it uses both a location and a project name unrelated to the values you specified in the first dialog. For example, I chose the following values on the first dialog:

Name: PythonApplication1 Location: d:\src\llvm\tools\lldb\PythonVS

On the second page, when it asks where my Python source is, I choose d:\src\llvm\tools\lldb\scripts

On the last page, the name it suggests for the project file is d:\src\llvm\tools\lldb\scripts\scripts1.pyproj. I would expect it to be called d:\src\llvm\tools\lldb\PythonVS\PythonApplication1.pyproj

int19h commented 9 years ago

Yep, that's the other (known) artifact of it being a hack. The initial dialog is the standard one that VS shows for all project templates. For "From Existing Code" pseudo-template, it's basically just ignored, but we can't hide those UI elements.

zooba commented 9 years ago

This is actually a deliberate design choice, otherwise people who ignore the initial text boxes get strange values later on. Changing the source location updates the project location until you modify the project.

You can always do a Save Project As after creating it to move it elsewhere.

zjturner commented 9 years ago

Hmm, i have to admit it feels strange to assume that users are going to ignore a dialog. It makes the experience very confusing for people who are doing things the "correct" way. but on the other hand I'm sure you all have thought about this more than i have.

Could it at least use the values from the initial dialog to populate the default project file path later on? Users could still change this. To make this easier, maybe you could have two radio buttons. First says "Save the project in a default location" and uses this "correct" value from the non extensible VS dialog. Second says "Manually specify a location" and defaults to what it currently defaults to. By default first radio button is checked.

This seems like a decent middle ground but optimized for people who didn't ignore the first dialog. On Sat, Apr 11, 2015 at 6:18 AM Steve Dower notifications@github.com wrote:

This is actually a deliberate design choice, otherwise people who ignore the initial text boxes get strange values later on. Changing the source location updates the project location until you modify the project.

You can always do a Save Project As after creating it to move it elsewhere.


From: Pavel Minaevmailto:notifications@github.com Sent: ‎4/‎10/‎2015 18:20 To: Microsoft/PTVSmailto:PTVS@noreply.github.com Subject: Re: [PTVS] Adding a new project to an existing solution tries to make a new solution (#13)

Yep, that's the other (known) artifact of it being a hack. The initial dialog is the standard one that VS shows for all project templates. For "From Existing Code" pseudo-template, it's basically just ignored, but we can't hide those UI elements.

— Reply to this email directly or view it on GitHub< https://github.com/Microsoft/PTVS/issues/13#issuecomment-91707331>.

— Reply to this email directly or view it on GitHub https://github.com/Microsoft/PTVS/issues/13#issuecomment-91844048.

zooba commented 9 years ago

The "default" in this case is for the project to be created in the source directory, so it currently behaves correctly in all cases that I'm aware of. There's an option to customize the location at the end of the wizard, and we'll only reset the project location if you modify the source path in the wizard as well.

So basically, if you set both paths in advance it will be fine, and if you set the both in the wizard you're also fine. The only issue is when you set both in advance and then change one in the wizard, and there's no good way for us to handle this since we don't know whether the original location was changed or not.

zjturner commented 9 years ago

Well, the case that it doesn't behave correctly in (at least for me) is this:

I have some python code in a repository. I can't check in my Visual Studio solution / project because not everyone on the team is using Windows, much less PythonTools, so it's not appropriate for putting in the general repository. So I want to put the solution and project off in My Documents somewhere. I click New Project. I choose From Existing Python Code and in the same dialog, before proceeding, I type a name for the project. So instead of PythonApplication1.pyproj I call it something like PythonTestSuite.pyproj. I choose the default folder location, which is something like C:\Users\zturner\Documents and Settings\Visual Studio 2013\PythonTestSuite.

When it asks me where the python source is, I choose the repository location. When I get to the end of the wizard, it's ignored the fact that I've chosen to name the project PythonTestSuite and put it in My Documents, instead creating a brand new project name and location in the same folder that I've said the Python source is in. So now I have to change it again to the same value that I thought I already set it to.

On the one hand I get what you're trying to do, which is that usually people will want the project / solution in the same folder as the source. But on the other hand it makes for a really confusing experience when you don't want this behavior, because Visual Studio has conditioned people (or at least me anyway, I guess I'm not the only one) to type the solution name and location in the first dialog you get when selecting the project template.

It seems like there should be some sort of reasonable UI solution to this. For example, two radio buttons like I mentioned, where the one selected by default is to use Visual Studio's location (C:\Users\zturner\Documents and Settings\Visual Studio 2013\PythonTestSuite\PythonTestSuite.pyproj or whatever), and another one which the user can click and get the location they've browsed to for their python source.

FWIW, I know you're using "the location of the python source" as the default, but I chose the other one as default because it seems to be what Visual Studio wants people to use (evidenced by the fact that the dialog is non-extensible). So I feel like it should play as nicely as possible with The One Blessed Way, if nothing else for consistency with the rest of the Visual Studio ecosystem.

Anyway, ultimately it's your call, I did my best ;-)

zooba commented 7 years ago

We pass through the paths from the New Project dialog to the wizard, but we still don't support Add to Solution.

zjturner commented 7 years ago

Has there been any progress on this? This, along with various other user interface quirks with the project wizard have been continually biting me for over 2 years. I thought I would grow into it after training my muscle memory, but I'm coming around to the belief that this really should be fixed.

To summarize:

  1. New -> Project -> From Existing Python Code doesn't remember your paths or names. The ultimate in frustration. This affects every single user who creates a new project from existing code, because it makes you go through several clicks just to throw all of your information away. After I type in Name, Location, and Solution name as in this screenshot, by the time I've gotten to the end of the wizard it has already forgotten and made up a new project name for me, as in this screenshot. Why doesn't it choose the location D:\src\llvm-mono\llvm\utils\ptvs\llvm.pyproj here?

  2. Add to Solution doesn't work. This is especially frustrating with solutions with large number of projects, because every new project requires 3-4 separate actions. One to create the project, one to close the new solution, one to re-open the old solution, and another to add the newly created project. 4 actions for what should require one, and for what the user interface tells you WILL in fact require just 1.

Now that we've been through 2 major VS releases since this was filed, has the VS team provided any additional hooks to make it possible to solve this?

zooba commented 6 years ago

Sorry, there hasn't been any progress on this. We've been burning down higher priority issues with the limited resources we have. There also hasn't been any improvement in what we get from the original dialog, so we are still in a position of having to make the best guesses we can.

To answer point 1, the intent is that you do not have to select the location and project name in the dialog. We try to disable those fields, but there are some combinations of settings that don't allow it, and so we do the best we can to flow them through. But since we can't distinguish between the default values and user-customized values, we still trigger the logic of "you selected a new source directory in the wizard, so we'll pick an appropriate project location and name from your selection". This is how you end up with a new project file location - you customize the source location and we don't have any way to know that you already customized the project location in a totally different place.

For point 2, this is probably easier to solve. It might be easiest as a checkbox on the last page of the wizard to Add rather than Create, and then we should be able to flow that into the logic that opens the project. Depending on how much time we have available we might be able to get this in, but no promises.

huguesv commented 6 years ago

I've moved the original "add to existing solution" bug to https://github.com/Microsoft/PTVS/issues/4028, and we can keep the discussion on folder paths and such here.