Step 107a: add text mode toggle
This commit is contained in:
@@ -11,20 +11,27 @@
|
||||
|
||||
class BufferManager {
|
||||
public:
|
||||
enum class BufferMode {
|
||||
Structured,
|
||||
Text
|
||||
};
|
||||
|
||||
struct BufferInfo {
|
||||
std::string path;
|
||||
std::string content;
|
||||
std::string language;
|
||||
bool modified = false;
|
||||
BufferMode mode = BufferMode::Structured;
|
||||
};
|
||||
|
||||
BufferManager() = default;
|
||||
|
||||
// Open a file into a buffer (makes it active)
|
||||
bool openBuffer(const std::string& path, const std::string& content,
|
||||
const std::string& language) {
|
||||
const std::string& language,
|
||||
BufferMode mode = BufferMode::Structured) {
|
||||
if (hasBuffer(path)) return false; // already open
|
||||
BufferInfo info{path, content, language, false};
|
||||
BufferInfo info{path, content, language, false, mode};
|
||||
buffers_[path] = info;
|
||||
activeBuffer_ = path;
|
||||
return true;
|
||||
@@ -70,6 +77,19 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void setBufferMode(const std::string& path, BufferMode mode) {
|
||||
auto it = buffers_.find(path);
|
||||
if (it != buffers_.end()) {
|
||||
it->second.mode = mode;
|
||||
}
|
||||
}
|
||||
|
||||
BufferMode getBufferMode(const std::string& path) const {
|
||||
auto it = buffers_.find(path);
|
||||
if (it != buffers_.end()) return it->second.mode;
|
||||
return BufferMode::Structured;
|
||||
}
|
||||
|
||||
// Get list of all open buffer paths
|
||||
std::vector<std::string> getOpenBuffers() const {
|
||||
std::vector<std::string> result;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "TextASTSync.h"
|
||||
#include "SyntaxHighlighter.h"
|
||||
#include "KeybindingManager.h"
|
||||
#include "BufferManager.h"
|
||||
#include "CodeEditorWidget.h"
|
||||
#include "EditorMode.h"
|
||||
#include "FileDialog.h"
|
||||
@@ -70,6 +71,7 @@ struct BufferState {
|
||||
std::string generatedLanguage = "python";
|
||||
std::string path = "(untitled)";
|
||||
bool readOnly = false;
|
||||
BufferManager::BufferMode mode = BufferManager::BufferMode::Structured;
|
||||
bool modified = false;
|
||||
int cursorLine = 1;
|
||||
int cursorCol = 1;
|
||||
@@ -251,7 +253,8 @@ struct EditorState {
|
||||
state->generatedHighlightsDirty = true;
|
||||
state->modified = false;
|
||||
state->lspVersion = 1;
|
||||
buffers.openBuffer(path, content, language);
|
||||
buffers.openBuffer(path, content, language, BufferManager::BufferMode::Structured);
|
||||
state->mode = BufferManager::BufferMode::Structured;
|
||||
activeBuffer = state.get();
|
||||
bufferStates[path] = std::move(state);
|
||||
if (path.rfind("(untitled", 0) != 0) watcher.watch(path);
|
||||
@@ -1328,6 +1331,15 @@ int main(int, char**) {
|
||||
ImGui::MenuItem("Show Minimap", nullptr, &state.showMinimap);
|
||||
ImGui::MenuItem("Show Annotations", nullptr, &state.showAnnotations);
|
||||
ImGui::MenuItem("LSP Servers...", nullptr, &state.showLspSettings);
|
||||
if (state.active()) {
|
||||
bool textMode = state.active()->mode == BufferManager::BufferMode::Text;
|
||||
if (ImGui::MenuItem("Text-Editor Mode", nullptr, textMode)) {
|
||||
state.active()->mode = textMode ?
|
||||
BufferManager::BufferMode::Structured :
|
||||
BufferManager::BufferMode::Text;
|
||||
state.buffers.setBufferMode(state.active()->path, state.active()->mode);
|
||||
}
|
||||
}
|
||||
if (ImGui::BeginMenu("Layout")) {
|
||||
if (ImGui::MenuItem("VSCode", nullptr, state.layoutPreset == LayoutPreset::VSCode))
|
||||
state.layoutPreset = LayoutPreset::VSCode;
|
||||
@@ -2575,6 +2587,16 @@ int main(int, char**) {
|
||||
ImGui::Text("-");
|
||||
ImGui::SameLine(0, 30);
|
||||
|
||||
// Mode
|
||||
if (state.active()) {
|
||||
const char* modeLabel =
|
||||
state.active()->mode == BufferManager::BufferMode::Text ? "Text" : "Structured";
|
||||
ImGui::Text("Mode: %s", modeLabel);
|
||||
} else {
|
||||
ImGui::Text("Mode: -");
|
||||
}
|
||||
ImGui::SameLine(0, 30);
|
||||
|
||||
// Keybinding profile
|
||||
ImGui::Text("Keys: %s", KeybindingManager::profileName(state.keys.getProfile()));
|
||||
ImGui::SameLine(0, 30);
|
||||
|
||||
Reference in New Issue
Block a user