示例#1
0
void Entity::setName(const std::string &newName) {
  onNameChange(newName);
  std::string oldName(std::move(m_name));
  m_name = newName;
  world.entityManager.changeEntityName(*this, oldName, newName);
  world.event.dispatch(NameChangedEvent(*this, oldName));
}
void PredicateDialog::onRenamePredicate() {
    Glib::RefPtr < Gtk::TreeView::Selection > ref = mTreePredicateList->
        get_selection();
    if (ref) {
        Gtk::TreeModel::iterator iter = ref->get_selected();
        if (iter) {
            Gtk::TreeModel::Row row = *iter;
            std::string oldName(row.get_value(m_viewscolumnrecord.name));
            savePreviousPredicate(oldName);

            SimpleTypeBox box(("Predicate new name?"), "");
            std::string name = boost::trim_copy(box.run());
            if (box.valid() and checkName(name)) {

                setSensitivePredicate(false);
                m_model->erase(iter);

                Gtk::TreeModel::Children children = m_model->children();
                m_iter = children.begin();

                iter = m_model->append();
                mPredicateNameEntry->set_text(name);
                Gtk::ListStore::Row row = *iter;
                row[m_viewscolumnrecord.name] = name;

                if (mPredicateFunction.find(oldName) !=
                        mPredicateFunction.end()) {
                    mTextViewFunction->get_buffer()->
                            set_text(mPredicateFunction[oldName]);
                    mPredicateFunction[name] = mPredicateFunction[oldName];
                    mPredicateFunction.erase(oldName);
                }

                mPredicateName.push_back(name);
                // Delete the element in the vector
                for (std::vector < std::string > ::iterator it =
                        mPredicateName.begin(); it != mPredicateName.end(); ) {
                    if ( *it == oldName ) {
                        it = mPredicateName.erase(it);
                    }
                    else {
                        ++it;
                    }
                }
                mTreePredicateList->set_cursor(m_model->get_path(iter));
                setSensitivePredicate(true);
            }
            else {
                Gtk::MessageDialog errorDial ("Name error !",
                    false,
                    Gtk::MESSAGE_ERROR,
                    Gtk::BUTTONS_OK,
                    true);
                errorDial.set_title("Error !");
                errorDial.run();
            }
        }
    }
}
示例#3
0
文件: doctypeedit.cpp 项目: KDE/kraft
void DocTypeEdit::saveDocTypes()
{
    // removed doctypes
    // FIXME: Remove unreferenced number cycles
    for ( QStringList::Iterator it = mRemovedTypes.begin(); it != mRemovedTypes.end(); ++it ) {
        if ( mOrigDocTypes.contains( *it ) ) {
            DocType dt = mOrigDocTypes[*it];
            removeTypeFromDb( *it );
            mOrigDocTypes.remove( *it );
            mChangedDocTypes.remove( *it );
            emit removedType( *it );
        }
    }

    // added doctypes
    for ( QStringList::Iterator it = mAddedTypes.begin(); it != mAddedTypes.end(); ++it ) {
        QString name = *it;
        if ( mOrigDocTypes.contains( name ) ) { // just to check
            DocType dt = mChangedDocTypes[name];
            QString numCycleName = dt.numberCycleName();
            kDebug() << "Number cycle name for to add doctype " << name << ": " << numCycleName;
            dt.save();
        }
    }

    // edited doctypes
    QMap<QString, QString>::Iterator it;
    for ( it = mTypeNameChanges.begin(); it != mTypeNameChanges.end(); ++it ) {
        QString oldName( it.key() );
        if ( mOrigDocTypes.contains( oldName ) ) {
            QString newName = it.value();
            kDebug() << "Renaming " << oldName << " to " << newName;
            DocType dt = mOrigDocTypes[oldName];
            if ( mChangedDocTypes.contains( newName ) ) {
                dt = mChangedDocTypes[newName];
            } else {
                dt.setName( newName );
            }
            mOrigDocTypes.remove( oldName );
            mOrigDocTypes[newName] = dt;
            dt.save();
        } else {
            kError() << "Can not find doctype to change named " << oldName;
        }
    }

    // check if numberCycles have changed.
    QMap<QString, DocType>::Iterator mapit;
    for ( mapit = mChangedDocTypes.begin(); mapit != mChangedDocTypes.end(); ++mapit ) {
        DocType dt = mapit.value();
        dt.save();
    }

    // now the list of document types should be up to date and reflected into
    // the database.
    DocType::clearMap();
}
示例#4
0
bool ModelViewer::checkTargetNameLegal(const string& modelName)
{
	bool result = true;
	for (auto& items : DataHandler::s_AnimFileData){
		string newName = modelName;
		string oldName(items.name);
		std::transform(newName.begin(), newName.end(), newName.begin(), tolower);
		std::transform(oldName.begin(), oldName.end(), oldName.begin(), tolower);

		if (oldName == newName){
			result = false;
			break;
		}

	}

	return result;
}
	virtual void SetName(IHashString *inName)
	{
		if (inName != NULL)
		{
			if ((m_Name.GetString() == NULL) ||
				(m_Name.GetUniqueID() != inName->GetUniqueID()))
			{
				CHANGEOBJNAME con;
				// save off temp old name.
				CHashString oldName(m_Name);
				CHashString tempNewName(inName);
				con.oldName = &oldName;
				con.newName = &tempNewName;
				con.compType = &m_ClassHashName;
				static DWORD msgHash_ChangeObjectName = CHashString(_T("ChangeObjectName")).GetUniqueID();
				m_ToolBox->SendMessage(msgHash_ChangeObjectName, sizeof(CHANGEOBJNAME), &con);

				m_Name = tempNewName;
			}
		}
	}
