Make single items editable in a list control (C++, MFC) - c++

I have a list control (CListCtrl) with two columns (Name, Value). I add entries dynamically from a xml file. Now i want to make the Value-Column editable and subscribe the Edit-Event to write the changes to the xml. How i do this?
My Code now:
LVITEM item_value;
item_value.iItem = row;
item_value.iSubItem = 1;
item_value.mask = LVIF_TEXT;
item_value.pszText = value;
ctrl->SetItem(&item_value);

Placing an edit control in CListCtrl is easier by setting the LVS_EDITLABELS style. Use EditLabel() function to place an edit control for a specific item, and retrieve the new text from edit control using GetEditControl() function by listening to the notification LVN_ENDLABELEDIT.

Related

How to add a separator to Gio::Menu

I'm writing an application using GTK3 and gtkmm. I'm adding a menu button to the header bar. So far, I got items to show up, but I can't add a separator.
Here's where I create the menu:
auto main_menu = Gio::Menu::create();
...and add some items:
main_menu->append("Export to WAV", "app.exportToWav");
main_menu->append("About", "app.about");
And here's what I get:
But I want to add a horizontal line between the two items. There seems to be no obvious way to do this with Gio::Menu, and I want that popover. I tried adding an item with "-" as its content, but that did nothing. Gtk::SeparatorMenuItem exists, but it doesn't seem to be compatible. Is this even doable with this kind of menu?
I've figured it out. Turns out, with Gio::Menu, you don't specify "separators," per se. Instead, you specify sections.
Essentially, what this means is creating multiple menus, and then grouping them all together in a single menu using the append_section(Gio::MenuModel) function.
Here's what I ended up doing:
// Create master menu
auto main_menu = Gio::Menu::create();
// Create menu sections
auto main_menu_section1 = Gio::Menu::create();
auto main_menu_section2 = Gio::Menu::create();
// Add item(s) to first section
main_menu_section1->append("Export to WAV", "app.exportToWav");
// Add item(s) to second section
main_menu_section2->append("About", "app.about");
// Append the new sections to the master menu
main_menu->append_section(main_menu_section1);
main_menu->append_section(main_menu_section2);
Then, each section is separated by a horizontal line:
It's faint, but it's there

Sitecore 8: Automatically fill a placeholder by a default rendering

I was playing around with dynamic placeholders and was struck by a prefilling concept.Is there a way to select a default rendering for one of my placeholders which would avoid the "select rendering" dialog in experience editor ??
Scenario: I have a rendeing called "PageHead" which has three renderings. One of them is a placeholder "PageTeaserPh" which currently allows two renderings: one is "PageTeaser" and second "PageTeaserWithImage". I want the placeholder "PageTeaserPh" to always have the rendering selected as "PageTeaser" and therefore avoid the dialog "Select rendering" .
I did some homework and was wondering if this is something related to Standard values (we can have it at template level; not sure for renderings though) and also i have heard of command template concept (not in-depth).
Any and all help appreciated.
You can have renderings assigned on standard values of templates, each new item would then have your PageTeaser rendering.
If you wanted to automate this process have a look at the <mvc.getXmlBasedLayoutDefinition> pipeline, we are injected common renderings by extending this pipeline.
Updated
I've found some code samples and blog posts that should help point you in the right direction for manipulating the layout details.
public void AddSublayoutToItem(string itemId, string sublayoutId)
{
using (new Sitecore.SecurityModel.SecurityDisabler())
{
if (Sitecore.Data.ID.IsID(itemId) && Sitecore.Data.ID.IsID(sublayoutId))
{
//Get the master database and get the item on which you want to add sublayout
Database masterDatabase = Database.GetDatabase("master");
Item item = masterDatabase.GetItem(Sitecore.Data.ID.Parse(itemId));
// Or you can also get Sitecore Item from Context Database as per your requirement
// Item item = Sitecore.Context.Database.GetItem(Sitecore.Data.ID.Parse(itemId));
if (item != null)
{
// Get the layout definitions and the device definition
LayoutField layoutField = new LayoutField(item.Fields[Sitecore.FieldIDs.LayoutField]);
LayoutDefinition layoutDefinition = LayoutDefinition.Parse(layoutField.Value);
DeviceDefinition deviceDefinition = layoutDefinition.GetDevice(Sitecore.Context.Device.ID.ToString());
//Create a RenderingDefinition and add the reference of sublayout or rendering
RenderingDefinition renderingDefinition = new RenderingDefinition();
renderingDefinition.ItemID = sublayoutId;
//Set placeholder where the rendering should be displayed
renderingDefinition.Placeholder = "content";
// Set the datasource of sublayout, if any
renderingDefinition.Datasource = "{24240FF2-B4AA-4EB2-B0A4-63E027934C38}";
// you can also set datasource of sublayout using Sitecore Path
// renderingDefinition.Datasource = "/sitecore/content/Home/Books";
//Add the RenderingReference to the DeviceDefinition
deviceDefinition.AddRendering(renderingDefinition);
// Save the layout changes
item.Editing.BeginEdit();
layoutField.Value = layoutDefinition.ToXml(); ;
item.Editing.EndEdit();
}
}
}
}
Taken from here - http://www.bugdebugzone.com/2014/06/how-to-add-sublayout-to-sitecore-item.html
Also a couple of other blogs on the topic

