From 2fd89b0ac4df2c66d9501ee7b6e41549ef1c3692 Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 26 Aug 2014 10:17:40 +0100 Subject: [PATCH] A few minor clean-ups. --- .../files/juce_WildcardFileFilter.cpp | 53 +++++++++---------- .../juce_core/files/juce_WildcardFileFilter.h | 4 -- modules/juce_core/text/juce_String.h | 6 +-- .../commands/juce_KeyPressMappingSet.cpp | 2 +- .../menus/juce_MenuBarComponent.cpp | 30 ++++++----- .../menus/juce_MenuBarComponent.h | 9 ++-- .../juce_gui_basics/menus/juce_MenuBarModel.h | 14 +++-- 7 files changed, 57 insertions(+), 61 deletions(-) diff --git a/modules/juce_core/files/juce_WildcardFileFilter.cpp b/modules/juce_core/files/juce_WildcardFileFilter.cpp index 1fef4553a2..f18a2eb9ac 100644 --- a/modules/juce_core/files/juce_WildcardFileFilter.cpp +++ b/modules/juce_core/files/juce_WildcardFileFilter.cpp @@ -26,32 +26,7 @@ ============================================================================== */ -WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns, - const String& directoryWildcardPatterns, - const String& desc) - : FileFilter (desc.isEmpty() ? fileWildcardPatterns - : (desc + " (" + fileWildcardPatterns + ")")) -{ - parse (fileWildcardPatterns, fileWildcards); - parse (directoryWildcardPatterns, directoryWildcards); -} - -WildcardFileFilter::~WildcardFileFilter() -{ -} - -bool WildcardFileFilter::isFileSuitable (const File& file) const -{ - return match (file, fileWildcards); -} - -bool WildcardFileFilter::isDirectorySuitable (const File& file) const -{ - return match (file, directoryWildcards); -} - -//============================================================================== -void WildcardFileFilter::parse (const String& pattern, StringArray& result) +static void parseWildcard (const String& pattern, StringArray& result) { result.addTokens (pattern.toLowerCase(), ";,", "\"'"); @@ -65,7 +40,7 @@ void WildcardFileFilter::parse (const String& pattern, StringArray& result) result.set (i, "*"); } -bool WildcardFileFilter::match (const File& file, const StringArray& wildcards) +static bool matchWildcard (const File& file, const StringArray& wildcards) { const String filename (file.getFileName()); @@ -75,3 +50,27 @@ bool WildcardFileFilter::match (const File& file, const StringArray& wildcards) return false; } + +WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns, + const String& directoryWildcardPatterns, + const String& desc) + : FileFilter (desc.isEmpty() ? fileWildcardPatterns + : (desc + " (" + fileWildcardPatterns + ")")) +{ + parseWildcard (fileWildcardPatterns, fileWildcards); + parseWildcard (directoryWildcardPatterns, directoryWildcards); +} + +WildcardFileFilter::~WildcardFileFilter() +{ +} + +bool WildcardFileFilter::isFileSuitable (const File& file) const +{ + return matchWildcard (file, fileWildcards); +} + +bool WildcardFileFilter::isDirectorySuitable (const File& file) const +{ + return matchWildcard (file, directoryWildcards); +} diff --git a/modules/juce_core/files/juce_WildcardFileFilter.h b/modules/juce_core/files/juce_WildcardFileFilter.h index 166ae4acba..fb398ce63b 100644 --- a/modules/juce_core/files/juce_WildcardFileFilter.h +++ b/modules/juce_core/files/juce_WildcardFileFilter.h @@ -75,12 +75,8 @@ private: //============================================================================== StringArray fileWildcards, directoryWildcards; - static void parse (const String& pattern, StringArray& result); - static bool match (const File& file, const StringArray& wildcards); - JUCE_LEAK_DETECTOR (WildcardFileFilter) }; - #endif // JUCE_WILDCARDFILEFILTER_H_INCLUDED diff --git a/modules/juce_core/text/juce_String.h b/modules/juce_core/text/juce_String.h index 4873bd9dde..6a511070bb 100644 --- a/modules/juce_core/text/juce_String.h +++ b/modules/juce_core/text/juce_String.h @@ -1204,16 +1204,16 @@ public: //============================================================================== #if JUCE_MAC || JUCE_IOS || DOXYGEN - /** MAC ONLY - Creates a String from an OSX CFString. */ + /** OSX ONLY - Creates a String from an OSX CFString. */ static String fromCFString (CFStringRef cfString); - /** MAC ONLY - Converts this string to a CFString. + /** OSX ONLY - Converts this string to a CFString. Remember that you must use CFRelease() to free the returned string when you're finished with it. */ CFStringRef toCFString() const; - /** MAC ONLY - Returns a copy of this string in which any decomposed unicode characters have + /** OSX ONLY - Returns a copy of this string in which any decomposed unicode characters have been converted to their precomposed equivalents. */ String convertToPrecomposedUnicode() const; #endif diff --git a/modules/juce_gui_basics/commands/juce_KeyPressMappingSet.cpp b/modules/juce_gui_basics/commands/juce_KeyPressMappingSet.cpp index b37a981269..bcfac4e80c 100644 --- a/modules/juce_gui_basics/commands/juce_KeyPressMappingSet.cpp +++ b/modules/juce_gui_basics/commands/juce_KeyPressMappingSet.cpp @@ -252,7 +252,7 @@ bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion) XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const { - ScopedPointer defaultSet; + ScopedPointer defaultSet; if (saveDifferencesFromDefaultSet) { diff --git a/modules/juce_gui_basics/menus/juce_MenuBarComponent.cpp b/modules/juce_gui_basics/menus/juce_MenuBarComponent.cpp index 5a22fc7a47..842fa59525 100644 --- a/modules/juce_gui_basics/menus/juce_MenuBarComponent.cpp +++ b/modules/juce_gui_basics/menus/juce_MenuBarComponent.cpp @@ -22,7 +22,7 @@ ============================================================================== */ -MenuBarComponent::MenuBarComponent (MenuBarModel* model_) +MenuBarComponent::MenuBarComponent (MenuBarModel* m) : model (nullptr), itemUnderMouse (-1), currentPopupIndex (-1), @@ -32,7 +32,7 @@ MenuBarComponent::MenuBarComponent (MenuBarModel* model_) setWantsKeyboardFocus (false); setMouseClickGrabsKeyboardFocus (false); - setModel (model_); + setModel (m); } MenuBarComponent::~MenuBarComponent() @@ -284,22 +284,26 @@ void MenuBarComponent::mouseMove (const MouseEvent& e) bool MenuBarComponent::keyPressed (const KeyPress& key) { - bool used = false; const int numMenus = menuNames.size(); - const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex); - if (key.isKeyCode (KeyPress::leftKey)) + if (numMenus > 0) { - showMenu ((currentIndex + numMenus - 1) % numMenus); - used = true; - } - else if (key.isKeyCode (KeyPress::rightKey)) - { - showMenu ((currentIndex + 1) % numMenus); - used = true; + const int currentIndex = jlimit (0, numMenus - 1, currentPopupIndex); + + if (key.isKeyCode (KeyPress::leftKey)) + { + showMenu ((currentIndex + numMenus - 1) % numMenus); + return true; + } + + if (key.isKeyCode (KeyPress::rightKey)) + { + showMenu ((currentIndex + 1) % numMenus); + return true; + } } - return used; + return false; } void MenuBarComponent::menuBarItemsChanged (MenuBarModel* /*menuBarModel*/) diff --git a/modules/juce_gui_basics/menus/juce_MenuBarComponent.h b/modules/juce_gui_basics/menus/juce_MenuBarComponent.h index b8fc2c315a..badd05a5cf 100644 --- a/modules/juce_gui_basics/menus/juce_MenuBarComponent.h +++ b/modules/juce_gui_basics/menus/juce_MenuBarComponent.h @@ -40,9 +40,9 @@ public: //============================================================================== /** Creates a menu bar. - @param model the model object to use to control this bar. You can - pass 0 into this if you like, and set the model later - using the setModel() method + @param model the model object to use to control this bar. You can + pass nullptr into this if you like, and set the model + later using the setModel() method */ MenuBarComponent (MenuBarModel* model); @@ -57,8 +57,7 @@ public: */ void setModel (MenuBarModel* newModel); - /** Returns the current menu bar model being used. - */ + /** Returns the current menu bar model being used. */ MenuBarModel* getModel() const noexcept; //============================================================================== diff --git a/modules/juce_gui_basics/menus/juce_MenuBarModel.h b/modules/juce_gui_basics/menus/juce_MenuBarModel.h index ceac89a3ae..99b698511e 100644 --- a/modules/juce_gui_basics/menus/juce_MenuBarModel.h +++ b/modules/juce_gui_basics/menus/juce_MenuBarModel.h @@ -80,8 +80,7 @@ public: virtual ~Listener() {} //============================================================================== - /** This callback is made when items are changed in the menu bar model. - */ + /** This callback is made when items are changed in the menu bar model. */ virtual void menuBarItemsChanged (MenuBarModel* menuBarModel) = 0; /** This callback is made when an application command is invoked that @@ -101,7 +100,6 @@ public: void addListener (Listener* listenerToAdd) noexcept; /** Removes a listener. - @see addListener */ void removeListener (Listener* listenerToRemove) noexcept; @@ -130,7 +128,7 @@ public: //============================================================================== #if JUCE_MAC || DOXYGEN - /** MAC ONLY - Sets the model that is currently being shown as the main + /** OSX ONLY - Sets the model that is currently being shown as the main menu bar at the top of the screen on the Mac. You can pass 0 to stop the current model being displayed. Be careful @@ -151,12 +149,12 @@ public: const PopupMenu* extraAppleMenuItems = nullptr, const String& recentItemsMenuName = String::empty); - /** MAC ONLY - Returns the menu model that is currently being shown as + /** OSX ONLY - Returns the menu model that is currently being shown as the main menu bar. */ static MenuBarModel* getMacMainMenu(); - /** MAC ONLY - Returns the menu that was last passed as the extraAppleMenuItems + /** OSX ONLY - Returns the menu that was last passed as the extraAppleMenuItems argument to setMacMainMenu(), or nullptr if none was specified. */ static const PopupMenu* getMacExtraAppleItemsMenu(); @@ -164,7 +162,7 @@ public: //============================================================================== /** @internal */ - void applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info) override; + void applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo&) override; /** @internal */ void applicationCommandListChanged() override; /** @internal */ @@ -172,7 +170,7 @@ public: private: ApplicationCommandManager* manager; - ListenerList listeners; + ListenerList listeners; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MenuBarModel) };