Skip to content
This repository has been archived by the owner on Dec 3, 2020. It is now read-only.

Commit

Permalink
Split save into Save and Save As
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy committed Mar 1, 2015
1 parent a7550bc commit 229649a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/FileFormat/NBE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Project *NBEFileFormat::read(const std::string &filename, Project *project)
} else {
merging = false;
project = new Project();
project->file = std::string(filename);
}
SimpleFileCombiner fc;
std::list<std::string> files = fc.read(filename.c_str(), tmpdir);
Expand Down
4 changes: 2 additions & 2 deletions src/FileFormat/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#include "../util/string.hpp"
#include "../util/filesys.hpp"

void save_file(FileFormat *writer, EditorState *state, std::string file)
void save_file(FileFormat *writer, EditorState *state, std::string file, bool check_ext)
{
if (!writer || !state)
return;

std::string after(file);

if (after.find('.') == std::string::npos) {
if (check_ext && after.find('.') == std::string::npos) {
after += '.';
after += writer->getExtension();
}
Expand Down
2 changes: 1 addition & 1 deletion src/FileFormat/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "../common.hpp"
#include "FileFormat.hpp"

void save_file(FileFormat *writer, EditorState *state, std::string file);
void save_file(FileFormat *writer, EditorState *state, std::string file, bool check_ext=true);

void export_textures(std::string dir, EditorState *state);

Expand Down
27 changes: 23 additions & 4 deletions src/MenuState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ void MenuState::init()
submenu = menubar->getSubMenu(0);
//submenu->addItem(L"New", GUI_FILE_NEW_PROJECT);
submenu->addItem(L"Open Project", GUI_FILE_OPEN_PROJECT);
submenu->addItem(L"Save Project As", GUI_FILE_SAVE_PROJECT);
submenu->addItem(L"Save Project", GUI_FILE_SAVE_PROJECT);
submenu->addItem(L"Save Project As", GUI_FILE_SAVE_PROJECT_AS);
submenu->addSeparator();
submenu->addItem(L"Run in Minetest", GUI_FILE_RUN_IN_MINETEST);
submenu->addItem(L"Export", -1, true, true);
Expand All @@ -45,7 +46,7 @@ void MenuState::init()
submenu->addItem(L"Exit", GUI_FILE_EXIT);

// File > Export
submenu = submenu->getSubMenu(4);
submenu = submenu->getSubMenu(5);
submenu->addItem(L"Standalone Lua File (.lua)", GUI_FILE_EXPORT_LUA);
submenu->addItem(L"Voxelands (.cpp)", GUI_FILE_EXPORT_CPP);
submenu->addItem(L"Minetest Mod", GUI_FILE_EXPORT_MOD);
Expand Down Expand Up @@ -98,7 +99,8 @@ void MenuState::init()
sidebar->setNotClipped(true);
}

bool MenuState::OnEvent(const SEvent& event){
bool MenuState::OnEvent(const SEvent& event)
{
if (dialog)
return dialog->OnEvent(event);

Expand Down Expand Up @@ -138,6 +140,19 @@ bool MenuState::OnEvent(const SEvent& event){
FileDialog_open_project(state);
return true;
case GUI_FILE_SAVE_PROJECT:
if (!state->project) {
state->device->getGUIEnvironment()->addMessageBox(
L"Unable to save",
L"You have not yet opened a project.");
return true;
}
if (state->project->file != "") {
save_file(getFromType(FILE_FORMAT_NBE, state), state, state->project->file, false);
} else {
FileDialog_save_project(state);
}
return true;
case GUI_FILE_SAVE_PROJECT_AS:
if (!state->project) {
state->device->getGUIEnvironment()->addMessageBox(
L"Unable to save",
Expand Down Expand Up @@ -243,7 +258,11 @@ bool MenuState::OnEvent(const SEvent& event){
L"You have not yet opened a project.");
return true;
}
FileDialog_save_project(state);
if (state->project->file != "") {
save_file(getFromType(FILE_FORMAT_NBE, state), state, state->project->file, false);
} else {
FileDialog_save_project(state);
}
return true;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/MenuState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ enum GUI_ID
GUI_FILE_NEW_ITEM,
GUI_FILE_OPEN_PROJECT,
GUI_FILE_SAVE_PROJECT,
GUI_FILE_SAVE_PROJECT_AS,
GUI_FILE_RUN_IN_MINETEST,
GUI_FILE_EXPORT_LUA,
GUI_FILE_EXPORT_CPP,
Expand Down

0 comments on commit 229649a

Please sign in to comment.