Skip to content
Permalink
Browse files

improved error check. (refs #76)

  • Loading branch information...
haraki committed Jun 5, 2019
1 parent a4074d1 commit ab05dd5936e8e5100edfdd3582f187a0913548b9
Showing with 106 additions and 15 deletions.
  1. +28 −5 doublefolderpanel.cpp
  2. +31 −6 folderform.cpp
  3. +29 −3 folderview.cpp
  4. +18 −1 mainwindow.cpp
@@ -532,6 +532,12 @@ void DoubleFolderPanel::onMakeDirectory()
return;
}

QString currentDirPath = activeForm->getCurrentDirPath();
if(currentDirPath.isEmpty())
{
return;
}

bool ok = false;
QString dirName = QInputDialog::getText(parentWidget(),
tr("Make a new directory"),
@@ -544,7 +550,7 @@ void DoubleFolderPanel::onMakeDirectory()
return;
}

emitMakeDirectory(activeForm->getCurrentDirPath(), dirName);
emitMakeDirectory(currentDirPath, dirName);
}

void DoubleFolderPanel::onCreateNewFile()
@@ -557,6 +563,12 @@ void DoubleFolderPanel::onCreateNewFile()
return;
}

QString currentDirPath = activeForm->getCurrentDirPath();
if(currentDirPath.isEmpty())
{
return;
}

bool ok = false;
QString fileName = QInputDialog::getText(this,
tr("Create a new file"),
@@ -569,7 +581,7 @@ void DoubleFolderPanel::onCreateNewFile()
return;
}

emitCreateNewFile(activeForm->getCurrentDirPath(), fileName);
emitCreateNewFile(currentDirPath, fileName);
}

void DoubleFolderPanel::onRename()
@@ -583,7 +595,13 @@ void DoubleFolderPanel::onRename()
}

QString oldName = activeForm->getCurrentFileName();
if(oldName == "..")
if(oldName.isEmpty() || oldName == "..")
{
return;
}

QString currentDirPath = activeForm->getCurrentDirPath();
if(currentDirPath.isEmpty())
{
return;
}
@@ -595,7 +613,11 @@ void DoubleFolderPanel::onRename()
}

QString newName = dialog.getNewName();
emitRenameFile(activeForm->getCurrentDirPath(), oldName, newName);
if(newName.isEmpty() || newName == "." || newName == "..")
{
return;
}
emitRenameFile(currentDirPath, oldName, newName);

activeForm->setCursor(newName);
}
@@ -610,7 +632,8 @@ void DoubleFolderPanel::onAttributes()
return;
}

if(activeForm->getCurrentFileName() == "..")
QString currentFileName = activeForm->getCurrentFileName();
if(currentFileName.isEmpty() || currentFileName == "..")
{
return;
}
@@ -206,23 +206,44 @@ int FolderForm::setPath(const QString& dirPath)

QString FolderForm::getCurrentDirPath()
{
return m_folderModel->filePath(ui->folderView->rootIndex());
QModelIndex index = ui->folderView->rootIndex();

if(index.isValid())
{
return m_folderModel->filePath(index);
}

return "";
}

QString FolderForm::getCurrentFileName()
{
return m_folderModel->fileName(ui->folderView->currentIndex());
QModelIndex index = ui->folderView->currentIndex();

if(index.isValid())
{
return m_folderModel->fileName(index);
}

return "";
}

QFileInfo FolderForm::getCurrentFileInfo()
{
return m_folderModel->fileInfo(ui->folderView->currentIndex());
QModelIndex index = ui->folderView->currentIndex();

if(index.isValid())
{
return m_folderModel->fileInfo(index);
}

return QFileInfo();
}

