Skip to content

Commit

Permalink
jx_layout_editor: name of layout must be a valid C class name
Browse files Browse the repository at this point in the history
  • Loading branch information
jafl committed Jan 2, 2024
1 parent cd4aa7e commit 3aaa1b4
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 18 deletions.
2 changes: 0 additions & 2 deletions todo-jxlayout
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
enforce that all selected widgets have the same container
if not, ignore shift

name of layout must be a valid C class name

align selected: top,bottom,center; right,left,center

shift
Expand Down
1 change: 1 addition & 0 deletions tools/jx_layout_editor/Make.files
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
.cpp ./code/CustomWidget
.cpp ./code/CoreWidget
.cpp ./code/TextButton
.cpp ./code/util

literal: ${LIB_DEPS}
16 changes: 12 additions & 4 deletions tools/jx_layout_editor/code/LayoutDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "CustomWidget.h"
#include "TextButton.h"
#include "MDIServer.h"
#include "util.h"
#include "globals.h"
#include <jx-af/jx/JXWindow.h>
#include <jx-af/jx/JXMenuBar.h>
Expand Down Expand Up @@ -50,10 +51,17 @@ LayoutDocument::Create

if (dlog->DoDialog())
{
*doc = jnew LayoutDocument(dlog->GetString(), false);
(**doc).SetDataReverted();
(**doc).Activate();
return true;
if (!IsValidIdentifier(dlog->GetString()))
{
JGetUserNotification()->ReportError(JGetString("LayoutNameMustBeValidIdentifier::LayoutDocument"));
}
else
{
*doc = jnew LayoutDocument(dlog->GetString(), false);
(**doc).SetDataReverted();
(**doc).Activate();
return true;
}
}

*doc = nullptr;
Expand Down
26 changes: 26 additions & 0 deletions tools/jx_layout_editor/code/util.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/******************************************************************************
util.cpp
Copyright © 2023 John Lindal.
******************************************************************************/

#include "util.h"
#include <jx-af/jcore/JRegex.h>
#include <jx-af/jcore/jAssert.h>

/******************************************************************************
IsValidIdentifier
******************************************************************************/

static const JRegex idPattern("^[_a-z][_a-z0-9]+$", "i");

bool
IsValidIdentifier
(
const JString& s
)
{
return idPattern.Match(s);
}
17 changes: 17 additions & 0 deletions tools/jx_layout_editor/code/util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/******************************************************************************
util.h
Copyright © 2023 by John Lindal.
******************************************************************************/

#ifndef _H_util
#define _H_util

#include "jx-af/jcore/jTypes.h"

class JString;

bool IsValidIdentifier(const JString& s);

#endif
22 changes: 12 additions & 10 deletions tools/jx_layout_editor/jx_layout_editor.jcc
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,31 @@ F
F
T
1 "misc"
T
2 "strings"
F
"./strings/strings"
T
2 "license"
F
"./strings/license"
1 "layouts"
T
2 "jx_layout_editor.fd"
F
"./jx_layout_editor.fd"
F
T
1 "help"
1 "strings"
T
2 "ChangeLog.html"
2 "strings"
F
"./release/doc/ChangeLog.html"
"./strings/strings"
F
T
1 "help"
T
2 "help.html"
F
"./release/doc/help.html"
T
2 "ChangeLog.html"
F
"./release/doc/ChangeLog.html"
F
F
# tasks
Expand All @@ -128,7 +130,7 @@ T "./" "/bin/bash -c \"cp jx_layout_editor ~/bin\"" "" FFFFFFF "Install" "" "" F
F
# build settings
1
F
T
"jx_layout_editor"
"${LIB_DEPS}"
"make -k all"
Expand Down
5 changes: 3 additions & 2 deletions tools/jx_layout_editor/strings/strings
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ You have just upgraded from version $vers"

# LayoutDocument

NewLayoutNameWindowTitle::LayoutDocument "New Layout"
EditLayoutNamePrompt::LayoutDocument "Enter the name of this layout:"
NewLayoutNameWindowTitle::LayoutDocument "New Layout"
EditLayoutNamePrompt::LayoutDocument "Enter the name of this layout:"
LayoutNameMustBeValidIdentifier::LayoutDocument "The layout name must be a valid C++ class name."

NeedNewerVersion::LayoutDocument "You need a newer version of this program to read this file."
UnsupportedFDesignVersion::LayoutDocument "Unable to read .fd file with version $v"
Expand Down

0 comments on commit 3aaa1b4

Please sign in to comment.