Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » Menus&Toolbars » query , update menu / submenu itens (build routine to query or change menu items at runtime)
query , update menu / submenu itens [message #58345] Tue, 03 May 2022 19:22 Go to next message
BetoValle is currently offline  BetoValle
Messages: 202
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member

Hi,

Based on my constructor routine below**,
How do I create a routine to access each of these menu and sub-menu items to consult the texts of the options (allow changing these texts) and also to enable or disable the option (enable/disable) of each said item?
(how to do in a loop ?
would be something like:
for... dynamic_cast<MenuBar *>(q) ?
how i do ?
)

  // ** my constructor!
    CtrlLayout ( *this, "Window title" );
    //menup is MenuBar created with layoutfile! 
    menup.Set([=](Bar& bar) {
        bar.Sub("Cadastros", [=](Bar& bar) {
            bar.Sub("Contas",[=](Bar& bar){
                bar.Sub("Disponibilidades",[=](Bar& bar){
                bar.Add(false,"Caixa", THISFN(go1));     
                bar.Add("Bancos", THISFN(go2));     
              });
              bar.Add("Despesas", THISFN(go3));  
            });
            bar.Add("Clientes", THISFN(go4));
        });
        bar.Add("Sai", THISBACK(Close));
    });




note: I didn't find anything similar on the forum!

Thanks!
Re: query , update menu / submenu itens [message #58347 is a reply to message #58345] Wed, 04 May 2022 16:00 Go to previous messageGo to next message
BetoValle is currently offline  BetoValle
Messages: 202
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
Hi, see

"I hit my head" and reached the maximum only in gaining access to the 2 menu items (Register and Sai) that are on the 1st level:


          LOG("HERE " << bar.GetFirstChild()->GetFirstChild()->GetDesc());
          LOG("HERE next " << bar.GetFirstChild()->GetFirstChild()->GetNext()->GetDesc());



from then on I can't get the submenu items because in the 1st item (Registers) it returns that it has no child!

        LOG("CHILD ? " <<  bar.GetFirstChild()->GetFirstChild()->GetChildCount() );


Could someone with more knowledge suggest something? Or even if this would be the way?
Note that at runtime, the U++ user could change the description of an item, or delete an item/sub-item, or disable/deactivate temporarily.

Thanks!

Re: query , update menu / submenu itens [message #58348 is a reply to message #58345] Thu, 05 May 2022 14:44 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
You probably can with some really great effort, but this is really bad way how to achieve dynamic menus.

Instead, you can do this:

void MyApp::CastradosMenu(Bar& bar)
{
    bar.Add(my_name, [=] { PromptOK("something") });
    if(should_have_something)
       bar.Add("something", ...);
....
}

MyApp::MyApp() {
    menup.Set([=](Bar& bar) {
        bar.Sub("Cadastros", [=](Bar& bar) { CastradosMenu(bar); });
    });
}


Now CastradosMenu will only get invoked when it gets open, so you can fully programatically setup its content.

Mirek
Re: query , update menu / submenu itens [message #58349 is a reply to message #58348] Thu, 05 May 2022 18:54 Go to previous messageGo to next message
BetoValle is currently offline  BetoValle
Messages: 202
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
thanks Mirek!

Do you know what made me put this post on menu? another post about ide bookmark! Then I tried to understand there, but first I needed to know more about the menu. And precisely about this situation I identified that the way it is programmed in IDE,
there is no option to unmark the marked bookmark!
https:// www.ultimatepp.org/forums/index.php?t=msg&th=11805&s tart=0&
But there it is quite complex to understand how to do this!
Re: query , update menu / submenu itens [message #58350 is a reply to message #58349] Thu, 05 May 2022 20:11 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
Hello BetoValle,

Mirek has alredy pointed to the right direction.

To give you the idea, just try the below rudimentary example.


It appends a simple, programmable popup menu to an array.
To program the menu, simply right click on the array and change its attributes or content...

#include <CtrlLib/Ctr<lLib.h>

using namespace Upp;

struct MenuTest : TopWindow {
	ArrayCtrl list;

	MenuTest()
	{
		SetRect(0, 0, 1024, 768);
		Sizeable().Zoomable().CenterScreen();
		
		// Let's Configure the array.
		Add(list.SizePos());
		list.AddColumn("Text").Edit(Single<EditString>());
		list.AddColumn("State").Ctrls<Option>();
		list.ColumnWidths("200, 20");
		list.Moving().Track().Appending().Removing().SetEditable();
		
		// Fill the array.
		for(int i = 0; i < 10; i++)
			list.Add(AsString(i), (bool) false);
		
		// Override the popup menu of the array
		list.WhenBar = [=](Bar& bar) {
			// RE-add the main popup menu of ArrayCtrl.
			list.StdBar(bar);
			int n = list.GetCount(); // Don't append the user menu to the array menu if the array is empty...
			if(n <= 0)
				return;
			bar.Separator();
			for(int i = 0; i < list.GetCount(); i++) {
				bool   enable = list.Get(i, 1);
				String text   = list.Get(i, 0);
				bar.Add(enable, text, [=]{ PromptOK(text); }); // action!
			}
		};
		
	}

};

GUI_APP_MAIN
{
	MenuTest().Run();
}





Best regards,
Oblivion


[Updated on: Thu, 05 May 2022 20:15]

Report message to a moderator

Re: query , update menu / submenu itens [message #58352 is a reply to message #58350] Fri, 06 May 2022 03:40 Go to previous message
BetoValle is currently offline  BetoValle
Messages: 202
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member

it may be old, but the idea takes creative shortcuts!

thanks!
Previous Topic: menu's small box when i18n
Next Topic: Accelerators stop after popup menu due to focus
Goto Forum:
  


Current Time: Thu Mar 28 21:14:30 CET 2024

Total time taken to generate the page: 0.01991 seconds