mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-29 03:32:48 +00:00
Add gui.xml version validation to avoid using an old customized gui.xml file.
This commit is contained in:
parent
df3c0c1d52
commit
c64a0d1171
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!-- ASE menus, tools and keyboard shortcuts -->
|
<!-- ASE menus, tools and keyboard shortcuts -->
|
||||||
<gui>
|
<gui version="0.9">
|
||||||
<!-- Keyboard shortcuts -->
|
<!-- Keyboard shortcuts -->
|
||||||
<keyboard>
|
<keyboard>
|
||||||
|
|
||||||
|
@ -661,6 +661,17 @@ void Widget::replaceChild(Widget* oldChild, Widget* newChild)
|
|||||||
jwidget_emit_signal(this, JI_SIGNAL_ADD_CHILD);
|
jwidget_emit_signal(this, JI_SIGNAL_ADD_CHILD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Widget::insertChild(int index, Widget* child)
|
||||||
|
{
|
||||||
|
ASSERT_VALID_WIDGET(this);
|
||||||
|
ASSERT_VALID_WIDGET(child);
|
||||||
|
|
||||||
|
jlist_insert(children, child, index);
|
||||||
|
child->parent = this;
|
||||||
|
|
||||||
|
jwidget_emit_signal(this, JI_SIGNAL_ADD_CHILD);
|
||||||
|
}
|
||||||
|
|
||||||
// ===============================================================
|
// ===============================================================
|
||||||
// LAYOUT & CONSTRAINT
|
// LAYOUT & CONSTRAINT
|
||||||
// ===============================================================
|
// ===============================================================
|
||||||
|
@ -249,6 +249,7 @@ public:
|
|||||||
void addChild(Widget* child);
|
void addChild(Widget* child);
|
||||||
void removeChild(Widget* child);
|
void removeChild(Widget* child);
|
||||||
void replaceChild(Widget* oldChild, Widget* newChild);
|
void replaceChild(Widget* oldChild, Widget* newChild);
|
||||||
|
void insertChild(int index, Widget* child);
|
||||||
|
|
||||||
// ===============================================================
|
// ===============================================================
|
||||||
// LAYOUT & CONSTRAINT
|
// LAYOUT & CONSTRAINT
|
||||||
|
@ -65,3 +65,16 @@ TiXmlDocument& GuiXml::doc()
|
|||||||
{
|
{
|
||||||
return m_doc;
|
return m_doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string GuiXml::version()
|
||||||
|
{
|
||||||
|
TiXmlHandle handle(&m_doc);
|
||||||
|
TiXmlElement* xmlKey = handle.FirstChild("gui").ToElement();
|
||||||
|
|
||||||
|
if (xmlKey && xmlKey->Attribute("version")) {
|
||||||
|
const char* guixml_version = xmlKey->Attribute("version");
|
||||||
|
return guixml_version;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#ifndef GUI_XML_INCLUDED
|
#ifndef GUI_XML_INCLUDED
|
||||||
#define GUI_XML_INCLUDED
|
#define GUI_XML_INCLUDED
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include "tinyxml.h"
|
#include "tinyxml.h"
|
||||||
|
|
||||||
// Singleton class to load and access "gui.xml" file.
|
// Singleton class to load and access "gui.xml" file.
|
||||||
@ -38,6 +39,8 @@ public:
|
|||||||
return m_doc.Value();
|
return m_doc.Value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string version();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GuiXml();
|
GuiXml();
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ static int load_root_menu();
|
|||||||
static Menu* load_menu_by_id(TiXmlHandle& handle, const char *id);
|
static Menu* load_menu_by_id(TiXmlHandle& handle, const char *id);
|
||||||
static Menu* convert_xmlelem_to_menu(TiXmlElement* elem);
|
static Menu* convert_xmlelem_to_menu(TiXmlElement* elem);
|
||||||
static Widget* convert_xmlelem_to_menuitem(TiXmlElement* elem);
|
static Widget* convert_xmlelem_to_menuitem(TiXmlElement* elem);
|
||||||
|
static Widget* create_invalid_version_menuitem();
|
||||||
static void apply_shortcut_to_menuitems_with_command(Menu* menu, Command* command, Params* params, JAccel accel);
|
static void apply_shortcut_to_menuitems_with_command(Menu* menu, Command* command, Params* params, JAccel accel);
|
||||||
|
|
||||||
int init_module_rootmenu()
|
int init_module_rootmenu()
|
||||||
@ -118,6 +119,10 @@ static int load_root_menu()
|
|||||||
throw base::Exception("Error loading main menu from file:\n%s\nReinstall the application.",
|
throw base::Exception("Error loading main menu from file:\n%s\nReinstall the application.",
|
||||||
static_cast<const char*>(path));
|
static_cast<const char*>(path));
|
||||||
|
|
||||||
|
// Add a warning element because the user is not using the last well-known gui.xml file.
|
||||||
|
if (GuiXml::instance()->version() != VERSION)
|
||||||
|
root_menu->insertChild(0, create_invalid_version_menuitem());
|
||||||
|
|
||||||
PRINTF("Main menu loaded.\n");
|
PRINTF("Main menu loaded.\n");
|
||||||
|
|
||||||
document_tab_popup_menu = load_menu_by_id(handle, "document_tab_popup");
|
document_tab_popup_menu = load_menu_by_id(handle, "document_tab_popup");
|
||||||
@ -342,6 +347,20 @@ static Widget* convert_xmlelem_to_menuitem(TiXmlElement* elem)
|
|||||||
return menuitem;
|
return menuitem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Widget* create_invalid_version_menuitem()
|
||||||
|
{
|
||||||
|
MenuItem2* menuitem = new MenuItem2("WARNING!", NULL, NULL);
|
||||||
|
Menu* subMenu = new Menu();
|
||||||
|
subMenu->addChild(new MenuItem2(PACKAGE " is using a customized gui.xml (maybe from your HOME directory).", NULL, NULL));
|
||||||
|
subMenu->addChild(new MenuItem2("You should update your customized gui.xml file to the new version to get", NULL, NULL));
|
||||||
|
subMenu->addChild(new MenuItem2("the latest commands available.", NULL, NULL));
|
||||||
|
subMenu->addChild(ji_separator_new(NULL, JI_HORIZONTAL));
|
||||||
|
subMenu->addChild(new MenuItem2("You can bypass this validation adding the correct version", NULL, NULL));
|
||||||
|
subMenu->addChild(new MenuItem2("number in <gui version=\"" VERSION "\"> element.", NULL, NULL));
|
||||||
|
menuitem->setSubmenu(subMenu);
|
||||||
|
return menuitem;
|
||||||
|
}
|
||||||
|
|
||||||
static void apply_shortcut_to_menuitems_with_command(Menu* menu, Command *command, Params* params, JAccel accel)
|
static void apply_shortcut_to_menuitems_with_command(Menu* menu, Command *command, Params* params, JAccel accel)
|
||||||
{
|
{
|
||||||
JList children = menu->getChildren();
|
JList children = menu->getChildren();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user