Example #1
0
std::string PDFImageObject::ObjectEntry()
{
//	if ( !ImageLen() )
//		buffer = ObjectHeader();
	buffer +=  "<<\r";
	buffer += "/Type /XObject\r";
	buffer += "/Subtype /Image\r";
	buffer += "/Name /";
	buffer += GetImageName();
	buffer += "\r";
	buffer += "/Width ";
	buffer += GetWidth();
	buffer += "\r";
	buffer += "/Height ";
	buffer += GetHeight();
	buffer += "\r";
	buffer += "/BitsPerComponent ";
	buffer += GetBitsPerComponent();
	buffer += "\r";

	buffer += "/ColorSpace ";
//	buffer += GetColorSpace();
//	buffer += "\r";
	buffer += GetColorSpaceObjIdStr();

	if ( !GetFilter().empty() ) 
	{
		buffer += "/Filter ";
		buffer += GetFilter();
		buffer += "\r";
	}

	buffer += "/Length ";
	if ( !ImageLen() )
		buffer += intToStr( imageData.length() );
	else
		buffer += intToStr( imageLen );
	buffer += "\r";

	buffer += ">>\r";
	buffer += "stream\r";
	if ( !ImageLen() )
	{
		buffer += imageData;
		buffer += "\r% Trev2\rendstream\r";
	}
	AddContents( buffer );
	if ( !ImageLen() )
		return PDFBodyObject::ObjectEntry();
	else
		return GetContents();
}
Example #2
0
/** 
 * @brief Set filter, returns old filter.
 */
