Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new UserInterfaceModule and migrate Layer context menu init code
UI module should take care of initialising the UI classes, in an effort to disentangle the UI code from the underlying model code.
- Loading branch information
1 parent
b62e6d0
commit 3b53afc
Showing
6 changed files
with
124 additions
and
35 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
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,83 @@ | ||
#include "UserInterfaceModule.h" | ||
|
||
#include "i18n.h" | ||
#include "ilayer.h" | ||
#include "iorthocontextmenu.h" | ||
|
||
#include "wxutil/menu/CommandMenuItem.h" | ||
|
||
#include "modulesystem/StaticModule.h" | ||
|
||
#include "ui/layers/LayerOrthoContextMenuItem.h" | ||
|
||
namespace ui | ||
{ | ||
|
||
namespace | ||
{ | ||
const char* const LAYER_ICON = "layers.png"; | ||
const char* const CREATE_LAYER_TEXT = N_("Create Layer..."); | ||
|
||
const char* const ADD_TO_LAYER_TEXT = N_("Add to Layer..."); | ||
const char* const MOVE_TO_LAYER_TEXT = N_("Move to Layer..."); | ||
const char* const REMOVE_FROM_LAYER_TEXT = N_("Remove from Layer..."); | ||
} | ||
|
||
const std::string& UserInterfaceModule::getName() const | ||
{ | ||
static std::string _name("UserInterfaceModule"); | ||
return _name; | ||
} | ||
|
||
const StringSet& UserInterfaceModule::getDependencies() const | ||
{ | ||
static StringSet _dependencies; | ||
|
||
if (_dependencies.empty()) | ||
{ | ||
_dependencies.insert(MODULE_LAYERSYSTEM); | ||
_dependencies.insert(MODULE_ORTHOCONTEXTMENU); | ||
_dependencies.insert(MODULE_UIMANAGER); | ||
} | ||
|
||
return _dependencies; | ||
} | ||
|
||
void UserInterfaceModule::initialiseModule(const ApplicationContext& ctx) | ||
{ | ||
rMessage() << getName() << "::initialiseModule called." << std::endl; | ||
|
||
// Create a new menu item connected to the CreateNewLayer command | ||
_layerMenuItems.push_back( | ||
std::make_shared<wxutil::CommandMenuItem>( | ||
new wxutil::IconTextMenuItem(_(CREATE_LAYER_TEXT), LAYER_ICON), "CreateNewLayer")); | ||
|
||
// Add the orthocontext menu's layer actions | ||
_layerMenuItems.push_back( | ||
std::make_shared<LayerOrthoContextMenuItem>(_(ADD_TO_LAYER_TEXT), LayerOrthoContextMenuItem::AddToLayer)); | ||
|
||
_layerMenuItems.push_back( | ||
std::make_shared<LayerOrthoContextMenuItem>(_(MOVE_TO_LAYER_TEXT), LayerOrthoContextMenuItem::MoveToLayer)); | ||
|
||
_layerMenuItems.push_back( | ||
std::make_shared<LayerOrthoContextMenuItem>(_(REMOVE_FROM_LAYER_TEXT), LayerOrthoContextMenuItem::RemoveFromLayer)); | ||
|
||
for (const IMenuItemPtr& item : _layerMenuItems) | ||
{ | ||
GlobalOrthoContextMenu().addItem(item, IOrthoContextMenu::SECTION_LAYER); | ||
} | ||
} | ||
|
||
void UserInterfaceModule::shutdownModule() | ||
{ | ||
// Remove layer items again | ||
for (const IMenuItemPtr& item : _layerMenuItems) | ||
{ | ||
GlobalOrthoContextMenu().removeItem(item); | ||
} | ||
} | ||
|
||
// Static module registration | ||
module::StaticModule<UserInterfaceModule> userInterfaceModule; | ||
|
||
} |
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,30 @@ | ||
#pragma once | ||
|
||
#include "imodule.h" | ||
#include "iorthocontextmenu.h" | ||
|
||
namespace ui | ||
{ | ||
|
||
/** | ||
* Module responsible of registering and intialising the various | ||
* UI classes in DarkRadiant, e.g. the LayerSystem. | ||
* | ||
* Currently many UI classes are spread and initialised all across | ||
* the main binary, so there's still work left to do. | ||
*/ | ||
class UserInterfaceModule : | ||
public RegisterableModule | ||
{ | ||
private: | ||
std::vector<IMenuItemPtr> _layerMenuItems; | ||
|
||
public: | ||
// RegisterableModule | ||
const std::string & getName() const override; | ||
const StringSet & getDependencies() const override; | ||
void initialiseModule(const ApplicationContext & ctx) override; | ||
void shutdownModule() override; | ||
}; | ||
|
||
} |
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