1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Introjucer: added command to open counterpart files.

This commit is contained in:
jules 2012-09-06 17:51:43 +01:00
parent d24ee139d3
commit b0b6a7ca25
7 changed files with 69 additions and 1 deletions

View file

@ -303,6 +303,7 @@ public:
menu.addCommandItem (commandManager, CommandIDs::goToPreviousDoc);
menu.addCommandItem (commandManager, CommandIDs::goToNextDoc);
menu.addCommandItem (commandManager, CommandIDs::goToCounterpart);
menu.addSeparator();
const int numDocs = jmin (50, getApp().openDocumentManager.getNumOpenDocuments());

View file

@ -49,6 +49,7 @@ namespace CommandIDs
static const int closeAllDocuments = 0x201000;
static const int goToPreviousDoc = 0x201002;
static const int goToNextDoc = 0x201003;
static const int goToCounterpart = 0x201004;
static const int toFront = 0x2020a0;
static const int toBack = 0x2030a1;

View file

@ -62,6 +62,7 @@ public:
virtual void fileHasBeenRenamed (const File& newFile) = 0;
virtual String getState() const = 0;
virtual void restoreState (const String& state) = 0;
virtual File getCounterpartFile() const { return File::nonexistent; }
};
//==============================================================================

View file

@ -50,6 +50,37 @@ public:
String getState() const { return lastState != nullptr ? lastState->toString() : String::empty; }
void restoreState (const String& state) { lastState = new CodeEditorComponent::State (state); }
File getCounterpartFile() const
{
const File file (getFile());
if (file.hasFileExtension ("cpp;c;mm;m"))
{
const char* extensions[] = { "h", "hpp", nullptr };
return findCounterpart (file, extensions);
}
else if (file.hasFileExtension ("h;hpp"))
{
const char* extensions[] = { "cpp", "mm", "cc", "cxx", "c", "m", nullptr };
return findCounterpart (file, extensions);
}
return File::nonexistent;
}
static File findCounterpart (const File& file, const char** extensions)
{
while (*extensions != nullptr)
{
const File f (file.withFileExtension (*extensions++));
if (f.existsAsFile())
return f;
}
return File::nonexistent;
}
void reloadFromFile();
bool save();

View file

@ -434,6 +434,25 @@ bool ProjectContentComponent::goToNextFile()
return showDocument (recentDocumentList.getNext(), true);
}
bool ProjectContentComponent::canGoToCounterpart() const
{
return currentDocument != nullptr
&& currentDocument->getCounterpartFile().exists();
}
bool ProjectContentComponent::goToCounterpart()
{
if (currentDocument != nullptr)
{
const File file (currentDocument->getCounterpartFile());
if (file.exists())
return showEditorForFile (file, true);
}
return false;
}
bool ProjectContentComponent::saveProject()
{
return project != nullptr
@ -502,6 +521,7 @@ void ProjectContentComponent::getAllCommands (Array <CommandID>& commands)
CommandIDs::showConfigPanel,
CommandIDs::goToPreviousDoc,
CommandIDs::goToNextDoc,
CommandIDs::goToCounterpart,
StandardApplicationCommandIDs::del };
commands.addArray (ids, numElementsInArray (ids));
@ -569,6 +589,16 @@ void ProjectContentComponent::getCommandInfo (const CommandID commandID, Applica
#endif
break;
case CommandIDs::goToCounterpart:
result.setInfo ("Open corresponding header or cpp file", "Open counterpart file", CommandCategories::general, 0);
result.setActive (canGoToCounterpart());
#if JUCE_MAC
result.defaultKeypresses.add (KeyPress (KeyPress::upKey, ModifierKeys::commandModifier | ModifierKeys::ctrlModifier, 0));
#else
result.defaultKeypresses.add (KeyPress (KeyPress::upKey, ModifierKeys::ctrlModifier | ModifierKeys::shiftModifier, 0));
#endif
break;
case CommandIDs::openInIDE:
#if JUCE_MAC
result.setInfo ("Open in XCode...",
@ -639,6 +669,7 @@ bool ProjectContentComponent::perform (const InvocationInfo& info)
case CommandIDs::closeDocument:
case CommandIDs::goToPreviousDoc:
case CommandIDs::goToNextDoc:
case CommandIDs::goToCounterpart:
case CommandIDs::saveAndOpenInIDE:
if (reinvokeCommandAfterCancellingModalComps (info))
{
@ -661,6 +692,7 @@ bool ProjectContentComponent::perform (const InvocationInfo& info)
case CommandIDs::closeDocument: closeDocument(); break;
case CommandIDs::goToPreviousDoc: goToPreviousFile(); break;
case CommandIDs::goToNextDoc: goToNextFile(); break;
case CommandIDs::goToCounterpart: goToCounterpart(); break;
case CommandIDs::showFilePanel: treeViewTabs.setCurrentTabIndex (0); break;
case CommandIDs::showConfigPanel: treeViewTabs.setCurrentTabIndex (1); break;

View file

@ -65,6 +65,8 @@ public:
bool goToPreviousFile();
bool goToNextFile();
bool canGoToCounterpart() const;
bool goToCounterpart();
bool saveProject();
void closeProject();

View file

@ -168,7 +168,7 @@ public:
{
// Two ScopedPointers should never be able to refer to the same object - if
// this happens, you must have done something dodgy!
jassert (object != other.object);
jassert (object != other.object || this == other.getAddress());
std::swap (object, other.object);
}