Sitecore: multilist during deployment

How to enable the multilist to be control in content editor?
for example I have a list of item, item1 to item10. In the standard template value, I defined item1,2,3. After I have deploy the solution, how am I going to enable users in content editor mode or page editor mode to select item7,8,9 and 10?
And also, after I tested/rendered the multilist, only RAW VALUES are being rendered, is there any possible to render the item name such as item1? Do I need to customize the multilist?
The multilist control should be directly visible to the user in the Content Editor, you do not need to do anything else. Since you defined some items in standard values then those will be "pre-selected" when that item is first created. The user can then add the additional items as required.
To allow users to select values from the Page Editor you can Use Sitecore EditFrame in PageEdit
The reason the item is being rendered as the raw value is because you need to get the item and then iterate over the target id's. There is an example of this here here
//Get a multilist field from the current item
Sitecore.Data.Fields.MultilistField multilistField = Sitecore.Context.Item.Fields["myMultilistField"];
if (multilistField != null)
{
//Iterate over all the selected items by using the property TargetIDs
foreach (ID id in multilistField.TargetIDs)
{
Item targetItem = Sitecore.Context.Database.Items[id];
litItemTitle = targetItem.DisplayName;
// Do something with the target items
// ...
}
}
You can use the following instead for the datasource of a repeater
Sitecore.Data.Fields.MultilistField multilistField = Sitecore.Context.Item.Fields["myMultilistField"];
Sitecore.Data.Items.Item[] items = multilistField.GetItems();

How to programmatically create/build up a CTabCtrl?

Without using the "Graphic Resources" how can I create and build up a CTabCtrl?
What I have so far creates it, but I don't know the MESSAGE_MAP for it. Also how to create different views for each "tab" as apposed to displaying/hiding controls depending upon what tab was selected?
thx
CTabCtrl *tabMain = new CTabCtrl();
tabMain->Create(WS_CHILD|WS_VISIBLE|TCS_TABS|TCS_SINGLELINE,CRect(700,100,1000,600),this,5);
TC_ITEM ti;
ti.mask = TCIF_TEXT;
ti.pszText = _T("Tab0");
tabMain->InsertItem(0,&ti);
ti.pszText = _T("Tab1");
tabMain->InsertItem(1,&ti);
ti.pszText = _T("Tab2");
tabMain->InsertItem(2,&ti);
The last parameter you pass to the Create function is the Id which you should use in the MESSAGE_MAP .
For eg:
ON_NOTIFY(TCN_SELCHANGE, 5 , OnSelchangeTab)

CMFCPropertyGridProperty with multi line edit box

How to create a multi line property with edit box? I need one more property that will show text in multi line box.
CMFCPropertyGridProperty* pGroup1 = new CMFCPropertyGridProperty(_T("Appearance"));
pGroup1->AddSubItem(new CMFCPropertyGridProperty(_T("Name"), (_variant_t) _T(""), _T("Specifies the text that will be displayed in the property")));
pGroup1->AddSubItem(new CMFCPropertyGridProperty(_T("Comments"), (_variant_t) _T(""), _T("Specifies the text that will be associated with the property")));
m_wndPropList.AddProperty(pGroup1);
It seems that multi-line properties are not implemented in MFC Property Grid. You can create a custom property with a button and show your own dialog with multi-line edit control when user click this button.
You can do it like in old style editors (replacing "\n","\n" so user can divide lines by "\n"):
Initialization:
CString s = m_initial_params.m_info;
s.Replace("\n","\\n");
CMFCPropertyGridProperty* pProp = new
CMFCPropertyGridProperty(misc_get_str_my(IDS_INFO),
(_variant_t) s, misc_get_str_my(IDS_INFO));
pProp->SetData(E_PROPERTY_DATA::OBJ_INFO);
pPropCtrl->AddProperty(pProp);
Reading Value:
int nProperty = pProperty->GetData();
if(E_PROPERTY_DATA::OBJ_INFO == nProperty)
{
m_initial_params.m_info = pProperty->GetValue().bstrVal;
m_initial_params.m_info.Replace("\\n","\n");
}