Menu

#579 Code::Blocks opens the same workspace by CmdLine/FileManager instead of the new selected

Undefined
fixed
nobody
Bug_Report
2021-12-18
2017-12-07
CBUser2017
No

Hello CB-Team,

in the Code::Blocks IDE is an issue, that the wrong workspace will be opend by a defined set of the configuration.

System:
Code::Blocks 16.01
Windows 10 (1703)

Konfiguration:
checked, (General Settings) -> Allow only one running instance (will take place after restart)
checkes, (General Settings) -> Use an already running instance (if possible)
!! The Filetype ".workspace" is registered to CB-Launcher !!

Plugins:
File-Manager (to open Workspace by double click)

Description:
By opening a workspace with a double click in the File-Manager-Tree the Code::Blocks IDE opens the correct workspace (first time). When i now close the workpace and try to open an other workspace, the codeblocks opens the first workspace again.

Analyse:
In the system the "Manager::GetCmdLineParser()" in the "src/app.cpp" add only new command lines an in the case of a workspace, only the first entry will be used every time.
See Function: int CodeBlocksApp::ParseCmdLine(MainFrame* handlerFrame, const wxString& CmdLineString)

I'm not sure if it is a good Idea to delete all entrys in the CmdLineParser, create a new wxCmdLineParser or if they are used for other parts.
My first solution was, that i change the direction of reading the parameter of the Parser, to get the last insertet entry first.

Code:
filesInCmdLine = (count != 0) || (!m_AutoFile.empty());

        for (int param = count - 1; param >= 0; param--)
        {
            // is it a project/workspace?
            FileType ft = FileTypeOf(parser.GetParam(param));
            wxFileName fn(parser.GetParam(param));
            ...

In th current trunk i see no changes for the following release at this function.
Please check if it is an issue that is still in the Code::Blocks.
I think it will also occur by opening/changing workspaces out of the windows explorer (doubleclick on workspacefiles).

Discussion

  • Teodor Petrov

    Teodor Petrov - 2017-12-07

    This report looks the same as [#384]. Is this the case?

    What is the value of CmdLineString every time the function is called?

     

    Related

    Tickets: #384

  • Teodor Petrov

    Teodor Petrov - 2017-12-07
    • labels: Allow only one running instance, Use an already running instance, Open Workspace, File Manager --> File Manager
     
  • CBUser2017

    CBUser2017 - 2017-12-07

    Thanks for the quick response.
    Sorry this issue is a little bit hard to explain.
    It is not a compile error, is a functional issue by open/change workspaces with CB.
    The value in the CmdLineString is the selected workspace-file.

    In the following line the parser will be set to a "static" Pointer of the CmdLineParser in the Manager-Class:
    wxCmdLineParser& parser = *Manager::GetCmdLineParser();

    With every "CloseWorkspace and DoubleClick on an other Workspacefile" the Manager::GetCmdLineParser()->GetParamCount() incremeted.

    Code with Log-Output an Comment-Description:

    int CodeBlocksApp::ParseCmdLine(MainFrame* handlerFrame, const wxString& CmdLineString)
    {

    Manager::Get()->GetLogManager()->Log(_("===================> APP Parse CmdLine -> CmdLineString ") + CmdLineString);
    // Here the CmdLineString is correct (new Workspacefile) every time
    
    Manager::Get()->GetLogManager()->Log(F(_("===================> APP Parse CmdLine -> GetCmdLineParser->Count=%d"), Manager::GetCmdLineParser()->GetParamCount()) );
    // Here the Count is 0 in the first time and everything works fine
    // When the Workspace is closed and a new will be open count ist 1
    
    wxCmdLineParser& parser = *Manager::GetCmdLineParser();
    if ( CmdLineString.IsEmpty() )
      parser.SetCmdLine(argc, argv);
    else
      parser.SetCmdLine(CmdLineString);
      // Here the new CmdLineString is added to the parser
    
    ...
    
    // Corrected Search-Direction in parser
    for (int param = count - 1; param >= 0; param--)
            {
                //Manager::Get()->GetLogManager()->Log(_("===================> APP Parse CmdLine ->Param: ") + parser.GetParam(param));
                // Now the last added workspace will be opend and not the first insertet workspace of pointer to the "static" Manager::GetCmdLineParser()
                // In the current code with "for (int param = 0; param < count; ++param)" the System opens the first entry with the wrong Workspacefile an jumps out of the loop, see the following else if block
    
               ...
    
                else if (ft == ftCodeBlocksWorkspace)
                {
                    // only one workspace can be opened
                    m_HasWorkSpace = true;
                    m_DelayedFilesToOpen.Clear(); // remove all other files
                    m_DelayedFilesToOpen.Add(fn.GetFullPath()); // and add only the workspace
                    break; // and stop processing any more files
                }
    

    I hope this helps to understand it a little bit better.

     
  • Teodor Petrov

    Teodor Petrov - 2017-12-07

    Ops, I've linked the wrong issue... See this one [#348].

    I don't think your solution is good...

     

    Related

    Tickets: #348

  • CBUser2017

    CBUser2017 - 2017-12-08

    Hi Teodor,

    yes i think thats exact the same issue.
    I know that it was a very quick and dirty workaround and it normally makes no sence to keep all the previous CmdLines in the Parser from the new CB instance, so i try to apply the patch in the wxWidgets.
    Thanks for this link.

     
  • CBUser2017

    CBUser2017 - 2017-12-08

    The patch works fine.
    The search direction can be "reverted" and the log output of the count stays at max 1, after the first workspace change.

    This Ticket can be closed.

     
  • Miguel Gimenez

    Miguel Gimenez - 2021-12-18
    • status: open --> fixed
     
  • Miguel Gimenez

    Miguel Gimenez - 2021-12-18

    wxWidgets problem, fixed in wx3.0.2

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.