CString ProjectFile::SetFilter(const CString& sFilter)
{
	CString sFilterOld = GetFilter();
	m_filter = sFilter;

	return sFilterOld;
}
Example #3
0
void InfoLogger::LogUser(LPCTSTR sFmt, va_list argList)
{

	if ((GetFilter() & LOG_SEVERITY_USER) == 0)
		return;
	LogVarArgs(sFmt, "USER: ", argList);
}
Example #4
0
void CuDlgMain::DoCompare()
{
	CString strNode;
	CString strDatabase;
	CString strUser;
	try
	{
		CheckValidParameters();
		if (m_bLoadedSchema1)
		{
			CString strFile;
			m_cEditFile1.GetWindowText(strFile);
			m_vsdaCtrl.LoadSchema1Param(strFile);
		}
		else
		if (GetSchemaParam (1, strNode, strDatabase, strUser))
		{
			m_vsdaCtrl.SetSchema1Param (strNode, strDatabase, strUser);
		}
		else
			return;

		if (m_bLoadedSchema2)
		{
			CString strFile;
			m_cEditFile2.GetWindowText(strFile);
			m_vsdaCtrl.LoadSchema2Param(strFile);
		}
		else
		if (GetSchemaParam (2, strNode, strDatabase, strUser))
		{
			m_vsdaCtrl.SetSchema2Param (strNode, strDatabase, strUser);
		}
		else
			return;
		short nCheck = m_cCheckIgnoreOwner.GetCheck();
		m_vsdaCtrl.DoCompare(nCheck);
		CString strFilter = _T("");
		GetFilter(strFilter);
		m_vsdaCtrl.UpdateDisplayFilter(strFilter);
	}
	catch(int nCode)
	{
		switch (nCode)
		{
		case 1:
		case 2:
		case 3:
			AfxMessageBox (IDS_MSG_PROVIDE_INPUTPARAM);
			break;
		case 4:
			AfxMessageBox (IDS_MSG_FILE_NOTFOUND);
			break;
		default:
			AfxMessageBox (IDS_MSG_PROVIDE_INPUTPARAM);
			break;
		}
	}
	m_bCompared = TRUE;
}
Example #5
0
void InfoLogger::LogUnimplemented(LPCTSTR sMsg)
{
	if ((GetFilter() & LOG_SEVERITY_UNIMPL) == 0)
		return;
	LogSomething(CString("UNIMPL: ")+sMsg);
//	ASSERT(false);
}
// Executes the select command and returns a reference to an IFeatureReader.
// During execution an attempt is made to place a lock on each feature. If
// there are conflicts the conflicts are reported and made available to the
// user via a lock conflict reader. The user retrieves the lock conflict
// reader when executing the function "GetLockConflicts()".
// NOTE: The current implementation is a work-around due some timing issues as
//       explained: When using DBI to apply a lock on an object the lock is
//       actually applied only when the object is fetched via the procedure
//       dbi_fetch. In this command the fetching of the object is delayed until
//       the user actually queries the feature reader. That means that locks
//       are applied at that time. As a result the feature reader should have a
//       method to retrieve the lock conflicts because this object documents
//       them. This is not the case. Therefore, until a better solution is found
//       the work-around is to have two passes for the execution of the command:
//       the first one actually locks the objects and provides lock conflict
//       information whereas the second pass prepares the feature reader for the
//       user to retrieve the requested data.
FdoIFeatureReader* FdoRdbmsSelectCommand::ExecuteWithLock()
{

    FdoFilter       *tempFilter     = NULL;
    FdoIdentifier   *tempClassName  = NULL;
    FdoIAcquireLock *acquireLockCmd = NULL;

    // If a lock conflict reader already exists dispose it.

    FDO_SAFE_RELEASE(mLockConflictReader);

    // Create the command to lock the objects, set the command parameters
    // and execute it.

    acquireLockCmd = (FdoIAcquireLock *) mConn->CreateCommand(
                                                    FdoCommandType_AcquireLock);

    tempClassName = GetFeatureClassName();
    acquireLockCmd->SetFeatureClassName(tempClassName);
    tempClassName->Release();
    tempFilter = GetFilter();
    acquireLockCmd->SetFilter(tempFilter);
    acquireLockCmd->SetLockStrategy(mLockStrategy);
    acquireLockCmd->SetLockType(mLockType);

    mLockConflictReader = (FdoRdbmsLockConflictReader *)acquireLockCmd->Execute();

    acquireLockCmd->Release();
    acquireLockCmd = NULL;

    // Get the data as requested by the user.

    return (Execute());
}
Example #7
0
StringFilter* StringFilter::ReadFromXml(
    /* [in] */ ValueProvider* valueProvider,
    /* [in] */ IXmlPullParser* parser)
{
    AutoPtr<StringFilter> filter;
    Int32 count;

    parser->GetAttributeCount(&count);
    for (Int32 i = 0;  i < count;  i++) {
        AutoPtr<StringFilter> newFilter = GetFilter(valueProvider, parser, i);
        if (newFilter != NULL) {
            if (filter != NULL) {
                //throw new XmlPullParserException("Multiple string filter attributes found");
                return NULL;
            }
            filter = newFilter;
        }
    }

    if (filter == NULL) {
        // if there are no string filter attributes, we default to isNull="false" so that an
        // empty filter is equivalent to an existence check
        filter = new IsNullFilter(valueProvider, FALSE);
    }
    REFCOUNT_ADD(filter);

    return filter;
}
Example #8
0
void CuDlgMain::OnCheckChangeIncluding()
{
	TRACE0("CuDlgMain::OnCheckChangeIncluding()\n");

	CString strFilter = _T("");
	GetFilter(strFilter);
	m_vsdaCtrl.UpdateDisplayFilter(strFilter);
}
Example #9
0
void InfoLogger::LogVerbose(LPCTSTR sFmt, ...)
{
	if ((GetFilter() & LOG_SEVERITY_VERBOSE) == 0)
		return;
	va_list argList;
	va_start(argList, sFmt);
	LogVarArgs(sFmt, "INFO: ", argList);
	va_end(argList);
}
Example #10
0
void CSearchDialog::OnSearch(wxCommandEvent& event)
{
	if (!m_pState->IsRemoteIdle())
	{
		wxBell();
		return;
	}

	CServerPath path;

	const CServer* pServer = m_pState->GetServer();
	if (!pServer)
	{
		wxMessageBox(_("Connection to server lost."), _("Remote file search"), wxICON_EXCLAMATION);
		return;
	}
	path.SetType(pServer->GetType());
	if (!path.SetPath(XRCCTRL(*this, "ID_PATH", wxTextCtrl)->GetValue()) || path.IsEmpty())
	{
		wxMessageBox(_("Need to enter valid remote path"), _("Remote file search"), wxICON_EXCLAMATION);
		return;
	}

	m_search_root = path;

	// Prepare filter
	wxString error;
	if (!ValidateFilter(error, true))
	{
		wxMessageBox(wxString::Format(_("Invalid search conditions: %s"), error.c_str()), _("Remote file search"), wxICON_EXCLAMATION);
		return;
	}
	m_search_filter = GetFilter();
	if (!CFilterManager::CompileRegexes(m_search_filter))
	{
		wxMessageBox(_("Invalid regular expression in search conditions."), _("Remote file search"), wxICON_EXCLAMATION);
		return;
	}
	m_search_filter.matchCase = XRCCTRL(*this, "ID_CASE", wxCheckBox)->GetValue();

	// Delete old results
	m_results->ClearSelection();
	m_results->m_indexMapping.clear();
	m_results->m_fileData.clear();
	m_results->SetItemCount(0);
	m_visited.clear();
	m_results->RefreshListOnly(true);

	m_results->GetFilelistStatusBar()->Clear();

	// Start
	m_searching = true;
	m_pState->GetRecursiveOperationHandler()->AddDirectoryToVisitRestricted(path, _T(""), true);
	std::list<CFilter> filters; // Empty, recurse into everything
	m_pState->GetRecursiveOperationHandler()->StartRecursiveOperation(CRecursiveOperation::recursive_list, path, filters, true);
}
Example #11
0
/**
 * Add a filter item
 */