QList<QFileInfo> FolderForm::getSelectedFileInfoList()
{
QModelIndexList indexList = m_folderModel->getSelectedIndexList();
if(indexList.size() == 0 && getCurrentFileName() != "..")
if(indexList.size() == 0 && getCurrentFileName() != "" && getCurrentFileName() != "..")
{
// 選択しているアイテムが無くても、".." 以外の箇所にカーソルがあれば、それを選択しているものとする
indexList.push_back(ui->folderView->currentIndex());
@@ -281,20 +302,24 @@ void FolderForm::onLayoutChanged(const QList<QPersistentModelIndex> &parents/* =

QModelIndex cursorIndex = ui->folderView->currentIndex();

qDebug() << "============================= cursorIndex.isValid() : " << cursorIndex.isValid() << ", cursorIndex.row() : " << cursorIndex.row();
qDebug() << "cursorIndex.isValid() : " << cursorIndex.isValid() << ", cursorIndex.row() : " << cursorIndex.row();

if(!cursorIndex.isValid() || cursorIndex.row() < 0)
{
// 初期カーソル位置はリストの先頭
cursorIndex = m_folderModel->index(0, 0, ui->folderView->rootIndex());
ui->folderView->setCursor(cursorIndex);
}

qDebug() << "rowCount : " << m_folderModel->rowCount(ui->folderView->rootIndex());
}

void FolderForm::onLayoutAboutToBeChanged(const QList<QPersistentModelIndex> &parents/* = QList<QPersistentModelIndex>()*/, QAbstractItemModel::LayoutChangeHint hint/* = QAbstractItemModel::NoLayoutChangeHint*/)
{
qDebug() << "FolderForm::onLayoutAboutToBeChanged()";
Q_UNUSED(parents)
Q_UNUSED(hint)

qDebug() << "FolderForm::onLayoutAboutToBeChanged()";
}

void FolderForm::setCursor(const QString& fileName)
@@ -55,6 +55,11 @@ void FolderView::selectCurrent(QItemSelectionModel::SelectionFlag selectionFlag/
Q_ASSERT(folderModel);

const QModelIndex index = currentIndex();
if(!index.isValid() || folderModel->rowCount(index.parent()) == 0)
{
return;
}

if(folderModel->fileName(index) != "..")
{
folderModel->setSelect(index.row(), selectionFlag, index.parent());
@@ -72,10 +77,15 @@ void FolderView::setCursor(const QModelIndex& index)

void FolderView::movePreviousCursor()
{
const QModelIndex index = currentIndex();
FolderModel* folderModel = qobject_cast<FolderModel*>(model());
Q_ASSERT(folderModel);

const QModelIndex index = currentIndex();
if(!index.isValid() || folderModel->rowCount(index.parent()) == 0)
{
return;
}

int rowNext = index.row() - 1;
if(rowNext < 0)
{
@@ -94,10 +104,15 @@ void FolderView::movePreviousCursor()

void FolderView::moveNextCursor()
{
const QModelIndex index = currentIndex();
FolderModel* folderModel = qobject_cast<FolderModel*>(model());
Q_ASSERT(folderModel);

const QModelIndex index = currentIndex();
if(!index.isValid() || folderModel->rowCount(index.parent()) == 0)
{
return;
}

int rowNext = index.row() + 1;
if(rowNext == folderModel->rowCount(index.parent()))
{
@@ -124,6 +139,11 @@ void FolderView::onDoubleClicked(const QModelIndex& index)
FolderModel* folderModel = qobject_cast<FolderModel*>(model());
Q_ASSERT(folderModel);

if(!index.isValid())
{
return;
}

const QString path = folderModel->fileInfo(index).absoluteFilePath();

emitOpen(path);
@@ -160,7 +180,13 @@ void FolderView::keyPressEvent(QKeyEvent *e)
FolderModel* folderModel = qobject_cast<FolderModel*>(model());
Q_ASSERT(folderModel);

const QString path = folderModel->fileInfo(currentIndex()).absoluteFilePath();
const QModelIndex index = currentIndex();
if(!index.isValid())
{
return;
}

const QString path = folderModel->fileInfo(index).absoluteFilePath();
if(e->modifiers() & Qt::ShiftModifier)
{
emitOpenWithApp(path);
@@ -192,7 +192,14 @@ int MainWindow::openFile(const QString& path, ViewerType viewerType/* = ViewerTy
return -1;
}

if(QFileInfo(path).isDir())
QFileInfo fileInfo = QFileInfo(path);

if(path.isEmpty() || !fileInfo.exists())
{
return -1;
}

if(fileInfo.isDir())
{
// ディレクトリ移動
if(viewerType == ViewerType::Auto)
@@ -272,6 +279,11 @@ int MainWindow::closeViewer(const QString& viewerObjectName)

int MainWindow::openWithApp(const QString& path)
{
if(path.isEmpty() || !QFileInfo(path).exists())
{
return -1;
}

if(!QDesktopServices::openUrl(QUrl("file:///" + path)))
{
qDebug() << "open url error:" << path;
@@ -285,6 +297,11 @@ int MainWindow::openWithApp(const QString& path)

int MainWindow::openWithTextEditor(const QString& dirPath, const QStringList& filePaths)
{
if(dirPath.isEmpty() || !QDir(dirPath).exists())
{
return -1;
}

QString appPath = Settings::getInstance()->getTextEditorPath();
QString args = Settings::getInstance()->getTextEditorArgs();

0 comments on commit ab05dd5

Please sign in to comment.
You can’t perform that action at this time.