Skip to content

Commit b75c573

Browse files
committed
Merge branch 'develop' into feature/heavy-dpf-nanovg-gui
2 parents fea7bad + 95d3b16 commit b75c573

5 files changed

Lines changed: 36 additions & 21 deletions

File tree

‎Source/Dialogs/Dialogs.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ bool Dialog::wantsRoundedCorners() const
9090
return true;
9191
}
9292

93-
Component* Dialogs::showTextEditorDialog(String const& text, String filename, std::function<void(String, bool)> closeCallback, std::function<void(String)> saveCallback, float const desktopScale, bool const enableSyntaxHighlighting)
93+
Component* Dialogs::showTextEditorDialog(String const& text, String filename, std::function<void(String, bool)> closeCallback, std::function<void(String)> saveCallback, float const desktopScale, bool const enableSyntaxHighlighting, File const& associatedFile)
9494
{
9595
#if ENABLE_TESTING
9696
return nullptr;
9797
#endif
98-
auto* editor = new TextEditorDialog(std::move(filename), enableSyntaxHighlighting, std::move(closeCallback), std::move(saveCallback), desktopScale);
98+
auto* editor = new TextEditorDialog(std::move(filename), enableSyntaxHighlighting, std::move(closeCallback), std::move(saveCallback), desktopScale, associatedFile);
9999
editor->editor.setText(text);
100100
return editor;
101101
}

‎Source/Dialogs/Dialogs.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class Dialog final : public Component {
172172
};
173173

174174
struct Dialogs {
175-
static Component* showTextEditorDialog(String const& text, String filename, std::function<void(String, bool)> closeCallback, std::function<void(String)> saveCallback, float desktopScale = 1.0f, bool enableSyntaxHighlighting = false);
175+
static Component* showTextEditorDialog(String const& text, String filename, std::function<void(String, bool)> closeCallback, std::function<void(String)> saveCallback, float desktopScale = 1.0f, bool enableSyntaxHighlighting = false, File const& associatedFile = File());
176176
static void appendTextToTextEditorDialog(Component* dialog, String const& text);
177177
static void clearTextEditorDialog(Component* dialog);
178178

‎Source/Dialogs/TextEditorDialog.h‎

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

‎Source/Objects/LuaObject.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ class LuaObject final : public ObjectBase
10741074
};
10751075

10761076
auto const scaleFactor = getApproximateScaleFactorForComponent(cnv->editor);
1077-
textEditor.reset(Dialogs::showTextEditorDialog(fileToOpen.loadFileAsString(), "lua: " + getText(), onClose, onSave, scaleFactor, true));
1077+
textEditor.reset(Dialogs::showTextEditorDialog(fileToOpen.loadFileAsString(), "lua: " + getText(), onClose, onSave, scaleFactor, true, fileToOpen));
10781078

10791079
if (textEditor)
10801080
cnv->editor->openTextEditors.add_unique(ptr);
@@ -1230,7 +1230,7 @@ class LuaTextObject final : public TextObjectBase {
12301230
};
12311231

12321232
auto const scaleFactor = getApproximateScaleFactorForComponent(cnv->editor);
1233-
textEditor.reset(Dialogs::showTextEditorDialog(fileToOpen.loadFileAsString(), "lua: " + getText(), onClose, onSave, scaleFactor, true));
1233+
textEditor.reset(Dialogs::showTextEditorDialog(fileToOpen.loadFileAsString(), "lua: " + getText(), onClose, onSave, scaleFactor, true, fileToOpen));
12341234

12351235
if (textEditor)
12361236
cnv->editor->openTextEditors.add_unique(ptr);

‎Tests/InspectorTest.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ class InspectorTest : public PlugDataUnitTest
133133

134134
void finish()
135135
{
136-
ColourPicker::getInstance()->clearSingletonInstance();
137136
if (auto* sidebar = editor->getSidebarForPanel(Sidebar::InspectorPanel))
138137
sidebar->clearInspector();
139138

0 commit comments

Comments
 (0)