SDK:Using Saved Settings

From Vectorworks Developer
Revision as of 15:39, 12 August 2013 by Root (talk | contribs) (1 revision)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

.SDK|SDK ..SDK:Types|SDK Types ..SDK:Using the SDK|Using the SDK ..VCOM:VCOM (Vectorworks Component Object Model)|VCOM Basics ..VCOM:Class Reference|VCOM Class Reference

Set up the saved settings mechanizm

First thing to do is to assign category of the saved settings dialog.

This is done in the dialog constructor, and the name provided is usually the name of the plug-in. This way all saved settings for this plug-in will be present under the same node in the settings XML file.

There are two available functions for setting the category:

void VWDialog::SetSavedSettingsTag(const TXString& category);
void VWDialog::SetSavedSettingsTag(const TXString& category,
                                   const TXString& dialogName);

The dialogName specified additional category inside the original category in which this dialog saved settings will be stored.

If the function without dialogName is used, the sub category is actually the title of the dialog.

Note! If you omit to specify dialogName the dialog title is used as sub category. This means that in localized dialogs, the localized name will be used. This is ok in the general case, as far as it concerns user-only settings file.

CSampleDlg1::CSampleDlg1()
{
    // ...

    // Specify category in which the dialog's saved settings will be stored
    this->SetSavedSettingsTag( "SampleCategory" );
}

Using dialog saved settings

In order for the mechanism to work properly you MUST call VWDialog::OnSetUpEvent(); if you have overridden this function.

void CSampleDlg1::OnSetUpEvent()
{
    VWDialog::OnSetUpEvent();
}


Saving dialog position and size

If you have done SetSavedSettingsTag in your dialog, then automatically it will store it's position and size on dialog exit, and it will restore them when the dialog is show.

Note! Saving will be done regardless how the dialog finishes with OK or Cancel.

Using custom saved settings values

The VWDialog has build-in mechanism for custom values (additional data) for this dialog that will go in the dialog's category and sub-category. The funtions to be used are:

void VWDialog::SetSavedValue(const TXString& name,
                             const TXString& value);

bool VWDialog::GetSavedValue(const TXString& name, TXString& outValue) const;

First thing to do is to provide the available value names before the dialog is run:

CSampleDlg1::CSampleDlg1()
{
    // ...

    // Specify category in which the dialog's saved settings will be stored
    this->SetSavedSettingsTag( "SampleCategory" );
    this->SetSavedValue( "myCustValue", "1" );
    this->SetSavedValue( "myCustValueName", "this is name" );
}

This will set default values for the custom saved settings.

Now you can use those value names whenever in the dialog handler code:

void CSampleDlg1::OnGetDataButton(long controlID,
                                  VWDialogEventArgs& eventArgs)
{
    TXString	value;
    this->GetSavedValue( "myCustValue", value );

     // ...
}

Also you can set new values whenever in the code you like:

void CSampleDlg1::OnGetDataButton(long controlID,
                                  VWDialogEventArgs& eventArgs)
{
    this->SetSavedValue( "myCustValue", "this is the new value" );

     // ...
}

Note! All custom values are string. You can use TXString conversion funtinos: TXString::Format, TXString::itoa, TXString::atoi, and TXString::atof

Note! If you are to be using VWDialog::SetSavedValue in VWDialog::OnSetDownEvent you HAVE TO do it before calling the base VWDialog function:

void CSampleDlg1::OnSetDownEvent()
{
    // save before calling the base,
    // because this base futnion actually writes the custom values
    this->SetSavedValue( "myCustValue", "this is the new value" );

    VWDialog::OnSetDownEvent();
}

See Also

SDK:Creating handler class for VectorScript layout dialog | SDK:Creating handler class for manual layout dialog | SDK:Working with Dynamic Data Exchange (DDX) |