[Uml-devel] CVS: kdesdk/umbrello/umbrello umbrelloui.rc,1.4,1.5 uml.cpp,1.11,1.12

kde at office.kde.org kde at office.kde.org
Mon Feb 3 14:43:06 UTC 2003


Update of /home/kde/kdesdk/umbrello/umbrello
In directory office:/tmp/cvs-serv3895/umbrello/umbrello

Modified Files:
	umbrelloui.rc uml.cpp 
Log Message:
Inserting our two dynamically generated menus (active language and zoom)
at hard-wired position menu->count() - x was ugly and dangerous.
Fixed. We now let KDE create the (empty) menus and we get a hold of them
and insert our menu entries.


Index: umbrelloui.rc
===================================================================
RCS file: /home/kde/kdesdk/umbrello/umbrello/umbrelloui.rc,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- umbrelloui.rc	3 Feb 2003 15:44:12 -0000	1.4
+++ umbrelloui.rc	3 Feb 2003 22:42:20 -0000	1.5
@@ -22,6 +22,8 @@
     <Action name="view_show_grid"/>
     <Action name="view_delete"/>
     <Action name="view_export_image"/>
+    <Menu name="zoom_menu"><text>&Zoom</text>
+    </Menu>
     <Action name="view_properties"/>
   </Menu>
 
@@ -34,6 +36,8 @@
     <Action name="generation_wizard"/>
     <Action name="generate_all"/>
     <Action name="configure_languages"/>
+    <Menu name="active_lang_menu"><text>Active &Language</text>
+    </Menu>
     <Separator/>
     <Action name="class_wizard"/>
   </Menu>

Index: uml.cpp
===================================================================
RCS file: /home/kde/kdesdk/umbrello/umbrello/uml.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- uml.cpp	3 Feb 2003 21:28:59 -0000	1.11
+++ uml.cpp	3 Feb 2003 22:42:20 -0000	1.12
@@ -42,9 +42,8 @@
 	config=kapp->config();
 	listView = 0;
 	ldict.setAutoDelete(true);
-	langSelect = new QPopupMenu(this);
-	zoomSelect = new QPopupMenu(this);
-
+	langSelect = 0L;
+	zoomSelect = 0L;
 	loading = false;
 	m_clipTimer = 0;
 	m_copyTimer = 0;
@@ -70,42 +69,75 @@
 	editCopy->setEnabled(false);
 	editPaste->setEnabled(false);
 
-	//insert Language Selection menu in "Code Generation" in the Menubar
-	// --> the name "Code Generation" as seen in the Menu is taken from .ui file..
-	// and depends on the language we are using (english, spanish, etc) so we need to
-	// look for the object name instead.
-	int t = menuBar() -> count();
-	int id=-1;
-	for( int i =0; i<t;i++) {
-		id = menuBar()->idAt(i);
-		if(id == -1)
-			break;
-		if(menuBar()->findItem(id)->popup()->name() == QString("code"))
-			break;
-	}
-	if(id!=-1) {
-		QPopupMenu *m = menuBar()->findItem(id)->popup();
-		if(m) {
-			m->insertItem(i18n("Active &Language"),langSelect,-1,m->count()-2);
+	//get a reference to the Code->Active Lanugage and to the Diagram->Zoom menu
+	//we need to search through the menuBar and the correspondig menus.
+	
+	QPopupMenu *menu = 0L;
+	int menu_count = menuBar() -> count();
+	
+	for( int i =0; i<menu_count; i++) 
+	{
+		if( menuBar()->findItem( menuBar()->idAt(i) )->popup()->name() == QString("code"))
+		{
+		//we've found the code menu
+			menu = menuBar()->findItem( menuBar()->idAt(i) )->popup();
+			menu_count = menu->count();
+			//look for the "active language" sub-menu
+			for( int i=0; i< menu_count; i++)
+			{
+				if(menu->findItem(menu->idAt(i))->popup() && 
+					menu->findItem( menu->idAt(i) )->popup()->name() == QString("active_lang_menu"))
+				{
+				//we found it. get a reference to it and get out.
+					langSelect = menu->findItem(menu->idAt(i))->popup();
+					break;
+				}
+			
+			}
+			
+		break;	
 		}
+	
 	}
+	
+	if(langSelect == 0L)
+	{//in case langSelect hasnt been initialized we create the Popup menu.
+	 //it will be hidden, but at least we wont crash if someone takes the entry away from the ui.rc file
+		langSelect = new QPopupMenu(this);
+	}		
 
-	//insert zoom menu. see comment above (language selection menu)
- 	id=-1;
-	for( int i =0; i<t;i++)
+ 	
+	menu = 0L;
+	menu_count = menuBar()->count();
+	for( int i =0; i<menu_count; i++ )
 	{
-		id = menuBar()->idAt(i);
-		if(id == -1)
-			break;
-		if(menuBar()->findItem(id)->popup()->name() == QString("views"))
-			break;
-	}
-	if(id!=-1) {
-		QPopupMenu *m = menuBar()->findItem(id)->popup();
-		if(m) {
-			m->insertItem(i18n("&Zoom"),zoomSelect,-1,m->count()-1);
+		if(menuBar()->findItem( menuBar()->idAt(i) )->popup()->name() == QString("views"))
+		{
+		//we've found the "Diagram" menu
+			menu = menuBar()->findItem( menuBar()->idAt(i) )->popup();
+			menu_count = menu->count();
+			//look for the "zoom" sub-menu
+			for( int i=0; i< menu_count; i++)
+			{
+				if(menu->findItem(menu->idAt(i))->popup() && 
+					menu->findItem(menu->idAt(i))->popup()->name() == QString("zoom_menu"))
+				{
+					zoomSelect = menu->findItem(menu->idAt(i))->popup();
+					break;
+				}
+			}
+		break;
 		}
 	}
+	
+		
+	if(zoomSelect == 0L)
+	{//in case zoomSelect hasnt been initialized we create the Popup menu.
+	 //it will be hidden, but at least we wont crash if some one takes the entry away from the ui.rc file
+		zoomSelect = new QPopupMenu(this);
+	}
+					
+	
 	//connect zoomSelect menu
 	zoomSelect->setCheckable(true);
 	connect(zoomSelect,SIGNAL(aboutToShow()),this,SLOT(setupZoomMenu()));





More information about the umbrello-devel mailing list