Shows accelerator keys on the right side of the FMenu

This commit is contained in:
Markus Gans 2015-11-12 23:14:12 +01:00
parent 6fd2e7c650
commit ca60b762a7
6 changed files with 85 additions and 37 deletions

View File

@ -1,5 +1,6 @@
2015-11-12 Markus Gans <guru.mail@muenster.de> 2015-11-12 Markus Gans <guru.mail@muenster.de>
* Improve menu accelerator keys * Improve menu accelerator keys
* Shows accelerator keys on the right side of the FMenu.
2015-11-08 Markus Gans <guru.mail@muenster.de> 2015-11-08 Markus Gans <guru.mail@muenster.de>
* Activate the previous window in case if the menu is open and * Activate the previous window in case if the menu is open and

View File

@ -416,31 +416,31 @@ keyname;
static keyname FkeyName[] = static keyname FkeyName[] =
{ {
{ fc::Fckey_at , "Ctrl+@" }, { fc::Fckey_at , "Ctrl+@" },
{ fc::Fckey_a , "Ctrl+a" }, { fc::Fckey_a , "Ctrl+A" },
{ fc::Fckey_b , "Ctrl+b" }, { fc::Fckey_b , "Ctrl+B" },
{ fc::Fckey_c , "Ctrl+c" }, { fc::Fckey_c , "Ctrl+C" },
{ fc::Fckey_d , "Ctrl+d" }, { fc::Fckey_d , "Ctrl+D" },
{ fc::Fckey_e , "Ctrl+e" }, { fc::Fckey_e , "Ctrl+E" },
{ fc::Fckey_f , "Ctrl+f" }, { fc::Fckey_f , "Ctrl+F" },
{ fc::Fckey_g , "Ctrl+g" }, { fc::Fckey_g , "Ctrl+G" },
{ fc::Fkey_erase , "Backspace" }, // Ctrl+h { fc::Fkey_erase , "Backspace" }, // Ctrl+H
{ fc::Fkey_tab , "Tab" }, // Ctrl+i { fc::Fkey_tab , "Tab" }, // Ctrl+I
{ fc::Fckey_h , "Ctrl+k" }, { fc::Fckey_h , "Ctrl+K" },
{ fc::Fckey_l , "Ctrl+l" }, { fc::Fckey_l , "Ctrl+L" },
{ fc::Fkey_return , "Return" }, // Ctrl+m { fc::Fkey_return , "Return" }, // Ctrl+M
{ fc::Fckey_n , "Ctrl+n" }, { fc::Fckey_n , "Ctrl+N" },
{ fc::Fckey_o , "Ctrl+o" }, { fc::Fckey_o , "Ctrl+O" },
{ fc::Fckey_p , "Ctrl+p" }, { fc::Fckey_p , "Ctrl+P" },
{ fc::Fckey_q , "Ctrl+q" }, { fc::Fckey_q , "Ctrl+Q" },
{ fc::Fckey_r , "Ctrl+r" }, { fc::Fckey_r , "Ctrl+R" },
{ fc::Fckey_s , "Ctrl+s" }, { fc::Fckey_s , "Ctrl+S" },
{ fc::Fckey_t , "Ctrl+t" }, { fc::Fckey_t , "Ctrl+T" },
{ fc::Fckey_u , "Ctrl+u" }, { fc::Fckey_u , "Ctrl+U" },
{ fc::Fckey_v , "Ctrl+v" }, { fc::Fckey_v , "Ctrl+V" },
{ fc::Fckey_w , "Ctrl+w" }, { fc::Fckey_w , "Ctrl+W" },
{ fc::Fckey_x , "Ctrl+x" }, { fc::Fckey_x , "Ctrl+X" },
{ fc::Fckey_y , "Ctrl+y" }, { fc::Fckey_y , "Ctrl+Y" },
{ fc::Fckey_z , "Ctrl+t" }, { fc::Fckey_z , "Ctrl+Z" },
{ fc::Fkey_escape , "Esc" }, // Ctrl+[ { fc::Fkey_escape , "Esc" }, // Ctrl+[
{ fc::Fckey_backslash , "Ctrl+\\" }, { fc::Fckey_backslash , "Ctrl+\\" },
{ fc::Fckey_right_square_bracket, "Ctrl+]" }, { fc::Fckey_right_square_bracket, "Ctrl+]" },

View File

@ -127,12 +127,19 @@ void FMenu::menu_dimension()
std::vector<FMenuItem*>::const_iterator iter, end; std::vector<FMenuItem*>::const_iterator iter, end;
iter = itemlist.begin(); iter = itemlist.begin();
end = itemlist.end(); end = itemlist.end();
maxItemWidth = 10; maxItemWidth = 10; // minimum width
// find the max item width // find the maximum item width
while ( iter != end ) while ( iter != end )
{ {
uInt item_width = (*iter)->getTextLength() + 2; uInt item_width = (*iter)->getTextLength() + 2;
int accel_key = (*iter)->accel_key;
if ( accel_key )
{
uInt accel_len = getKeyName(accel_key).getLength();
item_width += accel_len + 2;
}
if ( item_width > maxItemWidth ) if ( item_width > maxItemWidth )
maxItemWidth = item_width; maxItemWidth = item_width;
@ -489,6 +496,7 @@ void FMenu::drawItems()
FString txt; FString txt;
uInt txt_length; uInt txt_length;
int hotkeypos, to_char; int hotkeypos, to_char;
int accel_key = (*iter)->accel_key;
bool is_enabled = (*iter)->isEnabled(); bool is_enabled = (*iter)->isEnabled();
bool is_selected = (*iter)->isSelected(); bool is_selected = (*iter)->isSelected();
bool is_noUnderline = (((*iter)->getFlags() & NO_UNDERLINE) != 0); bool is_noUnderline = (((*iter)->getFlags() & NO_UNDERLINE) != 0);
@ -575,6 +583,19 @@ void FMenu::drawItems()
print (item_text[z]); print (item_text[z]);
} }
if ( accel_key )
{
FString accel_name (getKeyName(accel_key));
int accel_len = int(accel_name.getLength());
int len = maxItemWidth - (to_char + accel_len + 2);
if ( len > 0 )
{
FString line(len, wchar_t(' '));
print (line + accel_name);
to_char = maxItemWidth - 2;
}
}
if ( is_selected ) if ( is_selected )
{ {
for (uInt i=uInt(to_char); i < maxItemWidth-1; i++) for (uInt i=uInt(to_char); i < maxItemWidth-1; i++)

View File

@ -64,7 +64,7 @@ void FMenuBar::menu_dimension()
iter = itemlist.begin(); iter = itemlist.begin();
end = itemlist.end(); end = itemlist.end();
// find the max item width // find the maximum item width
while ( iter != end ) while ( iter != end )
{ {
uInt len = (*iter)->getTextLength(); uInt len = (*iter)->getTextLength();

View File

@ -125,7 +125,9 @@ FMenuItem::FMenuItem (int k, const char* txt, FWidget* parent)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FMenuItem::~FMenuItem() // destructor FMenuItem::~FMenuItem() // destructor
{ } {
delAccelerator();
}
// private methods of FMenuItem // private methods of FMenuItem
@ -260,6 +262,8 @@ void FMenuItem::processClicked()
void FMenuItem::addAccelerator (int key, FWidget* obj) void FMenuItem::addAccelerator (int key, FWidget* obj)
{ {
FWidget* super = super_menu; FWidget* super = super_menu;
if ( ! super )
return;
while ( super && strncmp ( super->getClassName() while ( super && strncmp ( super->getClassName()
, const_cast<char*>("FMenu"), 5) == 0 ) , const_cast<char*>("FMenu"), 5) == 0 )
@ -275,7 +279,17 @@ void FMenuItem::addAccelerator (int key, FWidget* obj)
if ( ! window ) if ( ! window )
window = getRootWidget(); window = getRootWidget();
if ( window && window->accelerator_list ) if ( window && window->accelerator_list )
{
accel_key = key;
window->accelerator_list->push_back(accel); window->accelerator_list->push_back(accel);
}
}
if ( isMenu(super_menu) )
{
FMenu* menu_ptr = dynamic_cast<FMenu*>(super_menu);
if ( menu_ptr )
menu_ptr->menu_dimension();
} }
} }
@ -283,6 +297,8 @@ void FMenuItem::addAccelerator (int key, FWidget* obj)
void FMenuItem::delAccelerator (FWidget* obj) void FMenuItem::delAccelerator (FWidget* obj)
{ {
FWidget* super = super_menu; FWidget* super = super_menu;
if ( ! super )
return;
while ( super && strncmp ( super->getClassName() while ( super && strncmp ( super->getClassName()
, const_cast<char*>("FMenu"), 5) == 0 ) , const_cast<char*>("FMenu"), 5) == 0 )
@ -306,12 +322,22 @@ void FMenuItem::delAccelerator (FWidget* obj)
while ( iter != window->accelerator_list->end() ) while ( iter != window->accelerator_list->end() )
{ {
if ( iter->object == obj ) if ( iter->object == obj )
{
accel_key = 0;
iter = window->accelerator_list->erase(iter); iter = window->accelerator_list->erase(iter);
}
else else
++iter; ++iter;
} }
} }
} }
if ( isMenu(super_menu) )
{
FMenu* menu_ptr = dynamic_cast<FMenu*>(super_menu);
if ( menu_ptr )
menu_ptr->menu_dimension();
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -219,9 +219,9 @@ MyDialog::MyDialog (FWidget* parent)
Quit->setStatusbarMessage ("Exit the program"); Quit->setStatusbarMessage ("Exit the program");
// "Edit" menu items // "Edit" menu items
FMenuItem* Undo = new FMenuItem ("Undo", Edit); FMenuItem* Undo = new FMenuItem (fc::Fckey_z, "Undo", Edit);
Undo->setDisable(); Undo->setDisable();
FMenuItem* Redo = new FMenuItem ("Redo", Edit); FMenuItem* Redo = new FMenuItem (fc::Fckey_y, "Redo", Edit);
Redo->setDisable(); Redo->setDisable();
FMenuItem* Line2 = new FMenuItem (Edit); FMenuItem* Line2 = new FMenuItem (Edit);
Line2->setSeparator(); Line2->setSeparator();
@ -231,11 +231,11 @@ MyDialog::MyDialog (FWidget* parent)
Copy->setStatusbarMessage ("Copy the input text into the clipboad"); Copy->setStatusbarMessage ("Copy the input text into the clipboad");
FMenuItem* Paste = new FMenuItem (fc::Fckey_v, "&Paste", Edit); FMenuItem* Paste = new FMenuItem (fc::Fckey_v, "&Paste", Edit);
Paste->setStatusbarMessage ("Insert text form clipboard"); Paste->setStatusbarMessage ("Insert text form clipboard");
FMenuItem* Clear = new FMenuItem ("C&lear", Edit); FMenuItem* Clear = new FMenuItem (fc::Fkey_dc, "C&lear", Edit);
Clear->setStatusbarMessage ("Delete input text"); Clear->setStatusbarMessage ("Delete input text");
// "View" menu items // "View" menu items
FMenuItem* Env = new FMenuItem ("&Terminal info...", View); FMenuItem* Env = new FMenuItem ("&Terminal...", View);
Env->setStatusbarMessage ("Informations about this terminal"); Env->setStatusbarMessage ("Informations about this terminal");
FMenuItem* Drive = new FMenuItem ("&Drive symbols...", View); FMenuItem* Drive = new FMenuItem ("&Drive symbols...", View);
Drive->setStatusbarMessage ("Show drive symbols"); Drive->setStatusbarMessage ("Show drive symbols");