Skip to content

Commit

Permalink
#5231: Grid module no longer depends on UI modules, this is handled b…
Browse files Browse the repository at this point in the history
…y the GridUserInterface module now.

The Toggle created by the GridUI module needs to be named the same as the bound statement, at least for the moment being.
  • Loading branch information
codereader committed May 4, 2020
1 parent ab44d76 commit d48cdda
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 59 deletions.
4 changes: 3 additions & 1 deletion include/igrid.h
Expand Up @@ -4,7 +4,7 @@
*
* Use these methods to set/get the grid size of the xyviews
*/

#include <stdexcept>
#include "imodule.h"
#include <sigc++/signal.h>

Expand Down Expand Up @@ -43,6 +43,8 @@ inline const char* getStringForSize(GridSize size)
case GRID_64: return "64";
case GRID_128: return "128";
case GRID_256: return "256";
default:
throw new std::logic_error("Grid size not handled in switch!");
};
}

Expand Down
13 changes: 13 additions & 0 deletions install/commandsystem.xml
Expand Up @@ -83,5 +83,18 @@
<bind name="HideLayer7" value="HideLayer 7" readonly="1" />
<bind name="HideLayer8" value="HideLayer 8" readonly="1" />
<bind name="HideLayer9" value="HideLayer 9" readonly="1" />
<!-- Grid Size Shortcuts -->
<bind name="SetGrid0.125" value="SetGrid -3" readonly="1" />
<bind name="SetGrid0.25" value="SetGrid -2" readonly="1" />
<bind name="SetGrid0.5" value="SetGrid -1" readonly="1" />
<bind name="SetGrid1" value="SetGrid 0" readonly="1" />
<bind name="SetGrid2" value="SetGrid 1" readonly="1" />
<bind name="SetGrid4" value="SetGrid 2" readonly="1" />
<bind name="SetGrid8" value="SetGrid 3" readonly="1" />
<bind name="SetGrid16" value="SetGrid 4" readonly="1" />
<bind name="SetGrid32" value="SetGrid 5" readonly="1" />
<bind name="SetGrid64" value="SetGrid 6" readonly="1" />
<bind name="SetGrid128" value="SetGrid 7" readonly="1" />
<bind name="SetGrid256" value="SetGrid 8" readonly="1" />
</binds>
</commandsystem>
24 changes: 12 additions & 12 deletions install/menu.xml
Expand Up @@ -181,18 +181,18 @@
<subMenu name="grid" caption="&amp;Grid">
<menuItem name="snapToGrid" caption="Snap selected to grid" command="SnapToGrid" />
<menuSeparator />
<menuItem name="grid0.125" caption="Grid0.125" command="ToggleGrid0.125" />
<menuItem name="grid0.25" caption="Grid0.25" command="ToggleGrid0.25" />
<menuItem name="grid0.5" caption="Grid0.5" command="ToggleGrid0.5" />
<menuItem name="grid1" caption="Grid1" command="ToggleGrid1" />
<menuItem name="grid2" caption="Grid2" command="ToggleGrid2" />
<menuItem name="grid4" caption="Grid4" command="ToggleGrid4" />
<menuItem name="grid8" caption="Grid8" command="ToggleGrid8" />
<menuItem name="grid16" caption="Grid16" command="ToggleGrid16" />
<menuItem name="grid32" caption="Grid32" command="ToggleGrid32" />
<menuItem name="grid64" caption="Grid64" command="ToggleGrid64" />
<menuItem name="grid128" caption="Grid128" command="ToggleGrid128" />
<menuItem name="grid256" caption="Grid256" command="ToggleGrid256" />
<menuItem name="grid0.125" caption="Grid0.125" command="SetGrid0.125" />
<menuItem name="grid0.25" caption="Grid0.25" command="SetGrid0.25" />
<menuItem name="grid0.5" caption="Grid0.5" command="SetGrid0.5" />
<menuItem name="grid1" caption="Grid1" command="SetGrid1" />
<menuItem name="grid2" caption="Grid2" command="SetGrid2" />
<menuItem name="grid4" caption="Grid4" command="SetGrid4" />
<menuItem name="grid8" caption="Grid8" command="SetGrid8" />
<menuItem name="grid16" caption="Grid16" command="SetGrid16" />
<menuItem name="grid32" caption="Grid32" command="SetGrid32" />
<menuItem name="grid64" caption="Grid64" command="SetGrid64" />
<menuItem name="grid128" caption="Grid128" command="SetGrid128" />
<menuItem name="grid256" caption="Grid256" command="SetGrid256" />
</subMenu>

