Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
8bb5eaa4
Commit
8bb5eaa4
authored
May 13, 2014
by
Maciej Suminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better way of adding CONTEXT_MENU entries.
parent
1cbf03cb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
37 deletions
+18
-37
context_menu.cpp
common/tool/context_menu.cpp
+18
-29
context_menu.h
include/tool/context_menu.h
+0
-8
No files found.
common/tool/context_menu.cpp
View file @
8bb5eaa4
...
@@ -101,17 +101,28 @@ void CONTEXT_MENU::Add( const TOOL_ACTION& aAction )
...
@@ -101,17 +101,28 @@ void CONTEXT_MENU::Add( const TOOL_ACTION& aAction )
{
{
/// ID numbers for tool actions need to have a value higher than m_actionId
/// ID numbers for tool actions need to have a value higher than m_actionId
int
id
=
m_actionId
+
aAction
.
GetId
();
int
id
=
m_actionId
+
aAction
.
GetId
();
wxString
menuEntry
;
wxMenuItem
*
item
=
new
wxMenuItem
(
&
m_menu
,
id
,
wxString
(
aAction
.
GetMenuItem
().
c_str
(),
wxConvUTF8
),
wxString
(
aAction
.
GetDescription
().
c_str
(),
wxConvUTF8
),
wxITEM_NORMAL
);
if
(
aAction
.
HasHotKey
()
)
if
(
aAction
.
HasHotKey
()
)
menuEntry
=
wxString
(
(
aAction
.
GetMenuItem
()
+
'\t'
+
{
getHotKeyDescription
(
aAction
)
).
c_str
(),
wxConvUTF8
)
;
int
key
=
aAction
.
GetHotKey
()
&
~
MD_MODIFIER_MASK
;
else
int
mod
=
aAction
.
GetHotKey
()
&
MD_MODIFIER_MASK
;
menuEntry
=
wxString
(
aAction
.
GetMenuItem
().
c_str
(),
wxConvUTF8
)
;
wxAcceleratorEntryFlags
flags
=
wxACCEL_NORMAL
;
m_menu
.
Append
(
new
wxMenuItem
(
&
m_menu
,
id
,
menuEntry
,
switch
(
mod
)
wxString
(
aAction
.
GetDescription
().
c_str
(),
wxConvUTF8
),
wxITEM_NORMAL
)
);
{
case
MD_ALT
:
flags
=
wxACCEL_ALT
;
break
;
case
MD_CTRL
:
flags
=
wxACCEL_CTRL
;
break
;
case
MD_SHIFT
:
flags
=
wxACCEL_SHIFT
;
break
;
}
item
->
SetAccel
(
new
wxAcceleratorEntry
(
flags
,
key
,
id
,
item
)
);
}
m_menu
.
Append
(
item
);
m_toolActions
[
id
]
=
&
aAction
;
m_toolActions
[
id
]
=
&
aAction
;
}
}
...
@@ -128,28 +139,6 @@ void CONTEXT_MENU::Clear()
...
@@ -128,28 +139,6 @@ void CONTEXT_MENU::Clear()
}
}
std
::
string
CONTEXT_MENU
::
getHotKeyDescription
(
const
TOOL_ACTION
&
aAction
)
const
{
int
hotkey
=
aAction
.
GetHotKey
();
std
::
string
description
=
""
;
if
(
hotkey
&
MD_ALT
)
description
+=
"ALT+"
;
if
(
hotkey
&
MD_CTRL
)
description
+=
"CTRL+"
;
if
(
hotkey
&
MD_SHIFT
)
description
+=
"SHIFT+"
;
// TODO dispatch keys such as Fx, TAB, PG_UP/DN, HOME, END, etc.
description
+=
char
(
hotkey
&
~
MD_MODIFIER_MASK
);
return
description
;
}
void
CONTEXT_MENU
::
CMEventHandler
::
onEvent
(
wxEvent
&
aEvent
)
void
CONTEXT_MENU
::
CMEventHandler
::
onEvent
(
wxEvent
&
aEvent
)
{
{
TOOL_EVENT
evt
;
TOOL_EVENT
evt
;
...
...
include/tool/context_menu.h
View file @
8bb5eaa4
...
@@ -128,14 +128,6 @@ private:
...
@@ -128,14 +128,6 @@ private:
m_tool
=
aTool
;
m_tool
=
aTool
;
}
}
/**
* Function getHotKeyDescription()
* Returns a hot key in the string format accepted by wxMenu.
* @param aAction is the action with hot key to be translated..
* @return Hot key in the string format compatible with wxMenu.
*/
std
::
string
getHotKeyDescription
(
const
TOOL_ACTION
&
aAction
)
const
;
///> Flag indicating that the menu title was set up.
///> Flag indicating that the menu title was set up.
bool
m_titleSet
;
bool
m_titleSet
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment