added :Export / :Setenv command

This commit is contained in:
akir 2004-10-06 11:40:28 +00:00
parent 997d7d7224
commit 6f96757fc4
3 changed files with 38 additions and 4 deletions

View file

@ -20,7 +20,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// $Id: FbCommandFactory.cc,v 1.35 2004/09/16 14:58:28 rathnor Exp $
// $Id: FbCommandFactory.cc,v 1.36 2004/10/06 11:40:28 akir Exp $
#include "FbCommandFactory.hh"
@ -66,6 +66,7 @@ FbCommandFactory::FbCommandFactory() {
"commanddialog",
"deiconify",
"detachclient",
"export",
"exec",
"execcommand",
"execute",
@ -116,6 +117,7 @@ FbCommandFactory::FbCommandFactory() {
"rightworkspace",
"rootmenu",
"saverc",
"setenv",
"sendtoworkspace",
"sendtonextworkspace",
"sendtoprevworkspace",
@ -176,8 +178,21 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command,
return new SaveResources();
else if (command == "execcommand" || command == "execute" || command == "exec")
return new ExecuteCmd(arguments); // execute command on key screen
else if (command == "exit")
else if (command == "exit")
return new ExitFluxboxCmd();
else if (command == "setenv" || command == "export") {
std::string name = arguments;
FbTk::StringUtil::removeFirstWhitespace(name);
FbTk::StringUtil::removeTrailingWhitespace(name);
size_t pos = name.find_first_of(command == "setenv" ? " \t" : "=");
if (pos == std::string::npos || pos == name.size())
return 0;
std::string value = name.substr(pos + 1);
name = name.substr(0, pos);
return new ExportCmd(name, value);
}
else if (command == "quit")
return new FbTk::SimpleCommand<Fluxbox>(*Fluxbox::instance(), &Fluxbox::shutdown);
else if (command == "commanddialog") // run specified fluxbox command

View file

@ -19,7 +19,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// $Id: FbCommands.cc,v 1.27 2004/09/11 20:28:35 fluxgen Exp $
// $Id: FbCommands.cc,v 1.28 2004/10/06 11:40:28 akir Exp $
#include "FbCommands.hh"
#include "fluxbox.hh"
@ -123,6 +123,15 @@ void ExecuteCmd::execute() {
}
ExportCmd::ExportCmd(const std::string& name, const std::string& value) :
m_name(name), m_value(value) {
}
void ExportCmd::execute() {
setenv(m_name.c_str(), m_value.c_str(), 1);
}
void ExitFluxboxCmd::execute() {
Fluxbox::instance()->shutdown();
}

View file

@ -19,7 +19,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// $Id: FbCommands.hh,v 1.19 2004/04/22 21:12:33 fluxgen Exp $
// $Id: FbCommands.hh,v 1.20 2004/10/06 11:40:28 akir Exp $
// \file contains basic commands to restart, reconfigure, execute command and exit fluxbox
@ -42,6 +42,16 @@ private:
const int m_screen_num;
};
/// sets environment
class ExportCmd : public FbTk::Command {
public:
ExportCmd(const std::string& name, const std::string& value);
void execute();
private:
std::string m_name;
std::string m_value;
};
/// exit fluxbox
class ExitFluxboxCmd: public FbTk::Command {
public: