Author Topic: How can I get the full path of the project file the editor displaying?  (Read 13661 times)

Offline bruce

  • Multiple posting newcomer
  • *
  • Posts: 13
    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!
« Last Edit: March 30, 2012, 02:04:54 pm by bruce »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
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"?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline bruce

  • Multiple posting newcomer
  • *
  • Posts: 13
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.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
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.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
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?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
If you just want to get the name of the file in the active editor, something like this should work:
Code
    
    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

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5516
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)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
killerbot: you can use: "right click on the tab->show file in the project tree"
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9693
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?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
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.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline bruce

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: How can I get the full path of the project file the editor displaying?
« Reply #10 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
    
    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?

Offline bruce

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: How can I get the full path of the project file the editor displaying?
« Reply #11 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.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5516
Re: How can I get the full path of the project file the editor displaying?
« Reply #12 on: April 02, 2012, 11:27:01 am »
killerbot: you can use: "right click on the tab->show file in the project tree"

 ;D

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5516
Re: How can I get the full path of the project file the editor displaying?
« Reply #13 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 .