Skip to content

Commit

Permalink
ide: store last filename
Browse files Browse the repository at this point in the history
we store the last filename such that a compilation error doesn't immediately get us into a state where we can't fix and resave it
  • Loading branch information
JoepVanlier committed Dec 11, 2024
1 parent 07f376a commit 39b3ebe
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions plugin/components/ide_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ struct YsfxIDEView::Impl {
juce::Array<VariableUI> m_vars;
std::unique_ptr<juce::Timer> m_varsUpdateTimer;

juce::File m_file{};

bool m_forceUpdate{false};

//==========================================================================
Expand Down Expand Up @@ -145,10 +147,11 @@ void YsfxIDEView::Impl::setupNewFx()
}
else {
juce::File file{juce::CharPointer_UTF8{ysfx_get_file_path(fx)}};
if (file != juce::File{}) m_file = file;

{
juce::MemoryBlock memBlock;
if (file.loadFileAsData(memBlock)) {
if (m_file.loadFileAsData(memBlock)) {
juce::String newContent = memBlock.toString();
memBlock = {};
if (newContent != m_document->getAllContent()) {
Expand Down Expand Up @@ -206,9 +209,8 @@ void YsfxIDEView::Impl::saveAs()
if (m_fileChooserActive) return;

juce::File initialPath;
juce::File prevFilePath{juce::CharPointer_UTF8{ysfx_get_file_path(m_fx.get())}};
if (prevFilePath != juce::File{}) {
initialPath = prevFilePath.getParentDirectory();
if (m_file != juce::File{}) {
initialPath = m_file.getParentDirectory();
}

m_fileChooser.reset(new juce::FileChooser(TRANS("Choose filename to save JSFX to"), initialPath));
Expand Down Expand Up @@ -272,10 +274,9 @@ void YsfxIDEView::Impl::saveCurrentFile()
if (!fx)
return;

juce::File file = juce::File{juce::CharPointer_UTF8{ysfx_get_file_path(fx)}};
if (file.existsAsFile()) {
if (m_file.existsAsFile()) {
m_btnSave->setEnabled(false);
saveFile(file);
saveFile(m_file);
} else {
saveAs();
}
Expand All @@ -287,11 +288,10 @@ void YsfxIDEView::Impl::checkFileForModifications()
if (!fx)
return;

juce::File file{juce::CharPointer_UTF8{ysfx_get_file_path(fx)}};
if (file == juce::File{})
if (m_file == juce::File{})
return;

juce::Time newMtime = file.getLastModificationTime();
juce::Time newMtime = m_file.getLastModificationTime();
if (newMtime == juce::Time{})
return;

Expand All @@ -301,11 +301,11 @@ void YsfxIDEView::Impl::checkFileForModifications()
if (!m_reloadDialogGuard) {
m_reloadDialogGuard = true;

auto callback = [this, file](int result) {
auto callback = [this](int result) {
m_reloadDialogGuard = false;
if (result != 0) {
if (m_self->onReloadRequested)
m_self->onReloadRequested(file);
m_self->onReloadRequested(m_file);
}
};

Expand Down

0 comments on commit 39b3ebe

Please sign in to comment.