Author Topic: How to auto open files with an external program?  (Read 10752 times)

Offline TerryP

  • Multiple posting newcomer
  • *
  • Posts: 26
    • My journal
How to auto open files with an external program?
« on: January 16, 2010, 10:42:52 pm »
I've tried searching the forum but it doesn't seem to turn anything up. In short, I want the IDE to auto open certain file types using an associated external program, whenever I double click the file in the managers projects tab. That should be fairly obvious from the topics title.


However as much as I've seen by poking around the UI, it's required to right click and use the 'open with' to reach that. Whether or not it's possible to create a toolbar button or keyboard shortcut to open the currently selected file with an external tool instead of the file extension handler or internal editor, I would consider that kind of solution to be side stepping something that should logically be built into the IDE, or a user demonstrating their level of brain damage \o/. The value of auto running a program on double click ranges from using an external code editor, to viewing attached image files, and well beyond. I doubt the internal code/hex editors were designed to handle every possible type of file, and there's no valid excuse for having to be explicit every time you want to open a file with a different program. Visual C++ can handle this type of configuration fairly well but rather lacks Code::Blocks portability, in both several senses of the word ^_^.



Since Code::Blocks has grown a scripting language since our last date (Cica 2005), it occurs to me to ask: is it possible to make a script (or even a plugin) that could enforce using a the file extension handler on the double click of a file in the manager window, rather then auto opening it in the IDEs editor? The stuff on the wiki is a bit, disappointing.


If not, the only things I can think of, is building my own binaries with a personal patch set to add it by force, or finding a more mature tool then Code::Blocks.
Just Another Computer Geek

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6613
    • My Best Post
Re: How to auto open files with an external program?
« Reply #1 on: January 16, 2010, 10:51:58 pm »
If inside Code::Blocks the MIME Plugin does this.

If outside Code::Blocks the operating system does the clicks.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline TerryP

  • Multiple posting newcomer
  • *
  • Posts: 26
    • My journal
Re: How to auto open files with an external program?
« Reply #2 on: January 16, 2010, 11:13:17 pm »
Where can I find this "MIME" plugin? There doesn't appear to be anything by that name in the files I installed, like wise searches of Forum, Wiki, and Google yield nothing of value. Anything I define in "Settings -> Environment -> File extension handling" are only respected when telling Code::Blocks context menu, to open it that way instead of with the internal editor.
Just Another Computer Geek

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: How to auto open files with an external program?
« Reply #3 on: January 16, 2010, 11:32:50 pm »
"Settings -> Environment... -> File extension handling"

Offline TerryP

  • Multiple posting newcomer
  • *
  • Posts: 26
    • My journal
Re: How to auto open files with an external program?
« Reply #4 on: January 17, 2010, 12:36:50 am »
Well then, unless *.extension is not a suitable wild card for all cases, there must be more to it then that. As a test, I've tried defining two file extensions:

*.c - set to open with associated application; it opens in the internal editor on double click.

*.png - set to open with associated application; it opens with the windows default on double click.


So it would seem, this problem only applies to file extensions built in. That could make it potentionally difficult, for sake of example, to use the internal editor for Java code but an external editor for C++ files. I want the file associations to work irregardless of whether the file extension is known to Code::Blocks already, perhaps a more indepth wild card is needed?



My apologies are apparently due, because the first tests I conducted were overriding *.cpp and *.c files before moving on to other file types.   (Well, testing against C/C++ files is the most obvious thing to try first after all... since C::B targets the language most strongly)



Is it possible to get it working with 'all' file types set?
Just Another Computer Geek

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9496
Re: How to auto open files with an external program?
« Reply #5 on: January 17, 2010, 06:31:55 am »
As a test, I've tried defining two file extensions:
*.c - set to open with associated application; it opens in the internal editor on double click.
*.png - set to open with associated application; it opens with the windows default on double click.
[...]
use the internal editor for Java code but an external editor for C++ files.
What's your use case? You are trying to edit natively supported files (all C/C++ files) with an external editor and others (like Java) with the internal one?! I don't get what you actually want. It's like trying to use Paint for documents and have it open images with word for me.