<subMenu name="map" caption="M&amp;ap">
Expand Down
46 changes: 2 additions & 44 deletions radiant/ui/grid/GridManager.cpp
Expand Up @@ -6,9 +6,6 @@
#include "debugging/debugging.h"
#include "imodule.h"
#include "icommandsystem.h"
#include "imainframe.h"
#include "ieventmanager.h"
#include "iuimanager.h"
#include "ipreferencesystem.h"
#include "string/string.h"

Expand Down Expand Up @@ -47,11 +44,8 @@ const StringSet& GridManager::getDependencies() const
if (_dependencies.empty())
{
_dependencies.insert(MODULE_XMLREGISTRY);
_dependencies.insert(MODULE_EVENTMANAGER);
_dependencies.insert(MODULE_COMMANDSYSTEM);
_dependencies.insert(MODULE_PREFERENCESYSTEM);
_dependencies.insert(MODULE_UIMANAGER);
_dependencies.insert(MODULE_MAINFRAME);
}

return _dependencies;
Expand Down Expand Up @@ -114,21 +108,8 @@ void GridManager::registerCommands()
std::bind(&GridManager::setGridCmd, this, std::placeholders::_1),
{ cmd::ARGTYPE_STRING });

// Grid size shortcuts are defined in commandsystem.xml like "SetGrid4" => "SetGrid 16"
// Create shortcut statements that can accept accelerator bindings
for (NamedGridItem& i : _gridItems)
{
std::string statement = "SetGrid " + i.first; // e.g. "SetGrid 64"
std::string name = "SetGrid" + i.first; // Makes "SetGrid" to "SetGrid64", for example

GlobalCommandSystem().addStatement(name, statement);
#if 0
GridItem& gridItem = i.second;

GlobalEventManager().addToggle(toggleName,
std::bind(&GridItem::activate, &gridItem, std::placeholders::_1));

#endif
}

GlobalCommandSystem().addCommand("GridDown", std::bind(&GridManager::gridDownCmd, this, std::placeholders::_1));
GlobalCommandSystem().addCommand("GridUp", std::bind(&GridManager::gridUpCmd, this, std::placeholders::_1));
Expand Down Expand Up @@ -244,7 +225,7 @@ void GridManager::setGridSize(GridSize gridSize)
{
_activeGridSize = gridSize;

gridChanged();
gridChangeNotify();
}

float GridManager::getGridSize() const
Expand All @@ -257,29 +238,6 @@ int GridManager::getGridPower() const
return static_cast<int>(_activeGridSize);
}

void GridManager::gridChanged()
{
#if 0
for (const NamedGridItem& i : _gridItems)
{
std::string toggleName = "SetGrid";
toggleName += i.first; // Makes "SetGrid" to "SetGrid64", for example
const GridItem& gridItem = i.second;

GlobalEventManager().setToggled(toggleName, _activeGridSize == gridItem.getGridSize());
}
#endif

#if 0
GlobalUIManager().getStatusBarManager().setText("GridStatus", fmt::format("{0:g}", getGridSize()));
#endif
gridChangeNotify();

#if 0
GlobalMainFrame().updateAllWindows();
#endif
}

GridLook GridManager::getLookFromNumber(int i)
{
if (i >= GRIDLOOK_LINES && i <= GRIDLOOK_SQUARES)
Expand Down
1 change: 0 additions & 1 deletion radiant/ui/grid/GridManager.h
Expand Up @@ -47,7 +47,6 @@ class GridManager :

private:
void gridChangeNotify();
void gridChanged();

void loadDefaultValue();

Expand Down
2 changes: 1 addition & 1 deletion radiant/ui/grid/GridUserInterface.cpp
Expand Up @@ -47,7 +47,7 @@ void GridUserInterface::initialiseModule(const ApplicationContext& ctx)
{
GridSize gridSize = static_cast<GridSize>(size);

std::string toggleName = std::string("ToggleGrid") + grid::getStringForSize(gridSize);
std::string toggleName = std::string("SetGrid") + grid::getStringForSize(gridSize);
auto toggle = GlobalEventManager().addToggle(toggleName,
std::bind(&GridUserInterface::toggleGrid, this, gridSize, std::placeholders::_1));

Expand Down

0 comments on commit d48cdda

Please sign in to comment.