Skip to content

Commit

Permalink
jx_menu_editor: move enum to separate file, for easier sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
jafl committed Dec 16, 2023
1 parent bf4507d commit 6b76f7a
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 28 deletions.
2 changes: 2 additions & 0 deletions todo
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jcc
javascript regex, incl char class - can contain php or jsp

glove
convert to jx_menu_editor

undo then redo "transform creates column": puts values back in inverted order

remember open documents and restore when start
Expand Down
72 changes: 53 additions & 19 deletions tools/jx_menu_editor/code/MenuDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,13 +472,13 @@ MenuDocument::GenerateCode()
return;
}

// header
// headers

JString headerFileName = JCombinePathAndName(path, root);
headerFileName = JCombineRootAndSuffix(headerFileName, "h");
JString headerFullName = JCombinePathAndName(path, root);
headerFullName = JCombineRootAndSuffix(headerFullName, "h");

JString tempHeaderFileName;
const JError err = JCreateTempFile(&path, nullptr, &tempHeaderFileName);
JString tempHeaderFullName;
JError err = JCreateTempFile(&path, nullptr, &tempHeaderFullName);
if (!err.OK())
{
const JUtf8Byte* map[] =
Expand All @@ -489,7 +489,7 @@ MenuDocument::GenerateCode()
JGetUserNotification()->ReportError(JGetString("CodeDirectoryNotWritable::MenuDocument", map, sizeof(map)));
return;
}
std::ofstream headerOutput(tempHeaderFileName.GetBytes());
std::ofstream headerOutput(tempHeaderFullName.GetBytes());

name = root;
JStringIterator nameIter(&name);
Expand All @@ -514,34 +514,68 @@ MenuDocument::GenerateCode()
};
JGetString("CodeHeader::MenuDocument", headerMap, sizeof(headerMap)).Print(headerOutput);

JString enumFullName = JCombinePathAndName(path, root + "-enum");
enumFullName = JCombineRootAndSuffix(enumFullName, "h");

JString tempEnumFullName;
err = JCreateTempFile(&path, nullptr, &tempEnumFullName);
assert( err.OK() );
std::ofstream enumOutput(tempEnumFullName.GetBytes());

const JUtf8Byte* enumMap[] =
{
"name", name.GetBytes(),
"title", title.GetBytes()
};
JGetString("EnumHeader::MenuDocument", enumMap, sizeof(enumMap)).Print(enumOutput);

JString enumFileName;
JSplitPathAndName(enumFullName, &path, &enumFileName);

itsTable->GenerateCode(headerOutput, itsClassNameInput->GetText()->GetText(),
title, itsWindowsKeyInput->GetText()->GetText());
title, itsWindowsKeyInput->GetText()->GetText(),
enumOutput, enumFileName);

JGetString("CodeFooter::MenuDocument").Print(headerOutput);
headerOutput.close();

// check if header file actually changed
JGetString("CodeFooter::MenuDocument").Print(enumOutput);
enumOutput.close();

// check if header files actually changed

JString origText, newText;
JReadFile(headerFullName, &origText);
JReadFile(tempHeaderFullName, &newText);
if (newText != origText)
{
JEditVCS(headerFullName);
JRenameFile(tempHeaderFullName, headerFullName, true);
}
else
{
JRemoveFile(tempHeaderFullName);
}

JString origHeaderText, newHeaderText;
JReadFile(headerFileName, &origHeaderText);
JReadFile(tempHeaderFileName, &newHeaderText);
if (newHeaderText != origHeaderText)
JReadFile(enumFullName, &origText);
JReadFile(tempEnumFullName, &newText);
if (newText != origText)
{
JEditVCS(headerFileName);
JRenameFile(tempHeaderFileName, headerFileName, true);
JEditVCS(enumFullName);
JRenameFile(tempEnumFullName, enumFullName, true);
}
else
{
JRemoveFile(tempHeaderFileName);
JRemoveFile(tempEnumFullName);
}

// strings

JString stringsFileName = JCombinePathAndName(projRoot, JString("strings", JString::kNoCopy));
stringsFileName = JCombinePathAndName(stringsFileName, root);
JString stringsFullName = JCombinePathAndName(projRoot, JString("strings", JString::kNoCopy));
stringsFullName = JCombinePathAndName(stringsFullName, root);

JEditVCS(stringsFileName);
std::ofstream stringsOutput(stringsFileName.GetBytes());
JEditVCS(stringsFullName);
std::ofstream stringsOutput(stringsFullName.GetBytes());

const JUtf8Byte* stringsMap[] =
{
Expand Down
18 changes: 11 additions & 7 deletions tools/jx_menu_editor/code/MenuTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1741,7 +1741,9 @@ MenuTable::GenerateCode
std::ostream& output,
const JString& className,
const JString& menuTitle,
const JString& menuTitleShortcut
const JString& menuTitleShortcut,
std::ostream& enumOutput,
const JString& enumFileName
)
const
{
Expand Down Expand Up @@ -1792,22 +1794,24 @@ MenuTable::GenerateCode

// enum

output << "enum {" << std::endl;
output << "#include " << enumFileName << std::endl << std::endl;

enumOutput << "enum {" << std::endl;

first = true;
for (const auto& item : *itsItemList)
{
output << '\t';
item.enumName->Print(output);
enumOutput << '\t';
item.enumName->Print(enumOutput);
if (first)
{
output << "=1";
enumOutput << "=1";
first = false;
}
output << ',' << std::endl;
enumOutput << ',' << std::endl;
}

output << "};" << std::endl << std::endl;
enumOutput << "};" << std::endl;

// attach icons

Expand Down
3 changes: 2 additions & 1 deletion tools/jx_menu_editor/code/MenuTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ class MenuTable : public JXEditTable, public JPrefObject
void RemoveSelectedItem();

void GenerateCode(std::ostream& output, const JString& className,
const JString& menuTitle, const JString& menuTitleShortcut) const;
const JString& menuTitle, const JString& menuTitleShortcut,
std::ostream& enumOutput, const JString& enumFileName) const;
void GenerateStrings(std::ostream& output, const JString& className) const;

void FillInItemIDs(const JString& className);
Expand Down
12 changes: 11 additions & 1 deletion tools/jx_menu_editor/strings/strings
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ CodeFooter::MenuDocument
#endif
"

EnumHeader::MenuDocument
"// This file was automatically generated by jx_menu_editor.
// Do not edit it directly!
// Any changes you make will be silently overwritten.

#ifndef _H_$name_enum
#define _H_$name_enum

"

StringsHeader::MenuDocument
"1

Expand Down Expand Up @@ -108,7 +118,7 @@ WarnInvalidShortcut::MenuTable "This is not a valid shortcut. Do you want to
DuplicateWindowsKey::MenuTable "These two menu items have the same key shortcut."

ConfigureMenuHeader::MenuTable
"inline void Configure$titleMenu(JXTextMenu* menu, const int offset = 0) {
"static void Configure$titleMenu(JXTextMenu* menu, const int offset = 0) {
"

ConfigureShortcut::MenuTable
Expand Down

0 comments on commit 6b76f7a

Please sign in to comment.