]> git.lyx.org Git - features.git/blobdiff - src/insets/InsetInfo.cpp
Simplify VC output from InsetInfo.
[features.git] / src / insets / InsetInfo.cpp
index ca4c081e0198daa30561ebb88a5bc6e915dcbe0c..45aae5251954fa11074ad266960f277b0e50120d 100644 (file)
@@ -61,6 +61,7 @@ NameTranslator const initTranslator()
        translator.addPair(InsetInfo::MENU_INFO, "menu");
        translator.addPair(InsetInfo::ICON_INFO, "icon");
        translator.addPair(InsetInfo::BUFFER_INFO, "buffer");
+       translator.addPair(InsetInfo::LYX_INFO, "lyxinfo");
 
        return translator;
 }
@@ -162,7 +163,7 @@ bool InsetInfo::validateModifyArgument(docstring const & arg) const
        case MENU_INFO:
        case ICON_INFO: {
                FuncRequest func = lyxaction.lookupFunc(name);
-               return func.action_ != LFUN_UNKNOWN_ACTION;
+               return func.action() != LFUN_UNKNOWN_ACTION;
        }
        case LYXRC_INFO: {
                ostringstream oss;
@@ -176,6 +177,8 @@ bool InsetInfo::validateModifyArgument(docstring const & arg) const
                return name == "name" || name == "path" || name == "class" ||
                       name == "vcs-revision" || name == "vcs-tree-revision" ||
                       name == "vcs-author" || name == "vcs-date" || name == "vcs-time";
+       case LYX_INFO:
+               return name == "version";
        }
        return false;
 }
@@ -191,7 +194,7 @@ bool InsetInfo::showInsetDialog(BufferView * bv) const
 bool InsetInfo::getStatus(Cursor & cur, FuncRequest const & cmd,
                FuncStatus & flag) const
 {
-       switch (cmd.action_) {
+       switch (cmd.action()) {
        case LFUN_INSET_SETTINGS:
                return InsetCollapsable::getStatus(cur, cmd, flag);
                
@@ -215,7 +218,7 @@ bool InsetInfo::getStatus(Cursor & cur, FuncRequest const & cmd,
 void InsetInfo::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        // allow selection, copy but not cut, delete etc
-       switch (cmd.action_) {
+       switch (cmd.action()) {
        case LFUN_INSET_SETTINGS:
                InsetCollapsable::doDispatch(cur, cmd);
                break;
@@ -265,8 +268,8 @@ void InsetInfo::updateInfo()
                break;
        case SHORTCUT_INFO:
        case SHORTCUTS_INFO: {
-               FuncRequest func = lyxaction.lookupFunc(name_);
-               if (func.action_ == LFUN_UNKNOWN_ACTION) {
+               FuncRequest const func = lyxaction.lookupFunc(name_);
+               if (func.action() == LFUN_UNKNOWN_ACTION) {
                        error("Unknown action %1$s");
                        break;
                }
@@ -305,8 +308,8 @@ void InsetInfo::updateInfo()
        }
        case MENU_INFO: {
                docstring_list names;
-               FuncRequest func = lyxaction.lookupFunc(name_);
-               if (func.action_ == LFUN_UNKNOWN_ACTION) {
+               FuncRequest const func = lyxaction.lookupFunc(name_);
+               if (func.action() == LFUN_UNKNOWN_ACTION) {
                        error("Unknown action %1$s");
                        break;
                }
@@ -360,31 +363,46 @@ void InsetInfo::updateInfo()
                break;
        }
        case BUFFER_INFO: {
-               if (name_ == "name")
+               if (name_ == "name") {
                        setText(from_utf8(buffer().fileName().onlyFileName()));
-               else if (name_ == "path")
+                       break;
+               }
+               if (name_ == "path") {
                        setText(from_utf8(buffer().filePath()));
-               else if (name_ == "class")
+                       break;
+               }
+               if (name_ == "class") {
                        setText(from_utf8(bp.documentClass().name()));
-               else if (name_ == "vcs-revision" && buffer().lyxvc().inUse() &&
-                        !buffer().lyxvc().revisionInfo(LyXVC::File).empty())
-                       setText(from_utf8(buffer().lyxvc().revisionInfo(LyXVC::File)));
-               else if (name_ == "vcs-tree-revision" && buffer().lyxvc().inUse() &&
-                        !buffer().lyxvc().revisionInfo(LyXVC::Tree).empty())
-                       setText(from_utf8(buffer().lyxvc().revisionInfo(LyXVC::Tree)));
-               else if (name_ == "vcs-author" && buffer().lyxvc().inUse() &&
-                        !buffer().lyxvc().revisionInfo(LyXVC::Author).empty())
-                       setText(from_utf8(buffer().lyxvc().revisionInfo(LyXVC::Author)));
-               else if (name_ == "vcs-time" && buffer().lyxvc().inUse() &&
-                        !buffer().lyxvc().revisionInfo(LyXVC::Time).empty())
-                       setText(from_utf8(buffer().lyxvc().revisionInfo(LyXVC::Time)));
-               else if (name_ == "vcs-date" && buffer().lyxvc().inUse() &&
-                        !buffer().lyxvc().revisionInfo(LyXVC::Date).empty())
-                       setText(from_utf8(buffer().lyxvc().revisionInfo(LyXVC::Date)));
+                       break;
+               }
+               
+               // everything that follows is for version control.
+               // nothing that isn't version control should go below this line.
+               if (!buffer().lyxvc().inUse()) {
+                       setText(_("No version control"));
+                       break;
+               }
+               LyXVC::RevisionInfo itype = LyXVC::Unknown;
+               if (name_ == "vcs-revision")
+                       itype = LyXVC::File;
+               else if (name_ == "vcs-tree-revision")
+                       itype = LyXVC::Tree;
+               else if (name_ == "vcs-author")
+                       itype = LyXVC::Author;
+               else if (name_ == "vcs-time")
+                       itype = LyXVC::Time;
+               else if (name_ == "vcs-date")
+                       itype = LyXVC::Date;
+               string binfo = buffer().lyxvc().revisionInfo(itype);
+               if (binfo.empty())
+                       setText(bformat(_("[[%1$s unknown]]"), name_));
                else
-                       setText(_("Unknown buffer info"));
+                       setText(from_utf8(binfo));
                break;
        }
+       case LYX_INFO:
+               if (name_ == "version")
+                       setText(from_ascii(PACKAGE_VERSION));
        }
 }