Added way to delete user-added prefs from the pref editor.

This commit is contained in:
smeredith%netscape.com 2002-01-28 19:09:00 +00:00
Родитель 0d54e27adc
Коммит f2e785b4b9
9 изменённых файлов: 153 добавлений и 48 удалений

Двоичные данные
cck/docs/prefstree/PrefsTreeEx3.jpg

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 17 KiB

После

Ширина:  |  Высота:  |  Размер: 19 KiB

Просмотреть файл

@ -1,5 +1,7 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"><meta name="author" content="Steve Meredith"><title>Structure of the Pref Editor XML File for the PrefsTree Widget</title></head><body text="#000000" bgcolor="#ffffcc" link="#0000ff" alink="darkblue" vlink="#cc0000">
<div align="Right">Removed elements <tt>INSTALLATIONFILE </tt>and <tt>PREFFILE.</tt> Changed <tt>processPrefsTree()</tt> number of params. &nbsp;&nbsp; 02 Jan 2002<br>
<div align="right">Added <tt>useradded</tt> attribute&nbsp;&nbsp;&nbsp; 28 Jan 2002<br>
Added the <tt>MANAGE </tt>element.&nbsp;&nbsp;&nbsp; <strike>24 Jan 2002</strike><br>
Removed elements <tt>INSTALLATIONFILE </tt>and <tt>PREFFILE. </tt>Changed <tt>processPrefsTree()</tt> number of params. &nbsp;&nbsp; <strike>02 Jan 2002</strike><br>
Removed <tt>choose </tt>attribute. &nbsp;&nbsp; <strike>13 Dec 2001</strike><br>
Original version. &nbsp;&nbsp; <strike>11 Dec 2001</strike><br>
Steve Meredith<br>
@ -16,22 +18,45 @@ The name of the XML file is specified in the .ini section for the PrefsTree
Widget. The default file must be located in the same directory as the <tt>WIZARDMACHINE.EXE</tt>
. When used, a copy of the file is saved in the working config directory.
This copy contains the changes made by the CCK/Factory user, and is used
by the install builder to write preferences in the install image. A SCRIPT.IB
entry must be made in order for it process the .XML file: <tt>processPrefsTree(,browser.xpi,bin/netscp6.cfg</tt><tt>)</tt>
. Note that spaces are not allowed between the parameters. For details on
by the install builder to write preferences in the install image. A <tt>SCRIPT.IB</tt>
entry must be made in order for it process the .XML file: <tt>processPrefsTree(,browser.xpi,bin/netscp6.cfg</tt><tt>)</tt>. Note that spaces are not allowed between the parameters. For details on
adding a PrefsTree control to wizard pages, see the document&nbsp;<a href="PrefsTree.htm">PrefsTree.htm</a>
<h2>A Note on Prefs</h2>The XML described herein contains elements for prefs and elements to control how they are
grouped in a UI. It was specifically designed for use in this <i>Pref Editor</i>
tree control, but a complete representation of prefs in XML could be useful
in other ways. But for this use, the only prefs which should be included
in this file are prefs which can be set in advance and saved to a .cfg or .jsc file.
Note that this excludes some prefs which might be found in a profile <tt>prefs.js</tt>
, such as those prefs which define specific mail and news accounts, servers,
and identities. These pref names are generated on the fly by the client.
If this XML is to be expanded for use in other ways, for example as described
in <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=17199">Bugzilla bug 17199</a>
, new tags could be added to each pref to indicate whether or not it could
be set in advance and stored in a .cfg file. The Pref Editor would have to
be modified to respect this new information and only present the appropriate
prefs for editting. Otherwise, any new elements and attributes are ignored
as long as the basic structure of the file remains valid (<tt>&lt;PREF&gt;</tt>s are grouped within <tt>&lt;PREFSGROUP&gt;</tt>s) and the required attributes and subelements exist.<br>
<br>
The following prefs should not be placed into this XML file for use in the
prefs editor because they are handled outside the prefs editor, and used
to point to the file created by the install builder and prefs editor.<br>
<ul>
<li><tt>autoadmin.global_config_url</tt></li>
<li><tt>autoadmin.append_emailaddr</tt></li>
<li><tt>autoadmin.offline_failover</tt></li>
</ul>
<h2>Who This Document is For</h2>
<h2></h2>
You will need to understand the structure of the XML file if you want to
add or remove prefs to the Pref Editor or change how they are grouped.<br>
add or remove prefs to the Pref Editor or change how they are grouped. <br>
<h2>Conventions</h2>
For XML item tags, we use ALL CAPS. For attribute names, we use lower case.
&#8220;true&#8221; and &#8220;false&#8221; are also written in lower case. Generally, for PREF items,
the attributes are those things about the pref which are fixed, and use elements
for thing the CCK/Factory app will change. The exception is for <tt>&lt;CHOICES&gt;</tt>, which are difficult to represent as attributes, so these are elements.<br>
<h2>General Structure</h2>
<h3>Example 1</h3>
<h2>General Structure</h2><h3>Example 1</h3>
The simplest file that may exist consists of one group containing one pref. <br>
<br>
<code>&lt;?xml version="1.0"?&gt;<br>
@ -106,19 +131,19 @@ Each <tt>&lt;PREFSGROUP&gt;</tt> element will make a new level of hierarchy in t
<table cellpadding="2" cellspacing="2" border="1" width="100%" bgcolor="#ffffff">
<tbody>
<tr>
<td valign="Top"><b>Attribute</b><br>
<td valign="top"><b>Attribute</b><br>
</td>
<td valign="Top"><b>Example</b><br>
<td valign="top"><b>Example</b><br>
</td>
<td valign="Top"><b>Description</b><br>
<td valign="top"><b>Description</b><br>
</td>
</tr>
<tr>
<td valign="Top"><tt>uiname</tt><br>
<td valign="top"><tt>uiname</tt><br>
</td>
<td valign="Top"><tt>uiname="Netscape Preferences"</tt><br>
<td valign="top"><tt>uiname="Netscape Preferences"</tt><br>
</td>
<td valign="Top">This is the name of the group as it appears in the tree control. <br>
<td valign="top">This is the name of the group as it appears in the tree control. <br>
</td>
</tr>
</tbody>
@ -130,36 +155,36 @@ the user can edit.These elements must be contained in some <tt>&lt;PREFSGROUP&gt
<table width="100%" border="1" cellspacing="2" cellpadding="2" bgcolor="#ffffff">
<tbody>
<tr>
<td valign="Top"><b>Attribute</b><br>
<td valign="top"><b>Attribute</b><br>
</td>
<td valign="Top"><b>Example</b><br>
<td valign="top"><b>Example</b><br>
</td>
<td valign="Top"><b>Description</b><br>
<td valign="top"><b>Description</b><br>
</td>
</tr>
<tr>
<td valign="Top"><tt>uiname</tt><br>
<td valign="top"><tt>uiname</tt><br>
</td>
<td valign="Top"><code>uiname="Open Browser on Startup"</code><br>
<td valign="top"><code>uiname="Open Browser on Startup"</code><br>
</td>
<td valign="Top">This is the name of the pref as is appears in the
<td valign="top">This is the name of the pref as is appears in the
tree control. It doesn't have to be the name of the pref--it should be something
easy for the user to understand.<br>
</td>
</tr>
<tr>
<td valign="Top"><tt>prefname</tt><br>
<td valign="top"><tt>prefname</tt><br>
</td>
<td valign="Top"><code>prefname="general.startup.browser"</code></td>
<td valign="Top">This is the real name of the pref as it is used by the Netscape client products.<br>
<td valign="top"><code>prefname="general.startup.browser"</code></td>
<td valign="top">This is the real name of the pref as it is used by the Netscape client products.<br>
</td>
</tr>
<tr>
<td valign="Top"><tt>type</tt><br>
<td valign="top"><tt>type</tt><br>
</td>
<td valign="Top"><code>type="bool"</code><br>
<td valign="top"><code>type="bool"</code><br>
</td>
<td valign="Top">Must be one of <b><tt>int</tt></b>, <b><tt>bool</tt></b>, or <b><tt>string</tt></b>. This determines how the pref will be edited in the Pref Editor and how it is written to the prefs file in the install image.<br>
<td valign="top">Must be one of <b><tt>int</tt></b>, <b><tt>bool</tt></b>, or <b><tt>string</tt></b>. This determines how the pref will be edited in the Pref Editor and how it is written to the prefs file in the install image.<br>
<br>
<tt><b>bool</b> </tt>Pref Editor user allowed to select &#8220;true&#8221; or &#8220;false&#8221;
from a drop-down. No quotes are used when writing the pref in the pref file.
@ -172,23 +197,36 @@ For example, <tt>pref("general.startup.browser", true);</tt><br>
</tr>
<tr>
<td valign="Top"><tt>lockable</tt><br>
<td valign="top"><tt>lockable</tt><br>
</td>
<td valign="Top"><code>lockable="true"</code><br>
<td valign="top"><code>lockable="true"</code><br>
</td>
<td valign="Top">Determines whether or not the Pref Editor user can change the lock state the pref.<br>
<td valign="top">Determines whether or not the Pref Editor user can change the lock state the pref.<br>
</td>
</tr>
<tr>
<td valign="Top"><tt>description</tt><br>
<td valign="top"><tt>description</tt><br>
</td>
<td valign="Top"><code>description="When the application starts, open a browser window."</code><br>
<td valign="top"><code>description="When the application starts, open a browser window."</code><br>
</td>
<td valign="Top">This is some text which further describes the pref
<td valign="top">This is some text which further describes the pref
to the Pref Editor user. It appears when the user selected the pref for editing.
Any text which helps the user under the pref should go here.<br>
Any text which helps the user under the pref should go here.
There is space in the editor for maybe 125 characters or so. Of course,
you can edit the dialog resource to hold more if this becomes a limitation.<br>
</td>
</tr><tr>
<td valign="top"><tt>useradded</tt><br>
</td>
<td valign="top"><tt>useradded="true"</tt><br>
</td>
<td valign="top">This pref is added by the Pref Editor for all new
prefs added by the user via the UI. It is normally not present, and is assumed
to be false if missing. User added prefs are deletable via the Pref Editor
UI.<br>
</td>
</tr>
</tbody>
</table>
<h3>&lt;CHOICES&gt;</h3>
@ -207,27 +245,27 @@ This element appears in <tt>&lt;CHOICES&gt;</tt> elements to describe one item o
<table cellpadding="2" cellspacing="2" border="1" width="100%" bgcolor="#ffffff">
<tbody>
<tr>
<td valign="Top"><b>Attribute</b><br>
<td valign="top"><b>Attribute</b><br>
</td>
<td valign="Top"><b>Example</b><br>
<td valign="top"><b>Example</b><br>
</td>
<td valign="Top"><b>Description</b><br>
<td valign="top"><b>Description</b><br>
</td>
</tr>
<tr>
<td valign="Top"><tt>uiname</tt><br>
<td valign="top"><tt>uiname</tt><br>
</td>
<td valign="Top"><code>uiname="Blank Page"</code><br>
<td valign="top"><code>uiname="Blank Page"</code><br>
</td>
<td valign="Top">The text of this choice in the list box for this choice.<br>
<td valign="top">The text of this choice in the list box for this choice.<br>
</td>
</tr>
<tr>
<td valign="Top"><tt>value</tt><br>
<td valign="top"><tt>value</tt><br>
</td>
<td valign="Top"><code>value="0"</code><br>
<td valign="top"><code>value="0"</code><br>
</td>
<td valign="Top">The value saved in the <tt>&lt;VALUE&gt;</tt> element for the <tt>&lt;PREF&gt;</tt> when the pref is edit and this choice is selected in the list box. The type of the value must be correct for the enclosing <tt>&lt;PREF&gt;</tt> element.<br>
<td valign="top">The value saved in the <tt>&lt;VALUE&gt;</tt> element for the <tt>&lt;PREF&gt;</tt> when the pref is edit and this choice is selected in the list box. The type of the value must be correct for the enclosing <tt>&lt;PREF&gt;</tt> element.<br>
</td>
</tr>
</tbody>
@ -236,5 +274,9 @@ This element appears in <tt>&lt;CHOICES&gt;</tt> elements to describe one item o
of type. This gets modified when the user edits the pref. Note that the modified
file is saved to the working config directory.<br>
<h3>&lt;LOCKED&gt;</h3>One and only one must appear in a <tt>&lt;PREF&gt;</tt> element. This is <tt>true </tt>or <tt>false, </tt>depending on whether the pref is locked or not. If locked, prefs are written as <tt>lockPref()</tt> instead of <tt>pref()</tt>. See also <tt>&lt;PREF lockable="true"&gt;</tt>.<br>
<br>
<h3>&lt;MANAGE&gt;</h3>
This pref is added by the pref editor, and is normally absent in a prefs
XML file until it has been processed by the prefs editor. If the <tt>&lt;MANAGE&gt;</tt>
tag is present, and its value is true, then this pref will be written to
the output prefs file when the XML is processed by the install builder app.<br>
</body></html>