CField * CBibList::AddFilter(CString name, CString cond)
{
	CBibItem *filter = GetFilter();
	if (!filter)
		filter = New();
	CField *flt = filter->New();
	flt->SetName(name);
	flt->SetValue(cond);
	return flt;
}
void NczFilteredPlayersList::ResetNextPlayer()
{
	// Remet l'itération à zero
	m_nextPlayer = nullptr;
	PLAYERS_LOOP_RUNTIME
	{
		if(ph->status < GetFilter()) continue;
		m_nextPlayer = ph;
		break;
	}
	END_PLAYERS_LOOP
}
Example #13
0
void AssExportFilterChain::Register(std::unique_ptr<AssExportFilter>&& filter) {
    int filter_copy = 1;
    std::string name = filter->name;
    // Find a unique name
    while (GetFilter(name))
        name = str(boost::format("%s (%d)") % filter->name % filter_copy++);

    filter->name = name;

    // Look for place to insert
    auto begin(filters().begin()), end(filters().end());
    while (begin != end && begin->priority >= filter->priority) ++begin;
    filters().insert(begin, *filter.release());
}
void BaseTimedTester::ProcessTests()
{
	if((Plat_FloatTime() - m_lastTestDone) < m_jobMinPeriod) return;
	m_lastTestDone = Plat_FloatTime();

	PlayerHandler* h = nullptr;
	for(int x = 1; x <= MAX_PLAYERS; ++x)
	{
		h = NczPlayerManager::GetInstance()->GetPlayerHandlerByIndex(x);
		if(h->status == GetFilter())
		{
			ProcessPlayerTest(h->playerClass);
		}
	}
}
NczPlayer* NczFilteredPlayersList::GetNextPlayer()
{
	// Met à jour le prochain pointeur en interne et retourne celui en cours
	NczPlayer* playerStor = m_nextPlayer->playerClass;
	if(playerStor == nullptr) return nullptr; // Liste vide

	for(int index = playerStor->GetIndex()+1; index < MAX_PLAYERS; ++index)
	{
		m_nextPlayer = NczPlayerManager::GetInstance()->GetPlayerHandlerByIndex(index);
		if(m_nextPlayer->status != GetFilter()) continue;
		break;
	}
	if(playerStor == m_nextPlayer->playerClass) return nullptr; // Fin de liste
	return playerStor;
}
CC_FILE_ERROR FileIOFilter::SaveToFile(	ccHObject* entities,
										const QString& filename,
										QString fileFilter)
{
	if (fileFilter.isEmpty())
		return CC_FERR_BAD_ARGUMENT;

	Shared filter = GetFilter(fileFilter,false);
	if (!filter)
	{
		ccLog::Error(QString("[Load] Internal error: no filter corresponds to filter '%1'").arg(fileFilter));
		return CC_FERR_UNKNOWN_FILE;
	}

	return SaveToFile(entities, filename, filter);
}
const JString&
CBSearchFilterHistoryMenu::GetFilter
	(
	const Message&	message,
	JBoolean*		invert
	)
	const
{
	assert( message.Is(JXMenu::kItemSelected) );

	const JXMenu::ItemSelected* selection =
		dynamic_cast<const JXMenu::ItemSelected*>(&message);
	assert( selection != NULL );

	return GetFilter(selection->GetIndex(), invert);
}
Example #18
0
void CFilterEditDialog::SaveFilter(CFilter& filter)
{
	filter = GetFilter();

	filter.matchCase = XRCCTRL(*this, "ID_CASE", wxCheckBox)->GetValue();

	filter.filterFiles = XRCCTRL(*this, "ID_FILES", wxCheckBox)->GetValue();
	filter.filterDirs = XRCCTRL(*this, "ID_DIRS", wxCheckBox)->GetValue();

	filter.name = XRCCTRL(*this, "ID_NAME", wxTextCtrl)->GetValue();
	if (filter.name != m_pFilterListCtrl->GetString(m_currentSelection))
	{
		int oldSelection = m_currentSelection;
		m_pFilterListCtrl->Delete(oldSelection);
		m_pFilterListCtrl->Insert(filter.name, oldSelection);
		m_pFilterListCtrl->SetSelection(oldSelection);
	}
}
Example #19
0
ccHObject* FileIOFilter::LoadFromFile(	const QString& filename,
										LoadParameters& loadParameters,
										CC_FILE_ERROR& result,
										QString fileFilter/*=QString()*/)
{
	Shared filter(0);
	
	//if the right filter is specified by the caller
	if (!fileFilter.isEmpty())
	{
		filter = GetFilter(fileFilter, true);
		if (!filter)
		{
			ccLog::Error(QString("[Load] Internal error: no I/O filter corresponds to filter '%1'").arg(fileFilter));
			result = CC_FERR_CONSOLE_ERROR;
			return 0;
		}
	}
	else //we need to guess the I/O filter based on the file format
	{
		//look for file extension (we trust Qt on this task)
		QString extension = QFileInfo(filename).suffix();
		if (extension.isEmpty())
		{
			ccLog::Error("[Load] Can't guess file format: no file extension");
			result = CC_FERR_CONSOLE_ERROR;
			return 0;
		}

		//convert extension to file format
		filter = FindBestFilterForExtension(extension);

		//unknown extension?
		if (!filter)
		{
			ccLog::Error(QString("[Load] Can't guess file format: unhandled file extension '%1'").arg(extension));
			result = CC_FERR_CONSOLE_ERROR;
			return 0;
		}
	}

	return LoadFromFile(filename, loadParameters, filter, result);
}
Example #20
0
int wxGISGPGxObjectDomain::GetPosByValue(const wxVariant &oVal) const
{
    if(!oVal.IsNull())
    {
		wxFileName oName(oVal.GetString());
        for(size_t i = 0; i < m_asoData.size(); ++i)
        {
            wxGxObjectFilter* poFilter = GetFilter(i);
            if(poFilter)
            {
                if( oName.GetExt().IsSameAs(poFilter->GetExt(), false) || poFilter->GetExt().IsEmpty() )
                {
                    return i;
                }
            }
        }
    }
	return wxNOT_FOUND;
}
Example #21
0
void CFilterPageImpl::OnLButtonUp(UINT /*nFlags*/, CPoint point)
{
	if (!m_dragImage.IsNull())
	{
		m_dragImage.DragLeave(*this);
		m_dragImage.EndDrag();
		ReleaseCapture();
		m_dragImage.Destroy();
		m_dragCursor.reset();

		UINT flags = 0;
		int item = std::min<int>(m_grid.HitTest(point, &flags), m_filters.size() - 1);
		if (item >= 0 && item < static_cast<int>(m_filters.size()))
		{
			auto filter = GetFilter(m_dragItem);
			m_grid.DeleteItem(m_dragItem);
			InsertFilter(item, filter);
		}
	}
}
bool FileSelectorSave(HWND hwnd, char *filename, int type)
{
	char *filter=GetFilter(type);
	static OPENFILENAME dia;
	dia.lStructSize = sizeof(OPENFILENAME);
	dia.hwndOwner = hwnd;
	dia.lpstrFile = chosen_filename[type];
	dia.nMaxFile = _MAX_DIR;
	dia.lpstrFileTitle = chosen_file[type];
	dia.nMaxFileTitle = _MAX_FNAME;
	dia.lpstrInitialDir = GetCurDir(type);
	dia.lpstrFilter = filter;
	dia.lpstrDefExt = fsel_defext;
	dia.lpstrTitle = "Save As";
	dia.Flags = OFN_EXPLORER | OFN_OVERWRITEPROMPT;
	if(!GetSaveFileName(&dia))
		return false;
	strcpy(filename, chosen_filename[type]);
	SetCurDir(type, chosen_filename[type]);
	return true;
}
Example #23
0
bool FileSelectorLoad(HWND hwnd, char *filename, FileType type, char* title)
{
	char *filter=GetFilter(type);
	static OPENFILENAME dia;
	dia.lStructSize = sizeof(OPENFILENAME);
	dia.hwndOwner = hwnd;
	dia.lpstrFile = g_chosen_filename[type];
	dia.nMaxFile = _MAX_DIR;
	dia.lpstrFileTitle = g_chosen_file[type];
	dia.nMaxFileTitle = _MAX_FNAME;
	dia.lpstrInitialDir = GetCurDir(type);
	dia.lpstrFilter = filter;
	dia.lpstrDefExt = fsel_defext;
	dia.lpstrTitle = title;
	dia.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST;
	if(!GetOpenFileName(&dia))
		return false;
	strcpy(filename, g_chosen_filename[type]);
	SetCurDir(type, g_chosen_filename[type]);
	return true;
}
Example #24
0
void CRssFilterWnd::OnLvnEndlabeleditRwFilterList(NMHDR *pNMHDR, LRESULT *pResult)
{
	ASSERT(pNMHDR != NULL);
	ASSERT(pResult != NULL);

	NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
	// TODO: 在此添加控件通知处理程序代码
	*pResult = FALSE;

	if ( pDispInfo->item.iItem == -1 )
	{
		return;
	}

	if ( pDispInfo->item.pszText != NULL )
	{
		CRssFilter * pFilter = GetFilter(pDispInfo->item.iItem);
		SaveFilterName(pFilter, pDispInfo->item.pszText);
		*pResult = TRUE;
	}
}
Example #25
0
void CRssFilterWnd::OnLvnItemchangedRwFilterList(NMHDR *pNMHDR, LRESULT *pResult)
{
	ASSERT(pNMHDR != NULL);
	ASSERT(pResult != NULL);

	LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
	// TODO: 在此添加控件通知处理程序代码
	*pResult = 0;
	if ( pNMLV->iItem == -1 )
	{
		return;
	}

    BOOL bNewIsSelected = pNMLV->uNewState & LVIS_SELECTED;
	BOOL bOldIsSelected = pNMLV->uOldState & LVIS_SELECTED;
	CRssFilter * pFilter = GetFilter(pNMLV->iItem);

	if ( bNewIsSelected && !bOldIsSelected )
	{
		// 由未选中到选中
		DrawFilter(pFilter);
		return;
	}

	if ( !bNewIsSelected && bOldIsSelected )
	{
		// 由选中到未选中
		//CString strNewName = m_listFilter.GetItemText(pNMLV->iItem, 0);
		SaveFilterContent(pFilter);
		return;
	}

	if ( !bNewIsSelected && !bOldIsSelected )
	{
		// 保存启用状态
		//SaveFilterEnable(pFilter, m_listFilter.GetCheck(pNMLV->iItem));
		return;
	}

}
NczPlayer* AsyncNczFilteredPlayersList::GetNextPlayer()
{
	// On re-vérifie le pointeur actuel
	if(m_nextPlayer == nullptr) ResetNextPlayer();
	if(m_nextPlayer == nullptr) return nullptr;
	if(m_nextPlayer->status < GetFilter())
	{
		ResetNextPlayer();
		if(m_nextPlayer == nullptr) return nullptr;
	}
	if(m_nextPlayer->status == INVALID) return nullptr;

	NczPlayer* playerStor = m_nextPlayer->playerClass;
	
	int index = m_nextPlayer->playerClass->GetIndex();
	int loop_count = 0;
	while((m_nextPlayer = NczPlayerManager::GetInstance()->GetPlayerHandlerByIndex(++index)) == nullptr && (++loop_count) != MAX_PLAYERS)
	{
		index %= MAX_PLAYERS;
	}
	return playerStor;
}
Example #27
0
/*
 * SaveConfigFile - save the configuration information
 */
