From 29c778459955d5aaa17e619f8acf09dc3ec1d9b2 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Sat, 20 Dec 2003 17:37:57 +0000 Subject: addBinding function and some cleaning --- src/Keys.cc | 172 +++++++++++++++++++++++++++++++++++------------------------- src/Keys.hh | 27 ++++++---- 2 files changed, 117 insertions(+), 82 deletions(-) diff --git a/src/Keys.cc b/src/Keys.cc index d5bf786..8ca47c3 100644 --- a/src/Keys.cc +++ b/src/Keys.cc @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -//$Id: Keys.cc,v 1.39 2003/12/04 21:31:02 fluxgen Exp $ +//$Id: Keys.cc,v 1.40 2003/12/20 17:37:57 fluxgen Exp $ #include "Keys.hh" @@ -118,97 +118,125 @@ bool Keys::load(const char *filename) { if (!infile) return false; // faild to open file - int line=0;//current line, so we can tell the user where the fault is + m_current_line = 0;//current line, so we can tell the user where the fault is while (!infile.eof()) { string linebuffer; getline(infile, linebuffer); - line++; - vector val; - //Parse arguments - FbTk::StringUtil::stringtok(val, linebuffer.c_str()); + m_current_line++; - //must have at least 1 argument - if (val.size() <= 0) - continue; + addBinding(linebuffer); + } // end while eof + + m_current_line = 0; + m_filename = filename; + return true; +} + +bool Keys::save(const char *filename) const { + //!! + //!! TODO: fix keybinding saving + //!! (we probably need to save key actions + //!! as strings instead of creating new Commands) + + // open file for writing + // ofstream outfile(filename); + // if (!outfile) + return false; + // return true; +} + +bool Keys::addBinding(const std::string &linebuffer) { + + vector val; + // Parse arguments + FbTk::StringUtil::stringtok(val, linebuffer.c_str()); + + // must have at least 1 argument + if (val.size() <= 0) + return true; // empty lines are valid. - if (val[0][0] == '#') //the line is commented - continue; + if (val[0][0] == '#') //the line is commented + return true; // still a valid line. - unsigned int key=0, mod=0; - char keyarg=0; - t_key *current_key=0, *last_key=0; - - for (unsigned int argc=0; argc1) { - - //keyarg=0; - int tmpmod = FbTk::KeyUtil::getModifier(val[argc].c_str()); - if(tmpmod) - mod|=tmpmod; //If it's a modifier - else { - key = FbTk::KeyUtil::getKey(val[argc].c_str()); // else get the key - if (key == 0) { - cerr<<"["<keylist.push_back(temp_key); - last_key = temp_key; - } + unsigned int key = 0, mod = 0; + char keyarg = 0; + t_key *current_key=0, *last_key=0; + + // for each argument + for (unsigned int argc=0; argc 1) { + + int tmpmod = FbTk::KeyUtil::getModifier(val[argc].c_str()); + if(tmpmod) + mod |= tmpmod; //If it's a modifier + else { + key = FbTk::KeyUtil::getKey(val[argc].c_str()); // else get the key + if (key == 0) { + cerr<<"Keys: Invalid key/modifier on line("<< + m_current_line<<"): "<keylist.push_back(temp_key); + last_key = temp_key; } - } - - } else { // parse command line - if (last_key == 0) { - cerr<<"File: "< "< "< "< "<m_command = CommandParser::instance().parseLine(str); + last_key->m_command = CommandParser::instance().parseLine(str); - if (*last_key->m_command == 0) { - cerr<<"File: "< "<m_command == 0) { + cerr<<"Keys: Error on line: "< "< m_keylist; Display *m_display; ///< display connection - + unsigned int m_current_line; }; #endif // KEYS_HH -- cgit v0.11.2