Bo Peng wrote:
On 10/8/07, Bo Peng <[EMAIL PROTECTED]> wrote:
Attached is a more polished patch,
So, what is the purpose of this inset? Only to display the shortcut or
also to modify them? If advantage of displaying it inside LyX is of be
able to generate the documentation automatically, which is good. But if
the purpose is ultimately to modify the shortcuts, I think that we
cannot escape the full blown GUI solution.
Some style comments below,
Abdel.
Index: src/insets/InsetInfo.cpp
===================================================================
--- src/insets/InsetInfo.cpp (revision 0)
+++ src/insets/InsetInfo.cpp (revision 0)
@@ -0,0 +1,150 @@
+/**
+ * \file InsetInfo.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Bo Peng
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+#include <config.h>
+
+#include "InsetInfo.h"
+
+#include "gettext.h"
+#include "Lexer.h"
+#include "MetricsInfo.h"
+#include "BufferView.h"
+
+// for shortcut:blah
+#include "KeyMap.h"
+#include "LyXAction.h"
+#include "FuncRequest.h"
+// for lyxrc:blah
+#include "LyXRC.h"
Alphabetic order please.
+#include <sstream>
Should go after our header.
+
+#include "support/lstrings.h"
+
+#include "debug.h"
+
+namespace lyx {
+
+using std::string;
+using std::ostream;
+using std::ostringstream;
Should be declared outside our namespace.
+
+using support::prefixIs;
+using support::trim;
+using support::rtrim;
+
+InsetInfo::InsetInfo(string const & name)
+ : name_(name),
+ mouse_hover_(false)
+{
+ info_ = getInfo();
This is not an external method so this would look better:
+ updateInfo();
+void InsetInfo::draw(PainterInfo & pi, int x, int y) const
+{
+ button_.draw(pi, x, y);
+ if (mouse_hover_)
+ pi.base.bv->message(from_utf8("Info: " + name_));
translation maybe?
+ pi.base.bv->message(_("Info: " + name_));
+
+/*
+This function interpret name_ and return its associated name.
+Currently, the supported names are:
+
+shortcut:font-bold (the same as in the bind file)
+lyxrc:rc_entries
+
+I am not sure if it is a good idea to add
+
+buffer:buffer_params
+
+The problem is that those are not 'stable' information.
What do you mean by stable? That they can change within an editing
context? I guess what you want to discribe is the document class and
associated layout, don't you?
+*/
+docstring InsetInfo::getInfo() const
As said above I think this would look better.
+void InsetInfo::updateInfo() const
+ case LFUN_INFO_INSERT: {
+ if (!cur.selection())
+ break;
+ Inset * inset = createInset(&cur.bv(), cmd);
+ if (!inset)
+ break;
+ // use selected text as info to avoid a separate UI
+ docstring ds = cur.selectionAsString(false);
+ cutSelection(cur, true, false);
+ insertInset(cur, inset);
+ static_cast<InsetInfo *>(inset)->setInfo(to_utf8(ds));
Isn't it possible to set the info within the ctor in order to avoid this
static_cast?