Author Topic: Bring C::B to front when opening file via command line  (Read 14267 times)

Offline daniloz

  • Regular
  • ***
  • Posts: 268
Bring C::B to front when opening file via command line
« on: April 14, 2011, 08:51:56 am »
Hi All,

Is it possible to "force" C::B to "pop up" (i.e. bring to front of other windows) when opening a file via command line?

I have the following command line
Code
c:\Path_to_CB\codeblocks.exe file.cpp

When I run it from the command line (or from another application - that's what I want ultimately), "file.cpp" is opened inside C::B, but the window doesn't pop up in front of others, so I have to manually click on it on the taskbar.

However, if I use the DDEserver, by just double-clicking in a file on Windows Explorer (Total Commander, actually ;-) ), then the C::B window DOES pop-up...

I haven't found any command line option to make what I want happen...

Thanks!
Btw, I'm running C::B rev. 7096 compiled from trunk with wx 2.8.10 on Windows 7.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Bring C::B to front when opening file via command line
« Reply #1 on: April 14, 2011, 10:08:21 am »
It works here on XP (will test on win7 with latest trunk later).

Are both checkboxes in "Settings -> Environment... -> General settings -> Dynamic Data Exchange" active ?

Offline daniloz

  • Regular
  • ***
  • Posts: 268
Re: Bring C::B to front when opening file via command line
« Reply #2 on: April 14, 2011, 10:36:22 am »
It works here on XP (will test on win7 with latest trunk later).

Are both checkboxes in "Settings -> Environment... -> General settings -> Dynamic Data Exchange" active ?

Yeah, both ticked... But, I'm not using DDE when I call it from the command line, am I?

EDIT:
It works if C::B is in back, but maximized... However, if C::B is minimized, then it only get maximized when double-clicking in a file in Explorer, not when using the command-line...
« Last Edit: April 14, 2011, 10:39:00 am by daniloz »

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Bring C::B to front when opening file via command line
« Reply #3 on: April 14, 2011, 11:31:06 am »
Yeah, both ticked... But, I'm not using DDE when I call it from the command line, am I?

EDIT:
It works if C::B is in back, but maximized... However, if C::B is minimized, then it only get maximized when double-clicking in a file in Explorer, not when using the command-line...

The newly started C::B uses DDE (on windows) or a socket (on linux) to communicate with the running instance of C::B.
Thanks for the second hint, that should be easy to fix (hopefully).

Offline daniloz

  • Regular
  • ***
  • Posts: 268
Re: Bring C::B to front when opening file via command line
« Reply #4 on: May 25, 2012, 09:28:00 am »
Thanks for the second hint, that should be easy to fix (hopefully).

Attached is a patch to fix it...

Also, related to some cross-posting, here are my answers to the following discussion:

No, I doubt that forcing the maximizing is the right thing to do, but you should provide a patch there, where the context is correct.

Btw: Instead of IsMaximized() you should check for !IsIconised() and issue a Show() then... IMHO that's the better option. Notice the Iconised, not Iconized... ;-)

Thanks MortenMacFly for the suggestion, I also think that IsIconized() is the right check here. However, instead of Show(), I'am issuing a Iconize(false), since the documentation says that Show() is the opposite of Hide(), whereas here I've found that Iconize(false) is what I want.

Just a strange thing. In my local copy (rev. 7993, wx2.8.12, win7 64-bit) and in the documentation, the functions are IsIconiZed() and IconiZe(false), both with Z. Do you have another version of wxWidgets??  :o

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Bring C::B to front when opening file via command line
« Reply #5 on: May 25, 2012, 10:32:47 am »
Attached is a patch to fix it...
Great, will try...

Thanks MortenMacFly for the suggestion, I also think that IsIconized() is the right check here. However, instead of Show(), I'am issuing a Iconize(false), since the documentation says that Show() is the opposite of Hide(), whereas here I've found that Iconize(false) is what I want.
That is true. I didn't consult the docs, but from what I see now it is the right thing to do.

Do you have another version of wxWidgets??  :o
No, all methods of wxWidgets are usually available in British and American English. We had this discussion just recently that we agreed to use the British English variant, if available. Documented are generally only the American versions... IMHO... To check, you have to open the interface (header) file, or just try if the compiler complains when using the British one... ;-)
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 daniloz

  • Regular
  • ***
  • Posts: 268
Re: Bring C::B to front when opening file via command line
« Reply #6 on: May 25, 2012, 10:41:06 am »
No, all methods of wxWidgets are usually available in British and American English. We had this discussion just recently that we agreed to use the British English variant, if available. Documented are generally only the American versions... IMHO... To check, you have to open the interface (header) file, or just try if the compiler complains when using the British one... ;-)

It seems that this time, only American versions are available... ;)
Code
C:\Work\codeblocks_trunk\src\src\app.cpp:139:26: error: 'class MainFrame' has no member named 'IsIconised'
C:\Work\codeblocks_trunk\src\src\app.cpp:140:14: error: 'class MainFrame' has no member named 'Iconise'

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Bring C::B to front when opening file via command line
« Reply #7 on: May 25, 2012, 10:54:24 am »
It seems that this time, only American versions are available... ;)
OK - so it seems the wx guys are in-consequent or changed their philosophy. Nevermind.

However, I wonder if instead of:
Code
        if (m_Frame)
        {
            if (m_Frame->IsIconized())
                m_Frame->Iconize(false);
            else
                m_Frame->Raise();
        }
...you should write:
Code
        if (m_Frame)
        {
            if (m_Frame->IsIconized())
                m_Frame->Iconize(false);
            m_Frame->Raise();
        }
? Or does Iconize(false) also raises the window automatically?
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 daniloz

  • Regular
  • ***
  • Posts: 268
Re: Bring C::B to front when opening file via command line
« Reply #8 on: May 25, 2012, 11:02:43 am »
Or does Iconize(false) also raises the window automatically?
As far as I can see/test, it also raises the window automatically.

What I did to test was to have the codeblocks window opened, then I maximized another window to cover it and clicked on the windows taskbar in order to iconize codeblocks. After calling it from the command line to open a file, the codeblocks window was de-iconized and was on top of all windows, i.e. I could see it. :D So, to me, just the call to Iconize(false) is enough...

Since I have no much experience with these things (windows, z-level, iconize etc..), do you have any other idea/concern/suggestion/test case? ;)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Bring C::B to front when opening file via command line
« Reply #9 on: May 25, 2012, 11:05:31 am »
do you have any other idea/concern/suggestion/test case? ;)
No, but I know that iconising and raising are two different things. So to be on the safe side, I would always raise. This might be a platform / configuration thing, too. For example, on Windows there is a switch to (dis-) allow stealing the focus of windows globally which affects Raise().
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 daniloz

  • Regular
  • ***
  • Posts: 268
Re: Bring C::B to front when opening file via command line
« Reply #10 on: May 25, 2012, 01:22:15 pm »
do you have any other idea/concern/suggestion/test case? ;)
No, but I know that iconising and raising are two different things. So to be on the safe side, I would always raise. This might be a platform / configuration thing, too. For example, on Windows there is a switch to (dis-) allow stealing the focus of windows globally which affects Raise().
Ok, as I said I have no experience in this area, so I accept your suggestion.

Attached is a patch with "always raise".

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Bring C::B to front when opening file via command line
« Reply #11 on: May 25, 2012, 04:50:39 pm »
Attached is a patch with "always raise".
...and applied in SVN after testing. Seems really to fix the bug.
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