Skip to content

Commit 748f406

Browse files
committed
feat: hide tab bar when only one tab, wire up File menu Save/Save As/Save All
1 parent 75d0bc8 commit 748f406

2 files changed

Lines changed: 79 additions & 25 deletions

File tree

TESTS.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# pcode-editor Test Suite
2+
3+
## Test 1: Build Test
4+
```bash
5+
cd build
6+
cmake --build . --config Release
7+
```
8+
**Expected**: Build completes without errors
9+
10+
## Test 2: Menu Functionality
11+
1. Run the app: `build/Release/pcode-editor.exe`
12+
2. Click on "File" menu in menu bar
13+
3. Click on "Edit" menu
14+
4. Click on "View" menu
15+
**Expected**: Menus should open and show menu items
16+
17+
## Test 3: Features Test
18+
After confirming menus work, test these features:
19+
20+
| Feature | Test Steps | Expected |
21+
|---------|------------|----------|
22+
| Line Numbers | View menu → toggle Line Numbers | Line numbers show/hide |
23+
| Whitespace | View menu → toggle Whitespace | Space dots show/hide |
24+
| Code Folding | View menu → toggle Code Folding | Toggle enabled |
25+
| Bookmarks | View menu → toggle Bookmarks | Toggle visible |
26+
| Change Markers | View menu → toggle Change Markers | Toggle visible |
27+
| Theme | View menu → toggle Dark/Light Theme | Colors change |
28+
| Zoom | Ctrl++ / Ctrl+- / Ctrl+0 | Font size changes |
29+
| Code Folding Hotkey | Ctrl+Shift+O on line with `{` | Line folds |
30+
| Unfold Hotkey | Ctrl+Shift+[ | Line unfolds |
31+
32+
## Test 4: File Operations
33+
1. File → Open → select a .cpp file
34+
2. File → Save (Ctrl+S)
35+
3. File → Save As → different name
36+
4. Close tab with X button
37+
38+
## Test 5: Editor Operations
39+
1. Type some text
40+
2. Ctrl+F to find
41+
3. Ctrl+H to replace
42+
4. Ctrl+G to go to line

src/editor_app.cpp

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -899,10 +899,14 @@ void EditorApp::render_menu_file() {
899899
open_file(settings_.recent_files[i]);
900900
}
901901
}
902-
ImGui::EndMenu();
902+
ImGui::EndMenu();
903903
}
904904
}
905905

906+
ImGui::Separator();
907+
if (ImGui::MenuItem("Save", "Ctrl+S")) save_tab(active_tab_);
908+
if (ImGui::MenuItem("Save As...", "Ctrl+Shift+S")) save_tab_as(active_tab_);
909+
if (ImGui::MenuItem("Save All", "Ctrl+Alt+S")) save_all();
906910
ImGui::Separator();
907911
// Page Setup — placeholder (requires native print dialog)
908912
if (ImGui::MenuItem("Page Setup...")) { /* TODO: native dialog */ }
@@ -1012,32 +1016,40 @@ void EditorApp::render_editor_area() {
10121016
new_tab();
10131017
}
10141018

1015-
// Tab bar
1016-
ImGuiTabBarFlags tab_flags = ImGuiTabBarFlags_Reorderable | ImGuiTabBarFlags_AutoSelectNewTabs;
1017-
if (ImGui::BeginTabBar("##Tabs", tab_flags)) {
1018-
for (int i = 0; i < (int)tabs_.size(); i++) {
1019-
auto& tab = tabs_[i];
1020-
std::string label = tab.display_name;
1021-
if (tab.dirty) label += " *";
1022-
1023-
ImGuiTabItemFlags tab_item_flags = 0;
1024-
if (i == active_tab_) tab_item_flags |= ImGuiTabItemFlags_SetSelected;
1025-
1026-
bool open = true;
1027-
if (ImGui::BeginTabItem(label.c_str(), &open, tab_item_flags)) {
1028-
active_tab_ = i;
1029-
1030-
// Render gutter with bookmarks and change history
1031-
render_editor_with_margins();
1032-
1033-
ImGui::EndTabItem();
1034-
}
1035-
if (!open) {
1036-
close_tab(i);
1037-
break;
1019+
// Tab bar - only show if more than one tab
1020+
bool show_tabs = tabs_.size() > 1;
1021+
if (show_tabs) {
1022+
ImGuiTabBarFlags tab_flags = ImGuiTabBarFlags_Reorderable | ImGuiTabBarFlags_AutoSelectNewTabs;
1023+
if (ImGui::BeginTabBar("##Tabs", tab_flags)) {
1024+
for (int i = 0; i < (int)tabs_.size(); i++) {
1025+
auto& tab = tabs_[i];
1026+
std::string label = tab.display_name;
1027+
if (tab.dirty) label += " *";
1028+
1029+
ImGuiTabItemFlags tab_item_flags = 0;
1030+
if (i == active_tab_) tab_item_flags |= ImGuiTabItemFlags_SetSelected;
1031+
1032+
bool open = true;
1033+
if (ImGui::BeginTabItem(label.c_str(), &open, tab_item_flags)) {
1034+
active_tab_ = i;
1035+
1036+
// Render gutter with bookmarks and change history
1037+
render_editor_with_margins();
1038+
1039+
ImGui::EndTabItem();
1040+
}
1041+
if (!open) {
1042+
close_tab(i);
1043+
break;
1044+
}
10381045
}
1046+
ImGui::EndTabBar();
1047+
}
1048+
} else {
1049+
// Single tab - just render the editor directly
1050+
if (active_tab_ >= 0 && active_tab_ < (int)tabs_.size()) {
1051+
render_editor_with_margins();
10391052
}
1040-
ImGui::EndTabBar();
10411053
}
10421054

10431055
ImGui::End();

0 commit comments

Comments
 (0)