Exemplo n.º 1
0
void BrowserOperation::instances(BrowserNodeList & result)
{
    IdIterator<BrowserOperation> it(all);
    BrowserOperation * op;

    while(it.hasNext()){
        it.next();
        if ((op = it.value()) != 0)
            if (!op->deletedp())
                result.append(op);

    }

    result.sort_it();
}
Exemplo n.º 2
0
bool BrowserNode::tool_cmd(ToolCom * com, const char * args) {
  switch ((unsigned char) args[-1]) {
  case applyCmd:
  {
      QLOG_FATAL() << Q_FUNC_INFO << "If this got called then we have a logic flaw going on and BrowserNode needs to have Q_OBJECT in it to properly catch ToolCom::Run execution result";
      Q_ASSERT_X(0, "applyCmd happened", "very bad");
      int runResult = ToolCom::run(args, this, FALSE, FALSE);
      com->write_unsigned(runResult);
      break;
  }
  case createCmd:
    // invalid creation
    com->write_id(0);
    break;
  case parentCmd:
    if (this != BrowserView::get_project())
      ((BrowserNode *) parent())->write_id(com);
    else
      com->write_id(0);
    break;
  case childrenCmd:
    {
      unsigned v = com->api_format();
      unsigned n = 0;
      Q3ListViewItem * child;
      
      for (child = firstChild(); child != 0; child = child->nextSibling())
	if (!((BrowserNode *) child)->deletedp() &&
	    ((BrowserNode *) child)->api_compatible(v))
	  n += 1;
      
      com->write_unsigned(n);
      
      for (child = firstChild(); child != 0; child = child->nextSibling())
	if (!((BrowserNode *) child)->deletedp() &&
	    ((BrowserNode *) child)->api_compatible(v))
	  ((BrowserNode *) child)->write_id(com);
    }
    break;
  case getDefCmd:
  case getUmlDefCmd:
  case getCppDefCmd:
  case getJavaDefCmd:
  case getPhpDefCmd:
  case getPythonDefCmd:
  case getIdlDefCmd:
    get_data()->send_uml_def(com, this, comment);
    break;
  case isWritableCmd:
    com->write_bool(!is_read_only);
    break;
  case supportFileCmd:
    // goes up to the package
    return ((BrowserNode *) parent())->tool_cmd(com, args);
  case isOpenCmd:
    com->write_bool(isOpen());
    break;
  case referencedByCmd:
    {
      BrowserNodeList targetof;
      
      referenced_by(targetof);
      // remove duplicats
      targetof.sort_it();
      
      BrowserNode * bn;
      
      targetof.first();
      while ((bn = targetof.current()) != 0)
	if (bn == targetof.next())
	  targetof.remove();
      
      com->write_unsigned(targetof.count());
      
      for (bn = targetof.first(); bn != 0; bn = targetof.next())
	bn->write_id(com);
    }
    break;
  case setCoupleValueCmd:
    if (is_read_only && !root_permission())
      com->write_ack(FALSE);
    else {
      set_value(args, args + strlen(args) + 1);
      package_modified();
      get_data()->modified();
      com->write_ack(TRUE);
    }
    break;
  case setDescriptionCmd:
    if (is_read_only && !root_permission())
      com->write_ack(FALSE);
    else {
      set_comment(args);
      package_modified();
      com->write_ack(TRUE);
    }
    break;
  case setNameCmd:
    if (is_read_only && !root_permission())
      com->write_ack(FALSE);
    else {
      if (name != args) {
	if (((BrowserNode *) parent())->wrong_child_name(args, get_type(),
							 allow_spaces(),
							 allow_empty())) {
	  com->write_ack(FALSE);
	  return TRUE;
	}
	else {
	  set_name(args);
	  update_stereotype();
	  package_modified();
	  get_data()->modified();
	}
      }
      com->write_ack(TRUE);
    }
    break;
  case setOpenCmd:
    BrowserView::select(this);
    setOpen(*args);
    com->write_ack(TRUE);
    break;
  case setMarkedCmd:
    if (*args) {
      if (this == BrowserView::get_project())
	com->write_ack(FALSE);
      else {
	if (!is_marked)
	  toggle_mark();
	com->write_ack(TRUE);
      }
    }
    else {
      if (is_marked)
	toggle_mark();
      com->write_ack(TRUE);
    }
    break;
  case moveAfterCmd:
    if (is_read_only && !root_permission())
      com->write_ack(FALSE);
    else {
      BrowserNode * p = (BrowserNode *) parent();
      BrowserNode * after = (BrowserNode *) com->get_id(args);
      
      if (after == 0) {
	if (p == 0)
	  com->write_ack(FALSE);
	else {
	  p->takeItem(this);
	  p->insertItem(this);
	  com->write_ack(TRUE);
	  p->package_modified();
	}
      }
      else if ((after->parent() != p) ||
	       (after == this)) {
	com->write_ack(FALSE);
      }
      else {
	moveItem(after);
	com->write_ack(TRUE);
	p->package_modified();
      }
    }
    break;
  case moveInCmd:
    // plug-out upgrade, limited checks
    if (is_read_only && !root_permission())
      com->write_ack(FALSE);
    else {
      BrowserNode * newparent = (BrowserNode *) com->get_id(args);
      BrowserNode * oldparent = (BrowserNode *) parent();
      
      if ((newparent == oldparent) || (newparent == this)) {
	com->write_ack(FALSE);
      }
      else {
	oldparent->takeItem(this);
	newparent->insertItem(this);
	com->write_ack(TRUE);
	oldparent->package_modified();
	newparent->package_modified();
      }
    }
    break;
  case old_deleteCmd:
  case deleteCmd:
    if (is_read_only && !root_permission())
      com->write_ack(FALSE);
    else {
      delete_it();
      ((BrowserNode *) parent())->get_data()->modified();
      package_modified();
      com->write_ack(TRUE);
    }
    break;
  case applyStereotypeCmd:
    if (is_read_only && !root_permission())
      com->write_ack(FALSE);
    else {
      ProfiledStereotypes::applyStereotype(this); // call package_modified() if needed
      com->write_ack(TRUE);
    }
    break;
  default:
    return FALSE;
  }
      
  return TRUE;
}