void FolderNavigationWidget::setCurrentFile(Core::IEditor *editor)
{
    if (!editor)
        return;

    const QString filePath = editor->document()->filePath().toString();
    // Try to find directory of current file
    bool pathOpened = false;
    if (!filePath.isEmpty())  {
        const QFileInfo fi(filePath);
        if (fi.exists())
            pathOpened = setCurrentDirectory(fi.absolutePath());
    }
    if (!pathOpened)  // Default to home.
        setCurrentDirectory(Utils::PathChooser::homePath());

    // Select the current file.
    if (pathOpened) {
        const QModelIndex fileIndex = m_fileSystemModel->index(filePath);
        if (fileIndex.isValid()) {
            QItemSelectionModel *selections = m_listView->selectionModel();
            const QModelIndex mainIndex = m_filterModel->mapFromSource(fileIndex);
            selections->setCurrentIndex(mainIndex, QItemSelectionModel::SelectCurrent
                                                 | QItemSelectionModel::Clear);
            m_listView->scrollTo(mainIndex);
        }
    }
}
void FolderNavigationWidget::openItem(const QModelIndex &srcIndex, bool openDirectoryAsProject)
{
    const QString fileName = m_fileSystemModel->fileName(srcIndex);
    if (fileName == QLatin1String("."))
        return;
    if (fileName == QLatin1String("..")) {
        // cd up: Special behaviour: The fileInfo of ".." is that of the parent directory.
        const QString parentPath = m_fileSystemModel->fileInfo(srcIndex).absoluteFilePath();
        setCurrentDirectory(parentPath);
        return;
    }
    const QString path = m_fileSystemModel->filePath(srcIndex);
    if (m_fileSystemModel->isDir(srcIndex)) {
        const QFileInfo fi = m_fileSystemModel->fileInfo(srcIndex);
        if (!fi.isReadable() || !fi.isExecutable())
            return;
        // Try to find project files in directory and open those.
        if (openDirectoryAsProject) {
            QDir dir(path);
            QStringList proFiles;
            foreach (const QFileInfo &i, dir.entryInfoList(ProjectExplorerPlugin::projectFileGlobs(), QDir::Files))
                proFiles.append(i.absoluteFilePath());
            if (!proFiles.isEmpty())
                Core::ICore::instance()->openFiles(proFiles);
            return;
        }
        // Change to directory
        setCurrentDirectory(path);
        return;
    }
    // Open file.
    Core::ICore::instance()->openFiles(QStringList(path));
}
Ejemplo n.º 3
0
void FileSelectorWidget::on_FileView_doubleClicked(const QModelIndex& index)
{
	// If the target is a directory, change to that directory.
	// Otherwise, adjust the selectedFilenames_ list and emit the selectionMade() signal.
	if (fileSystemModel_.isDir(index))
	{
		setCurrentDirectory(fileSystemModel_.filePath(index));

		// Need to clear the current files list, since it will no longer be valid
		selectedFilenames_.clear();
		emit(selectionValid(false));

		return;
	}

	// Not a dir, so adjust the filenames list and emit the signal
	QItemSelectionModel* selectionModel = ui.FileView->selectionModel();
	QModelIndexList selectedRows = selectionModel->selectedRows();
	selectedFilenames_.clear();
	for (int n=0; n<selectedRows.count(); ++n)
	{
		if (fileSystemModel_.isDir(selectedRows.at(n))) continue;
		selectedFilenames_ << fileSystemModel_.fileName(selectedRows.at(n));
	}

	emit(selectionValid(selectedFilenames_.count() > 0));

	updateWidgets();

	emit(selectionMade(false));
}
Ejemplo n.º 4
0
extern int main (int __unused__ argc, char **argv)
{
	cookedArgs *args;
#ifdef VMS
	extern int getredirection (int *ac, char ***av);

	/* do wildcard expansion and I/O redirection */
	getredirection (&argc, &argv);
#endif

#ifdef AMIGA
	/* This program doesn't work when started from the Workbench */
	if (argc == 0)
		exit (1);
#endif

#ifdef __EMX__
	_wildcard (&argc, &argv);  /* expand wildcards in argument list */
#endif

#if defined (macintosh) && BUILD_MPW_TOOL == 0
	argc = ccommand (&argv);
#endif

	setCurrentDirectory ();
	setExecutableName (*argv++);
	sanitizeEnviron ();
	checkRegex ();

	args = cArgNewFromArgv (argv);
	previewFirstOption (args);
	testEtagsInvocation ();
	initializeParsing ();
	initOptions ();
	readOptionConfiguration ();
	verbose ("Reading initial options from command line\n");
	parseOptions (args);
	checkOptions ();
	unifyLanguageMaps ();
	makeTags (args);

	/*  Clean up.
	 */
	cArgDelete (args);
	freeKeywordTable ();
	freeRoutineResources ();
	freeSourceFileResources ();
	freeTagFileResources ();
	freeOptionResources ();
	freeParserResources ();
	freeRegexResources ();
	freeXcmdResources ();

	if (Option.guessParser)
		return (Option.guessParser == TRUE)? 0: 1;

	exit (0);
	return 0;
}
void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
{
    QMenu menu;
    // Open current item
    const QModelIndex current = currentItem();
    const bool hasCurrentItem = current.isValid();
    QAction *actionOpen = menu.addAction(actionOpenText(m_fileSystemModel, current));
    actionOpen->setEnabled(hasCurrentItem);
    // Explorer & teminal
    QAction *actionExplorer = menu.addAction(Core::FileUtils::msgGraphicalShellAction());
    actionExplorer->setEnabled(hasCurrentItem);
    QAction *actionTerminal = menu.addAction(Core::FileUtils::msgTerminalAction());
    actionTerminal->setEnabled(hasCurrentItem);

    QAction *actionFind = menu.addAction(msgFindOnFileSystem());
    actionFind->setEnabled(hasCurrentItem);
    // open with...
    if (!m_fileSystemModel->isDir(current)) {
        QMenu *openWith = menu.addMenu(tr("Open with"));
        Core::DocumentManager::populateOpenWithMenu(openWith,
                                                m_fileSystemModel->filePath(current));
    }

    // Open file dialog to choose a path starting from current
    QAction *actionChooseFolder = menu.addAction(tr("Choose Folder..."));

    QAction *action = menu.exec(ev->globalPos());
    if (!action)
        return;

    ev->accept();
    if (action == actionOpen) { // Handle open file.
        openItem(current);
        return;
    }
    if (action == actionChooseFolder) { // Open file dialog
        const QString newPath = QFileDialog::getExistingDirectory(this, tr("Choose Folder"), currentDirectory());
        if (!newPath.isEmpty())
            setCurrentDirectory(newPath);
        return;
    }
    if (action == actionTerminal) {
        Core::FileUtils::openTerminal(m_fileSystemModel->filePath(current));
        return;
    }
    if (action == actionExplorer) {
        Core::FileUtils::showInGraphicalShell(this, m_fileSystemModel->filePath(current));
        return;
    }
    if (action == actionFind) {
        QFileInfo info = m_fileSystemModel->fileInfo(current);
        if (m_fileSystemModel->isDir(current))
            findOnFileSystem(info.absoluteFilePath());
        else
            findOnFileSystem(info.absolutePath());
        return;
    }
    Core::DocumentManager::executeOpenWithMenuAction(action);
}
Ejemplo n.º 6
0
void FileSelectorWidget::on_FavouritesTable_currentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous)
{
	if (refreshing_ || (!current)) return;

	// Set current directory
	setCurrentDirectory(favourites_.at(current->data(Qt::UserRole).toInt()));

	updateWidgets();
}
Ejemplo n.º 7
0
void FileSelectorWidget::on_DirectoryEdit_returnPressed()
{
	if (refreshing_) return;

	// Try to convert the text to a proper directory
	QDir newDirectory;
	newDirectory.setPath(ui.DirectoryEdit->text());

	setCurrentDirectory(newDirectory.absolutePath());
}
Ejemplo n.º 8
0
void FileSelector::goUp()
{
    QModelIndex current = m_view->rootIndex();
    if (current.isValid()) {
        QModelIndex up = current.parent();
        if (up.isValid()) {
            setCurrentDirectory(up);
        }
    }
}
Ejemplo n.º 9
0
bool MWindow::getOpenMultipleFiles(const char * title, const char * filter, string * repertory, list <string> * filesList)
{
	const char * currentDir = getCurrentDirectory();
	setActive(false);

	static char filename[65536];
	OPENFILENAME fn;

	memset(&fn, 0, sizeof(fn));
	strcpy(filename, "");

	fn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_EXPLORER | OFN_ALLOWMULTISELECT;
	fn.lStructSize	= sizeof(fn);
	fn.lpstrFilter	= filter;
	fn.lpstrFile	= filename;
	fn.nMaxFile		= 65536*4;
	fn.lpstrTitle	= title;
	fn.hwndOwner    = m_hWnd;
	filename[0]		= NULL;

	if(GetOpenFileName(&fn))
	{
		setCurrentDirectory(currentDir);

		if(fn.nFileOffset < lstrlen(filename))
		{
			char rep[256];
			getRepertory(rep, filename);
			getLocalFilename(filename, rep, filename);
			(*repertory) = rep;
			filesList->push_back(filename);
		}
		else
		{
			char filePath[256];
			strcpy(filePath, filename);
			filePath[fn.nFileOffset] = 0;
			(*repertory) = filePath;

			while(filename[fn.nFileOffset] != 0)
			{
				char Message[256];
				strcpy(Message, filename+fn.nFileOffset);
				filesList->push_back(Message);
				fn.nFileOffset += (strlen(filename+fn.nFileOffset) + 1);
			}
		}
		setActive(true);
		return true;
	}

	setActive(true);
	return false;
}
Ejemplo n.º 10
0
void FolderNavigationWidget::openItem(const QModelIndex &srcIndex)
{
    const QString fileName = m_fileSystemModel->fileName(srcIndex);
    if (fileName == QLatin1String("."))
        return;
    if (fileName == QLatin1String("..")) {
        // cd up: Special behaviour: The fileInfo of ".." is that of the parent directory.
        const QString parentPath = m_fileSystemModel->fileInfo(srcIndex).absoluteFilePath();
        setCurrentDirectory(parentPath);
        return;
    }
    if (m_fileSystemModel->isDir(srcIndex)) { // Change to directory
        const QFileInfo fi = m_fileSystemModel->fileInfo(srcIndex);
        if (fi.isReadable() && fi.isExecutable())
            setCurrentDirectory(m_fileSystemModel->filePath(srcIndex));
        return;
    }
    // Open file.
    Core::EditorManager::openEditor(m_fileSystemModel->filePath(srcIndex), Core::Id(), Core::EditorManager::ModeSwitch);
}
Ejemplo n.º 11
0
// Set mode of file selector
void FileSelectorWidget::setMode(FileSelectorWidget::SelectionMode mode, QDir startingDir)
{
	mode_ = mode;

	// Set relevant selection mode for file view
	if (mode_ == FileSelectorWidget::OpenMultipleMode) ui.FileView->setSelectionMode(QTableView::ExtendedSelection);
	else ui.FileView->setSelectionMode(QTableView::SingleSelection);

	setCurrentDirectory(startingDir.absolutePath());
	updateWidgets();
}
Ejemplo n.º 12
0
void FileSelector::enter(const QModelIndex &index)
{
    if (m_model->isDir(index)) {
        setCurrentDirectory(index);
    } else {
        QModelIndexList selected = m_view->selectionModel()->selectedIndexes();
        QStringList files;
        foreach (const QModelIndex &i, selected) {
            files << m_model->filePath(i);
        }
        emit fileSelected(files.first());
    }
Ejemplo n.º 13
0
QString getVLCPath() {
	static const char *psz_libvlc_control_name = "libvlc";
	static const char *psz_libvlc_control_functionToTest = "libvlc_exception_init";

	static QString libvlc_path;

	if( !libvlc_path.isEmpty() )
	{
		return libvlc_path;
	}

	//Tries to autodetect the VLC path with a default list of path

	QStringList pathList;
	pathList << QCoreApplication::libraryPaths();

#ifdef Q_OS_LINUX
	pathList << "/usr/local/lib";
#endif	//Q_OS_LINUX

#ifdef Q_OS_WIN
	static const char *psz_libvlc_version = "0.9";

	saveCurrentDirectory();

	//QSettings allows us to read the Windows registry
	//Check if there is a standard VLC installation under Windows
	//If there is a VLC Windows installation, check we get the good version i.e 0.9
	QSettings settings( QSettings::SystemScope, "VideoLAN", "VLC" );
	if( settings.value("Version").toString().contains( psz_libvlc_version ) )
	{
		QString vlcInstallDir = settings.value("InstallDir").toString();
		pathList << vlcInstallDir;

		setCurrentDirectory( vlcInstallDir.toAscii().constData() );
	}
#endif	//Q_OS_WIN

	p_libvlc_control = new QLibrary();
	foreach ( libvlc_path, pathList )
	{
		p_libvlc_control->setFileName( libvlc_path + QDir::separator() + psz_libvlc_control_name );

		if( p_libvlc_control->load() && p_libvlc_control->resolve( psz_libvlc_control_functionToTest ) )
		{
			qDebug() << "VLC path found:" << libvlc_path;
			return libvlc_path;
		}
		qDebug() << "Warning:" << p_libvlc_control->errorString();
	}
void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
{
    QMenu menu;
    // Open current item
    const QModelIndex current = currentItem();
    const bool hasCurrentItem = current.isValid();
    QAction *actionOpen = menu.addAction(actionOpenText(m_fileSystemModel, current));
    actionOpen->setEnabled(hasCurrentItem);
    // Explorer & teminal
    QAction *actionExplorer = menu.addAction(msgGraphicalShellAction());
    actionExplorer->setEnabled(hasCurrentItem);
    QAction *actionTerminal = menu.addAction(msgTerminalAction());
    actionTerminal->setEnabled(hasCurrentItem);

    // open with...
    if (!m_fileSystemModel->isDir(current)) {
        QMenu *openWith = menu.addMenu(tr("Open with"));
        ProjectExplorerPlugin::populateOpenWithMenu(openWith,
                                                    m_fileSystemModel->filePath(current));
    }

    // Open file dialog to choose a path starting from current
    QAction *actionChooseFolder = menu.addAction(tr("Choose folder..."));

    QAction *action = menu.exec(ev->globalPos());
    if (!action)
        return;

    ev->accept();
    if (action == actionOpen) { // Handle open file.
        openItem(current);
        return;
    }
    if (action == actionChooseFolder) { // Open file dialog
        const QString newPath = QFileDialog::getExistingDirectory(this, tr("Choose folder"), currentDirectory());
        if (!newPath.isEmpty())
            setCurrentDirectory(newPath);
        return;
    }
    if (action == actionTerminal) {
        openTerminal(m_fileSystemModel->filePath(current));
        return;
    }
    if (action == actionExplorer) {
        showInGraphicalShell(this, m_fileSystemModel->filePath(current));
        return;
    }
    ProjectExplorerPlugin::openEditorFromAction(action,
                                                m_fileSystemModel->filePath(current));
}
Ejemplo n.º 15
0
// Set current filename selection
void FileSelectorWidget::setSelectedFilename(QString filename)
{
	selectedFilenames_.clear();

	// Set current directory to match that of the filename
	QFileInfo fileInfo(filename);
	setCurrentDirectory(fileInfo.absolutePath());
	selectedFilenames_ << fileInfo.fileName();

	// Check to see if the filename exists in the current dir
	QModelIndex index = fileSystemModel_.index(currentDirectory_.filePath(filename));
	if (index.isValid()) ui.FileView->selectRow(index.row());

	// Update selected plugin
	if (updatePluginFromFilename_) updatePluginFromCurrentFilename();
}
Ejemplo n.º 16
0
//-----------------------------------------------------------------------------
void ctkPathLineEditPrivate::init()
{
  Q_Q(ctkPathLineEdit);
  this->ComboBox = new QComboBox(q);
  QHBoxLayout* layout = new QHBoxLayout(q);
  layout->addWidget(this->ComboBox);
  layout->setContentsMargins(0,0,0,0);

  this->ComboBox->setEditable(true);
  q->setSizePolicy(QSizePolicy(
                     QSizePolicy::Expanding, QSizePolicy::Fixed,
                     QSizePolicy::LineEdit));

  QObject::connect(this->ComboBox,SIGNAL(editTextChanged(QString)),
                   q, SLOT(setCurrentDirectory(QString)));
  QObject::connect(this->ComboBox,SIGNAL(editTextChanged(QString)),
                   q, SLOT(updateHasValidInput()));
}
Ejemplo n.º 17
0
void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
{
    QMenu menu;
    // Open current item
    const QModelIndex current = currentItem();
    const bool hasCurrentItem = current.isValid();
    QAction *actionOpen = menu.addAction(actionOpenText(m_fileSystemModel, current));
    actionOpen->setEnabled(hasCurrentItem);

    // we need dummy DocumentModel::Entry with absolute file path in it
    // to get EditorManager::addNativeDirAndOpenWithActions() working
    Core::DocumentModel::Entry fakeEntry;
    Core::IDocument document;
    document.setFilePath(Utils::FileName::fromString(m_fileSystemModel->filePath(current)));
    fakeEntry.document = &document;
    Core::EditorManager::addNativeDirAndOpenWithActions(&menu, &fakeEntry);

    const bool isDirectory = hasCurrentItem && m_fileSystemModel->isDir(current);
    QAction *actionOpenDirectoryAsProject = 0;
    if (isDirectory && m_fileSystemModel->fileName(current) != QLatin1String("..")) {
        actionOpenDirectoryAsProject =
            menu.addAction(tr("Open Project in \"%1\"")
                           .arg(m_fileSystemModel->fileName(current)));
    }

    // Open file dialog to choose a path starting from current
    QAction *actionChooseFolder = menu.addAction(tr("Choose Folder..."));

    QAction *action = menu.exec(ev->globalPos());
    if (!action)
        return;

    ev->accept();
    if (action == actionOpen) { // Handle open file.
        openItem(current);
    } else if (action == actionOpenDirectoryAsProject) {
        openItem(current, true);
    } else if (action == actionChooseFolder) { // Open file dialog
        const QString newPath = QFileDialog::getExistingDirectory(this, tr("Choose Folder"), currentDirectory());
        if (!newPath.isEmpty())
            setCurrentDirectory(newPath);
    }
}
Ejemplo n.º 18
0
Archivo: main.c Proyecto: koron/ctags
extern int main (int __unused__ argc, char **argv)
{
	cookedArgs *args;

	setCurrentDirectory ();
	setExecutableName (*argv++);
	sanitizeEnviron ();
	checkRegex ();

	args = cArgNewFromArgv (argv);
	previewFirstOption (args);
	testEtagsInvocation ();
	initializeParsing ();
	initOptions ();
	readOptionConfiguration ();
	verbose ("Reading initial options from command line\n");
	parseOptions (args);
	checkOptions ();
	unifyLanguageMaps ();
	makeTags (args);

	/*  Clean up.
	 */
	cArgDelete (args);
	freeKeywordTable ();
	freeRoutineResources ();
	freeSourceFileResources ();
	freeTagFileResources ();
	freeOptionResources ();
	freeParserResources ();
	freeRegexResources ();
	freeXcmdResources ();
#ifdef HAVE_ICONV
	freeEncodingResources ();
#endif

	if (Option.printLanguage)
		return (Option.printLanguage == TRUE)? 0: 1;

	exit (0);
	return 0;
}
Ejemplo n.º 19
0
const char * MWindow::getSaveFilename(const char * title, const char * filter, const char * startPath)
{
	char winStartPath[256] = "";
	if(startPath)
	{
		strcpy(winStartPath, startPath);
		strrep(winStartPath, '/', '\\');
	}

	const char * currentDir = getCurrentDirectory();
	setActive(false);

	static char filename[256];
	OPENFILENAME fn;

	memset(&fn, 0, sizeof(fn));
	strcpy(filename, "");

	fn.lpstrInitialDir = winStartPath;
	fn.lStructSize	= sizeof(fn);
	fn.lpstrFilter	= filter;
	fn.lpstrFile	= filename;
	fn.nMaxFile		= 256*4;
	fn.Flags		= OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
	fn.lpstrTitle	= title;
	filename[0]		= NULL;
	fn.hwndOwner    = m_hWnd;

	if(GetSaveFileName(&fn))
	{
		setCurrentDirectory(currentDir);
		setActive(true);
		return filename;
	}

	setActive(true);
	return NULL;
}
Ejemplo n.º 20
0
//------------------------------------------------------------------------------
void ctkPathLineEditPrivate::createPathLineEditWidget(bool useComboBox)
{
  Q_Q(ctkPathLineEdit);

  QString path = q->currentPath();

  if (useComboBox)
    {
    this->ComboBox = new QComboBox(q);
    this->ComboBox->setEditable(true);
    this->ComboBox->setInsertPolicy(QComboBox::NoInsert);
    this->LineEdit = this->ComboBox->lineEdit();
    }
  else
    {
    this->ComboBox = 0;
    this->LineEdit = new QLineEdit(q);
    }

  if (q->layout() && q->layout()->itemAt(0))
    {
    delete q->layout()->itemAt(0)->widget();
    }
  qobject_cast<QHBoxLayout*>(q->layout())->insertWidget(
    0,
    this->ComboBox ? qobject_cast<QWidget*>(this->ComboBox) :
    qobject_cast<QWidget*>(this->LineEdit));

  this->updateFilter();
  q->retrieveHistory();
  q->setCurrentPath(path);

  QObject::connect(this->LineEdit, SIGNAL(textChanged(QString)),
                   q, SLOT(setCurrentDirectory(QString)));
  QObject::connect(this->LineEdit, SIGNAL(textChanged(QString)),
                   q, SLOT(updateHasValidInput()));
  q->updateGeometry();
}
Ejemplo n.º 21
0
void FileSelectorWidget::on_DirectoryUpButton_clicked(bool checked)
{
	if (currentDirectory_.cdUp()) setCurrentDirectory(currentDirectory_.absolutePath());
}
Ejemplo n.º 22
0
void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
{
    QMenu menu;
    // Open current item
    const QModelIndex current = currentItem();
    const bool hasCurrentItem = current.isValid();
    QAction *actionOpen = menu.addAction(actionOpenText(m_fileSystemModel, current));
    actionOpen->setEnabled(hasCurrentItem);
    const bool isDirectory = hasCurrentItem && m_fileSystemModel->isDir(current);
    QAction *actionOpenDirectoryAsProject = 0;
    if (isDirectory && m_fileSystemModel->fileName(current) != QLatin1String("..")) {
        actionOpenDirectoryAsProject =
            menu.addAction(tr("Open Project in \"%1\"")
                           .arg(m_fileSystemModel->fileName(current)));
    }
    // Explorer & teminal
    QAction *actionExplorer = menu.addAction(Core::FileUtils::msgGraphicalShellAction());
    actionExplorer->setEnabled(hasCurrentItem);
    QAction *actionTerminal = menu.addAction(Core::FileUtils::msgTerminalAction());
    actionTerminal->setEnabled(hasCurrentItem);

    QAction *actionFind = menu.addAction(Core::FileUtils::msgFindInDirectory());
    actionFind->setEnabled(hasCurrentItem);
    // open with...
    if (hasCurrentItem && !isDirectory) {
        QMenu *openWith = menu.addMenu(tr("Open With"));
        Core::EditorManager::populateOpenWithMenu(openWith,
                                                  m_fileSystemModel->filePath(current));
    }

    // Open file dialog to choose a path starting from current
    QAction *actionChooseFolder = menu.addAction(tr("Choose Folder..."));

    QAction *action = menu.exec(ev->globalPos());
    if (!action)
        return;

    ev->accept();
    if (action == actionOpen) { // Handle open file.
        openItem(current);
        return;
    }
    if (action == actionOpenDirectoryAsProject) {
        openItem(current, true);
        return;
    }
    if (action == actionChooseFolder) { // Open file dialog
        const QString newPath = QFileDialog::getExistingDirectory(this, tr("Choose Folder"), currentDirectory());
        if (!newPath.isEmpty())
            setCurrentDirectory(newPath);
        return;
    }
    if (action == actionTerminal) {
        Core::FileUtils::openTerminal(m_fileSystemModel->filePath(current));
        return;
    }
    if (action == actionExplorer) {
        Core::FileUtils::showInGraphicalShell(this, m_fileSystemModel->filePath(current));
        return;
    }
    if (action == actionFind) {
        TextEditor::FindInFiles::findOnFileSystem(m_fileSystemModel->filePath(current));
        return;
    }
}
Ejemplo n.º 23
0
// if childData is NULL, the size will be returned in childDataLen
bool ChildData::decode(void* childData)//, int childDataSize)
{
	bool	result = false;
	int		strLen;

	if (childData == NULL)// || childDataSize < sizeof(DWORD))
		return false;

	char* p = (char*)childData;

	// total size
	DWORD size;
	memcpy(&size, p, sizeof(DWORD));
	p += sizeof(DWORD);
//	// check that size encoded in buffer isn't bigger that passed-in size
//	if (size > childDataSize)
//		return false;
	size -= sizeof(DWORD);

	// reserved (ignore)
	p += sizeof(DWORD);
	size -= sizeof(DWORD);

	// get current directory
	strLen = ts_strlen((WCHAR*)p);
	if ((strLen+1)*2 > (int)size)
		goto cleanup;
	if (strLen == 0)
		resetCurrentDirectory();
	else
	{
#ifdef UNICODE
		setCurrentDirectory((WCHAR*)p);
#else
		char buf[256];
		unicode2ascii((WCHAR*)p, buf);
		setCurrentDirectory(buf);
#endif
	}
	p += (strLen + 1) * 2;
	size -= (strLen + 1)*2;

	// num redirs
	memcpy(&numRedirArgs, p, sizeof(DWORD));
	p += sizeof(DWORD);
	size -= sizeof(DWORD);

	// allocate redirs array
	if (redirArgs != NULL)
		free(redirArgs);
	redirArgs = (RedirArg*)malloc(sizeof(RedirArg)*numRedirArgs);
	if (redirArgs == NULL)
		goto cleanup;

	// redirs
	{
	for (int i=0; i<numRedirArgs; i++)
	{
		// flags
		DWORD flags;
		memcpy(&flags, p, sizeof(DWORD));
		p += sizeof(DWORD);
		size -= sizeof(DWORD);
		switch (flags&0x00000003)
		{
			case 0:
				redirArgs[i].redirType = RT_PIPE_UNSPEC;
				break;
			case 1:
				redirArgs[i].redirType = RT_FILE;
				break;
			case 2:
				redirArgs[i].redirType = RT_HANDLE;
				break;
		}
		bool filenamePresent = false;
		if (flags & 0x00000004)
			filenamePresent = true;
		redirArgs[i].append			= ((flags & 0x00000008) != 0);
		redirArgs[i].openForRead	= ((flags & 0x00000010) != 0);
		redirArgs[i].openForWrite	= ((flags & 0x00000020) != 0);
		// fd
		memcpy(&redirArgs[i].fd, p, sizeof(DWORD));
		p += sizeof(DWORD);
		size -= sizeof(DWORD);
		// fd2
		memcpy(&redirArgs[i].fd2, p, sizeof(DWORD));
		p += sizeof(DWORD);
		size -= sizeof(DWORD);
		// pipe/file name
		if (filenamePresent)
		{
			int strLen = ts_strlen((WCHAR*)p);
			if ((strLen+1)*2 > (int)size)
				goto cleanup;
			redirArgs[i].filename = _tcsdup((WCHAR*)p);
			p += (strLen + 1)*2;
			size -= (strLen + 1)*2;
		}
		else
			redirArgs[i].filename = NULL;
	}
	}

	// get environment
	if (size <= 0)
		return false;
	p += sizeof(DWORD);	// skip env size
	resetEnvironment();
	addEnvironmentList((WCHAR*)p);

	// success
	result = true;

cleanup:

	return result;
}
Ejemplo n.º 24
0
FileSelector::FileSelector(QWidget *parent)
    : QWidget(parent),
    m_view(new QListView(this)),
    m_model(new QFileSystemModel(this)),
    m_title(new QLabel(this)),
    m_path(new QLabel(this)),
    m_bookmarkButton(new QPushButton(this)),
    m_bookmarkMenu(new QMenu(this)),
    m_bookmarks(),
    m_signalMapper(new QSignalMapper(this))
{
    QGridLayout *layout = new QGridLayout(this);
    layout->setContentsMargins(0, 0, 0, 0);
    layout->setRowStretch(5, 1);
    layout->setSpacing(0);

    m_title->setAlignment(Qt::AlignCenter);
    layout->addWidget(m_title, 0, 0, 1, 2);
    layout->addWidget(m_path, 1, 0, 1, 2);

    m_view->setModel(m_model);
    connect(m_view, SIGNAL(activated(QModelIndex)), this, SLOT(enter(QModelIndex)));
    layout->addWidget(m_view, 2, 0, 6, 1);
    m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    m_view->setSelectionMode(QListView::ExtendedSelection);
    QFont font = m_view->font();
    font.setPointSize(8);
    m_view->setFont(font);

    m_model->setNameFilterDisables(false);
    m_model->setRootPath("/");

    connect(m_signalMapper, SIGNAL(mapped(QString)), this, SLOT(setCurrentDirectory(QString)));

    m_bookmarkButton->setIcon(QIcon(":nobookmark.png"));
    m_bookmarkButton->setShortcut(QKeySequence(Qt::ALT+Qt::Key_B));
    connect(m_bookmarkButton, SIGNAL(clicked()), this, SLOT(toggleBookmark()));
    layout->addWidget(m_bookmarkButton, 2, 1);

    QPushButton *button = new QPushButton();
    button->setIcon(QIcon(":up.png"));
    button->setShortcut(QKeySequence(Qt::ALT+Qt::Key_Up));
    connect(button, SIGNAL(clicked()), this, SLOT(goUp()));
    layout->addWidget(button, 3, 1);

    button = new QPushButton();
    button->setIcon(QIcon(":ok.png"));
    connect(button, SIGNAL(clicked()), this, SLOT(accept()));
    layout->addWidget(button, 6, 1);

    button = new QPushButton();
    button->setIcon(QIcon(":cancel.png"));
    button->setShortcut(QKeySequence(Qt::Key_Escape));
    connect(button, SIGNAL(clicked()), this, SIGNAL(cancel()));
    layout->addWidget(button, 7, 1);

    QSettings conf(QDir::homePath()+"Maps/nanomap.conf", QSettings::NativeFormat);
    conf.beginGroup("fileselector");
    m_bookmarks = conf.value("bookmarks").toStringList();
    conf.endGroup();

    setCurrentDirectory(m_model->index(QDir::homePath()));
    updateBookmarkMenu();

    m_view->setFocus(Qt::OtherFocusReason);
    resize(320, 240);
}