Enhancement

- Began detailed implementation of commands and columns objects.
This commit is contained in:
Paul Beckingham 2011-04-24 19:11:56 -04:00
parent 1c23b28514
commit 120562a7e9
9 changed files with 148 additions and 21 deletions

View file

@ -32,15 +32,15 @@
#include <string.h>
#include <unistd.h>
#include <sys/select.h>
#include "Context.h"
#include "Directory.h"
#include "File.h"
#include "Timer.h"
#include "text.h"
#include "util.h"
#include "main.h"
#include "i18n.h"
#include "../cmake.h"
#include <Context.h>
#include <Directory.h>
#include <File.h>
#include <Timer.h>
#include <text.h>
#include <util.h>
#include <main.h>
#include <i18n.h>
#include <../cmake.h>
////////////////////////////////////////////////////////////////////////////////
Context::Context ()
@ -75,10 +75,17 @@ void Context::initialize2 (int argc, char** argv)
// TODO Scan for rc:<file> overrides --> apply.
// TODO Combine command line into one string.
// TODO Load relevant rc file.
// TODO Instantiate built-in command objects.
commands.push_back (Command::factory ("install"));
// TODO Instantiate extension command objects.
// TODO Instantiate default command object.
// TODO Chain-of-command pattern dispatch.
// TODO Instantiate column objects.
// TODO Instantiate UDA objects.
// TODO Instantiate format objects.
// TODO Instantiate extension format objects.
// TODO Hook: on-launch
}
////////////////////////////////////////////////////////////////////////////////
@ -237,7 +244,8 @@ int Context::dispatch (std::string &out)
std::cout << "]0;task " << title << "" << std::endl;
}
// TODO Just look at this thing. It cries out for a dispatch table.
// TODO Chain-of-command pattern dispatch.
if (cmd.command == "projects") { rc = handleProjects (out); }
else if (cmd.command == "tags") { rc = handleTags (out); }
else if (cmd.command == "colors") { rc = handleColor (out); }

View file

@ -28,6 +28,7 @@
#define INCLUDED_CONTEXT
#include <Command.h>
#include <Column.h>
#include <Filter.h>
#include <Config.h>
#include <Sequence.h>
@ -101,6 +102,7 @@ public:
std::vector <std::string> debugMessages;
bool inShadow;
std::vector <Column*> columns;
std::vector <Command*> commands;
int terminal_width;

View file

@ -4,7 +4,8 @@ include_directories (${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/src/columns
${TASK_INCLUDE_DIRS})
set (columns_SRCS Column.cpp Column.h)
set (columns_SRCS Column.cpp Column.h
ID.cpp ID.h)
add_library (columns STATIC ${columns_SRCS})

View file

@ -45,11 +45,13 @@ Column* Column::factory (const std::string& name)
////////////////////////////////////////////////////////////////////////////////
Column::Column ()
: _name ("")
/*
, _minimum (0)
, _maximum (0)
, _wrap (false)
, _just (left)
, _sizing (minimal)
*/
{
}
@ -57,11 +59,13 @@ Column::Column ()
Column::Column (const Column& other)
{
_name = other._name;
/*
_minimum = other._minimum;
_maximum = other._maximum;
_wrap = other._wrap;
_just = other._just;
_sizing = other._sizing;
*/
}
////////////////////////////////////////////////////////////////////////////////
@ -70,11 +74,13 @@ Column& Column::operator= (const Column& other)
if (this != &other)
{
_name = other._name;
/*
_minimum = other._minimum;
_maximum = other._maximum;
_wrap = other._wrap;
_just = other._just;
_sizing = other._sizing;
*/
}
return *this;
@ -83,12 +89,12 @@ Column& Column::operator= (const Column& other)
////////////////////////////////////////////////////////////////////////////////
bool Column::operator== (const Column& other) const
{
return _name == other._name &&
return _name == other._name /*&&
_minimum == other._minimum &&
_maximum == other._maximum &&
_wrap == other._wrap &&
_just == other._just &&
_sizing == other._sizing;
_sizing == other._sizing*/;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -28,12 +28,15 @@
#define INCLUDED_COLUMN
#include <string>
#include <Task.h>
class Column
{
public:
/*
enum just {right = 0, left, center};
enum sizing {minimal = 0, fixed, proportional, maximal};
*/
static Column* factory (const std::string&);
@ -43,17 +46,19 @@ public:
bool operator== (const Column&) const; // TODO Is this necessary?
~Column ();
void setName (const std::string&);
std::string render (Task*, int, int, const std::string style = "default");
std::string type () const;
virtual void setName (const std::string&);
virtual std::string render (Task*, int, int, const std::string style = "default") = 0;
virtual std::string type () const = 0;
private:
protected:
std::string _name;
/*
int _minimum;
int _maximum;
bool _wrap;
just _just;
sizing _sizing;
*/
};
#endif

59
src/columns/ID.cpp Normal file
View file

@ -0,0 +1,59 @@
////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager.
//
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
// All rights reserved.
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the
//
// Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor,
// Boston, MA
// 02110-1301
// USA
//
////////////////////////////////////////////////////////////////////////////////
#include <Context.h>
#include <ID.h>
extern Context context;
////////////////////////////////////////////////////////////////////////////////
ColumnID::ColumnID ()
{
setName ("id");
}
////////////////////////////////////////////////////////////////////////////////
ColumnID::~ColumnID ()
{
}
////////////////////////////////////////////////////////////////////////////////
std::string ColumnID::render (
Task* task,
int width,
int height,
const std::string style)
{
}
////////////////////////////////////////////////////////////////////////////////
std::string ColumnID::type () const
{
return "number";
}
////////////////////////////////////////////////////////////////////////////////

47
src/columns/ID.h Normal file
View file

@ -0,0 +1,47 @@
////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager.
//
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
// All rights reserved.
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the
//
// Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor,
// Boston, MA
// 02110-1301
// USA
//
////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_ID
#define INCLUDED_ID
#include <string>
#include <Column.h>
#include <Task.h>
class ColumnID : public Column
{
public:
ColumnID ();
~ColumnID ();
std::string render (Task*, int, int, const std::string style = "default");
std::string type () const;
private:
};
#endif
////////////////////////////////////////////////////////////////////////////////

View file

@ -27,6 +27,7 @@
#include <iostream>
#include <Command.h>
#include <Install.h>
#include <Context.h>
extern Context context;
@ -34,11 +35,9 @@ extern Context context;
////////////////////////////////////////////////////////////////////////////////
Command* Command::factory (const std::string& name)
{
/*
if (name == "install") return new Install ();
throw std::string ("Unrecognized command '") + name + "'";
*/
return NULL;
}

View file

@ -30,7 +30,7 @@
#include <string>
#include <Command.h>
class Install : Command
class Install : public Command
{
public:
Install ();