void SaveConfigFile( void )
{
    char        msgfilter[MFILTER_LAST_MSG - MFILTER_FIRST_MSG + 2];
    char        cbfilter[CFILTER_LAST_MSG - CFILTER_FIRST_MSG + 2];
    char        buf[10];
    WORD        i;

    /* monitoring information */
    putProfileBool( MONSENT, Monitoring[MON_SENT_IND] );
    putProfileBool( MONCB, Monitoring[MON_CB_IND] );
    putProfileBool( MONSTR, Monitoring[MON_STR_IND] );
    putProfileBool( MONERR, Monitoring[MON_ERR_IND] );
    putProfileBool( MONLNK, Monitoring[MON_LNK_IND] );
    putProfileBool( MONCONV, Monitoring[MON_CONV_IND] );
    putProfileBool( MONPOST, Monitoring[MON_POST_IND] );

    /* Global Settings */
    putProfileBool( CFG_SCROLL, ConfigInfo.scroll );
    putProfileBool( CFG_ALIAS, ConfigInfo.alias );
    putProfileBool( CFG_SCREEN, ConfigInfo.screen_out );
    putProfileBool( CFG_SHOW_TB, ConfigInfo.show_tb );
    putProfileBool( CFG_SHOW_HINTS, ConfigInfo.show_hints );
    putProfileBool( CFG_ON_TOP, ConfigInfo.on_top );

    /* window position/size information */
    for( i = 0; i < NO_TRK_WND; i++ ) {
        itoa( i, buf, 10 );
        writeWindowInfo( Tracking + i, buf );
    }
    writeWindowInfo( &MainWndConfig, MAIN_WND_EXT );

    /* filter information */
    GetFilter( msgfilter, cbfilter );
    WritePrivateProfileString( SECT_NAME, MSGFLTER, msgfilter, iniPath );
    WritePrivateProfileString( SECT_NAME, CBFLTER, cbfilter, iniPath );
    SaveLogConfig( iniPath, SECT_NAME );
    SaveMonoFont( SECT_NAME, iniPath );

} /* SaveConfigFile */
	void SetDownFactor( int iDownFactor )
	{
		m_iDownFactor = iDownFactor;
		m_pPolyphase = GetFilter( m_iDownFactor );
	}
