mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-29 19:20:09 +00:00
Update commands strings when language change
This commit is contained in:
parent
bbfae36d8f
commit
ab56186d79
@ -20,12 +20,7 @@ Command::Command(const char* id, CommandFlags flags)
|
||||
: m_id(id)
|
||||
, m_flags(flags)
|
||||
{
|
||||
std::string strId = "commands.";
|
||||
strId += this->id();
|
||||
if (auto s = Strings::instance())
|
||||
m_friendlyName = s->translate(strId.c_str());
|
||||
else
|
||||
m_friendlyName = strId;
|
||||
generateFriendlyName();
|
||||
}
|
||||
|
||||
Command::~Command()
|
||||
@ -69,6 +64,15 @@ bool Command::isChecked(Context* context)
|
||||
}
|
||||
}
|
||||
|
||||
void Command::generateFriendlyName()
|
||||
{
|
||||
std::string strId = "commands." + this->id();
|
||||
if (auto s = Strings::instance())
|
||||
m_friendlyName = s->translate(strId.c_str());
|
||||
else
|
||||
m_friendlyName = strId;
|
||||
}
|
||||
|
||||
void Command::execute(Context* context)
|
||||
{
|
||||
onExecute(context);
|
||||
|
@ -35,6 +35,7 @@ namespace app {
|
||||
void loadParams(const Params& params);
|
||||
bool isEnabled(Context* context);
|
||||
bool isChecked(Context* context);
|
||||
void generateFriendlyName();
|
||||
|
||||
protected:
|
||||
virtual bool onNeedsParams() const;
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include "app/app.h"
|
||||
#include "app/app_menus.h"
|
||||
#include "app/commands/command.h"
|
||||
#include "app/commands/commands.h"
|
||||
#include "app/crash/data_recovery.h"
|
||||
#include "app/i18n/strings.h"
|
||||
@ -159,12 +160,7 @@ MainWindow::MainWindow()
|
||||
|
||||
// When the language is change, we reload the menu bar strings and
|
||||
// relayout the whole main window.
|
||||
Strings::instance()->LanguageChange.connect(
|
||||
[this]{
|
||||
m_menuBar->reload();
|
||||
layout();
|
||||
invalidate();
|
||||
});
|
||||
Strings::instance()->LanguageChange.connect([this] { onLanguageChange(); });
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@ -203,6 +199,22 @@ MainWindow::~MainWindow()
|
||||
m_menuBar->setMenu(NULL);
|
||||
}
|
||||
|
||||
void MainWindow::onLanguageChange()
|
||||
{
|
||||
auto commands = Commands::instance();
|
||||
std::vector<std::string> commandIDs;
|
||||
commands->getAllIds(commandIDs);
|
||||
|
||||
for (const auto& commandID : commandIDs) {
|
||||
Command* command = commands->byId(commandID.c_str());
|
||||
command->generateFriendlyName();
|
||||
}
|
||||
|
||||
m_menuBar->reload();
|
||||
layout();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
DocView* MainWindow::getDocView()
|
||||
{
|
||||
return dynamic_cast<DocView*>(m_workspace->activeView());
|
||||
|
@ -116,6 +116,7 @@ namespace app {
|
||||
void onSaveLayout(ui::SaveLayoutEvent& ev) override;
|
||||
void onResize(ui::ResizeEvent& ev) override;
|
||||
void onActiveViewChange();
|
||||
void onLanguageChange();
|
||||
|
||||
private:
|
||||
DocView* getDocView();
|
||||
|
Loading…
x
Reference in New Issue
Block a user