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

Introjucer: misc internal refactoring.

This commit is contained in:
jules 2012-07-09 10:15:26 +01:00
parent 1f2b26a30b
commit c65c7dd4a4
13 changed files with 158 additions and 138 deletions

View file

@ -209,7 +209,7 @@ struct AppearanceEditor
void closeButtonPressed()
{
JucerApplication::getApp()->appearanceEditorWindow = nullptr;
JucerApplication::getApp().appearanceEditorWindow = nullptr;
}
private:

View file

@ -132,9 +132,11 @@ public:
openFile (commandLine.unquoted());
}
static JucerApplication* getApp()
static JucerApplication& getApp()
{
return dynamic_cast<JucerApplication*> (JUCEApplication::getInstance());
JucerApplication* const app = dynamic_cast<JucerApplication*> (JUCEApplication::getInstance());
jassert (app != nullptr);
return *app;
}
//==============================================================================
@ -148,105 +150,13 @@ public:
StringArray getMenuBarNames()
{
const char* const names[] = { "File", "Edit", "View", "Window", "Tools", 0 };
return StringArray ((const char**) names);
return getApp().getMenuNames();
}
PopupMenu getMenuForIndex (int topLevelMenuIndex, const String& /*menuName*/)
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;
getAppSettings().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.addSeparator();
menu.addCommandItem (commandManager, CommandIDs::closeProject);
menu.addCommandItem (commandManager, CommandIDs::saveProject);
menu.addSeparator();
menu.addCommandItem (commandManager, CommandIDs::openInIDE);
menu.addCommandItem (commandManager, CommandIDs::saveAndOpenInIDE);
#if ! JUCE_MAC
menu.addSeparator();
menu.addCommandItem (commandManager, StandardApplicationCommandIDs::quit);
#endif
}
else if (topLevelMenuIndex == 1) // "Edit" menu
{
menu.addCommandItem (commandManager, StandardApplicationCommandIDs::undo);
menu.addCommandItem (commandManager, StandardApplicationCommandIDs::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::showAppearanceSettings);
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();
menu.addCommandItem (commandManager, CommandIDs::goToPreviousDoc);
menu.addCommandItem (commandManager, CommandIDs::goToNextDoc);
menu.addSeparator();
const int numDocs = jmin (50, getApp()->openDocumentManager.getNumOpenDocuments());
for (int i = 0; i < numDocs; ++i)
{
OpenDocumentManager::Document* doc = getApp()->openDocumentManager.getOpenDocument(i);
menu.addItem (300 + i, doc->getName());
}
menu.addSeparator();
menu.addCommandItem (commandManager, CommandIDs::closeAllDocuments);
}
else if (topLevelMenuIndex == 4) // "Tools" menu
{
menu.addCommandItem (commandManager, CommandIDs::updateModules);
menu.addCommandItem (commandManager, CommandIDs::showUTF8Tool);
}
getApp().createMenu (menu, menuName);
return menu;
}
@ -255,20 +165,117 @@ public:
if (menuItemID >= 100 && menuItemID < 200)
{
// open a file from the "recent files" menu
const File file (getAppSettings().recentFiles.getFile (menuItemID - 100));
getApp()->openFile (file);
getApp().openFile (getAppSettings().recentFiles.getFile (menuItemID - 100));
}
else if (menuItemID >= 300 && menuItemID < 400)
{
OpenDocumentManager::Document* doc = getApp()->openDocumentManager.getOpenDocument (menuItemID - 300);
OpenDocumentManager::Document* doc = getApp().openDocumentManager.getOpenDocument (menuItemID - 300);
jassert (doc != nullptr);
getApp()->mainWindowList.openDocument (doc);
getApp().mainWindowList.openDocument (doc);
}
}
};
virtual StringArray getMenuNames()
{
const char* const names[] = { "File", "Edit", "View", "Window", "Tools", nullptr };
return StringArray (names);
}
virtual void createMenu (PopupMenu& menu, const String& menuName)
{
if (menuName == "File") createFileMenu (menu);
else if (menuName == "Edit") createEditMenu (menu);
else if (menuName == "View") createViewMenu (menu);
else if (menuName == "Window") createWindowMenu (menu);
else if (menuName == "Tools") createToolsMenu (menu);
else jassertfalse; // names have changed?
}
virtual void createFileMenu (PopupMenu& menu)
{
menu.addCommandItem (commandManager, CommandIDs::newProject);
menu.addSeparator();
menu.addCommandItem (commandManager, CommandIDs::open);
PopupMenu recentFiles;
getAppSettings().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.addSeparator();
menu.addCommandItem (commandManager, CommandIDs::closeProject);
menu.addCommandItem (commandManager, CommandIDs::saveProject);
menu.addSeparator();
menu.addCommandItem (commandManager, CommandIDs::openInIDE);
menu.addCommandItem (commandManager, CommandIDs::saveAndOpenInIDE);
#if ! JUCE_MAC
menu.addSeparator();
menu.addCommandItem (commandManager, StandardApplicationCommandIDs::quit);
#endif
}
virtual void createEditMenu (PopupMenu& menu)
{
menu.addCommandItem (commandManager, StandardApplicationCommandIDs::undo);
menu.addCommandItem (commandManager, StandardApplicationCommandIDs::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);
}
virtual void createViewMenu (PopupMenu& menu)
{
menu.addCommandItem (commandManager, CommandIDs::showFilePanel);
menu.addCommandItem (commandManager, CommandIDs::showConfigPanel);
menu.addSeparator();
menu.addCommandItem (commandManager, CommandIDs::showAppearanceSettings);
}
virtual void createWindowMenu (PopupMenu& menu)
{
menu.addCommandItem (commandManager, CommandIDs::closeWindow);
menu.addSeparator();
menu.addCommandItem (commandManager, CommandIDs::goToPreviousDoc);
menu.addCommandItem (commandManager, CommandIDs::goToNextDoc);
menu.addSeparator();
const int numDocs = jmin (50, getApp().openDocumentManager.getNumOpenDocuments());
for (int i = 0; i < numDocs; ++i)
{
OpenDocumentManager::Document* doc = getApp().openDocumentManager.getOpenDocument(i);
menu.addItem (300 + i, doc->getName());
}
menu.addSeparator();
menu.addCommandItem (commandManager, CommandIDs::closeAllDocuments);
}
virtual void createToolsMenu (PopupMenu& menu)
{
menu.addCommandItem (commandManager, CommandIDs::updateModules);
menu.addCommandItem (commandManager, CommandIDs::showUTF8Tool);
}
//==============================================================================
void getAllCommands (Array <CommandID>& commands)
{
@ -345,9 +352,7 @@ public:
case CommandIDs::showUTF8Tool: showUTF8ToolWindow(); break;
case CommandIDs::showAppearanceSettings: showAppearanceEditorWindow(); break;
case CommandIDs::updateModules: runModuleUpdate (String::empty); break;
default:
return JUCEApplication::perform (info);
default: return JUCEApplication::perform (info);
}
return true;
@ -455,8 +460,9 @@ private:
stopTimer();
delete this;
if (getApp() != nullptr)
getApp()->systemRequestedQuit();
JUCEApplication* app = JUCEApplication::getInstance();
if (app != nullptr)
app->systemRequestedQuit();
}
JUCE_DECLARE_NON_COPYABLE (AsyncQuitRetrier);

