forked from jpcima/ysfx
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ide: start work on multi-file support
- Loading branch information
1 parent
7f35370
commit be2d9c9
Showing
5 changed files
with
169 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include "ysfx_document.h" | ||
#include "modal_textinputbox.h" | ||
|
||
|
||
YSFXCodeDocument::YSFXCodeDocument() : CodeDocument() | ||
{ | ||
reset(); | ||
}; | ||
|
||
void YSFXCodeDocument::reset() | ||
{ | ||
replaceAllContent(juce::String{}); | ||
} | ||
|
||
void YSFXCodeDocument::loadFile(juce::File file) | ||
{ | ||
if (file != juce::File{}) m_file = file; | ||
if (!m_file.existsAsFile()) return; | ||
|
||
{ | ||
juce::MemoryBlock memBlock; | ||
if (m_file.loadFileAsData(memBlock)) { | ||
juce::String newContent = memBlock.toString(); | ||
memBlock = {}; | ||
if (newContent != getAllContent()) { | ||
replaceAllContent(newContent); | ||
// m_editor->moveCaretToTop(false); | ||
} | ||
} | ||
} | ||
} | ||
|
||
bool YSFXCodeDocument::loaded(void) { | ||
return bool(m_file != juce::File{}); | ||
} | ||
|
||
juce::File YSFXCodeDocument::getPath(void) { | ||
return m_file; | ||
} | ||
|
||
void YSFXCodeDocument::checkFileForModifications() | ||
{ | ||
if (m_file == juce::File{}) | ||
return; | ||
|
||
juce::Time newMtime = m_file.getLastModificationTime(); | ||
if (newMtime == juce::Time{}) | ||
return; | ||
|
||
if (m_changeTime == juce::Time{} || newMtime > m_changeTime) { | ||
m_changeTime = newMtime; | ||
|
||
if (!m_reloadDialogGuard) { | ||
m_reloadDialogGuard = true; | ||
|
||
auto callback = [this](int result) { | ||
m_reloadDialogGuard = false; | ||
if (result != 0) { | ||
loadFile(m_file); | ||
} | ||
}; | ||
|
||
m_alertWindow.reset(show_option_window(TRANS("Reload?"), TRANS("The file ") + m_file.getFileNameWithoutExtension() + TRANS(" has been modified outside this editor. Reload it?"), std::vector<juce::String>{"Yes", "No"}, callback)); | ||
} | ||
} | ||
} | ||
|
||
bool YSFXCodeDocument::saveFile(juce::File path) | ||
{ | ||
const juce::String content = getAllContent(); | ||
|
||
if (path == juce::File{}) { | ||
saveFile(m_file); | ||
} | ||
|
||
bool success = m_file.replaceWithData(content.toRawUTF8(), content.getNumBytesAsUTF8()); | ||
if (!success) { | ||
m_alertWindow.reset(show_option_window(TRANS("Error"), TRANS("Could not save ") + m_file.getFileNameWithoutExtension() + TRANS("."), std::vector<juce::String>{"OK"}, [](int result){ (void) result; })); | ||
return false; | ||
} | ||
|
||
m_changeTime = juce::Time::getCurrentTime(); | ||
return true; | ||
} |
Oops, something went wrong.