Intelligently choose CWD in open and saveAs dialogs.

This commit is contained in:
Jim Evins
2017-01-06 04:44:29 -05:00
parent 56418ac72a
commit 602e3f9ab6
3 changed files with 53 additions and 18 deletions
+6 -1
View File
@@ -1,3 +1,6 @@
Glabels Coding Style
====================
Tabs vs. Spaces
---------------
@@ -13,7 +16,7 @@ See https://www.emacswiki.org/emacs/SmartTabs for more information.
Indentation Style
-----------------
Glabels code uses the Allman (a.k.a "BSD Style") of code indentation. I.e. the brace associated with a
Glabels code uses the Allman style (a.k.a "BSD Style") of code indentation. I.e. the brace associated with a
control statement is placed on the next line, indented to the same level as the control statement.
Statements within the braces are indented to the next level.
@@ -34,4 +37,6 @@ else
}
```
Also applies to class and namespace declaration statements.
See https://en.wikipedia.org/wiki/Indent_style#Allman_style for more information.
+40 -15
View File
@@ -31,7 +31,11 @@
#include <QDebug>
/// @TODO keep track of cwd between open/save dialogs
///
/// Static data
///
QString File::mCwd = ".";
///
/// New Label Dialog
@@ -78,10 +82,21 @@ bool File::newLabel( MainWindow *window )
///
void File::open( MainWindow *window )
{
// Either use the saved CWD from a previous open/save or grab it from the path of the current file
QString cwd = mCwd;
if ( window->model() && !window->model()->fileName().isEmpty() )
{
QFileInfo fileInfo( window->model()->fileName() );
if ( fileInfo.isFile() )
{
cwd = fileInfo.absolutePath();
}
}
QString fileName =
QFileDialog::getOpenFileName( window,
tr("gLabels - Open Project"),
".",
cwd,
tr("glabels files (*.glabels);;All files (*)")
);
if ( !fileName.isEmpty() )
@@ -102,6 +117,9 @@ void File::open( MainWindow *window )
newWindow->setModel( label );
newWindow->show();
}
// Save CWD
mCwd = QFileInfo( fileName ).absolutePath();
}
else
{
@@ -132,7 +150,10 @@ bool File::save( MainWindow *window )
XmlLabelCreator::writeFile( window->model(), window->model()->fileName() );
window->model()->clearModified();
// Save CWD
mCwd = QFileInfo( window->model()->fileName() ).absolutePath();
return true;
}
@@ -142,14 +163,24 @@ bool File::save( MainWindow *window )
///
bool File::saveAs( MainWindow *window )
{
// Either use the saved CWD from a previous open/save or grab it from the path of the current file
QString cwd = mCwd;
if ( window->model() && !window->model()->fileName().isEmpty() )
{
QFileInfo fileInfo( window->model()->fileName() );
if ( fileInfo.isFile() )
{
cwd = fileInfo.filePath();
}
}
QString rawFileName =
QFileDialog::getSaveFileName( window,
tr("gLabels - Save Project As"),
".",
cwd,
tr("glabels files (*.glabels);;All files (*)"),
0,
QFileDialog::DontConfirmOverwrite
);
QFileDialog::DontConfirmOverwrite );
if ( !rawFileName.isEmpty() )
{
QString fileName = FileUtil::addExtension( rawFileName, ".glabels" );
@@ -175,6 +206,9 @@ bool File::saveAs( MainWindow *window )
window->model()->setFileName( fileName );
window->model()->clearModified();
// Save CWD
mCwd = QFileInfo( fileName ).absolutePath();
return true;
}
@@ -182,15 +216,6 @@ bool File::saveAs( MainWindow *window )
}
///
/// Print file
///
void File::print( MainWindow *window )
{
qDebug() << "ACTION: file->print";
}
///
/// Close file
///
+7 -2
View File
@@ -1,6 +1,6 @@
/* File.h
*
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
* Copyright (C) 2017 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
@@ -31,6 +31,8 @@ class MainWindow;
///
/// File Actions
///
/// Note: class provides a translation context for these static functions.
///
class File : public QObject
{
Q_OBJECT
@@ -40,9 +42,12 @@ public:
static void open( MainWindow *window );
static bool save( MainWindow *window );
static bool saveAs( MainWindow *window );
static void print( MainWindow *window );
static void close( MainWindow *window );
static void exit();
private:
static QString mCwd;
};