View file

@ -37,10 +37,11 @@ namespace CommandIDs
static const int saveProject = 0x200060;
static const int openInIDE = 0x200072;
static const int saveAndOpenInIDE = 0x200073;
static const int showProjectSettings = 0x200074;
static const int updateModules = 0x200075;
static const int showUTF8Tool = 0x200076;
static const int showAppearanceSettings = 0x200077;
static const int showConfigPanel = 0x200074;
static const int showFilePanel = 0x200078;
static const int saveAll = 0x200080;

View file

@ -32,12 +32,12 @@
DocumentEditorComponent::DocumentEditorComponent (OpenDocumentManager::Document* document_)
: document (document_)
{
JucerApplication::getApp()->openDocumentManager.addListener (this);
JucerApplication::getApp().openDocumentManager.addListener (this);
}
DocumentEditorComponent::~DocumentEditorComponent()
{
JucerApplication::getApp()->openDocumentManager.removeListener (this);
JucerApplication::getApp().openDocumentManager.removeListener (this);
}
void DocumentEditorComponent::documentAboutToClose (OpenDocumentManager::Document* closingDoc)

View file

@ -35,7 +35,7 @@ ScopedPointer<ApplicationCommandManager> commandManager;
//==============================================================================
MainWindow::MainWindow()
: DocumentWindow (JucerApplication::getApp()->getApplicationName(),
: DocumentWindow (JucerApplication::getApp().getApplicationName(),
Colour::greyLevel (0.6f),
DocumentWindow::allButtons,
false)
@ -44,7 +44,7 @@ MainWindow::MainWindow()
createProjectContentCompIfNeeded();
#if ! JUCE_MAC
setMenuBar (JucerApplication::getApp()->menuModel);
setMenuBar (JucerApplication::getApp().menuModel);
#endif
setResizable (true, false);
@ -93,7 +93,7 @@ void MainWindow::createProjectContentCompIfNeeded()
if (getProjectContentComponent() == nullptr)
{
clearContentComponent();
setContentOwned (JucerApplication::getApp()->createProjectContentComponent(), false);
setContentOwned (JucerApplication::getApp().createProjectContentComponent(), false);
jassert (getProjectContentComponent() != nullptr);
}
}
@ -115,7 +115,7 @@ ProjectContentComponent* MainWindow::getProjectContentComponent() const
void MainWindow::closeButtonPressed()
{
JucerApplication::getApp()->mainWindowList.closeWindow (this);
JucerApplication::getApp().mainWindowList.closeWindow (this);
}
bool MainWindow::closeProject (Project* project)
@ -136,7 +136,7 @@ bool MainWindow::closeProject (Project* project)
pcc->hideEditor();
}
if (! JucerApplication::getApp()->openDocumentManager.closeAllDocumentsUsingProject (*project, true))
if (! JucerApplication::getApp().openDocumentManager.closeAllDocumentsUsingProject (*project, true))
return false;
FileBasedDocument::SaveResult r = project->saveIfNeededAndUserAgrees();
@ -179,7 +179,7 @@ void MainWindow::restoreWindowPosition()
bool MainWindow::canOpenFile (const File& file) const
{
return file.hasFileExtension (Project::projectFileExtension)
|| JucerApplication::getApp()->openDocumentManager.canOpenFile (file);
|| JucerApplication::getApp().openDocumentManager.canOpenFile (file);
}
bool MainWindow::openFile (const File& file)
@ -232,12 +232,12 @@ void MainWindow::activeWindowStatusChanged()
if (getProjectContentComponent() != nullptr)
getProjectContentComponent()->updateMissingFileStatuses();
JucerApplication::getApp()->openDocumentManager.reloadModifiedFiles();
JucerApplication::getApp().openDocumentManager.reloadModifiedFiles();
}
void MainWindow::updateTitle (const String& documentName)
{
String name (JucerApplication::getApp()->getApplicationName());
String name (JucerApplication::getApp().getApplicationName());
if (currentProject != nullptr)
name = currentProject->getDocumentTitle() + " - " + name;

View file

@ -304,12 +304,12 @@ void OpenDocumentManager::fileHasBeenRenamed (const File& oldFile, const File& n
//==============================================================================
RecentDocumentList::RecentDocumentList()
{
JucerApplication::getApp()->openDocumentManager.addListener (this);
JucerApplication::getApp().openDocumentManager.addListener (this);
}
RecentDocumentList::~RecentDocumentList()
{
JucerApplication::getApp()->openDocumentManager.removeListener (this);
JucerApplication::getApp().openDocumentManager.removeListener (this);
}
void RecentDocumentList::clear()
@ -378,7 +378,7 @@ static void restoreDocList (Project& project, Array <OpenDocumentManager::Docume
{
if (xml != nullptr)
{
OpenDocumentManager& odm = JucerApplication::getApp()->openDocumentManager;
OpenDocumentManager& odm = JucerApplication::getApp().openDocumentManager;
forEachXmlChildElementWithTagName (*xml, e, "DOC")
{

View file

@ -358,7 +358,7 @@ namespace ProjectSettingsTreeClasses
void addSubItems()
{
addSubItem (new ModulesItem (project));
JucerApplication::getApp()->addExtraConfigItems (project, *this);
JucerApplication::getApp().addExtraConfigItems (project, *this);
int i = 0;
for (Project::ExporterIterator exporter (project); exporter.next(); ++i)

View file

@ -495,7 +495,7 @@ public:
MainWindow* mw = dynamic_cast<MainWindow*> (getTopLevelComponent());
jassert (mw != nullptr);
JucerApplication::getApp()->mainWindowList.closeWindow (mw);
JucerApplication::getApp().mainWindowList.closeWindow (mw);
}
}

View file

@ -66,7 +66,7 @@ Project::Project (const File& file_)
Project::~Project()
{
projectRoot.removeListener (this);
JucerApplication::getApp()->openDocumentManager.closeAllDocumentsUsingProject (*this, false);
JucerApplication::getApp().openDocumentManager.closeAllDocumentsUsingProject (*this, false);
}
//==============================================================================
@ -537,7 +537,7 @@ bool Project::Item::renameFile (const File& newFile)
|| (newFile.exists() && ! oldFile.exists()))
{
setFile (newFile);
JucerApplication::getApp()->openDocumentManager.fileHasBeenRenamed (oldFile, newFile);
JucerApplication::getApp().openDocumentManager.fileHasBeenRenamed (oldFile, newFile);
return true;
}

View file

@ -259,7 +259,7 @@ void ProjectContentComponent::updateMissingFileStatuses()
bool ProjectContentComponent::showEditorForFile (const File& f)
{
return getCurrentFile() == f
|| showDocument (JucerApplication::getApp()->openDocumentManager.openFile (project, f));
|| showDocument (JucerApplication::getApp().openDocumentManager.openFile (project, f));
}
File ProjectContentComponent::getCurrentFile() const
@ -375,7 +375,8 @@ void ProjectContentComponent::getAllCommands (Array <CommandID>& commands)
CommandIDs::closeProject,
CommandIDs::openInIDE,
CommandIDs::saveAndOpenInIDE,
CommandIDs::showProjectSettings,
CommandIDs::showFilePanel,
CommandIDs::showConfigPanel,
CommandIDs::goToPreviousDoc,
CommandIDs::goToNextDoc,
StandardApplicationCommandIDs::del };
@ -472,16 +473,24 @@ void ProjectContentComponent::getCommandInfo (const CommandID commandID, Applica
result.defaultKeypresses.add (KeyPress ('l', ModifierKeys::commandModifier, 0));
break;
case CommandIDs::showProjectSettings:
result.setInfo ("Show Project Build Settings",
case CommandIDs::showFilePanel:
result.setInfo ("Show File Panel",
"Shows the tree of files for this project",
CommandCategories::general, 0);
result.setActive (project != nullptr);
result.defaultKeypresses.add (KeyPress ('p', ModifierKeys::commandModifier, 0));
break;
case CommandIDs::showConfigPanel:
result.setInfo ("Show Config Panel",
"Shows the build options for the project",
CommandCategories::general, 0);
result.setActive (project != nullptr);
result.defaultKeypresses.add (KeyPress ('i', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
result.defaultKeypresses.add (KeyPress ('i', ModifierKeys::commandModifier, 0));
break;
case StandardApplicationCommandIDs::del:
result.setInfo ("Delete", String::empty, CommandCategories::general, 0);
result.setInfo ("Delete Selected File", String::empty, CommandCategories::general, 0);
result.defaultKeypresses.add (KeyPress (KeyPress::deleteKey, 0, 0));
result.defaultKeypresses.add (KeyPress (KeyPress::backspaceKey, 0, 0));
result.setActive (dynamic_cast<TreePanelBase*> (treeViewTabs.getCurrentContentComponent()) != nullptr);
@ -530,7 +539,7 @@ bool ProjectContentComponent::perform (const InvocationInfo& info)
case CommandIDs::closeDocument:
if (currentDocument != nullptr)
JucerApplication::getApp()->openDocumentManager.closeDocument (currentDocument, true);
JucerApplication::getApp().openDocumentManager.closeDocument (currentDocument, true);
break;
case CommandIDs::goToPreviousDoc:
@ -567,7 +576,11 @@ bool ProjectContentComponent::perform (const InvocationInfo& info)
}
break;
case CommandIDs::showProjectSettings:
case CommandIDs::showFilePanel:
treeViewTabs.setCurrentTabIndex (0);
break;
case CommandIDs::showConfigPanel:
treeViewTabs.setCurrentTabIndex (1);
break;

View file

@ -220,7 +220,7 @@ void ProjectTreeViewBase::deleteAllSelectedItems()
if (treeRootItem != nullptr)
{
OpenDocumentManager& om = JucerApplication::getApp()->openDocumentManager;
OpenDocumentManager& om = JucerApplication::getApp().openDocumentManager;
for (int i = filesToTrash.size(); --i >= 0;)
{

View file

@ -191,7 +191,7 @@ public:
void resized()
{
item.textX = item.getIconSize() + 8;
item.textX = (int) item.getIconSize() + 8;
}
JucerTreeViewBase& item;

View file

@ -30,7 +30,7 @@
//==============================================================================
StoredSettings& getAppSettings()
{
return JucerApplication::getApp()->settings;
return JucerApplication::getApp().settings;
}
PropertiesFile& getAppProperties()
@ -211,7 +211,7 @@ File StoredSettings::getSchemesFolder()
//==============================================================================
const Icons& getIcons()
{
return JucerApplication::getApp()->icons;
return JucerApplication::getApp().icons;
}
Icons::Icons()