1
0
mirror of synced 2025-02-20 04:01:01 +01:00

Added error messages for file opening issues

This commit is contained in:
WerWolv 2021-01-31 00:05:07 +01:00
parent b4cbfa02cf
commit 8dd76a6cc8
2 changed files with 18 additions and 12 deletions

View File

@ -36,19 +36,17 @@ namespace hex {
}
void View::drawCommonInterfaces() {
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20, 10));
if (ImGui::BeginPopupModal("Error", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text("%s", SharedData::errorPopupMessage.c_str());
ImGui::NewLine();
if (ImGui::BeginChild("##scrolling", ImVec2(300, 100))) {
ImGui::SetCursorPosX((300 - ImGui::CalcTextSize(SharedData::errorPopupMessage.c_str(), nullptr, false).x) / 2.0F);
ImGui::TextWrapped("%s", SharedData::errorPopupMessage.c_str());
ImGui::EndChild();
}
ImGui::NewLine();
ImGui::SetCursorPosX(75);
if (ImGui::Button("Okay", ImVec2(150, 20)) || ImGui::IsKeyDown(ImGuiKey_Escape))
ImGui::Separator();
if (ImGui::Button("Okay") || ImGui::IsKeyDown(ImGuiKey_Escape))
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
ImGui::PopStyleVar();
if (SharedData::fileBrowser.showFileDialog(SharedData::fileBrowserTitle, SharedData::fileBrowserDialogMode, ImVec2(0, 0), SharedData::fileBrowserValidExtensions)) {
SharedData::fileBrowserCallback(SharedData::fileBrowser.selected_path);

View File

@ -505,17 +505,25 @@ namespace hex {
delete provider;
provider = new prv::FileProvider(path);
this->m_memoryEditor.ReadOnly = !provider->isWritable();
if (!provider->isWritable()) {
this->m_memoryEditor.ReadOnly = true;
View::showErrorPopup("Couldn't get write access. File opened in read-only mode.");
} else {
this->m_memoryEditor.ReadOnly = false;
}
if (provider->isAvailable())
ProjectFile::setFilePath(path);
if (!provider->isAvailable()) {
View::showErrorPopup("Failed to open file!");
return;
}
ProjectFile::setFilePath(path);
this->getWindowOpenState() = true;
View::postEvent(Events::FileLoaded);
View::postEvent(Events::DataChanged);
View::postEvent(Events::PatternChanged);
ProjectFile::markDirty();
}
bool ViewHexEditor::saveToFile(std::string path, const std::vector<u8>& data) {