@@ -28,8 +28,7 @@ | |||
#include "../jucer_Headers.h" | |||
#include "jucer_MainWindow.h" | |||
ApplicationCommandManager* commandManager = 0; | |||
#include "../Project/jucer_NewProjectWizard.h" | |||
//============================================================================== | |||
@@ -57,22 +56,41 @@ public: | |||
commandManager = new ApplicationCommandManager(); | |||
commandManager->registerAllCommandsForTarget (this); | |||
theMainWindow = new MainWindow(); | |||
menuModel = new MainMenuModel(); | |||
MainWindow* main = createNewMainWindow (false); | |||
doExtraInitialisation(); | |||
ImageCache::setCacheTimeout (30 * 1000); | |||
if (commandLine.trim().isNotEmpty() && ! commandLine.trim().startsWithChar ('-')) | |||
{ | |||
anotherInstanceStarted (commandLine); | |||
} | |||
else | |||
{ | |||
Array<File> projects (StoredSettings::getInstance()->getLastProjects()); | |||
theMainWindow->reloadLastProject(); | |||
for (int i = 0; i < projects.size(); ++ i) | |||
openFile (projects.getReference(i)); | |||
} | |||
#if JUCE_MAC | |||
MenuBarModel::setMacMainMenu (menuModel); | |||
#endif | |||
theMainWindow->getLookAndFeel().setColour (ColourSelector::backgroundColourId, Colours::transparentBlack); | |||
main->setVisible (true); | |||
} | |||
void shutdown() | |||
{ | |||
theMainWindow = 0; | |||
#if JUCE_MAC | |||
MenuBarModel::setMacMainMenu (0); | |||
#endif | |||
menuModel = 0; | |||
StoredSettings::deleteInstance(); | |||
mainWindows.clear(); | |||
OpenDocumentManager::deleteInstance(); | |||
deleteAndZero (commandManager); | |||
@@ -81,13 +99,28 @@ public: | |||
//============================================================================== | |||
void systemRequestedQuit() | |||
{ | |||
if (theMainWindow == 0 || theMainWindow->closeCurrentProject()) | |||
while (mainWindows.size() > 0) | |||
{ | |||
theMainWindow = 0; | |||
StoredSettings::deleteInstance(); | |||
if (! mainWindows[0]->closeCurrentProject()) | |||
return; | |||
quit(); | |||
mainWindows.remove (0); | |||
} | |||
quit(); | |||
} | |||
void closeWindow (MainWindow* w) | |||
{ | |||
jassert (mainWindows.contains (w)); | |||
mainWindows.removeObject (w); | |||
#if ! JUCE_MAC | |||
if (mainWindows.size() == 0) | |||
systemRequestedQuit(); | |||
#endif | |||
updateRecentProjectList(); | |||
} | |||
//============================================================================== | |||
@@ -112,14 +145,335 @@ public: | |||
void anotherInstanceStarted (const String& commandLine) | |||
{ | |||
if (theMainWindow != 0) | |||
theMainWindow->openFile (commandLine.unquoted()); | |||
openFile (commandLine.unquoted()); | |||
} | |||
virtual void doExtraInitialisation() {} | |||
//============================================================================== | |||
class MainMenuModel : public MenuBarModel | |||
{ | |||
public: | |||
MainMenuModel() | |||
{ | |||
setApplicationCommandManagerToWatch (commandManager); | |||
} | |||
const StringArray getMenuBarNames() | |||
{ | |||
const char* const names[] = { "File", "Edit", "View", "Window", 0 }; | |||
return StringArray ((const char**) names); | |||
} | |||
const PopupMenu getMenuForIndex (int topLevelMenuIndex, const String& menuName) | |||
{ | |||
PopupMenu menu; | |||
if (topLevelMenuIndex == 0) // "File" menu | |||
{ | |||
menu.addCommandItem (commandManager, CommandIDs::newProject); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::open); | |||
PopupMenu recentFiles; | |||
StoredSettings::getInstance()->recentFiles.createPopupMenuItems (recentFiles, 100, true, true); | |||
menu.addSubMenu ("Open recent file", recentFiles); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::closeDocument); | |||
menu.addCommandItem (commandManager, CommandIDs::saveDocument); | |||
menu.addCommandItem (commandManager, CommandIDs::saveDocumentAs); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::closeProject); | |||
menu.addCommandItem (commandManager, CommandIDs::saveProject); | |||
menu.addCommandItem (commandManager, CommandIDs::saveProjectAs); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::openProjectInIDE); | |||
#if ! JUCE_MAC | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, StandardApplicationCommandIDs::quit); | |||
#endif | |||
} | |||
else if (topLevelMenuIndex == 1) // "Edit" menu | |||
{ | |||
menu.addCommandItem (commandManager, CommandIDs::undo); | |||
menu.addCommandItem (commandManager, CommandIDs::redo); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, StandardApplicationCommandIDs::cut); | |||
menu.addCommandItem (commandManager, StandardApplicationCommandIDs::copy); | |||
menu.addCommandItem (commandManager, StandardApplicationCommandIDs::paste); | |||
menu.addCommandItem (commandManager, StandardApplicationCommandIDs::del); | |||
menu.addCommandItem (commandManager, StandardApplicationCommandIDs::selectAll); | |||
menu.addCommandItem (commandManager, StandardApplicationCommandIDs::deselectAll); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::toFront); | |||
menu.addCommandItem (commandManager, CommandIDs::toBack); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::group); | |||
menu.addCommandItem (commandManager, CommandIDs::ungroup); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::bringBackLostItems); | |||
} | |||
else if (topLevelMenuIndex == 2) // "View" menu | |||
{ | |||
menu.addCommandItem (commandManager, CommandIDs::showProjectSettings); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::test); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::showGrid); | |||
menu.addCommandItem (commandManager, CommandIDs::enableSnapToGrid); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::zoomIn); | |||
menu.addCommandItem (commandManager, CommandIDs::zoomOut); | |||
menu.addCommandItem (commandManager, CommandIDs::zoomNormal); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::useTabbedWindows); | |||
} | |||
else if (topLevelMenuIndex == 3) // "Window" menu | |||
{ | |||
menu.addCommandItem (commandManager, CommandIDs::closeWindow); | |||
menu.addSeparator(); | |||
const int numDocs = jmin (50, OpenDocumentManager::getInstance()->getNumOpenDocuments()); | |||
for (int i = 0; i < numDocs; ++i) | |||
{ | |||
OpenDocumentManager::Document* doc = OpenDocumentManager::getInstance()->getOpenDocument(i); | |||
menu.addItem (300 + i, doc->getName()); | |||
} | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::closeAllDocuments); | |||
} | |||
return menu; | |||
} | |||
void menuItemSelected (int menuItemID, int topLevelMenuIndex) | |||
{ | |||
if (menuItemID >= 100 && menuItemID < 200) | |||
{ | |||
// open a file from the "recent files" menu | |||
const File file (StoredSettings::getInstance()->recentFiles.getFile (menuItemID - 100)); | |||
getApp()->openFile (file); | |||
} | |||
else if (menuItemID >= 300 && menuItemID < 400) | |||
{ | |||
OpenDocumentManager::Document* doc = OpenDocumentManager::getInstance()->getOpenDocument (menuItemID - 300); | |||
getApp()->getOrCreateFrontmostWindow (true)->getProjectContentComponent()->showDocument (doc); | |||
} | |||
} | |||
private: | |||
JucerApplication* getApp() const | |||
{ | |||
return static_cast<JucerApplication*> (JUCEApplication::getInstance()); | |||
} | |||
}; | |||
//============================================================================== | |||
void getAllCommands (Array <CommandID>& commands) | |||
{ | |||
JUCEApplication::getAllCommands (commands); | |||
const CommandID ids[] = { CommandIDs::newProject, | |||
CommandIDs::open, | |||
CommandIDs::showPrefs, | |||
CommandIDs::closeAllDocuments, | |||
CommandIDs::saveAll }; | |||
commands.addArray (ids, numElementsInArray (ids)); | |||
} | |||
void getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result) | |||
{ | |||
switch (commandID) | |||
{ | |||
case CommandIDs::newProject: | |||
result.setInfo ("New Project...", "Creates a new Jucer project", CommandCategories::general, 0); | |||
result.defaultKeypresses.add (KeyPress ('o', ModifierKeys::commandModifier, 0)); | |||
break; | |||
case CommandIDs::open: | |||
result.setInfo ("Open...", "Opens a Jucer project", CommandCategories::general, 0); | |||
result.defaultKeypresses.add (KeyPress ('o', ModifierKeys::commandModifier, 0)); | |||
break; | |||
case CommandIDs::showPrefs: | |||
result.setInfo ("Preferences...", "Shows the preferences panel.", CommandCategories::general, 0); | |||
result.defaultKeypresses.add (KeyPress (',', ModifierKeys::commandModifier, 0)); | |||
break; | |||
case CommandIDs::closeAllDocuments: | |||
result.setInfo ("Close All Documents", "Closes all open documents", CommandCategories::general, 0); | |||
result.setActive (OpenDocumentManager::getInstance()->getNumOpenDocuments() > 0); | |||
break; | |||
case CommandIDs::saveAll: | |||
result.setInfo ("Save All", "Saves all open documents", CommandCategories::general, 0); | |||
result.setActive (OpenDocumentManager::getInstance()->anyFilesNeedSaving()); | |||
break; | |||
default: | |||
JUCEApplication::getCommandInfo (commandID, result); | |||
break; | |||
} | |||
} | |||
bool perform (const InvocationInfo& info) | |||
{ | |||
switch (info.commandID) | |||
{ | |||
case CommandIDs::newProject: createNewProject(); break; | |||
case CommandIDs::open: askUserToOpenFile(); break; | |||
case CommandIDs::showPrefs: showPrefsPanel(); break; | |||
case CommandIDs::saveAll: OpenDocumentManager::getInstance()->saveAll(); break; | |||
case CommandIDs::closeAllDocuments: closeAllDocuments (true); break; | |||
default: return JUCEApplication::perform (info); | |||
} | |||
return true; | |||
} | |||
//============================================================================== | |||
void showPrefsPanel() | |||
{ | |||
jassertfalse; | |||
} | |||
void createNewProject() | |||
{ | |||
MainWindow* mw = createNewMainWindow (false); | |||
ScopedPointer <Project> newProj (NewProjectWizard::runNewProjectWizard (mw)); | |||
if (newProj != 0) | |||
mw->setProject (newProj.release()); | |||
else | |||
closeWindow (mw); | |||
mw->setVisible (true); | |||
} | |||
void askUserToOpenFile() | |||
{ | |||
FileChooser fc ("Open File"); | |||
if (fc.browseForFileToOpen()) | |||
openFile (fc.getResult()); | |||
} | |||
bool openFile (const File& file) | |||
{ | |||
if (file.hasFileExtension (Project::projectFileExtension)) | |||
{ | |||
ScopedPointer <Project> newDoc (new Project (file)); | |||
if (file == File::nonexistent ? newDoc->loadFromUserSpecifiedFile (true) | |||
: newDoc->loadFrom (file, true)) | |||
{ | |||
MainWindow* w = getOrCreateEmptyWindow (false); | |||
w->setProject (newDoc.release()); | |||
w->restoreWindowPosition(); | |||
w->setVisible (true); | |||
return true; | |||
} | |||
} | |||
else if (file.exists()) | |||
{ | |||
return getOrCreateFrontmostWindow (true)->openFile (file); | |||
} | |||
return false; | |||
} | |||
bool closeAllDocuments (bool askUserToSave) | |||
{ | |||
for (int i = OpenDocumentManager::getInstance()->getNumOpenDocuments(); --i >= 0;) | |||
{ | |||
OpenDocumentManager::Document* doc = OpenDocumentManager::getInstance()->getOpenDocument (i); | |||
for (int j = mainWindows.size(); --j >= 0;) | |||
mainWindows.getUnchecked(j)->getProjectContentComponent()->hideDocument (doc); | |||
if (! OpenDocumentManager::getInstance()->closeDocument (i, askUserToSave)) | |||
return false; | |||
} | |||
return true; | |||
} | |||
void updateRecentProjectList() | |||
{ | |||
Array<File> projects; | |||
for (int i = 0; i < mainWindows.size(); ++i) | |||
{ | |||
MainWindow* mw = mainWindows[i]; | |||
if (mw != 0 && mw->getProject() != 0) | |||
projects.add (mw->getProject()->getFile()); | |||
} | |||
StoredSettings::getInstance()->setLastProjects (projects); | |||
} | |||
private: | |||
ScopedPointer <MainWindow> theMainWindow; | |||
OwnedArray <MainWindow> mainWindows; | |||
ScopedPointer<MainMenuModel> menuModel; | |||
MainWindow* createNewMainWindow (bool makeVisible) | |||
{ | |||
MainWindow* mw = new MainWindow(); | |||
for (int i = mainWindows.size(); --i >= 0;) | |||
if (mw->getBounds() == mainWindows.getUnchecked(i)->getBounds()) | |||
mw->setBounds (mw->getBounds().translated (20, 20)); | |||
mainWindows.add (mw); | |||
if (makeVisible) | |||
mw->setVisible (true); | |||
mw->restoreWindowPosition(); | |||
return mw; | |||
} | |||
MainWindow* getOrCreateFrontmostWindow (bool makeVisible) | |||
{ | |||
if (mainWindows.size() == 0) | |||
return createNewMainWindow (makeVisible); | |||
for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;) | |||
{ | |||
MainWindow* mw = dynamic_cast <MainWindow*> (Desktop::getInstance().getComponent (i)); | |||
if (mainWindows.contains (mw)) | |||
return mw; | |||
} | |||
return mainWindows.getLast(); | |||
} | |||
MainWindow* getOrCreateEmptyWindow (bool makeVisible) | |||
{ | |||
if (mainWindows.size() == 0) | |||
return createNewMainWindow (makeVisible); | |||
for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;) | |||
{ | |||
MainWindow* mw = dynamic_cast <MainWindow*> (Desktop::getInstance().getComponent (i)); | |||
if (mainWindows.contains (mw) && mw->getProject() == 0) | |||
return mw; | |||
} | |||
return createNewMainWindow (makeVisible); | |||
} | |||
}; | |||
@@ -44,6 +44,7 @@ namespace CommandIDs | |||
static const int undo = 0x200090; | |||
static const int redo = 0x2000a0; | |||
static const int closeWindow = 0x201001; | |||
static const int closeAllDocuments = 0x201000; | |||
static const int test = 0x202090; | |||
@@ -54,6 +55,13 @@ namespace CommandIDs | |||
static const int showOrHideMarkers = 0x2030b2; | |||
static const int toggleSnapping = 0x2030b3; | |||
static const int makeLineSegment = 0x2030c0; | |||
static const int makeCubicSegment = 0x2030c1; | |||
static const int breakSegment = 0x2030c2; | |||
static const int pointModeCorner = 0x2030c3; | |||
static const int pointModeRounded = 0x2030c4; | |||
static const int pointModeSymmetric = 0x2030c5; | |||
static const int group = 0x202170; | |||
static const int ungroup = 0x202180; | |||
@@ -24,11 +24,14 @@ | |||
*/ | |||
#include "../jucer_Headers.h" | |||
#include "jucer_Application.h" | |||
#include "jucer_MainWindow.h" | |||
#include "jucer_OpenDocumentManager.h" | |||
#include "../Code Editor/jucer_SourceCodeEditor.h" | |||
#include "../Project/jucer_NewProjectWizard.h" | |||
ApplicationCommandManager* commandManager = 0; | |||
//============================================================================== | |||
MainWindow::MainWindow() | |||
@@ -39,22 +42,15 @@ MainWindow::MainWindow() | |||
setUsingNativeTitleBar (true); | |||
setContentComponent (new ProjectContentComponent()); | |||
setApplicationCommandManagerToWatch (commandManager); | |||
#if JUCE_MAC | |||
setMacMainMenu (this); | |||
#else | |||
setMenuBar (this); | |||
#if ! JUCE_MAC | |||
JucerApplication* app = static_cast<JucerApplication*> (JUCEApplication::getInstance()); | |||
setMenuBar (app); | |||
#endif | |||
setResizable (true, false); | |||
centreWithSize (700, 600); | |||
// restore the last size and position from our settings file.. | |||
restoreWindowStateFromString (StoredSettings::getInstance()->getProps() | |||
.getValue ("lastMainWindowPos")); | |||
// Register all the app commands.. | |||
{ | |||
commandManager->registerAllCommandsForTarget (this); | |||
@@ -80,15 +76,12 @@ MainWindow::MainWindow() | |||
setWantsKeyboardFocus (false); | |||
//getPeer()->setCurrentRenderingEngine (0); | |||
setVisible (true); | |||
getLookAndFeel().setColour (ColourSelector::backgroundColourId, Colours::transparentBlack); | |||
} | |||
MainWindow::~MainWindow() | |||
{ | |||
#if JUCE_MAC | |||
setMacMainMenu (0); | |||
#else | |||
#if ! JUCE_MAC | |||
setMenuBar (0); | |||
#endif | |||
@@ -109,7 +102,11 @@ ProjectContentComponent* MainWindow::getProjectContentComponent() const | |||
void MainWindow::closeButtonPressed() | |||
{ | |||
JUCEApplication::getInstance()->systemRequestedQuit(); | |||
if (! closeCurrentProject()) | |||
return; | |||
JucerApplication* jucer = static_cast<JucerApplication*> (JUCEApplication::getInstance()); | |||
jucer->closeWindow (this); | |||
} | |||
bool MainWindow::closeProject (Project* project) | |||
@@ -119,6 +116,9 @@ bool MainWindow::closeProject (Project* project) | |||
if (project == 0) | |||
return true; | |||
StoredSettings::getInstance()->getProps() | |||
.setValue (getProjectWindowPosName(), getWindowStateAsString()); | |||
if (! OpenDocumentManager::getInstance()->closeAllDocumentsUsingProject (*project, true)) | |||
return false; | |||
@@ -138,41 +138,29 @@ bool MainWindow::closeCurrentProject() | |||
return currentProject == 0 || closeProject (currentProject); | |||
} | |||
bool MainWindow::closeAllDocuments (bool askUserToSave) | |||
{ | |||
for (int i = OpenDocumentManager::getInstance()->getNumOpenDocuments(); --i >= 0;) | |||
{ | |||
OpenDocumentManager::Document* doc = OpenDocumentManager::getInstance()->getOpenDocument (i); | |||
getProjectContentComponent()->hideDocument (doc); | |||
if (! OpenDocumentManager::getInstance()->closeDocument (i, askUserToSave)) | |||
return false; | |||
} | |||
return true; | |||
} | |||
void MainWindow::setProject (Project* newProject) | |||
{ | |||
if (newProject != 0) | |||
StoredSettings::getInstance()->setLastProject (newProject->getFile()); | |||
getProjectContentComponent()->setProject (newProject); | |||
currentProject = newProject; | |||
commandManager->commandStatusChanged(); | |||
} | |||
void MainWindow::reloadLastProject() | |||
{ | |||
openFile (StoredSettings::getInstance()->getLastProject()); | |||
// (mustn't do this when the project is 0, because that'll happen on shutdown, | |||
// which will erase the list of recent projects) | |||
if (newProject != 0) | |||
static_cast<JucerApplication*> (JUCEApplication::getInstance())->updateRecentProjectList(); | |||
} | |||
void MainWindow::askUserToOpenFile() | |||
void MainWindow::restoreWindowPosition() | |||
{ | |||
FileChooser fc ("Open File"); | |||
String windowState; | |||
if (currentProject != 0) | |||
windowState = StoredSettings::getInstance()->getProps().getValue (getProjectWindowPosName()); | |||
if (windowState.isEmpty()) | |||
windowState = StoredSettings::getInstance()->getProps().getValue ("lastMainWindowPos"); | |||
if (fc.browseForFileToOpen()) | |||
openFile (fc.getResult()); | |||
restoreWindowStateFromString (windowState); | |||
} | |||
bool MainWindow::canOpenFile (const File& file) const | |||
@@ -205,14 +193,6 @@ bool MainWindow::openFile (const File& file) | |||
return false; | |||
} | |||
void MainWindow::createNewProject() | |||
{ | |||
ScopedPointer <Project> newProj (NewProjectWizard::runNewProjectWizard (this)); | |||
if (newProj != 0 && closeCurrentProject()) | |||
setProject (newProj.release()); | |||
} | |||
bool MainWindow::isInterestedInFileDrag (const StringArray& filenames) | |||
{ | |||
for (int i = filenames.size(); --i >= 0;) | |||
@@ -252,140 +232,6 @@ void MainWindow::updateTitle (const String& documentName) | |||
setName (name); | |||
} | |||
//============================================================================== | |||
const StringArray MainWindow::getMenuBarNames() | |||
{ | |||
const char* const names[] = { "File", "Edit", "View", "Window", 0 }; | |||
return StringArray ((const char**) names); | |||
} | |||
const PopupMenu MainWindow::getMenuForIndex (int topLevelMenuIndex, | |||
const String& menuName) | |||
{ | |||
PopupMenu menu; | |||
if (topLevelMenuIndex == 0) | |||
{ | |||
// "File" menu | |||
menu.addCommandItem (commandManager, CommandIDs::newProject); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::open); | |||
PopupMenu recentFiles; | |||
StoredSettings::getInstance()->recentFiles.createPopupMenuItems (recentFiles, 100, true, true); | |||
menu.addSubMenu ("Open recent file", recentFiles); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::closeDocument); | |||
menu.addCommandItem (commandManager, CommandIDs::saveDocument); | |||
menu.addCommandItem (commandManager, CommandIDs::saveDocumentAs); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::closeProject); | |||
menu.addCommandItem (commandManager, CommandIDs::saveProject); | |||
menu.addCommandItem (commandManager, CommandIDs::saveProjectAs); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::openProjectInIDE); | |||
#if ! JUCE_MAC | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, StandardApplicationCommandIDs::quit); | |||
#endif | |||
} | |||
else if (topLevelMenuIndex == 1) | |||
{ | |||
// "Edit" menu | |||
menu.addCommandItem (commandManager, CommandIDs::undo); | |||
menu.addCommandItem (commandManager, CommandIDs::redo); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, StandardApplicationCommandIDs::cut); | |||
menu.addCommandItem (commandManager, StandardApplicationCommandIDs::copy); | |||
menu.addCommandItem (commandManager, StandardApplicationCommandIDs::paste); | |||
menu.addCommandItem (commandManager, StandardApplicationCommandIDs::del); | |||
menu.addCommandItem (commandManager, StandardApplicationCommandIDs::selectAll); | |||
menu.addCommandItem (commandManager, StandardApplicationCommandIDs::deselectAll); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::toFront); | |||
menu.addCommandItem (commandManager, CommandIDs::toBack); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::group); | |||
menu.addCommandItem (commandManager, CommandIDs::ungroup); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::bringBackLostItems); | |||
} | |||
else if (topLevelMenuIndex == 2) | |||
{ | |||
// "View" menu | |||
menu.addCommandItem (commandManager, CommandIDs::showProjectSettings); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::test); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::showGrid); | |||
menu.addCommandItem (commandManager, CommandIDs::enableSnapToGrid); | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::zoomIn); | |||
menu.addCommandItem (commandManager, CommandIDs::zoomOut); | |||
menu.addCommandItem (commandManager, CommandIDs::zoomNormal); | |||
/* menu.addSeparator(); | |||
PopupMenu overlays; | |||
overlays.addCommandItem (commandManager, CommandIDs::compOverlay0); | |||
overlays.addCommandItem (commandManager, CommandIDs::compOverlay33); | |||
overlays.addCommandItem (commandManager, CommandIDs::compOverlay66); | |||
overlays.addCommandItem (commandManager, CommandIDs::compOverlay100); | |||
menu.addSubMenu ("Component Overlay", overlays, | |||
getActiveDocument() != 0 && getActiveDocument()->getComponentLayout() != 0);*/ | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::useTabbedWindows); | |||
//menu.addSeparator(); | |||
//menu.addCommandItem (commandManager, CommandIDs::showPrefs); | |||
} | |||
else if (topLevelMenuIndex == 3) | |||
{ | |||
// "Window" menu | |||
const int numDocs = jmin (50, OpenDocumentManager::getInstance()->getNumOpenDocuments()); | |||
for (int i = 0; i < numDocs; ++i) | |||
{ | |||
OpenDocumentManager::Document* doc = OpenDocumentManager::getInstance()->getOpenDocument(i); | |||
menu.addItem (300 + i, doc->getName()); | |||
} | |||
menu.addSeparator(); | |||
menu.addCommandItem (commandManager, CommandIDs::closeAllDocuments); | |||
} | |||
return menu; | |||
} | |||
void MainWindow::menuItemSelected (int menuItemID, | |||
int topLevelMenuIndex) | |||
{ | |||
if (menuItemID >= 100 && menuItemID < 200) | |||
{ | |||
// open a file from the "recent files" menu | |||
const File file (StoredSettings::getInstance()->recentFiles.getFile (menuItemID - 100)); | |||
openFile (file); | |||
} | |||
else if (menuItemID == 201) | |||
{ | |||
LookAndFeel::setDefaultLookAndFeel (0); | |||
} | |||
else if (menuItemID >= 300 && menuItemID < 400) | |||
{ | |||
OpenDocumentManager::Document* doc = OpenDocumentManager::getInstance()->getOpenDocument (menuItemID - 300); | |||
getProjectContentComponent()->showDocument (doc); | |||
} | |||
} | |||
//============================================================================== | |||
ApplicationCommandTarget* MainWindow::getNextCommandTarget() | |||
@@ -395,11 +241,7 @@ ApplicationCommandTarget* MainWindow::getNextCommandTarget() | |||
void MainWindow::getAllCommands (Array <CommandID>& commands) | |||
{ | |||
const CommandID ids[] = { CommandIDs::newProject, | |||
CommandIDs::open, | |||
CommandIDs::showPrefs, | |||
CommandIDs::closeAllDocuments, | |||
CommandIDs::saveAll }; | |||
const CommandID ids[] = { CommandIDs::closeWindow }; | |||
commands.addArray (ids, numElementsInArray (ids)); | |||
} | |||
@@ -408,39 +250,9 @@ void MainWindow::getCommandInfo (const CommandID commandID, ApplicationCommandIn | |||
{ | |||
switch (commandID) | |||
{ | |||
case CommandIDs::newProject: | |||
result.setInfo ("New Project...", | |||
"Creates a new Jucer project", | |||
CommandCategories::general, 0); | |||
result.defaultKeypresses.add (KeyPress ('o', ModifierKeys::commandModifier, 0)); | |||
break; | |||
case CommandIDs::open: | |||
result.setInfo ("Open...", | |||
"Opens a Jucer project", | |||
CommandCategories::general, 0); | |||
result.defaultKeypresses.add (KeyPress ('o', ModifierKeys::commandModifier, 0)); | |||
break; | |||
case CommandIDs::showPrefs: | |||
result.setInfo ("Preferences...", | |||
"Shows the preferences panel.", | |||
CommandCategories::general, 0); | |||
result.defaultKeypresses.add (KeyPress (',', ModifierKeys::commandModifier, 0)); | |||
break; | |||
case CommandIDs::closeAllDocuments: | |||
result.setInfo ("Close All Documents", | |||
"Closes all open documents", | |||
CommandCategories::general, 0); | |||
result.setActive (OpenDocumentManager::getInstance()->getNumOpenDocuments() > 0); | |||
break; | |||
case CommandIDs::saveAll: | |||
result.setInfo ("Save All", | |||
"Saves all open documents", | |||
CommandCategories::general, 0); | |||
result.setActive (OpenDocumentManager::getInstance()->anyFilesNeedSaving()); | |||
case CommandIDs::closeWindow: | |||
result.setInfo ("Close Window", "Closes the current window", CommandCategories::general, 0); | |||
result.defaultKeypresses.add (KeyPress ('w', ModifierKeys::commandModifier, 0)); | |||
break; | |||
default: | |||
@@ -452,28 +264,12 @@ bool MainWindow::perform (const InvocationInfo& info) | |||
{ | |||
switch (info.commandID) | |||
{ | |||
case CommandIDs::newProject: | |||
createNewProject(); | |||
break; | |||
case CommandIDs::open: | |||
askUserToOpenFile(); | |||
break; | |||
case CommandIDs::showPrefs: | |||
// PrefsPanel::show(); | |||
break; | |||
case CommandIDs::saveAll: | |||
OpenDocumentManager::getInstance()->saveAll(); | |||
break; | |||
case CommandIDs::closeAllDocuments: | |||
closeAllDocuments (true); | |||
break; | |||
case CommandIDs::closeWindow: | |||
closeButtonPressed(); | |||
break; | |||
default: | |||
return false; | |||
default: | |||
return false; | |||
} | |||
return true; | |||
@@ -34,7 +34,6 @@ | |||
The big top-level window where everything happens. | |||
*/ | |||
class MainWindow : public DocumentWindow, | |||
public MenuBarModel, | |||
public ApplicationCommandTarget, | |||
public FileDragAndDropTarget, | |||
public DragAndDropContainer | |||
@@ -48,16 +47,14 @@ public: | |||
void closeButtonPressed(); | |||
//============================================================================== | |||
void askUserToOpenFile(); | |||
bool canOpenFile (const File& file) const; | |||
bool openFile (const File& file); | |||
void createNewProject(); | |||
void setProject (Project* newProject); | |||
void reloadLastProject(); | |||
Project* getProject() const { return currentProject; } | |||
void restoreWindowPosition(); | |||
bool closeProject (Project* project); | |||
bool closeCurrentProject(); | |||
bool closeAllDocuments (bool askUserToSave); | |||
bool isInterestedInFileDrag (const StringArray& files); | |||
void filesDropped (const StringArray& filenames, int mouseX, int mouseY); | |||
@@ -66,10 +63,7 @@ public: | |||
void updateTitle (const String& documentName); | |||
//============================================================================== | |||
const StringArray getMenuBarNames(); | |||
const PopupMenu getMenuForIndex (int topLevelMenuIndex, const String& menuName); | |||
void menuItemSelected (int menuItemID, int topLevelMenuIndex); | |||
ProjectContentComponent* getProjectContentComponent() const; | |||
//============================================================================== | |||
ApplicationCommandTarget* getNextCommandTarget(); | |||
@@ -83,7 +77,14 @@ public: | |||
private: | |||
ScopedPointer <Project> currentProject; | |||
ProjectContentComponent* getProjectContentComponent() const; | |||
const String getProjectWindowPosName() const | |||
{ | |||
jassert (currentProject != 0); | |||
if (currentProject == 0) | |||
return String::empty; | |||
return "projectWindowPos_" + currentProject->getProjectUID(); | |||
} | |||
}; | |||
@@ -281,8 +281,12 @@ bool ProjectContentComponent::perform (const InvocationInfo& info) | |||
break; | |||
case CommandIDs::closeProject: | |||
if (((MainWindow*) getParentComponent())->closeCurrentProject()) | |||
StoredSettings::getInstance()->setLastProject (File::nonexistent); | |||
{ | |||
MainWindow* mw = Component::findParentComponentOfClass ((MainWindow*) 0); | |||
if (mw != 0) | |||
mw->closeCurrentProject(); | |||
} | |||
break; | |||
@@ -102,14 +102,25 @@ void StoredSettings::flush() | |||
} | |||
} | |||
const File StoredSettings::getLastProject() const | |||
const Array<File> StoredSettings::getLastProjects() const | |||
{ | |||
return props->getValue ("lastProject"); | |||
StringArray s; | |||
s.addTokens (props->getValue ("lastProjects"), "|", ""); | |||
Array<File> f; | |||
for (int i = 0; i < s.size(); ++i) | |||
f.add (File (s[i])); | |||
return f; | |||
} | |||
void StoredSettings::setLastProject (const File& file) | |||
void StoredSettings::setLastProjects (const Array<File>& files) | |||
{ | |||
props->setValue ("lastProject", file.getFullPathName()); | |||
StringArray s; | |||
for (int i = 0; i < files.size(); ++i) | |||
s.add (files.getReference(i).getFullPathName()); | |||
props->setValue ("lastProjects", s.joinIntoString ("|")); | |||
} | |||
const File StoredSettings::getLastKnownJuceFolder() const | |||
@@ -47,8 +47,8 @@ public: | |||
//============================================================================== | |||
RecentlyOpenedFilesList recentFiles; | |||
const File getLastProject() const; | |||
void setLastProject (const File& file); | |||
const Array<File> getLastProjects() const; | |||
void setLastProjects (const Array<File>& files); | |||
const File getLastKnownJuceFolder() const; | |||
void setLastKnownJuceFolder (const File& file); | |||
@@ -64,7 +64,7 @@ | |||
*/ | |||
#define JUCE_MAJOR_VERSION 1 | |||
#define JUCE_MINOR_VERSION 52 | |||
#define JUCE_BUILDNUMBER 28 | |||
#define JUCE_BUILDNUMBER 29 | |||
/** Current Juce version number. | |||
@@ -33,7 +33,7 @@ | |||
*/ | |||
#define JUCE_MAJOR_VERSION 1 | |||
#define JUCE_MINOR_VERSION 52 | |||
#define JUCE_BUILDNUMBER 28 | |||
#define JUCE_BUILDNUMBER 29 | |||
/** Current Juce version number. | |||