Example #29
0
SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibTree(
        const SCHLIB_FILTER*                aFilter,
        std::vector<COMPONENT_SELECTION>&   aHistoryList,
        bool                                aAllowBrowser,
        int                                 aUnit,
        int                                 aConvert,
        bool                                aShowFootprints,
        const LIB_ID*                       aHighlight,
        bool                                aAllowFields )
{
    std::unique_lock<std::mutex> dialogLock( DIALOG_CHOOSE_COMPONENT::g_Mutex, std::defer_lock );
    wxString                     dialogTitle;
    SYMBOL_LIB_TABLE*            libs = Prj().SchSymbolLibTable();

    // One CHOOSE_COMPONENT dialog at a time.  User probaby can't handle more anyway.
    if( !dialogLock.try_lock() )
        return COMPONENT_SELECTION();

    auto adapterPtr( SYMBOL_TREE_MODEL_ADAPTER::Create( libs ) );
    auto adapter = static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( adapterPtr.get() );
    bool loaded = false;

    if( aFilter )
    {
        const wxArrayString& liblist = aFilter->GetAllowedLibList();

        for( unsigned ii = 0; ii < liblist.GetCount(); ii++ )
        {
            if( libs->HasLibrary( liblist[ii], true ) )
            {
                loaded = true;
                adapter->AddLibrary( liblist[ii] );
            }
        }

        adapter->AssignIntrinsicRanks();

        if( aFilter->GetFilterPowerParts() )
            adapter->SetFilter( SYMBOL_TREE_MODEL_ADAPTER::CMP_FILTER_POWER );
    }

    std::vector< LIB_TREE_ITEM* > history_list;

    for( auto const& i : aHistoryList )
    {
        LIB_ALIAS* alias = GetLibAlias( i.LibId );

        if( alias )
            history_list.push_back( alias );
    }

    adapter->DoAddLibrary( "-- " + _( "Recently Used" ) + " --", wxEmptyString, history_list, true );

    if( !aHistoryList.empty() )
        adapter->SetPreselectNode( aHistoryList[0].LibId, aHistoryList[0].Unit );

    const std::vector< wxString > libNicknames = libs->GetLogicalLibs();

    if( !loaded )
        adapter->AddLibraries( libNicknames, this );

    if( aHighlight && aHighlight->IsValid() )
        adapter->SetPreselectNode( *aHighlight, /* aUnit */ 0 );

    if( adapter->GetFilter() == SYMBOL_TREE_MODEL_ADAPTER::CMP_FILTER_POWER )
        dialogTitle.Printf( _( "Choose Power Symbol (%d items loaded)" ), adapter->GetItemCount() );
    else
        dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetItemCount() );

    DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapterPtr, aConvert,
                                 aAllowFields, aShowFootprints, aAllowBrowser );

    if( dlg.ShowQuasiModal() == wxID_CANCEL )
        return COMPONENT_SELECTION();

    COMPONENT_SELECTION sel;
    LIB_ID id = dlg.GetSelectedLibId( &sel.Unit );

    if( dlg.IsExternalBrowserSelected() )   // User requested component browser.
    {
        sel = SelectComponentFromLibBrowser( this, aFilter, id, sel.Unit, sel.Convert );
        id = sel.LibId;
    }

    if( !id.IsValid() )     // Dialog closed by OK button,
                            // or the selection by lib browser was requested,
                            // but no symbol selected
        return COMPONENT_SELECTION();

    if( sel.Unit == 0 )
        sel.Unit = 1;

    sel.Fields = dlg.GetFields();
    sel.LibId = id;

    if( sel.LibId.IsValid() )
    {
        aHistoryList.erase(
            std::remove_if(
                aHistoryList.begin(),
                aHistoryList.end(),
                [ &sel ]( COMPONENT_SELECTION const& i ){ return i.LibId == sel.LibId; } ),
            aHistoryList.end() );

        aHistoryList.insert( aHistoryList.begin(), sel );
    }

    return sel;
}
Example #30
0
void PHPExpression::Suggest(PHPEntityBase::Ptr_t resolved, PHPLookupTable& lookup, PHPEntityBase::List_t& matches)
{
    // sanity
    if(!resolved) return;
    PHPEntityBase::Ptr_t currentScope = GetSourceFile()->CurrentScope();

    // GetCount() == 0 && !GetFilter().IsEmpty() i.e. a word completion is required.
    // We enhance the list with the following:
    // - PHP keywords
    // - Global functions
    // - Global constants
    // - Function arguments
    // - Local variables (of the current scope)
    // - And aliases e.g. 'use foo\bar as Bar;'
    if(GetCount() == 0 && !GetFilter().IsEmpty()) {

        // For functions and constants, PHP will fall back to global functions or constants if a
        // namespaced function or constant does not exist.
        PHPEntityBase::List_t globals =
            lookup.FindGlobalFunctionAndConsts(PHPLookupTable::kLookupFlags_Contains, GetFilter());
        matches.insert(matches.end(), globals.begin(), globals.end());

        if(currentScope && (currentScope->Is(kEntityTypeFunction) || currentScope->Is(kEntityTypeNamespace))) {
            // If the current scope is a function
            // add the local variables + function arguments to the current list of matches
            const PHPEntityBase::List_t& children = currentScope->GetChildren();
            PHPEntityBase::List_t::const_iterator iter = children.begin();
            for(; iter != children.end(); ++iter) {
                PHPEntityBase::Ptr_t child = *iter;
                if(child->Is(kEntityTypeVariable) && child->GetShortName().Contains(GetFilter()) &&
                   child->GetShortName() != GetFilter()) {
                    matches.push_back(child);
                }
            }
        }

        {
            // Add aliases
            PHPEntityBase::List_t aliases = GetSourceFile()->GetAliases();
            PHPEntityBase::List_t::iterator iter = aliases.begin();
            for(; iter != aliases.end(); ++iter) {
                if((*iter)->GetShortName().Contains(GetFilter())) {
                    matches.push_back(*iter);
                }
            }
        }

        {
            // Add $this incase we are inside a class (but only if '$this' contains the filter string)
            wxString lcFilter = GetFilter().Lower();
            if(GetSourceFile()->Class() && wxString("$this").Contains(lcFilter)) {
                PHPEntityBase::Ptr_t thiz(new PHPEntityVariable());
                thiz->SetFullName("$this");
                thiz->SetShortName("$this");
                thiz->SetFilename(currentScope->GetFilename());
                matches.push_back(thiz);
            }
        }
    }

    // Add the scoped matches
    // for the code completion
    size_t flags = PHPLookupTable::kLookupFlags_Contains | GetLookupFlags();
    if(resolved->Is(kEntityTypeClass)) {
        if(resolved->Cast<PHPEntityClass>()->IsInterface() || resolved->Cast<PHPEntityClass>()->IsAbstractClass()) {
            flags |= PHPLookupTable::kLookupFlags_IncludeAbstractMethods;
        }
    }
    
    PHPEntityBase::List_t scopeChildren = lookup.FindChildren(resolved->GetDbId(), flags, GetFilter());
    matches.insert(matches.end(), scopeChildren.begin(), scopeChildren.end());

    // Incase the resolved is a namespace, suggest all children namespaces
    if(resolved->Is(kEntityTypeNamespace)) {
        PHPEntityBase::List_t namespaces = lookup.FindNamespaces(resolved->GetFullName(), GetFilter());
        matches.insert(matches.end(), namespaces.begin(), namespaces.end());
    }

    // and make the list unique
    DoMakeUnique(matches);
}