Code::Blocks

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: bruce on March 30, 2012, 11:33:48 am

Title: How can I get the full path of the project file the editor displaying?
Post by: bruce on March 30, 2012, 11:33:48 am
    I am developing a plugin for CB. I encountered a problem that how to obtain the message of the a project whose file is being displaying by the editor.
    That is, I need to know the full path of the project whose file is the focus of the editor of CB. I need the absolute path to create a new file under the project folder.
    Which library functions could help me to accomplish this task?
    I will appreciate your tips!
Title: Re: How can I get the full path of the project file the editor displaying?
Post by: oBFusCATed on March 30, 2012, 12:04:34 pm
Sorry, but you'll have to try again and be more clear.
It is not possible to understand what you're trying to achieve from your first post.

What is the meaning for "message"?
Title: Re: How can I get the full path of the project file the editor displaying?
Post by: bruce on March 30, 2012, 02:02:50 pm
Sorry, but you'll have to try again and be more clear.
It is not possible to understand what you're trying to achieve from your first post.

What is the meaning for "message"?

The "message" is the full path of the project whose file is the focus of the editor of the CB. Do I make it clear for you ? Thanks you for your reading.
Title: Re: How can I get the full path of the project file the editor displaying?
Post by: ollydbg on March 30, 2012, 03:12:56 pm
Still not clear, but I can guess. You need is the cbEVT_EDITOR_ACTIVATED and cbEVT_PROJECT_ACTIVATE event.
Search those words in C::B's source, you can see many usage of those events.
Title: Re: How can I get the full path of the project file the editor displaying?
Post by: oBFusCATed on March 30, 2012, 03:17:13 pm
Ollydbg: I doubt it is that.
Bruce: If you really want to help you, you have to try harder to explain what do you want to achieve.

As far as I can understand, you want to find a way to get the full path to the active file?
Title: Re: How can I get the full path of the project file the editor displaying?
Post by: jens on March 30, 2012, 03:42:12 pm
If you just want to get the name of the file in the active editor, something like this should work:
Code: [Select]
   
    wxString theName;
    EditorManager* em = Manager::Get()->GetEditorManager();
    if (em)
    {
        EditorBase* eb = em->GetActiveEditor();
        if (eb)
        {
            theName = eb->GetFilename();
        }
    }

Warning: not tested, just written from memory
Title: Re: How can I get the full path of the project file the editor displaying?
Post by: killerbot on March 30, 2012, 05:41:00 pm
I think he wants the the full path of the project (cbp file) which is the parant (owner) of the file open in the active editor.

To be honest we should do something similar on the inside, since I also have a nice use case for this :
addition in our right click menu : activate project containing "this" file.

Why : my workspace contains a whole lot of projects, sometimes starting from project x I include file open and end up at file foo.h (F11 to foo.cpp) and suddenly I want to change it's code and build the project it belongs too ...., and searching for the project is hard, even with the find file (since that one is really case sensitive, and no wildcards)
Title: Re: How can I get the full path of the project file the editor displaying?
Post by: oBFusCATed on March 30, 2012, 06:25:24 pm
killerbot: you can use: "right click on the tab->show file in the project tree"
Title: Re: How can I get the full path of the project file the editor displaying?
Post by: MortenMacFly on March 30, 2012, 08:30:09 pm
To be honest we should do something similar on the inside, since I also have a nice use case for this :
addition in our right click menu : activate project containing "this" file.
Well a file can belong to many projects/targets. What would you do then? Ask which one to activate?
Title: Re: How can I get the full path of the project file the editor displaying?
Post by: ollydbg on March 31, 2012, 08:33:50 am
Well a file can belong to many projects/targets. What would you do then? Ask which one to activate?
CodeCompletion plugin also have such issue. Currently, we just search every opened projects, and choose the first one matches the file.
Title: Re: How can I get the full path of the project file the editor displaying?
Post by: bruce on March 31, 2012, 10:06:48 am
If you just want to get the name of the file in the active editor, something like this should work:
Code: [Select]
   
    wxString theName;
    EditorManager* em = Manager::Get()->GetEditorManager();
    if (em)
    {
        EditorBase* eb = em->GetActiveEditor();
        if (eb)
        {
            theName = eb->GetFilename();
        }
    }

Warning: not tested, just written from memory

    Your code satisfied my needs, thanks very much for your solution to my problem. I succeeded in getting the full path of the file in the active editor.
    But I encountered another problem that I wanted to know what is the definition of the Manager class. I have used this class before. I searched my CB sdk documentation for its definition , but in vain, I only get its members, and its members' usage. Which website can help to query the main purpose of the Manager class?
Title: Re: How can I get the full path of the project file the editor displaying?
Post by: bruce on March 31, 2012, 10:08:59 am
Ollydbg: I doubt it is that.
Bruce: If you really want to help you, you have to try harder to explain what do you want to achieve.

As far as I can understand, you want to find a way to get the full path to the active file?

Yes, that is my aim. I have accomplished this task, Thanks very much.
Title: Re: How can I get the full path of the project file the editor displaying?
Post by: killerbot on April 02, 2012, 11:27:01 am
killerbot: you can use: "right click on the tab->show file in the project tree"

 ;D
Title: Re: How can I get the full path of the project file the editor displaying?
Post by: killerbot on April 02, 2012, 11:27:56 am
To be honest we should do something similar on the inside, since I also have a nice use case for this :
addition in our right click menu : activate project containing "this" file.
Well a file can belong to many projects/targets. What would you do then? Ask which one to activate?

I guess this is something we could do. Will be easier to make a choice from the selected alternatives, then manual search .