void SpectrumMUCConversation::renameUser(AbstractUser *user, const char *old_name, const char *new_name, const char *new_alias) {
	std::string oldName(old_name);
	std::string newName(new_name);
	Tag *tag = new Tag("presence");
	tag->addAttribute("from", m_jid + "/" + oldName);
	tag->addAttribute("to", user->jid() + m_res);
	tag->addAttribute("type", "unavailable");

	Tag *x = new Tag("x");
	x->addAttribute("xmlns", "http://jabber.org/protocol/muc#user");

	Tag *item = new Tag("item");
	item->addAttribute("affiliation", "member");
	item->addAttribute("role", "participant");
	item->addAttribute("nick", newName);

	Tag *status = new Tag("status");
	status->addAttribute("code","303");

	x->addChild(item);
	x->addChild(status);
	tag->addChild(x);
	Transport::instance()->send(tag);


	tag = new Tag("presence");
	tag->addAttribute("from", m_jid + "/" + newName);
	tag->addAttribute("to", user->jid() + m_res);

	x = new Tag("x");
	x->addAttribute("xmlns", "http://jabber.org/protocol/muc#user");

	item = new Tag("item");
	item->addAttribute("affiliation", "member");
	item->addAttribute("role", "participant");

	x->addChild(item);
	tag->addChild(x);
	Transport::instance()->send(tag);
}
示例#7
0
void KReportDesignerItemLine::propertyChanged(KPropertySet &s, KProperty &p)
{
    Q_UNUSED(s);

    if (p.name() == "startposition" || p.name() == "endposition") {
        QPointF s = scenePosition(m_start->value().toPointF());
        QPointF e = scenePosition(m_end->value().toPointF());
        
        setLine ( s.x(), s.y(), e.x(), e.y() );
    }
    else if (p.name() == "name") {
        //For some reason p.oldValue returns an empty string
        if (!designer()->isEntityNameUnique(p.value().toString(), this)) {
            p.setValue(oldName());
        } else {
            setOldName(p.value().toString());
        }
    }
    if (designer())
        designer()->setModified(true);

    update();
}
示例#8
0
TEST_F( NameTests, CopyConstructorWorks )
{
    Moge::Name oldName( genericName );
    Moge::Name newName( oldName );
    ASSERT_EQ( newName.GetName(), oldName.GetName() );
}
示例#9
0
void wxSTEditorNotebook::SortTabs(int style)
{
    if ((int)GetPageCount() < 2)
        return;

    if (STE_HASBIT(style, STN_ALPHABETICAL_TABS))
    {
        int sel = GetSelection();
        int new_sel = sel;
        size_t page_count = GetPageCount();
        size_t n;

        if (page_count < 2)
            return;

        wxString curPageName;
        wxArrayString names;

        for (n = 0; n < page_count; n++)
        {
            wxString name(GetPageText(n));
            if ((name.Length() > 0) && (name[0u] == wxT('*')))
                name = name.Mid(1);

            names.Add(name + wxString::Format(wxT("=%d"), (int)n));
        }

        names.Sort(STN_SortNameCompareFunction);

        bool sel_changed = false;

        for (n = 0; n < page_count; n++)
        {
            long old_page = 0;
            names[n].AfterLast(wxT('=')).ToLong(&old_page);

            if (old_page != long(n))
            {
                wxWindow *oldWin = GetPage(old_page);
                wxString oldName(GetPageText(old_page));

                if (oldWin && RemovePage(old_page))
                {
                    sel_changed = true;

                    if (old_page == sel)
                        new_sel = (int)n;

                    if (n < page_count - 1)
                        InsertPage((int)(n+1), oldWin, oldName, old_page == sel);
                    else
                        AddPage(oldWin, oldName, old_page == sel);
                }
            }
        }

        if (sel_changed)
        {
            wxNotebookEvent noteEvent(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, GetId(),
                                    new_sel, new_sel);
            noteEvent.SetString(wxT("wxSTEditorNotebook Page Change"));
            noteEvent.SetExtraLong(new_sel); // FIXME no Clone in wxNotebookEvent
            // NOTE: this may have to be AddPendingEvent for wx < 2.7 since gtk
            //       can become reentrant
            GetEventHandler()->AddPendingEvent(noteEvent);
        }

        // causes reentrant assert in gtk, even though it's necessary sometimes
        //SetSelection(new_sel); // force selection for GTK
    }
}
int DBSettingChanged(WPARAM wParam, LPARAM lParam)
{
	// We can't upload changes to NULL contact
	MCONTACT hContact = wParam;
	if (hContact == NULL)
		return 0;

	DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *) lParam;
	if (!mir_strcmp(cws->szModule, "CList")) {
		int invalidpresent = 0;

		char *szProto = GetContactProto(hContact);
		if (szProto == NULL || mir_strcmp(szProto, MODULENAME))
			return 0;

		// A contact is renamed
		if (!mir_strcmp(cws->szSetting, "MyHandle")) {
			ptrT oldName( db_get_tsa(hContact, MODULENAME, PRESERVE_NAME_KEY));
			if (oldName == NULL)
				return 0;

			TCHAR nick[100];
			ptrT oldnick( db_get_tsa(hContact, "CList", "MyHandle"));
			if (oldnick != NULL)
				_tcsncpy_s(nick, oldnick, _TRUNCATE);
			else
				nick[0] = 0;

			for (int i=0; i < _countof(szInvalidChars); i++ ) {
				TCHAR *p = _tcschr(nick, szInvalidChars[i]);
				if (p != NULL) {
					WErrorPopup((UINT_PTR)"ERROR", TranslateT("Invalid symbol present in contact name."));
					*p = '_';
					invalidpresent =1;
				}
			}

			if (invalidpresent) {
				srand((unsigned)time(NULL));
				TCHAR ranStr[7];
				_itot((int)10000 *rand() / (RAND_MAX + 1.0), ranStr, 10);
				mir_tstrcat(nick, ranStr); 
			}  

			if ( _tcschr(nick, '(') == 0) {
				db_set_ts(hContact, MODULENAME, PRESERVE_NAME_KEY, nick);
				db_set_ts(hContact, MODULENAME, "Nick", nick);
				db_set_ts(hContact, "CList", "MyHandle", nick);
			}

			// TEST GET NAME FOR CACHE
			TCHAR cachepath[MAX_PATH], cachedirectorypath[MAX_PATH];
			GetModuleFileName(hInst, cachepath, _countof(cachepath));
			TCHAR *cacheend = _tcsrchr(cachepath, '\\');
			cacheend++;
			*cacheend = '\0';
			mir_sntprintf(cachedirectorypath, _T("%s")_T(MODULENAME)_T("cache\\"), cachepath);
			CreateDirectory(cachedirectorypath, NULL);

			TCHAR newcachepath[MAX_PATH + 50], renamedcachepath[MAX_PATH + 50];
			mir_sntprintf(newcachepath, _T("%s")_T(MODULENAME)_T("cache\\%s.txt"), cachepath, oldName);
			mir_sntprintf(renamedcachepath, _T("%s")_T(MODULENAME)_T("cache\\%s.txt"), cachepath, nick);

			// file exists?
			if ( _taccess(newcachepath, 0) != -1) {
				FILE *pcachefile = _tfopen(newcachepath, _T("r"));
				if (pcachefile != NULL) {
					fclose(pcachefile);
					if (mir_tstrcmp(newcachepath, renamedcachepath)) {
						MoveFile(newcachepath, renamedcachepath);
						db_set_ts(hContact, MODULENAME, CACHE_FILE_KEY, renamedcachepath);
					}
				}
			}
		}
	}
	return 0;
}
示例#11
0
void AckFunctionDialog::onRenameAck() {
    Glib::RefPtr < Gtk::TreeView::Selection > ref = mTreeAckList->
        get_selection();
    if (ref) {
        Gtk::TreeModel::iterator iter = ref->get_selected();
        if (iter) {
            Gtk::TreeModel::Row row = *iter;
            std::string oldName(row.get_value(m_viewscolumnrecord.name));
            savePreviousAck(oldName);

            SimpleTypeBox box(("Acknowledge function new name?"), "");
            std::string name = boost::trim_copy(box.run());
            if (box.valid()) {
                if (checkName(name)) {
                    setSensitiveAck(false);
                    m_model->erase(iter);

                    Gtk::TreeModel::Children children = m_model->children();
                    m_iter = children.begin();

                    iter = m_model->append();
                    mAckNameEntry->set_text(name);
                    Gtk::ListStore::Row row = *iter;
                    row[m_viewscolumnrecord.name] = name;

                    if (mAckFunction.find(oldName) != mAckFunction.end()) {
                        mTextViewFunction->get_buffer()->
                                set_text(mAckFunction[oldName]);
                        mAckFunction[name] = mAckFunction[oldName];
                        mAckFunction.erase(oldName);
                    }

                    mAckName.push_back(name);

                    mRenameList.push_back(std::make_pair(oldName, name));

                    mHeaderAck->set_text("void " + name + "(const std::string&"\
                        "activityname,\n\t"\
                        "const ved::Activity& activity) {");
                    // Delete the element in the vector
                    for (std::vector < std::string > ::iterator it =
                            mAckName.begin(); it != mAckName.end(); ) {
                        if ( *it == oldName ) {
                            it = mAckName.erase(it);
                        }
                        else {
                            ++it;
                        }
                    }
                    mTreeAckList->set_cursor(m_model->get_path(iter));
                    setSensitiveAck(true);
                }
                else {
                    Gtk::MessageDialog errorDial ("Name error !",
                        false,
                        Gtk::MESSAGE_ERROR,
                        Gtk::BUTTONS_OK,
                        true);
                    errorDial.set_title("Error !");
                    errorDial.run();
                }
            }
        }
    }
}