Open any text files in IDE, such as .c or .cpp

I don't use 2.x often but I do like the modern IDE features when I am exploring some new code, or libraries. What I can do is to easily open definition files (.h) and read the definitions but I can't open any files that are not .pde or .ino if I want to manually open the .c/.cpp file in the IDE to read. So I had to open those in Notepad++ to read. I wonder if there is any way to open these files like VSCode can. Especially helpful if I can tick a read-only box per tab to prevent fat-fingering library code. Thanks.

Right-click >> Open with >> Choose Another App >> Arduino IDE >> Just Once >> OK not working on .h.

Right-click >> Properties >> General >> Read Only >> OK

Do you mean make the file read only? I was talking about opening a file as read-only, there's a subtle difference. Thanks for trying to help.

This is for an example sketch; it should also work for your sketches that use libraries.

Right click on the class (in this case AF_Stepper on line 15) and use "Go to Definition".

This will open the the included file in a new tab (and is read-only).

Thanks. I saw the padlock symbols now. Is there any way to open .c or .cpp files besides .h files?

I haven't found a way for that.

On Windows at least, you can drag&drop a file (like from File Explorer) onto the IDE's editor tab bar. The icon should show "Link"; when you release, it will open in a new tab.

If you hover over a tab, it will show the full path to the file. So if you used Go To Definition to open a .h, that will help you file related files. In some rare cases, GTD opens the .cpp; haven't figured out why.

1 Like

That works; it unfortunately does not open in read-only and corrupts the file in the tab that has the focus. E.g.

#include "src/bitmaps/bm1.h"

void setup()
{
  Serial.begin(115200);
  Serial.println(txt);
}
c:\Users\bugge\OneDrive\Documents\Arduino\1_forum.arduino.cc\1302359_srcDirectory\testSrcDirectory\src\bitmaps\bm1.h
void loop()
{
  // put your main code here, to run repeatedly:
}

Note the line after the setup() function.

OK, how about on the tab bar?

If the current tab is read-only, then added file path has no effect. But directly on the tab bar would be the safer bet. Either onto an existing tab, or the blank area to the right, if you have any.

I missed that; I just dragged it into the editor window, not the tab bar.

Dragging onto the tab bar works :+1:

Damn, you learn something new every day. Thanks.

If the files are in the root of the sketch folder, they will be opened in Arduino IDE by default along with the .ino files of the sketch.

If the files are under the src subfolder of the sketch, they will not be opened by default, but you can open them on demand from the "SKETCHBOOK" view that is opened by clicking the icon that looks like a folder in the "Activity Bar" on the left side of the Arduino IDE window. If you have enabled "Show files inside Sketches" in the Arduino IDE preferences, you will see icons in the "SKETCHBOOK" view that allow you to expand folders. Navigate to the file you want to open under the src subfolder of the current sketch and click on that file to open it in an editor tab in Arduino IDE. These tabs can also be closed by clicking the X icon on the tab.

Files from inside the sketch folder are always editable, while any file from outside the sketch folder is always treated as read-only.

Thanks friends! I now learn something new today as well!

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.