Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5231: Move MRU implementation to core and extract IMRUManager interf…
…ace, leave MRU menu handling in the UI binary. Move some Selection classes to libs/ folder. More refactoring in Map class.
- Loading branch information
1 parent
0d0c1fe
commit 2a3e4d5
Showing
30 changed files
with
473 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#pragma once | ||
|
||
#include "imodule.h" | ||
#include <sigc++/signal.h> | ||
|
||
namespace map | ||
{ | ||
|
||
const char* const LOAD_MRU_MAP_CMD = "LoadMRUMap"; | ||
const char* const LOAD_MRU_STATEMENT_FORMAT = "MRUOpen{0:d}"; | ||
|
||
class IMRUManager : | ||
public RegisterableModule | ||
{ | ||
public: | ||
virtual ~IMRUManager() {} | ||
|
||
typedef std::function<void(std::size_t index, const std::string & fileName)> ItemFunctor; | ||
|
||
virtual std::size_t getMaxNumberOfItems() const = 0; | ||
|
||
// Visits each item, ordered by the 0-based index | ||
virtual void foreachItem(const ItemFunctor& functor) = 0; | ||
|
||
// Inserts the given map filename at the top of the list | ||
// Duplicates are relocated, the number of list items is constrained | ||
virtual void insert(const std::string& fileName) = 0; | ||
|
||
// Returns the filename of the last opened map, or "" if there doesn't exist one | ||
virtual std::string getLastMapName() = 0; | ||
|
||
virtual sigc::signal<void>& signal_MapListChanged() = 0; | ||
}; | ||
|
||
} | ||
|
||
const char* const MODULE_MRU_MANAGER = "MRUManager"; | ||
|
||
inline map::IMRUManager& GlobalMRU() | ||
{ | ||
// Cache the reference locally | ||
static map::IMRUManager& _manager( | ||
*std::static_pointer_cast<map::IMRUManager>( | ||
module::GlobalModuleRegistry().getModule(MODULE_MRU_MANAGER) | ||
) | ||
); | ||
return _manager; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "MapCommands.h" | ||
|
||
#include "prefabselector/PrefabSelector.h" | ||
|
||
namespace ui | ||
{ | ||
|
||
void loadPrefabDialog(const cmd::ArgumentList& args) | ||
{ | ||
auto result = PrefabSelector::ChoosePrefab(); | ||
|
||
if (!result.prefabPath.empty()) | ||
{ | ||
GlobalCommandSystem().executeCommand(LOAD_PREFAB_AT_CMD, Vector3(0, 0, 0)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
|
||
#include "icommandsystem.h" | ||
|
||
namespace ui | ||
{ | ||
|
||
void loadPrefabDialog(const cmd::ArgumentList& args); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#pragma once | ||
|
||
#include "imru.h" | ||
#include "iuimanager.h" | ||
|
||
#include <list> | ||
#include <sigc++/connection.h> | ||
#include <sigc++/functors/mem_fun.h> | ||
#include <fmt/format.h> | ||
#include "string/convert.h" | ||
|
||
namespace ui | ||
{ | ||
|
||
namespace | ||
{ | ||
const char* const RECENT_FILES_CAPTION = N_("Recently used Maps"); | ||
} | ||
|
||
class MRUMenu | ||
{ | ||
private: | ||
sigc::connection _mruUpdateConn; | ||
|
||
public: | ||
MRUMenu() | ||
{ | ||
_mruUpdateConn = GlobalMRU().signal_MapListChanged().connect( | ||
sigc::mem_fun(*this, &MRUMenu::onMRUListChanged) | ||
); | ||
|
||
constructMenu(); | ||
} | ||
|
||
~MRUMenu() | ||
{ | ||
clearMenu(); | ||
|
||
_mruUpdateConn.disconnect(); | ||
} | ||
|
||
private: | ||
void clearMenu() | ||
{ | ||
IMenuManager& menuManager = GlobalUIManager().getMenuManager(); | ||
|
||
// Remove all items from the menu | ||
for (std::size_t i = GlobalMRU().getMaxNumberOfItems(); i > 0; i--) | ||
{ | ||
menuManager.remove("main/file/MRU" + string::to_string(i)); | ||
} | ||
|
||
menuManager.remove("main/file/mruempty"); | ||
} | ||
|
||
void updateMenu() | ||
{ | ||
clearMenu(); | ||
|
||
std::vector<std::string> filenames(GlobalMRU().getMaxNumberOfItems()); | ||
|
||
GlobalMRU().foreachItem([&](std::size_t index, const std::string& filename) | ||
{ | ||
filenames.emplace_back(filename); | ||
}); | ||
|
||
// Get the menumanager | ||
IMenuManager& menuManager = GlobalUIManager().getMenuManager(); | ||
|
||
if (filenames.empty()) | ||
{ | ||
// Create the "empty" MRU menu item (the desensitised one) | ||
menuManager.insert( | ||
"main/file/mruseparator", | ||
"mruempty", | ||
ui::menuItem, | ||
RECENT_FILES_CAPTION, | ||
"", // empty icon | ||
"" // empty event | ||
); | ||
|
||
return; | ||
} | ||
|
||
// Add one item for each filename in the MRU list | ||
for (std::size_t index = 0; index < filenames.size(); ++index) | ||
{ | ||
// The default string to be loaded into the widget (i.e. "inactive") | ||
std::string filename = filenames[index]; | ||
|
||
std::string label = string::to_string(index + 1) + " - " + filename; | ||
|
||
auto statement = fmt::format(map::LOAD_MRU_STATEMENT_FORMAT, index + 1); | ||
|
||
// Create the menu item | ||
menuManager.insert( | ||
"main/file/mruseparator", | ||
"MRU" + string::to_string(index + 1), | ||
ui::menuItem, | ||
label, | ||
"", // empty icon | ||
statement | ||
); | ||
} | ||
} | ||
|
||
void constructMenu() | ||
{ | ||
// Insert the last separator to split the MRU file list from the "Exit" command. | ||
GlobalUIManager().getMenuManager().insert( | ||
"main/file/exit", | ||
"mruseparator", | ||
ui::menuSeparator, | ||
"", // empty caption | ||
"", // empty icon | ||
"" // empty command | ||
); | ||
|
||
// Call the update routine to load the values into the widgets | ||
updateMenu(); | ||
} | ||
|
||
void onMRUListChanged() | ||
{ | ||
updateMenu(); | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.