From af3bab799f9e5a1eb29390c20043ccb79a6b5fb9 Mon Sep 17 00:00:00 2001 From: jules Date: Thu, 26 Jul 2012 18:47:24 +0100 Subject: [PATCH] Introjucer: fine-tuned some command behaviours. --- .../Source/Application/jucer_Application.h | 2 +- .../Source/Application/jucer_MainWindow.cpp | 10 +- .../Project Saving/jucer_ResourceFile.cpp | 7 +- .../Project/jucer_ProjectContentComponent.cpp | 235 +++++++++--------- .../Project/jucer_ProjectContentComponent.h | 12 +- 5 files changed, 134 insertions(+), 132 deletions(-) diff --git a/extras/Introjucer/Source/Application/jucer_Application.h b/extras/Introjucer/Source/Application/jucer_Application.h index 126dd53fc4..e87fe5700b 100644 --- a/extras/Introjucer/Source/Application/jucer_Application.h +++ b/extras/Introjucer/Source/Application/jucer_Application.h @@ -128,7 +128,7 @@ public: //============================================================================== const String getApplicationName() { - return String (ProjectInfo::projectName) + " " + getApplicationVersion(); + return "Introjucer"; } const String getApplicationVersion() diff --git a/extras/Introjucer/Source/Application/jucer_MainWindow.cpp b/extras/Introjucer/Source/Application/jucer_MainWindow.cpp index bedb3b4a8e..07e1d31266 100644 --- a/extras/Introjucer/Source/Application/jucer_MainWindow.cpp +++ b/extras/Introjucer/Source/Application/jucer_MainWindow.cpp @@ -160,6 +160,7 @@ void MainWindow::setProject (Project* newProject) createProjectContentCompIfNeeded(); getProjectContentComponent()->setProject (newProject); currentProject = newProject; + getProjectContentComponent()->updateMainWindowTitle(); commandManager->commandStatusChanged(); } @@ -240,10 +241,10 @@ void MainWindow::updateTitle (const String& documentName) String name (JucerApplication::getApp().getApplicationName()); if (currentProject != nullptr) - name = currentProject->getDocumentTitle() + " - " + name; + name << " - " << currentProject->getDocumentTitle(); if (documentName.isNotEmpty()) - name = documentName + " - " + name; + name << " - " << documentName; setName (name); } @@ -375,7 +376,10 @@ bool MainWindowList::openFile (const File& file) if (newDoc->loadFrom (file, true)) { MainWindow* const w = getOrCreateEmptyWindow(); - w->setProject (newDoc.release()); + w->setProject (newDoc); + + newDoc.release()->setChangedFlag (false); + w->makeVisible(); avoidSuperimposedWindows (w); diff --git a/extras/Introjucer/Source/Project Saving/jucer_ResourceFile.cpp b/extras/Introjucer/Source/Project Saving/jucer_ResourceFile.cpp index 28fbe6e0ec..fea8945128 100644 --- a/extras/Introjucer/Source/Project Saving/jucer_ResourceFile.cpp +++ b/extras/Introjucer/Source/Project Saving/jucer_ResourceFile.cpp @@ -123,9 +123,10 @@ bool ResourceFile::write (const File& cppFile, OutputStream& cpp, OutputStream& { String comment; comment << newLine << newLine - << " This is an auto-generated file, created by " << JUCEApplication::getInstance()->getApplicationName() << newLine - << " Do not edit anything in this file!" << newLine << newLine - << "*/" << newLine << newLine; + << " This is an auto-generated file: Any edits you make may be overwritten!" << newLine + << newLine + << "*/" << newLine + << newLine; header << "/* =========================================================================================" << comment; diff --git a/extras/Introjucer/Source/Project/jucer_ProjectContentComponent.cpp b/extras/Introjucer/Source/Project/jucer_ProjectContentComponent.cpp index df06ebd053..1f93412152 100644 --- a/extras/Introjucer/Source/Project/jucer_ProjectContentComponent.cpp +++ b/extras/Introjucer/Source/Project/jucer_ProjectContentComponent.cpp @@ -91,20 +91,17 @@ public: class LogoComponent : public Component { public: - LogoComponent() - { - Rectangle iconSize (getIcons().mainJuceLogo.getBounds()); - setSize (400, (int) (400 * iconSize.getWidth() / iconSize.getHeight())); - } + LogoComponent() {} void paint (Graphics& g) { - g.setColour (findColour (mainBackgroundColourId).contrasting (0.3f)); + const Path& logo = getIcons().mainJuceLogo; + const AffineTransform trans (RectanglePlacement (RectanglePlacement::centred) + .getTransformToFit (logo.getBounds(), + getLocalBounds().toFloat())); - g.fillPath (getIcons().mainJuceLogo, - RectanglePlacement (RectanglePlacement::centred) - .getTransformToFit (getIcons().mainJuceLogo.getBounds(), - getLocalBounds().toFloat())); + g.setColour (findColour (mainBackgroundColourId).contrasting (0.3f)); + g.fillPath (logo, trans); } }; @@ -172,15 +169,9 @@ void ProjectContentComponent::resized() resizerBar->setBounds (r.removeFromLeft (4)); if (contentView != nullptr) - { contentView->setBounds (r); - logo->setVisible (false); - } - else - { - logo->setBounds (r.reduced (r.getWidth() / 4, r.getHeight() / 4)); - logo->setVisible (true); - } + + logo->setBounds (r.reduced (r.getWidth() / 4, r.getHeight() / 4)); } void ProjectContentComponent::lookAndFeelChanged() @@ -414,14 +405,31 @@ bool ProjectContentComponent::setEditorComponent (Component* editor, return false; } +void ProjectContentComponent::closeDocument() +{ + if (currentDocument != nullptr) + JucerApplication::getApp().openDocumentManager.closeDocument (currentDocument, true); + else if (contentView != nullptr) + if (! goToPreviousFile()) + hideEditor(); +} + +void ProjectContentComponent::saveDocument() +{ + if (currentDocument != nullptr) + currentDocument->save(); + else + saveProject(); +} + bool ProjectContentComponent::goToPreviousFile() { - OpenDocumentManager::Document* currentSourceDoc = recentDocumentList.getCurrentDocument(); + OpenDocumentManager::Document* doc = recentDocumentList.getCurrentDocument(); - if (currentSourceDoc != nullptr && currentSourceDoc != getCurrentDocument()) - return showDocument (currentSourceDoc, true); - else - return showDocument (recentDocumentList.getPrevious(), true); + if (doc == nullptr || doc == getCurrentDocument()) + doc = recentDocumentList.getPrevious(); + + return showDocument (doc, true); } bool ProjectContentComponent::goToNextFile() @@ -429,6 +437,39 @@ bool ProjectContentComponent::goToNextFile() return showDocument (recentDocumentList.getNext(), true); } +bool ProjectContentComponent::saveProject() +{ + return project != nullptr + && project->save (true, true) == FileBasedDocument::savedOk; +} + +void ProjectContentComponent::closeProject() +{ + MainWindow* const mw = findParentComponentOfClass(); + + if (mw != nullptr) + mw->closeCurrentProject(); +} + +void ProjectContentComponent::openInIDE() +{ + if (project != nullptr) + { + ScopedPointer exporter (ProjectExporter::createPlatformDefaultExporter (*project)); + + if (exporter != nullptr) + exporter->launchProject(); + } +} + +void ProjectContentComponent::deleteSelectedTreeItems() +{ + TreePanelBase* const tree = dynamic_cast (treeViewTabs.getCurrentContentComponent()); + + if (tree != nullptr) + tree->deleteSelectedItems(); +} + void ProjectContentComponent::updateMainWindowTitle() { MainWindow* mw = findParentComponentOfClass(); @@ -437,6 +478,17 @@ void ProjectContentComponent::updateMainWindowTitle() mw->updateTitle (currentDocument != nullptr ? currentDocument->getName() : String::empty); } +void ProjectContentComponent::showBubbleMessage (const Rectangle& pos, const String& text) +{ + addChildComponent (&bubbleMessage); + bubbleMessage.setColour (BubbleComponent::backgroundColourId, Colours::white.withAlpha (0.7f)); + bubbleMessage.setColour (BubbleComponent::outlineColourId, Colours::black.withAlpha (0.8f)); + bubbleMessage.setAlwaysOnTop (true); + + bubbleMessage.showAt (pos, AttributedString (text), 3000, true, false); +} + +//============================================================================== ApplicationCommandTarget* ProjectContentComponent::getNextCommandTarget() { return findFirstTargetParentComponent(); @@ -493,7 +545,7 @@ void ProjectContentComponent::getCommandInfo (const CommandID commandID, Applica result.setInfo ("Close" + documentName, "Closes the current document", CommandCategories::general, 0); - result.setActive (currentDocument != nullptr); + result.setActive (contentView != nullptr); #if JUCE_MAC result.defaultKeypresses.add (KeyPress ('w', ModifierKeys::commandModifier | ModifierKeys::ctrlModifier, 0)); #else @@ -585,114 +637,51 @@ bool ProjectContentComponent::perform (const InvocationInfo& info) { switch (info.commandID) { - case CommandIDs::saveProject: - if (project != nullptr && ! reinvokeCommandAfterClosingPropertyEditors (info)) - project->save (true, true); - - break; - - case CommandIDs::closeProject: - { - MainWindow* const mw = findParentComponentOfClass(); - - if (mw != nullptr && ! reinvokeCommandAfterClosingPropertyEditors (info)) - mw->closeCurrentProject(); - } - - break; - - case CommandIDs::saveDocument: - if (! reinvokeCommandAfterClosingPropertyEditors (info)) - { - if (currentDocument != nullptr) - currentDocument->save(); - else if (project != nullptr) - project->save (true, true); - } - - break; - - case CommandIDs::closeDocument: - if (currentDocument != nullptr) - JucerApplication::getApp().openDocumentManager.closeDocument (currentDocument, true); - break; - - case CommandIDs::goToPreviousDoc: - goToPreviousFile(); - break; - - case CommandIDs::goToNextDoc: - goToNextFile(); - break; - - case CommandIDs::openInIDE: - if (project != nullptr) - { - ScopedPointer exporter (ProjectExporter::createPlatformDefaultExporter (*project)); - - if (exporter != nullptr) - exporter->launchProject(); - } - break; - - case CommandIDs::saveAndOpenInIDE: - if (project != nullptr) - { - if (! reinvokeCommandAfterClosingPropertyEditors (info)) + case CommandIDs::saveProject: + case CommandIDs::closeProject: + case CommandIDs::saveDocument: + case CommandIDs::closeDocument: + case CommandIDs::goToPreviousDoc: + case CommandIDs::goToNextDoc: + case CommandIDs::saveAndOpenInIDE: + if (reinvokeCommandAfterCancellingModalComps (info)) { - if (project->save (true, true) == FileBasedDocument::savedOk) - { - ScopedPointer exporter (ProjectExporter::createPlatformDefaultExporter (*project)); - - if (exporter != nullptr) - exporter->launchProject(); - } + grabKeyboardFocus(); // to force any open labels to close their text editors + return true; } - } - break; - case CommandIDs::showFilePanel: - treeViewTabs.setCurrentTabIndex (0); - break; + break; - case CommandIDs::showConfigPanel: - treeViewTabs.setCurrentTabIndex (1); - break; + default: + break; + } - case StandardApplicationCommandIDs::del: - { - TreePanelBase* const tree = dynamic_cast (treeViewTabs.getCurrentContentComponent()); + switch (info.commandID) + { + case CommandIDs::saveProject: saveProject(); break; + case CommandIDs::closeProject: closeProject(); break; + case CommandIDs::saveDocument: saveDocument(); break; - if (tree != nullptr) - tree->deleteSelectedItems(); - } + case CommandIDs::closeDocument: closeDocument(); break; + case CommandIDs::goToPreviousDoc: goToPreviousFile(); break; + case CommandIDs::goToNextDoc: goToNextFile(); break; - break; + case CommandIDs::showFilePanel: treeViewTabs.setCurrentTabIndex (0); break; + case CommandIDs::showConfigPanel: treeViewTabs.setCurrentTabIndex (1); break; - default: - return false; + case CommandIDs::openInIDE: openInIDE(); break; + + case StandardApplicationCommandIDs::del: deleteSelectedTreeItems(); break; + + case CommandIDs::saveAndOpenInIDE: + if (saveProject()) + openInIDE(); + + break; + + default: + return false; } return true; } - -bool ProjectContentComponent::reinvokeCommandAfterClosingPropertyEditors (const InvocationInfo& info) -{ - if (reinvokeCommandAfterCancellingModalComps (info)) - { - grabKeyboardFocus(); // to force any open labels to close their text editors - return true; - } - - return false; -} - -void ProjectContentComponent::showBubbleMessage (const Rectangle& pos, const String& text) -{ - addChildComponent (&bubbleMessage); - bubbleMessage.setColour (BubbleComponent::backgroundColourId, Colours::white.withAlpha (0.7f)); - bubbleMessage.setColour (BubbleComponent::outlineColourId, Colours::black.withAlpha (0.8f)); - bubbleMessage.setAlwaysOnTop (true); - - bubbleMessage.showAt (pos, AttributedString (text), 3000, true, false); -} diff --git a/extras/Introjucer/Source/Project/jucer_ProjectContentComponent.h b/extras/Introjucer/Source/Project/jucer_ProjectContentComponent.h index e5adea8978..9364350653 100644 --- a/extras/Introjucer/Source/Project/jucer_ProjectContentComponent.h +++ b/extras/Introjucer/Source/Project/jucer_ProjectContentComponent.h @@ -56,6 +56,8 @@ public: bool showDocument (OpenDocumentManager::Document* doc, bool grabFocus); void hideDocument (OpenDocumentManager::Document* doc); OpenDocumentManager::Document* getCurrentDocument() const { return currentDocument; } + void closeDocument(); + void saveDocument(); void hideEditor(); bool setEditorComponent (Component* editor, OpenDocumentManager::Document* doc); @@ -64,6 +66,14 @@ public: bool goToPreviousFile(); bool goToNextFile(); + bool saveProject(); + void closeProject(); + void openInIDE(); + + void deleteSelectedTreeItems(); + + void updateMainWindowTitle(); + void updateMissingFileStatuses(); virtual void createProjectTabs(); @@ -97,8 +107,6 @@ protected: void documentAboutToClose (OpenDocumentManager::Document*); void changeListenerCallback (ChangeBroadcaster*); - void updateMainWindowTitle(); - bool reinvokeCommandAfterClosingPropertyEditors (const InvocationInfo&); TreeView* getFilesTreeView() const; ProjectTreeViewBase* getFilesTreeRoot() const;