Двоичные данные
cck/driver/WizardMachine.aps

Двоичный файл не отображается.

Просмотреть файл

@ -516,6 +516,15 @@ BEGIN
MENUITEM "&Find Pref\tCtrl+F", ID_FINDPREF
MENUITEM "Find &Next Pref\tF3", ID_FINDNEXTPREF
END
POPUP "UserAddedItemSubMenu"
BEGIN
MENUITEM "&Edit Pref", ID_EDITPREFITEM
MENUITEM "&Add Pref", ID_ADDPREF
MENUITEM "&Delete Pref", ID_DELPREF
MENUITEM SEPARATOR
MENUITEM "&Find Pref\tCtrl+F", ID_FINDPREF
MENUITEM "Find &Next\tF3", ID_FINDNEXTPREF
END
END

Просмотреть файл

@ -27,6 +27,10 @@ const int bm_lockedPad = 2;
const int bm_unlockedPad = 3;
const int bm_unlockedPadGray = 4;
// submenus
const int menu_pref = 0;
const int menu_group = 1;
const int menu_userAddedPref = 2;
/////////////////////////////////////////////////////////////////////////////
// CPrefEditView
@ -42,6 +46,7 @@ BEGIN_MESSAGE_MAP(CPrefEditView, CTreeView)
ON_COMMAND(ID_FINDPREF, OnFindPref)
ON_COMMAND(ID_FINDNEXTPREF, OnFindNextPref)
ON_COMMAND(ID_ADDPREF, OnAddPref)
ON_COMMAND(ID_DELPREF, OnDelPref)
ON_WM_KEYDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
@ -610,8 +615,10 @@ void CPrefEditView::OnFindNextPref()
// User added prefs go into the root group.
HTREEITEM CPrefEditView::AddPref(CString& rstrPrefName, CString& rstrPrefDesc, CString& rstrPrefType)
{
// Modify it.
// Create it.
CPrefElement* newPref = new CPrefElement(rstrPrefName, rstrPrefDesc, rstrPrefType);
newPref->SetUserAdded(TRUE);
// Add it to the tree.
CTreeCtrl &treeCtrl = GetTreeCtrl();
@ -664,6 +671,28 @@ void CPrefEditView::OnAddPref()
}
// Delete the user-added pref.
void CPrefEditView::OnDelPref()
{
CTreeCtrl &treeCtrl = GetTreeCtrl();
HTREEITEM hTreeCtrlItem = treeCtrl.GetSelectedItem();
// Can't edit a pref group--only a pref (leaf).
if (treeCtrl.ItemHasChildren(hTreeCtrlItem))
return;
// If user added-pref, delete the CPrefElement that was created with new.
CPrefElement* pe = (CPrefElement*)treeCtrl.GetItemData(hTreeCtrlItem);
ASSERT(pe); // There must be a CPrefElement object for each pref in the tree.
if ((pe == NULL) || !pe->IsUserAdded())
return;
delete pe;
// Remove item from the tree.
treeCtrl.DeleteItem(hTreeCtrlItem);
}
// Open the edit dialog box for the selected pref item. A pref should be selected,
// not a group.
void CPrefEditView::EditSelectedPrefsItem()
@ -759,9 +788,21 @@ void CPrefEditView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult)
int submenu;
if (!treeCtrl.ItemHasChildren(hTreeCtrlItem)) // no children == leaf node == pref
submenu = 0;
{
CPrefElement* pe = (CPrefElement*)treeCtrl.GetItemData(hTreeCtrlItem);
ASSERT(pe); // there must be a CPrefElement object for each leaf node.
if (!pe)
return;
if (pe->IsUserAdded())
submenu = menu_userAddedPref;
else
submenu = menu_pref;
}
else
submenu = 1;
{
submenu = menu_group;
}
ShowPopupMenu(pt, submenu);
}
@ -782,6 +823,11 @@ void CPrefEditView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
OnFindPref();
}
else if (nChar == VK_DELETE)
{
OnDelPref();
}
else
{
CTreeView::OnKeyDown(nChar, nRepCnt, nFlags);

Просмотреть файл

@ -68,6 +68,7 @@ protected:
afx_msg void OnFindPref();
afx_msg void OnFindNextPref();
afx_msg void OnAddPref();
afx_msg void OnDelPref();
afx_msg void OnRclick(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);

Просмотреть файл

@ -58,13 +58,14 @@
#define ID_FINDPREF 32774
#define ID_FINDNEXTPREF 32776
#define ID_ADDPREF 32777
#define ID_DELPREF 32778
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 148
#define _APS_NEXT_COMMAND_VALUE 32778
#define _APS_NEXT_COMMAND_VALUE 32779
#define _APS_NEXT_CONTROL_VALUE 1020
#define _APS_NEXT_SYMED_VALUE 101
#endif

Просмотреть файл

@ -49,6 +49,7 @@ void CPrefElement::ReInit()
m_bLocked = FALSE;
m_bLockable = TRUE;
m_bManage = FALSE;
m_bUserAdded = FALSE;
m_iChoices = 0;
}
@ -143,6 +144,8 @@ void CPrefElement::startElement(const char* name, const char** atts)
m_bLockable = (stricmp(attrVal, "true") == 0);
else if (stricmp(attrName, "description") == 0)
m_strDescription = attrVal;
else if (stricmp(attrName, "useradded") == 0)
m_bUserAdded = (stricmp(attrVal, "true") == 0);
}
}
@ -316,9 +319,9 @@ CString CPrefElement::XML(int iIndentSize, int iIndentLevel)
int iIndentSpaces = iIndentSize * iIndentLevel;
CString strRet;
strRet.Format("%*s<PREF uiname=\"%s\" prefname=\"%s\" type=\"%s\" lockable=\"%s\" description=\"%s\">\n",
strRet.Format("%*s<PREF uiname=\"%s\" prefname=\"%s\" type=\"%s\" lockable=\"%s\" description=\"%s\" useradded=\"%s\">\n",
iIndentSpaces, " ", GetUIName(), GetPrefName(), GetPrefType(),
IsLockable()?"true":"false", GetPrefDescription());
IsLockable()?"true":"false", GetPrefDescription(), IsUserAdded()?"true":"false");
CString strTmp;
if (IsChoose())

Просмотреть файл

@ -26,6 +26,8 @@ public:
void SetLocked(BOOL bLocked) { m_bLocked = bLocked; };
BOOL IsManage() { return m_bManage; };
void SetManage(BOOL bManage) { m_bManage = bManage; };
BOOL IsUserAdded() { return m_bUserAdded; };
void SetUserAdded(BOOL bUserAdded) { m_bUserAdded = bUserAdded; };
CString GetUIName() { return m_strUIName; };
CString GetPrefValue() { return m_strPrefValue; };
void SetPrefValue(CString strValue);
@ -59,6 +61,7 @@ private:
BOOL m_bLocked;
BOOL m_bLockable;
BOOL m_bManage;
BOOL m_bUserAdded;
CString m_astrChoiceName[MAX_CHOICES+1]; // Array of possible choice names. Last is empty string.
CString m_astrChoiceVal[MAX_CHOICES+1]; // Matching values for the above names.