@@ -2975,6 +2975,7 @@ struct TextEditorDialog final : public Component
29752975 MainToolbarButton undoButton = MainToolbarButton(Icons::Undo);
29762976 MainToolbarButton redoButton = MainToolbarButton(Icons::Redo);
29772977 MainToolbarButton searchButton = MainToolbarButton(Icons::Search);
2978+ MainToolbarButton openExternallyButton = MainToolbarButton(Icons::OpenLink);
29782979
29792980 SmallIconButton zoomComboButton;
29802981 SearchEditor searchInput;
@@ -2984,13 +2985,15 @@ struct TextEditorDialog final : public Component
29842985
29852986 String title;
29862987 int margin;
2988+ File associatedFile;
29872989
2988- explicit TextEditorDialog (String name, bool const enableSyntaxHighlighting, std::function<void (String, bool )> const & closeCallback, std::function<void(String)> const & saveCallback, float const scale)
2990+ explicit TextEditorDialog (String name, bool const enableSyntaxHighlighting, std::function<void (String, bool )> const & closeCallback, std::function<void(String)> const & saveCallback, float const scale, File fileToOpen = File() )
29892991 : resizer(this , &constrainer)
29902992 , onClose(closeCallback)
29912993 , onSave(saveCallback)
29922994 , title(std::move(name))
29932995 , margin(ProjectInfo::canUseSemiTransparentWindows() ? 15 : 0)
2996+ , associatedFile(std::move(fileToOpen))
29942997 , desktopScale(scale)
29952998 {
29962999 closeButton.reset (LookAndFeel::getDefaultLookAndFeel ().createDocumentWindowButton (-1 ));
@@ -3011,15 +3014,20 @@ struct TextEditorDialog final : public Component
30113014 addToDesktop (0 );
30123015 setVisible (true );
30133016
3014- // Position in centre of screen
3015- setBounds ((Desktop::getInstance ().getDisplays ().getPrimaryDisplay ()->userBounds / desktopScale).withSizeKeepingCentre (700 , 500 ).getSmallestIntegerContainer ());
3016-
30173017 addAndMakeVisible (saveButton);
30183018 addAndMakeVisible (undoButton);
30193019 addAndMakeVisible (redoButton);
30203020 addAndMakeVisible (searchButton);
30213021 addAndMakeVisible (zoomComboButton);
30223022
3023+ // Only text that is backed by a file on disk can be opened in an external editor
3024+ addChildComponent (openExternallyButton);
3025+ openExternallyButton.setVisible (associatedFile.existsAsFile ());
3026+ openExternallyButton.setTooltip (" Open in default text editor" );
3027+
3028+ // Position in centre of screen
3029+ setBounds ((Desktop::getInstance ().getDisplays ().getPrimaryDisplay ()->userBounds / desktopScale).withSizeKeepingCentre (700 , 500 ).getSmallestIntegerContainer ());
3030+
30233031 zoomComboButton.setButtonText (Icons::ThinDown);
30243032
30253033 zoomComboButton.onClick = [this ] {
@@ -3056,6 +3064,15 @@ struct TextEditorDialog final : public Component
30563064 editor.setUnchanged ();
30573065 };
30583066
3067+ openExternallyButton.onClick = [this ] {
3068+ // Make sure the external editor sees the text as it currently is in this dialog
3069+ if (editor.hasChanged ()) {
3070+ onSave (editor.getText ());
3071+ editor.setUnchanged ();
3072+ }
3073+ associatedFile.startAsProcess ();
3074+ };
3075+
30593076 searchButton.onClick = [this ] {
30603077 searchInput.setVisible (searchButton.getToggleState ());
30613078 editor.setSearchText (" " );
@@ -3117,20 +3134,19 @@ struct TextEditorDialog final : public Component
31173134 auto const closeButtonBounds = toolbarBounds.removeFromRight (30 ).reduced (0 , 5 ).translated (-5 , 1 );
31183135 closeButton->setBounds (closeButtonBounds);
31193136
3137+ if (openExternallyButton.isVisible ()) {
3138+ toolbarBounds.removeFromRight (10 );
3139+ openExternallyButton.setBounds (toolbarBounds.removeFromRight (39 ));
3140+ }
3141+ searchButton.setBounds (toolbarBounds.removeFromRight (39 ));
3142+ searchInput.setBounds (toolbarBounds.reduced (5 , 5 ));
3143+
31203144 toolbarBounds.removeFromRight (10 );
3121- auto const searchButtonBounds = toolbarBounds.removeFromRight (39 );
3122- auto const saveButtonBounds = toolbarBounds.removeFromLeft (39 );
3145+ saveButton.setBounds (toolbarBounds.removeFromLeft (39 ));
31233146 toolbarBounds.removeFromLeft (10 );
3124- auto const undoButtonBounds = toolbarBounds.removeFromLeft (39 );
3147+ undoButton. setBounds ( toolbarBounds.removeFromLeft (39 ) );
31253148 toolbarBounds.removeFromLeft (10 );
3126- auto const redoButtonBounds = toolbarBounds.removeFromLeft (39 );
3127-
3128- searchInput.setBounds (toolbarBounds.reduced (5 , 5 ));
3129-
3130- searchButton.setBounds (searchButtonBounds);
3131- saveButton.setBounds (saveButtonBounds);
3132- undoButton.setBounds (undoButtonBounds);
3133- redoButton.setBounds (redoButtonBounds);
3149+ redoButton.setBounds (toolbarBounds.removeFromLeft (39 ));
31343150
31353151 auto statusBarBounds = b.removeFromBottom (28 );
31363152 editor.setBounds (b);
0 commit comments