Index: src/Actions/SelectionAction/MoleculeByOrderAction.cpp
===================================================================
--- src/Actions/SelectionAction/MoleculeByOrderAction.cpp	(revision fd19ffcfb7e86ca4783fbcedf0584c4608df7c1c)
+++ src/Actions/SelectionAction/MoleculeByOrderAction.cpp	(revision fd19ffcfb7e86ca4783fbcedf0584c4608df7c1c)
@@ -0,0 +1,117 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C)  2010 University of Bonn. All rights reserved.
+ * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
+ */
+
+/*
+ * MoleculeByOrderAction.cpp
+ *
+ *  Created on: May 12, 2010
+ *      Author: heber
+ */
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "Helpers/MemDebug.hpp"
+
+#include "molecule.hpp"
+#include "Helpers/Log.hpp"
+#include "Helpers/Verbose.hpp"
+#include "World.hpp"
+
+#include <iostream>
+#include <string>
+
+using namespace std;
+
+#include "Actions/SelectionAction/MoleculeByOrderAction.hpp"
+
+// and construct the stuff
+#include "MoleculeByOrderAction.def"
+#include "Action_impl_pre.hpp"
+/** =========== define the function ====================== */
+
+molecule * SearchMoleculeByOrder(int molindex)
+{
+  molecule *mol = NULL;
+  std::vector<molecule *> molecules = World::getInstance().getAllMolecules();
+  int i=0;
+  if (molindex > 0) {
+    std::vector<molecule *>::const_iterator iter = molecules.begin();
+    for (;iter != molecules.end();++iter) {
+      ++i;
+      if (molindex == i)
+        break;
+    }
+    mol = *iter;
+  } else {
+    std::vector<molecule *>::const_reverse_iterator iter = molecules.rbegin();
+    for (;iter != molecules.rend();--iter) {
+      --i;
+      if (molindex == i)
+        break;
+    }
+    mol = *iter;
+  }
+
+  return mol;
+}
+
+Action::state_ptr SelectionMoleculeByOrderAction::performCall() {
+  // obtain information
+  getParametersfromValueStorage();
+
+  molecule *mol = SearchMoleculeByOrder(params.molindex);
+
+  if (mol != NULL) {
+    if (!World::getInstance().isSelected(mol)) {
+      DoLog(1) && (Log() << Verbose(1) << "Selecting molecule " << mol->name << endl);
+      World::getInstance().selectMolecule(mol);
+      return Action::state_ptr(new SelectionMoleculeByOrderState(params));
+    } else {
+      return Action::success;
+    }
+  } else {
+    return Action::failure;
+  }
+}
+
+Action::state_ptr SelectionMoleculeByOrderAction::performUndo(Action::state_ptr _state) {
+  SelectionMoleculeByOrderState *state = assert_cast<SelectionMoleculeByOrderState*>(_state.get());
+
+  molecule *mol = SearchMoleculeByOrder(state->params.molindex);
+
+  if (mol != NULL) {
+    World::getInstance().unselectMolecule(mol);
+    return Action::state_ptr(_state);
+  } else {
+    return Action::failure;
+  }
+}
+
+Action::state_ptr SelectionMoleculeByOrderAction::performRedo(Action::state_ptr _state){
+  SelectionMoleculeByOrderState *state = assert_cast<SelectionMoleculeByOrderState*>(_state.get());
+
+  molecule *mol = SearchMoleculeByOrder(state->params.molindex);
+
+  if (mol != NULL) {
+    World::getInstance().selectMolecule(mol);
+    return Action::state_ptr(state);
+  } else {
+    return Action::failure;
+  }
+}
+
+bool SelectionMoleculeByOrderAction::canUndo() {
+  return true;
+}
+
+bool SelectionMoleculeByOrderAction::shouldUndo() {
+  return true;
+}
+/** =========== end of function ====================== */
Index: src/Actions/SelectionAction/MoleculeByOrderAction.def
===================================================================
--- src/Actions/SelectionAction/MoleculeByOrderAction.def	(revision fd19ffcfb7e86ca4783fbcedf0584c4608df7c1c)
+++ src/Actions/SelectionAction/MoleculeByOrderAction.def	(revision fd19ffcfb7e86ca4783fbcedf0584c4608df7c1c)
@@ -0,0 +1,33 @@
+/*
+ * MoleculeByIdAction.def
+ *
+ *  Created on: Aug 26, 2010
+ *      Author: heber
+ */
+
+// all includes and forward declarations necessary for non-integral types below
+class molecule;
+
+// i.e. there is an integer with variable name Z that can be found in
+// ValueStorage by the token "Z" -> first column: int, Z, "Z"
+// "undefine" if no parameters are required, use (NODEFAULT) for each (undefined) default value
+#define paramtypes (int)
+#define paramtokens ("select-molecule-by-order")
+#define paramdescriptions ("molecule order index, start at 1 or -1")
+#undef paramdefaults
+#define paramreferences (molindex)
+
+#undef statetypes
+#undef statereferences
+
+// some defines for all the names, you may use ACTION, STATE and PARAMS
+#define CATEGORY Selection
+#define MENUNAME "selection"
+#define MENUPOSITION 9
+#define ACTIONNAME MoleculeByOrder
+#define TOKEN "select-molecule-by-order"
+
+
+// finally the information stored in the ActionTrait specialization
+#define DESCRIPTION "select a molecule by order of appearance"
+#undef SHORTFORM
Index: src/Actions/SelectionAction/MoleculeByOrderAction.hpp
===================================================================
--- src/Actions/SelectionAction/MoleculeByOrderAction.hpp	(revision fd19ffcfb7e86ca4783fbcedf0584c4608df7c1c)
+++ src/Actions/SelectionAction/MoleculeByOrderAction.hpp	(revision fd19ffcfb7e86ca4783fbcedf0584c4608df7c1c)
@@ -0,0 +1,16 @@
+/*
+ * MoleculeByOrderAction.hpp
+ *
+ *  Created on: May 12, 2010
+ *      Author: heber
+ */
+
+#ifndef MOLECULEBYORDERACTION_HPP_
+#define MOLECULEBYORDERACTION_HPP_
+
+#include "Actions/Action.hpp"
+
+#include "MoleculeByOrderAction.def"
+#include "Action_impl_header.hpp"
+
+#endif /* MOLECULEBYORDERACTION_HPP_ */
