summaryrefslogtreecommitdiff
path: root/vgui2/vlocalize/CreateTokenDialog.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /vgui2/vlocalize/CreateTokenDialog.cpp
downloadarchived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.tar.xz
archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.zip
Diffstat (limited to 'vgui2/vlocalize/CreateTokenDialog.cpp')
-rw-r--r--vgui2/vlocalize/CreateTokenDialog.cpp151
1 files changed, 151 insertions, 0 deletions
diff --git a/vgui2/vlocalize/CreateTokenDialog.cpp b/vgui2/vlocalize/CreateTokenDialog.cpp
new file mode 100644
index 0000000..1737d1f
--- /dev/null
+++ b/vgui2/vlocalize/CreateTokenDialog.cpp
@@ -0,0 +1,151 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+
+#include "CreateTokenDialog.h"
+#include "LocalizationDialog.h"
+
+#include "vgui_controls/TextEntry.h"
+#include "vgui_controls/Button.h"
+#include "vgui_controls/MessageBox.h"
+#include "tier1/KeyValues.h"
+#include "vgui/ILocalize.h"
+
+using namespace vgui;
+
+//-----------------------------------------------------------------------------
+// Purpose: Cosntructor
+//-----------------------------------------------------------------------------
+CCreateTokenDialog::CCreateTokenDialog( CLocalizationDialog *pLocalizationDialog ) : Frame(NULL, "CreateTokenDialog"),
+ m_pLocalizationDialog( m_pLocalizationDialog )
+{
+ Assert( m_pLocalizationDialog );
+
+ MakePopup();
+
+ SetTitle("Create New Token - Localizer", true);
+
+ m_pSkipButton = new Button(this, "SkipButton", "&Skip Token");
+ m_pTokenName = new TextEntry(this, "TokenName");
+
+ m_pTokenValue = new TextEntry(this, "TokenValue");
+ m_pTokenValue->SetMultiline(true);
+ m_pTokenValue->SetCatchEnterKey(true);
+
+ m_pSkipButton->SetCommand("SkipToken");
+ m_pSkipButton->SetVisible(false);
+
+ LoadControlSettings("Resource/CreateTokenDialog.res");
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Destructor
+//-----------------------------------------------------------------------------
+CCreateTokenDialog::~CCreateTokenDialog()
+{
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: prompts user to create a single token
+//-----------------------------------------------------------------------------
+void CCreateTokenDialog::CreateSingleToken()
+{
+ // bring us to the front
+ SetVisible(true);
+ RequestFocus();
+ MoveToFront();
+ m_pTokenName->RequestFocus();
+ m_pSkipButton->SetVisible(false);
+
+ m_bMultiToken = false;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: loads a file to create multiple tokens
+//-----------------------------------------------------------------------------
+void CCreateTokenDialog::CreateMultipleTokens()
+{
+ SetVisible(true);
+ RequestFocus();
+ MoveToFront();
+ m_pTokenValue->RequestFocus();
+ m_pSkipButton->SetVisible(true);
+
+ m_bMultiToken = true;
+
+ //!! read tokens from file, prompt user to each in turn
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Handles an OK message, creating the current token
+//-----------------------------------------------------------------------------
+void CCreateTokenDialog::OnOK()
+{
+ // get the data
+ char tokenName[1024], tokenValue[1024];
+ m_pTokenName->GetText( tokenName, sizeof( tokenName ) );
+ m_pTokenValue->GetText( tokenValue, sizeof( tokenValue ) );
+
+ if ( Q_strlen( tokenName ) < 4 )
+ {
+ MessageBox *box = new MessageBox("Create Token Error", "Could not create token.\nToken names need to be at least 4 characters long.");
+ box->DoModal();
+ }
+ else
+ {
+ // create the token
+ wchar_t unicodeString[1024];
+ g_pVGuiLocalize->ConvertANSIToUnicode(tokenValue, unicodeString, sizeof(unicodeString) / sizeof(wchar_t));
+ g_pVGuiLocalize->AddString(tokenName, unicodeString, m_pLocalizationDialog->GetFileName() );
+
+ // notify the dialog creator
+ PostActionSignal(new KeyValues("TokenCreated", "name", tokenName));
+
+ // close
+ if (!m_bMultiToken)
+ {
+ PostMessage(this, new KeyValues("Close"));
+ }
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: skips the current token in the multitoken edit mode
+//-----------------------------------------------------------------------------
+void CCreateTokenDialog::OnSkip()
+{
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: handles a button command
+// Input : *command -
+//-----------------------------------------------------------------------------
+void CCreateTokenDialog::OnCommand(const char *command)
+{
+ if (!stricmp(command, "OK"))
+ {
+ OnOK();
+ }
+ else if (!stricmp(command, "SkipToken"))
+ {
+ OnSkip();
+ }
+ else
+ {
+ BaseClass::OnCommand(command);
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: handles the close message
+//-----------------------------------------------------------------------------
+void CCreateTokenDialog::OnClose()
+{
+ BaseClass::OnClose();
+ MarkForDeletion();
+}
+
+