However, if I setup e.g. *.png to be used with an external program it works for me. Are you sure you did the setup correctly? You need to choose "use external program" and select the program in the settings field accordingly (see the attached image).

[attachment deleted by admin]
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: How to auto open files with an external program?
« Reply #6 on: January 17, 2010, 09:57:41 am »
However, if I setup e.g. *.png to be used with an external program it works for me. Are you sure you did the setup correctly? You need to choose "use external program" and select the program in the settings field accordingly (see the attached image).

Burt you have to make sure, that you have no other wildcard that matches the file you want to open, that comes earlier in the list, otherwise this one is used.

Offline TerryP

  • Multiple posting newcomer
  • *
  • Posts: 26
    • My journal
Re: How to auto open files with an external program?
« Reply #7 on: January 17, 2010, 06:51:30 pm »
Burt you have to make sure, that you have no other wildcard that matches the file you want to open, that comes earlier in the list, otherwise this one is used.

File types known to Code::Blocks already (e.g. no file extension settings needed) wouldn't happen to come first on that list, would they? :-).


What's your use case? You are trying to edit natively supported files (all C/C++ files) with an external editor and others (like Java) with the internal one?! I don't get what you actually want. It's like trying to use Paint for documents and have it open images with word for me.

My personal use case: would be to edit all code files by handing it off to a custom program that intelligently forwards to a vim server. That goes for all program source code short of APL.

The wider interest in adapting an IDE for project maintenance, is to make cross platform builds easier, while presenting a standardisable environment that is both friendly to vim / emacs / ed / TextMate / blah blah users and those preferring the internal editor, and doing it in a way that isn't a pain in the neck to support on work stations running different OSes.


As a matter of engineering, I would kind of expect telling Code::Blocks to open all *.cpp files in notepad, would make them open in notepad without regard for the internal editor \o/.


However, if I setup e.g. *.png to be used with an external program it works for me. Are you sure you did the setup correctly? You need to choose "use external program" and select the program in the settings field accordingly (see the attached image).

Unless there is a secret manual that no one told me about, yes; and fully tested under 8.02 and the nightly mentioned in my OP. It seems only file types already known to C::B are having their user assigned file extension settings ignored.
Just Another Computer Geek

Offline TerryP

  • Multiple posting newcomer
  • *
  • Posts: 26
    • My journal
Re: How to auto open files with an external program?
« Reply #8 on: January 19, 2010, 05:14:12 am »
A little bit of source editing and a recompile of rev6089, and Code::Blocks now obeys such orders more diligently, like would be expected in the first place....
Just Another Computer Geek

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9496
Re: How to auto open files with an external program?
« Reply #9 on: January 19, 2010, 02:03:30 pm »
A little bit of source editing and a recompile of rev6089, and Code::Blocks now obeys such orders more diligently, like would be expected in the first place....
...patch?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline TerryP

  • Multiple posting newcomer
  • *
  • Posts: 26
    • My journal
Re: How to auto open files with an external program?
« Reply #10 on: January 19, 2010, 11:01:32 pm »
When I checked out the trunk on my laptop, I submitted two patches, one for a missing #include in ConsoleRunner and another one with the necessary changes for this opening behaviour.


Whether or not the second patch will be accepted is beyond my ability to foresee - the source code seems to indicate that either support for external editors was an after thought or that the developers must really love the internal editor... if it's accepted, it'll make my life easier anyway. I also experimented with changes to make Code::Blocks respect those same file associations when handling a failed project build, e.g. auto opening the MIME handler for file.xyz after a build error or when clicking an entry in the build messages tab, instead of the built in editor. Doing that is like changing one or two functions in compilergcc, but it feels more like trying to fight C::Bs design then improving it, so I've skipped making patches for that. No sense pushing my luck, lol.


Code::Blocks has a few rough corners here and there, but I really do like it.
Just Another Computer Geek