backend-infra-engineer: Release v0.3.3 snapshot
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
#include "assembly_editor.h"
|
||||
#include "app/editor/system/editor_card_registry.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/match.h"
|
||||
#include "util/file_util.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "app/editor/system/editor_card_registry.h"
|
||||
#include "app/gui/core/icons.h"
|
||||
#include "app/gui/core/ui_helpers.h"
|
||||
#include "app/gui/widgets/text_editor.h"
|
||||
#include "util/file_util.h"
|
||||
|
||||
namespace yaze::editor {
|
||||
|
||||
@@ -18,7 +18,7 @@ using util::FileDialogWrapper;
|
||||
|
||||
namespace {
|
||||
|
||||
static const char *const kKeywords[] = {
|
||||
static const char* const kKeywords[] = {
|
||||
"ADC", "AND", "ASL", "BCC", "BCS", "BEQ", "BIT", "BMI", "BNE", "BPL",
|
||||
"BRA", "BRL", "BVC", "BVS", "CLC", "CLD", "CLI", "CLV", "CMP", "CPX",
|
||||
"CPY", "DEC", "DEX", "DEY", "EOR", "INC", "INX", "INY", "JMP", "JSR",
|
||||
@@ -29,7 +29,7 @@ static const char *const kKeywords[] = {
|
||||
"TCS", "TDC", "TRB", "TSB", "TSC", "TSX", "TXA", "TXS", "TXY", "TYA",
|
||||
"TYX", "WAI", "WDM", "XBA", "XCE", "ORG", "LOROM", "HIROM"};
|
||||
|
||||
static const char *const kIdentifiers[] = {
|
||||
static const char* const kIdentifiers[] = {
|
||||
"abort", "abs", "acos", "asin", "atan", "atexit",
|
||||
"atof", "atoi", "atol", "ceil", "clock", "cosh",
|
||||
"ctime", "div", "exit", "fabs", "floor", "fmod",
|
||||
@@ -42,9 +42,10 @@ static const char *const kIdentifiers[] = {
|
||||
|
||||
TextEditor::LanguageDefinition GetAssemblyLanguageDef() {
|
||||
TextEditor::LanguageDefinition language_65816;
|
||||
for (auto &k : kKeywords) language_65816.mKeywords.emplace(k);
|
||||
for (auto& k : kKeywords)
|
||||
language_65816.mKeywords.emplace(k);
|
||||
|
||||
for (auto &k : kIdentifiers) {
|
||||
for (auto& k : kIdentifiers) {
|
||||
TextEditor::Identifier id;
|
||||
id.mDeclaration = "Built-in function";
|
||||
language_65816.mIdentifiers.insert(std::make_pair(std::string(k), id));
|
||||
@@ -175,27 +176,37 @@ FolderItem LoadFolder(const std::string& folder) {
|
||||
|
||||
void AssemblyEditor::Initialize() {
|
||||
text_editor_.SetLanguageDefinition(GetAssemblyLanguageDef());
|
||||
|
||||
|
||||
// Register cards with EditorCardManager
|
||||
if (!dependencies_.card_registry) return;
|
||||
if (!dependencies_.card_registry)
|
||||
return;
|
||||
auto* card_registry = dependencies_.card_registry;
|
||||
card_registry->RegisterCard({.card_id = "assembly.editor", .display_name = "Assembly Editor",
|
||||
.icon = ICON_MD_CODE, .category = "Assembly",
|
||||
.shortcut_hint = "", .priority = 10});
|
||||
card_registry->RegisterCard({.card_id = "assembly.file_browser", .display_name = "File Browser",
|
||||
.icon = ICON_MD_FOLDER_OPEN, .category = "Assembly",
|
||||
.shortcut_hint = "", .priority = 20});
|
||||
|
||||
// Don't show by default - only show when user explicitly opens Assembly Editor
|
||||
card_registry->RegisterCard({.card_id = "assembly.editor",
|
||||
.display_name = "Assembly Editor",
|
||||
.icon = ICON_MD_CODE,
|
||||
.category = "Assembly",
|
||||
.shortcut_hint = "",
|
||||
.priority = 10});
|
||||
card_registry->RegisterCard({.card_id = "assembly.file_browser",
|
||||
.display_name = "File Browser",
|
||||
.icon = ICON_MD_FOLDER_OPEN,
|
||||
.category = "Assembly",
|
||||
.shortcut_hint = "",
|
||||
.priority = 20});
|
||||
|
||||
// Don't show by default - only show when user explicitly opens Assembly
|
||||
// Editor
|
||||
}
|
||||
|
||||
absl::Status AssemblyEditor::Load() {
|
||||
// Register cards with EditorCardRegistry (dependency injection)
|
||||
// Note: Assembly editor uses dynamic file tabs, so we register the main editor window
|
||||
if (!dependencies_.card_registry) return absl::OkStatus();
|
||||
// Note: Assembly editor uses dynamic file tabs, so we register the main
|
||||
// editor window
|
||||
if (!dependencies_.card_registry)
|
||||
return absl::OkStatus();
|
||||
auto* card_registry = dependencies_.card_registry;
|
||||
|
||||
return absl::OkStatus();
|
||||
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
void AssemblyEditor::OpenFolder(const std::string& folder_path) {
|
||||
@@ -239,7 +250,8 @@ void AssemblyEditor::UpdateCodeView() {
|
||||
gui::VerticalSpacing(2.0f);
|
||||
|
||||
// Create session-aware card (non-static for multi-session support)
|
||||
gui::EditorCard file_browser_card(MakeCardTitle("File Browser").c_str(), ICON_MD_FOLDER);
|
||||
gui::EditorCard file_browser_card(MakeCardTitle("File Browser").c_str(),
|
||||
ICON_MD_FOLDER);
|
||||
bool file_browser_open = true;
|
||||
if (file_browser_card.Begin(&file_browser_open)) {
|
||||
if (current_folder_.name != "") {
|
||||
@@ -259,22 +271,22 @@ void AssemblyEditor::UpdateCodeView() {
|
||||
|
||||
// Ensure we have a TextEditor instance for this file
|
||||
if (file_id >= open_files_.size()) {
|
||||
open_files_.resize(file_id + 1);
|
||||
open_files_.resize(file_id + 1);
|
||||
}
|
||||
if (file_id >= files_.size()) {
|
||||
// This can happen if a file was closed and its ID is being reused.
|
||||
// For now, we just skip it.
|
||||
continue;
|
||||
// This can happen if a file was closed and its ID is being reused.
|
||||
// For now, we just skip it.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create session-aware card title for each file
|
||||
std::string card_name = MakeCardTitle(files_[file_id]);
|
||||
gui::EditorCard file_card(card_name.c_str(), ICON_MD_DESCRIPTION, &open);
|
||||
if (file_card.Begin()) {
|
||||
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows)) {
|
||||
active_file_id_ = file_id;
|
||||
}
|
||||
open_files_[file_id].Render(absl::StrCat("##", card_name).c_str());
|
||||
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows)) {
|
||||
active_file_id_ = file_id;
|
||||
}
|
||||
open_files_[file_id].Render(absl::StrCat("##", card_name).c_str());
|
||||
}
|
||||
file_card.End(); // ALWAYS call End after Begin
|
||||
|
||||
@@ -286,26 +298,26 @@ void AssemblyEditor::UpdateCodeView() {
|
||||
}
|
||||
|
||||
absl::Status AssemblyEditor::Save() {
|
||||
if (active_file_id_ != -1 && active_file_id_ < open_files_.size()) {
|
||||
std::string content = open_files_[active_file_id_].GetText();
|
||||
util::SaveFile(files_[active_file_id_], content);
|
||||
return absl::OkStatus();
|
||||
}
|
||||
return absl::FailedPreconditionError("No active file to save.");
|
||||
if (active_file_id_ != -1 && active_file_id_ < open_files_.size()) {
|
||||
std::string content = open_files_[active_file_id_].GetText();
|
||||
util::SaveFile(files_[active_file_id_], content);
|
||||
return absl::OkStatus();
|
||||
}
|
||||
return absl::FailedPreconditionError("No active file to save.");
|
||||
}
|
||||
|
||||
void AssemblyEditor::DrawToolset() {
|
||||
static gui::Toolset toolbar;
|
||||
toolbar.Begin();
|
||||
static gui::Toolset toolbar;
|
||||
toolbar.Begin();
|
||||
|
||||
if (toolbar.AddAction(ICON_MD_FOLDER_OPEN, "Open Folder")) {
|
||||
current_folder_ = LoadFolder(FileDialogWrapper::ShowOpenFolderDialog());
|
||||
}
|
||||
if (toolbar.AddAction(ICON_MD_SAVE, "Save File")) {
|
||||
Save();
|
||||
}
|
||||
if (toolbar.AddAction(ICON_MD_FOLDER_OPEN, "Open Folder")) {
|
||||
current_folder_ = LoadFolder(FileDialogWrapper::ShowOpenFolderDialog());
|
||||
}
|
||||
if (toolbar.AddAction(ICON_MD_SAVE, "Save File")) {
|
||||
Save();
|
||||
}
|
||||
|
||||
toolbar.End();
|
||||
toolbar.End();
|
||||
}
|
||||
|
||||
void AssemblyEditor::DrawCurrentFolder() {
|
||||
@@ -358,7 +370,6 @@ void AssemblyEditor::DrawCurrentFolder() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AssemblyEditor::DrawFileMenu() {
|
||||
if (ImGui::BeginMenu("File")) {
|
||||
if (ImGui::MenuItem("Open", "Ctrl+O")) {
|
||||
@@ -398,36 +409,36 @@ void AssemblyEditor::DrawEditMenu() {
|
||||
}
|
||||
}
|
||||
|
||||
void AssemblyEditor::ChangeActiveFile(const std::string_view &filename) {
|
||||
// Check if file is already open
|
||||
for (int i = 0; i < active_files_.Size; ++i) {
|
||||
int file_id = active_files_[i];
|
||||
if (files_[file_id] == filename) {
|
||||
// Optional: Focus window
|
||||
return;
|
||||
}
|
||||
void AssemblyEditor::ChangeActiveFile(const std::string_view& filename) {
|
||||
// Check if file is already open
|
||||
for (int i = 0; i < active_files_.Size; ++i) {
|
||||
int file_id = active_files_[i];
|
||||
if (files_[file_id] == filename) {
|
||||
// Optional: Focus window
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Add new file
|
||||
int new_file_id = files_.size();
|
||||
files_.push_back(std::string(filename));
|
||||
active_files_.push_back(new_file_id);
|
||||
// Add new file
|
||||
int new_file_id = files_.size();
|
||||
files_.push_back(std::string(filename));
|
||||
active_files_.push_back(new_file_id);
|
||||
|
||||
// Resize open_files_ if needed
|
||||
if (new_file_id >= open_files_.size()) {
|
||||
open_files_.resize(new_file_id + 1);
|
||||
}
|
||||
// Resize open_files_ if needed
|
||||
if (new_file_id >= open_files_.size()) {
|
||||
open_files_.resize(new_file_id + 1);
|
||||
}
|
||||
|
||||
// Load file content using utility
|
||||
std::string content = util::LoadFile(std::string(filename));
|
||||
if (!content.empty()) {
|
||||
open_files_[new_file_id].SetText(content);
|
||||
open_files_[new_file_id].SetLanguageDefinition(GetAssemblyLanguageDef());
|
||||
open_files_[new_file_id].SetPalette(TextEditor::GetDarkPalette());
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error opening file: %s\n",
|
||||
std::string(filename).c_str());
|
||||
}
|
||||
// Load file content using utility
|
||||
std::string content = util::LoadFile(std::string(filename));
|
||||
if (!content.empty()) {
|
||||
open_files_[new_file_id].SetText(content);
|
||||
open_files_[new_file_id].SetLanguageDefinition(GetAssemblyLanguageDef());
|
||||
open_files_[new_file_id].SetPalette(TextEditor::GetDarkPalette());
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error opening file: %s\n",
|
||||
std::string(filename).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
absl::Status AssemblyEditor::Cut() {
|
||||
@@ -455,6 +466,8 @@ absl::Status AssemblyEditor::Redo() {
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
absl::Status AssemblyEditor::Update() { return absl::OkStatus(); }
|
||||
absl::Status AssemblyEditor::Update() {
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
} // namespace yaze::editor
|
||||
|
||||
Reference in New Issue
Block a user