Skip to content

Commit af855a0

Browse files
committed
Add "New" button to clear workspace and start a new document
1 parent ba10d96 commit af855a0

File tree

4 files changed

+51
-14
lines changed

4 files changed

+51
-14
lines changed

Editor/EditorApp.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ namespace RTEGUI {
158158
std::string controlName = editorEvent.GetControl()->GetName();
159159
switch (editorEvent.GetType()) {
160160
case GUIEvent::Command:
161-
if (controlName == "QuitButton") {
162-
OnQuitButton();
161+
if (controlName == "NewButton") {
162+
OnNewButton();
163163
} else if (controlName == "LoadButton") {
164164
OnLoadButton();
165165
} else if (controlName == "AddButton") {
@@ -168,6 +168,8 @@ namespace RTEGUI {
168168
OnSaveButton();
169169
} else if (controlName == "SaveAsButton") {
170170
OnSaveButton(true);
171+
} else if (controlName == "QuitButton") {
172+
OnQuitButton();
171173
} else if (controlName.substr(0, 2).compare("C_") == 0) {
172174
m_UnsavedChanges = m_EditorManager->AddNewControl(editorEvent);
173175
}
@@ -222,6 +224,24 @@ namespace RTEGUI {
222224
blit(m_BackBuffer, screen, 0, 0, 0, 0, screen->w, screen->h);
223225
}
224226

227+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
228+
229+
void EditorApp::OnNewButton() {
230+
if (m_UnsavedChanges) {
231+
int result = EditorUtil::DisplayDialogBox("Save changes made?", win_get_window());
232+
if (result == 0) {
233+
return;
234+
} else if (result == 1) {
235+
OnSaveButton();
236+
}
237+
}
238+
m_ActiveFileName.clear();
239+
m_EditorManager->GetWorkspaceManager()->Clear();
240+
m_EditorManager->CreateRootControl();
241+
m_EditorManager->UpdateCollectionBoxList();
242+
m_EditorManager->UpdateCollectionBoxChildrenList(dynamic_cast<GUICollectionBox *>(m_EditorManager->GetRootControl()));
243+
}
244+
225245
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
226246

227247
void EditorApp::OnLoadButton(bool addControls) {

Editor/EditorApp.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,24 @@ namespace RTEGUI {
7070

7171
#pragma region File Panel Button Handling
7272
/// <summary>
73-
/// Called when the load button has been pushed.
73+
/// Called when the "New" button has been pressed.
74+
/// </summary>
75+
void OnNewButton();
76+
77+
/// <summary>
78+
/// Called when the "Load" or "Add File" button has been pressed.
7479
/// </summary>
7580
/// <param name="addControls">Whether to add controls as opposed to wiping out the current layout.</param>
7681
void OnLoadButton(bool addControls = false);
7782

7883
/// <summary>
79-
/// Called when the save button has been pushed.
84+
/// Called when the "Save" or "Save As" button has been pressed.
8085
/// </summary>
8186
/// <param name="saveAsNewFile">Whether to save to a new file or not.</param>
8287
void OnSaveButton(bool saveAsNewFile = false);
8388

8489
/// <summary>
85-
/// Called when the quit button has been pushed.
90+
/// Called when the "Quit" button has been pressed.
8691
/// </summary>
8792
void OnQuitButton();
8893
#pragma endregion

Editor/EditorManager.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,17 @@ namespace RTEGUI {
3636
GUICollectionBox *filePanel = dynamic_cast<GUICollectionBox *>(m_EditorControlManager->AddControl("FilePanel", "COLLECTIONBOX", m_LeftColumn.get(), 5, 5, 270, 55));
3737
filePanel->SetDrawType(GUICollectionBox::Panel);
3838

39-
GUIButton *toolboxButton = dynamic_cast<GUIButton *>(m_EditorControlManager->AddControl("LoadButton", "BUTTON", filePanel, 10, 5, 80, 20));
39+
GUIButton *toolboxButton = dynamic_cast<GUIButton *>(m_EditorControlManager->AddControl("NewButton", "BUTTON", filePanel, 6, 5, 61, 20));
40+
toolboxButton->SetText("New");
41+
toolboxButton = dynamic_cast<GUIButton *>(m_EditorControlManager->AddControl("LoadButton", "BUTTON", filePanel, 71, 5, 62, 20));
4042
toolboxButton->SetText("Load");
41-
toolboxButton = dynamic_cast<GUIButton *>(m_EditorControlManager->AddControl("AddButton", "BUTTON", filePanel, 10, 30, 80, 20));
43+
toolboxButton = dynamic_cast<GUIButton *>(m_EditorControlManager->AddControl("AddButton", "BUTTON", filePanel, 71, 30, 62, 20));
4244
toolboxButton->SetText("Add File");
43-
toolboxButton = dynamic_cast<GUIButton *>(m_EditorControlManager->AddControl("SaveButton", "BUTTON", filePanel, 95, 5, 80, 20));
45+
toolboxButton = dynamic_cast<GUIButton *>(m_EditorControlManager->AddControl("SaveButton", "BUTTON", filePanel, 137, 5, 62, 20));
4446
toolboxButton->SetText("Save");
45-
toolboxButton = dynamic_cast<GUIButton *>(m_EditorControlManager->AddControl("SaveAsButton", "BUTTON", filePanel, 95, 30, 80, 20));
47+
toolboxButton = dynamic_cast<GUIButton *>(m_EditorControlManager->AddControl("SaveAsButton", "BUTTON", filePanel, 137, 30, 62, 20));
4648
toolboxButton->SetText("Save As");
47-
toolboxButton = dynamic_cast<GUIButton *>(m_EditorControlManager->AddControl("QuitButton", "BUTTON", filePanel, 180, 5, 80, 20));
49+
toolboxButton = dynamic_cast<GUIButton *>(m_EditorControlManager->AddControl("QuitButton", "BUTTON", filePanel, 203, 5, 61, 20));
4850
toolboxButton->SetText("Quit");
4951

5052
GUICollectionBox *editorControls = dynamic_cast<GUICollectionBox *>(m_EditorControlManager->AddControl("EditorControlsPanel", "COLLECTIONBOX", m_LeftColumn.get(), filePanel->GetRelXPos(), filePanel->GetRelYPos() + 65, 270, 155));
@@ -109,10 +111,15 @@ namespace RTEGUI {
109111
workspace->SetDrawColor(makecol(64, 64, 64));
110112
workspace->SetDrawType(GUICollectionBox::Color);
111113

112-
// Create the root CollectionBox for the edited document and add it to the CollectionBox list
113-
GUICollectionBox *rootBox = dynamic_cast<GUICollectionBox *>(m_WorkspaceManager->AddControl("root", "COLLECTIONBOX", nullptr, m_WorkspacePosX, m_WorkspacePosY, m_WorkspaceWidth, m_WorkspaceHeight));
114-
rootBox->SetDrawBackground(false);
115-
m_RootControl = rootBox;
114+
CreateRootControl();
115+
}
116+
117+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
118+
119+
void EditorManager::CreateRootControl() {
120+
GUICollectionBox *rootCollectionBox = dynamic_cast<GUICollectionBox *>(m_WorkspaceManager->AddControl("root", "COLLECTIONBOX", nullptr, m_WorkspacePosX, m_WorkspacePosY, m_WorkspaceWidth, m_WorkspaceHeight));
121+
rootCollectionBox->SetDrawBackground(false);
122+
m_RootControl = rootCollectionBox;
116123
m_CollectionBoxList->AddItem(m_RootControl->GetName());
117124
}
118125

Editor/EditorManager.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ namespace RTEGUI {
3636
/// <param name="skinDir">The directory containing the skin file to load.</param>
3737
/// <param name="skinFilename">The file name of the skin file to load.</param>
3838
void Initialize(GUIScreen *screen, GUIInput *input, const std::string &skinDir, const std::string &skinFilename);
39+
40+
/// <summary>
41+
/// Creates the root CollectionBox for the edited document and adds it to the CollectionBox list.
42+
/// </summary>
43+
void CreateRootControl();
3944
#pragma endregion
4045

4146
#pragma region Getters and Setters

0 commit comments

Comments
 (0)