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 Tabs vs. Spaces
--------------- ---------------
@@ -13,7 +16,7 @@ See https://www.emacswiki.org/emacs/SmartTabs for more information.
Indentation Style 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. 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. 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. See https://en.wikipedia.org/wiki/Indent_style#Allman_style for more information.
+39 -14
View File
@@ -31,7 +31,11 @@
#include <QDebug> #include <QDebug>
/// @TODO keep track of cwd between open/save dialogs ///
/// Static data
///
QString File::mCwd = ".";
/// ///
/// New Label Dialog /// New Label Dialog
@@ -78,10 +82,21 @@ bool File::newLabel( MainWindow *window )
/// ///
void File::open( 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 = QString fileName =
QFileDialog::getOpenFileName( window, QFileDialog::getOpenFileName( window,
tr("gLabels - Open Project"), tr("gLabels - Open Project"),
".", cwd,
tr("glabels files (*.glabels);;All files (*)") tr("glabels files (*.glabels);;All files (*)")
); );
if ( !fileName.isEmpty() ) if ( !fileName.isEmpty() )
@@ -102,6 +117,9 @@ void File::open( MainWindow *window )
newWindow->setModel( label ); newWindow->setModel( label );
newWindow->show(); newWindow->show();
} }
// Save CWD
mCwd = QFileInfo( fileName ).absolutePath();
} }
else else
{ {
@@ -133,6 +151,9 @@ bool File::save( MainWindow *window )
XmlLabelCreator::writeFile( window->model(), window->model()->fileName() ); XmlLabelCreator::writeFile( window->model(), window->model()->fileName() );
window->model()->clearModified(); window->model()->clearModified();
// Save CWD
mCwd = QFileInfo( window->model()->fileName() ).absolutePath();
return true; return true;
} }
@@ -142,14 +163,24 @@ bool File::save( MainWindow *window )
/// ///
bool File::saveAs( 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 = QString rawFileName =
QFileDialog::getSaveFileName( window, QFileDialog::getSaveFileName( window,
tr("gLabels - Save Project As"), tr("gLabels - Save Project As"),
".", cwd,
tr("glabels files (*.glabels);;All files (*)"), tr("glabels files (*.glabels);;All files (*)"),
0, 0,
QFileDialog::DontConfirmOverwrite QFileDialog::DontConfirmOverwrite );
);
if ( !rawFileName.isEmpty() ) if ( !rawFileName.isEmpty() )
{ {
QString fileName = FileUtil::addExtension( rawFileName, ".glabels" ); QString fileName = FileUtil::addExtension( rawFileName, ".glabels" );
@@ -175,6 +206,9 @@ bool File::saveAs( MainWindow *window )
window->model()->setFileName( fileName ); window->model()->setFileName( fileName );
window->model()->clearModified(); window->model()->clearModified();
// Save CWD
mCwd = QFileInfo( fileName ).absolutePath();
return true; return true;
} }
@@ -182,15 +216,6 @@ bool File::saveAs( MainWindow *window )
} }
///
/// Print file
///
void File::print( MainWindow *window )
{
qDebug() << "ACTION: file->print";
}
/// ///
/// Close file /// Close file
/// ///
+7 -2
View File
@@ -1,6 +1,6 @@
/* File.h /* 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. * This file is part of gLabels-qt.
* *
@@ -31,6 +31,8 @@ class MainWindow;
/// ///
/// File Actions /// File Actions
/// ///
/// Note: class provides a translation context for these static functions.
///
class File : public QObject class File : public QObject
{ {
Q_OBJECT Q_OBJECT
@@ -40,9 +42,12 @@ public:
static void open( MainWindow *window ); static void open( MainWindow *window );
static bool save( MainWindow *window ); static bool save( MainWindow *window );
static bool saveAs( MainWindow *window ); static bool saveAs( MainWindow *window );
static void print( MainWindow *window );
static void close( MainWindow *window ); static void close( MainWindow *window );
static void exit(); static void exit();
private:
static QString mCwd;
}; };