Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: bear24rw on October 21, 2007, 10:27:58 pm

Title: Get current project path name
Post by: bear24rw on October 21, 2007, 10:27:58 pm
Hi, how do i find the current projects complete directory location...

I thought it might be something like this..

    wxString exeFileName = _("${TARGET_OUTPUT_DIR}${TARGET_OUTPUT_FILE}");
    Manager::Get()->GetMacrosManager()->ReplaceEnvVars (exeFileName);

But I don't know what the variable name would be..

Any help would be appreciated
Title: Re: Get current project path name
Post by: bear24rw on October 21, 2007, 10:30:48 pm
Answered my own question
I found a list of variables in macrosmanager.cpp

I am now using

    wxString proj_direc= _("${PROJECT_DIRECTORY}");
    Manager::Get()->GetMacrosManager()->ReplaceEnvVars (proj_direc);

And it works, but...

If i open a project, it gives me the right path.. if i close the project and immediately open another one.. it still gives me the path of the old project.. but if i close the project.. try to get the path its blank (like it should be) and then open a project it gives me the right path of the new project

Is there any way of like making sure the variables are 'refreshed'?


//// EDIT

So I just traced back the functions to figure out what they were doing and ending up with...

wxString exeFileName = UnixFilename(Manager::Get()->GetProjectManager()->GetActiveProject()->GetBasePath());

Which solves the problem i was having before, so im good now
Title: Re: Get current project path name
Post by: thomas on October 22, 2007, 10:10:25 am
Quote
If i open a project, it gives me the right path.. if i close the project and immediately open another one.. it still gives me the path of the old project.. but if i close the project.. try to get the path its blank (like it should be) and then open a project it gives me the right path of the new project
This is a "normal" behaviour from MacrosManager's point of view. And although it is obviously wrong, there is little one can do about it right now.
The problem lies in a deficiency of ProjectManager paired with a bad use of build targets (which, unluckily, Code::Blocks encourages you to do, too).

Quote
wxString exeFileName = UnixFilename(Manager::Get()->GetProjectManager()->GetActiveProject()->GetBasePath());
That's the correct way to do what you wanted.