ouch, that coding styles - i am mixing different styles from different 
projects...
thanks abdel, i will rework it acordingly.

bernhard

Abdelrazak Younes schrieb:
Bernhard Roider wrote:
Andre Poenitz schrieb:
On Fri, Oct 05, 2007 at 12:24:45AM +0200, Bernhard Roider wrote:
hello all,

the attached patch adds
- the possibility to define macros in the bind file, like

\define "my macro" "command-sequence inset-insert ert 1; char-backward; self-insert some important latex code; char-forward"

- the lfun "call" to execute that macro. this call can be used in key bindings (\bind "X-y" "call my macro") menus and toolbar definitions (Item "My complex ert" "call my macro") as well as in the command buffer ("call my macro").

the benefits from that:
+ customization is easier because the definition is done in one place and can be used as descriebed above + it is possible to add complex commands (like the one above) to the toolbar with an image on the button, because the image name used equals the macro name ("my macro.png" in the above example)

oppinions?

Patch is too short.


so here it is, now tested as i managed to compile again (after hours of investigation and no idea what the real problem was).

if there are no objections i'll commit later this week

Looks good and this is a very welcome feature. Some not very important style comments:

+/// information for a macro
+struct LyXAction::macro_info {

macroInfo please.

+    /// the expanded FuncRequest
+    FuncRequest func;
+    /// to avoid recursive calls
+    bool locked;
+};

A ctor is missing so that you can replace this:

+    macro_info * info = new macro_info;
+    info->func = func;
+    info->locked = false;
+    lyx_macro_map[name] = info;

with:
+    lyx_macro_map[name] = new macroInfo(func, false);


+LyXAction::~LyXAction()
+{
+    macro_map::iterator pos = lyx_macro_map.begin();
+    while (pos != lyx_macro_map.end()) {
+        delete pos->second;
+        ++pos;
+    }

This is better optimization wise:

+    macro_map::iterator end = lyx_macro_map.end();
+ for (macro_map::iterator pos = lyx_macro_map.begin(); pos != end; ++pos)
+        delete pos->second;


+    /// possible reasons for not allowed macros
+    enum new_macro_error {

I think NewMacroError is more according to our coding rule.

+        MacroOk,
+        MacroNameEmpty,
+        MacroDefInvalid,
+        MacroExists

And I am not sure about these...



+    case LFUN_CALL: {
+        FuncRequest func;
+        std::string name(to_utf8(cmd.argument()));
+        if (lyxaction.lockMacro(name, func)) {
+            func.origin = cmd.origin;
+            flag = getStatus(func);
+            lyxaction.releaseMacro(name);
+        } else {
+            // catch recursion
+ // all operations until the recursion occures are performed, so
+            // set the state to enabled

Hum, if the recursion problem is frequent, this deserve an alert dialog to the user. You can use ExceptionMessage if you prefer.

Abdel.



Reply via email to