Ejemplo n.º 1
0
void Spreadsheet::updateCell(std::string cell_name, std::string cell_contents, SpreadsheetCallbackInterface * caller)
{
  
  pthread_mutex_lock(&lock1);
   
  std::map<std::string, Cell>::iterator cellContents = cells.find(cell_name);
  if(cellContents != cells.end())
  {
    //put the old stuff into the undo stack
    std::pair<std::string, std::string> undoElement(cell_name, cellContents->second.getContents());
    undoStack.push_back(undoElement);
  }
  else
  {
    //push an empty element to the stack.
    std::pair<std::string, std::string> undoElement(cell_name, "");
    undoStack.push_back(undoElement);
  }
  //will need to update when cell can take a formula...
  cells[cell_name].setContents(cell_contents);
  
  if(cell_contents.substr(0,1).compare("=") == 0 )
  {
    dependencies.changeCell(cell_name, cell_contents);
    
    bool circular = checkForCircularDependency(cell_name);
    if(circular)
    {
      //do an undo and send out an error
      pthread_mutex_unlock(&lock1);
      requestUndo();
      //send an error
      std::cout << "ERROR GOES HERE...NEED TO IMPLEMENT" << std::endl;
      caller -> errorCallback(2, "circular dependency");
    }
    else
    {
      pthread_mutex_unlock(&lock1);
      notifyUsers(cell_name, cell_contents);
    }
  }
  else
  {
    pthread_mutex_unlock(&lock1);
    notifyUsers(cell_name, cell_contents);
  }
  
}
Ejemplo n.º 2
0
void Notes_Logic::handlerAddComment (int identifier)
{
  notifyUsers (identifier, notifyNoteComment);
  // If the note status was Done, and a comment is added, mark it Reopened.
  Database_Notes database_notes (webserver_request);
  string status = database_notes.getRawStatus (identifier);
  if (status == "Done") {
    database_notes.setStatus (identifier, "Reopened");
  }
}
Ejemplo n.º 3
0
void Spreadsheet::requestUndo()
{

  //check if anything is on the stack.
  if(undoStack.size() > 0)
  {
    pthread_mutex_lock(&lock1);
    //pop the last action off the stack and apply it.
    std::pair<std::string, std::string> undoElement = undoStack.back();
    undoStack.pop_back();
    //updateCell(undoElement.first, undoElement.second);
    cells[undoElement.first].setContents(undoElement.second);
    dependencies.changeCell(undoElement.first, undoElement.second);
    pthread_mutex_unlock(&lock1);
    notifyUsers(undoElement.first, undoElement.second);
    
  }
  
}
Ejemplo n.º 4
0
void Notes_Logic::handlerDeleteNote (int identifier)
{
  notifyUsers (identifier, notifyNoteDelete);
}
Ejemplo n.º 5
0
void Notes_Logic::handlerMarkNoteForDeletion (int identifier)
{
  notifyUsers (identifier, notifyMarkNoteForDeletion);
}
Ejemplo n.º 6
0
void Notes_Logic::handlerNewNote (int identifier)
{
  notifyUsers (identifier, notifyNoteNew);
}