jung6717 / arduino

Automatically exported from code.google.com/p/arduino
0 stars 0 forks source link

Tab-Menu doesn't open files with only different extension (with solution) #191

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Start a new Sketch
2. Add a file "test.cpp" to the Sketch
3. Add a file "test.h" to the Sketch
4. Open the tab menu and select the first "test" (the test.cpp opens)
5. Open the tab menu and select the second "test" (the test.cpp opens again)

What is the expected output? What do you see instead?
Only one of the files (alphabetically first seemingly) can be opened from
the tab-menu if there are multiple files with the same name, and only a
different extension.

What version of the Arduino software are you using? 
Arduino 0017 and Arduino 0018 running on Windows Vista.

Please provide any additional information below.
The solution is quite simple.
Sketch.setCurrentCode(String fileName) already checks for file name as well
as 'pretty name'.
The jumpListener in SketchHeader already uses the action command to get the
filename (which is the button text if none is set, and thus the pretty name).
Setting the action command specifically allows the tab menu to function
properly.

Old code
      for (SketchCode code : sketch.getCode()) {
        item = new JMenuItem(code.getPrettyName());
        item.addActionListener(jumpListener);
        menu.add(item);
      }

New code
      for (SketchCode code : sketch.getCode()) {
        item = new JMenuItem(code.getPrettyName());
        item.setActionCommand(code.getFileName());
        item.addActionListener(jumpListener);
        menu.add(item);
      }

For more clarity it's maybe a good idea to also show the extension in the
tab menu. The easiest way to do this would be:
      for (SketchCode code : sketch.getCode()) {
        item = new JMenuItem(code.getFileName());
        item.addActionListener(jumpListener);
        menu.add(item);
      }

Original issue reported on code.google.com by qistoph on 25 Jan 2010 at 3:35

GoogleCodeExporter commented 9 years ago

Original comment by dmel...@gmail.com on 28 Jan 2010 at 2:26

GoogleCodeExporter commented 9 years ago
r965

Original comment by dmel...@gmail.com on 16 May 2010 at 4:43