News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

Bring C::B to front when opening file via command line

Started by daniloz, April 14, 2011, 08:51:56 AM

Previous topic - Next topic

daniloz

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

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.

Jenna

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 ?

daniloz

Quote from: jens 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 ?

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...

Jenna

Quote from: daniloz on April 14, 2011, 10:36:22 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).

daniloz

Quote from: jens on April 14, 2011, 11:31:06 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:

Quote from: oBFusCATed on May 24, 2012, 08:01:38 PM
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.

Quote from: MortenMacFly on May 24, 2012, 08:24:22 PM
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

MortenMacFly

Quote from: daniloz on May 25, 2012, 09:28:00 AM
Attached is a patch to fix it...
Great, will try...

Quote from: daniloz on May 25, 2012, 09:28:00 AM
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.

Quote from: daniloz on May 25, 2012, 09:28:00 AM
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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

daniloz

Quote from: MortenMacFly on May 25, 2012, 10:32:47 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... ;)

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'

MortenMacFly

Quote from: daniloz on May 25, 2012, 10:41:06 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:
       if (m_Frame)
       {
           if (m_Frame->IsIconized())
               m_Frame->Iconize(false);
           else
               m_Frame->Raise();
       }

...you should write:
       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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

daniloz

Quote from: MortenMacFly on May 25, 2012, 10:54:24 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? ;)

MortenMacFly

Quote from: daniloz on May 25, 2012, 11:02:43 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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

daniloz

Quote from: MortenMacFly on May 25, 2012, 11:05:31 AM
Quote from: daniloz on May 25, 2012, 11:02:43 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().
Ok, as I said I have no experience in this area, so I accept your suggestion.

Attached is a patch with "always raise".

MortenMacFly

Quote from: daniloz on May 25, 2012, 01:22:15 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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]