mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Add buttons to open and save SQL files to SQL tab in main window
This commit is contained in:
@@ -1108,7 +1108,7 @@ void MainWindow::closeSqlTab(int index, bool force)
|
||||
delete w;
|
||||
}
|
||||
|
||||
void MainWindow::openSqlTab(bool resetCounter)
|
||||
unsigned int MainWindow::openSqlTab(bool resetCounter)
|
||||
{
|
||||
static unsigned int tabNumber = 0;
|
||||
|
||||
@@ -1122,4 +1122,40 @@ void MainWindow::openSqlTab(bool resetCounter)
|
||||
w->getEditor()->insertFieldCompleterModels(completerModelsFields);
|
||||
int index = ui->tabSqlAreas->addTab(w, QString("SQL %1").arg(++tabNumber));
|
||||
ui->tabSqlAreas->setCurrentIndex(index);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
void MainWindow::openSqlFile()
|
||||
{
|
||||
QString file = QFileDialog::getOpenFileName(
|
||||
this,
|
||||
tr("Select SQL file to open"),
|
||||
PreferencesDialog::getSettingsValue("db", "defaultlocation").toString(),
|
||||
tr("Text files(*.sql *.txt);;All files(*)"));
|
||||
|
||||
if(QFile::exists(file))
|
||||
{
|
||||
QFile f(file);
|
||||
f.open(QIODevice::ReadOnly);
|
||||
unsigned int index = openSqlTab();
|
||||
qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas->widget(index))->getEditor()->setPlainText(f.readAll());
|
||||
QFileInfo fileinfo(file);
|
||||
ui->tabSqlAreas->setTabText(index, fileinfo.fileName());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::saveSqlFile()
|
||||
{
|
||||
QString file = QFileDialog::getSaveFileName(
|
||||
this,
|
||||
tr("Select file name"),
|
||||
PreferencesDialog::getSettingsValue("db", "defaultlocation").toString(),
|
||||
tr("Text files(*.sql *.txt);;All files(*)"));
|
||||
|
||||
QFile f(file);
|
||||
f.open(QIODevice::WriteOnly);
|
||||
f.write(qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas->currentWidget())->getSql().toUtf8());
|
||||
QFileInfo fileinfo(file);
|
||||
ui->tabSqlAreas->setTabText(ui->tabSqlAreas->currentIndex(), fileinfo.fileName());
|
||||
}
|
||||
|
||||
@@ -136,8 +136,10 @@ private slots:
|
||||
virtual void mainTabSelected( int tabindex );
|
||||
virtual void browseTableHeaderClicked(int logicalindex);
|
||||
virtual void createSyntaxHighlighters();
|
||||
virtual void openSqlTab(bool resetCounter = false);
|
||||
virtual unsigned int openSqlTab(bool resetCounter = false);
|
||||
virtual void closeSqlTab(int index, bool force = false);
|
||||
virtual void openSqlFile();
|
||||
virtual void saveSqlFile();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -292,7 +292,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>763</width>
|
||||
<width>278</width>
|
||||
<height>444</height>
|
||||
</rect>
|
||||
</property>
|
||||
@@ -746,6 +746,9 @@
|
||||
<string>toolBar1</string>
|
||||
</property>
|
||||
<addaction name="actionSqlOpenTab"/>
|
||||
<addaction name="actionSqlOpenFile"/>
|
||||
<addaction name="actionSqlSaveFile"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionExecuteSql"/>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -1271,6 +1274,24 @@
|
||||
<string>F5</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSqlOpenFile">
|
||||
<property name="icon">
|
||||
<iconset resource="icons/icons.qrc">
|
||||
<normaloff>:/icons/open_sql</normaloff>:/icons/open_sql</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Open SQL file</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSqlSaveFile">
|
||||
<property name="icon">
|
||||
<iconset resource="icons/icons.qrc">
|
||||
<normaloff>:/icons/save_sql</normaloff>:/icons/save_sql</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save SQL file</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
@@ -1971,6 +1992,38 @@
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>actionSqlOpenFile</sender>
|
||||
<signal>activated()</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>openSqlFile()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>-1</x>
|
||||
<y>-1</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>399</x>
|
||||
<y>299</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>actionSqlSaveFile</sender>
|
||||
<signal>activated()</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>saveSqlFile()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>-1</x>
|
||||
<y>-1</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>399</x>
|
||||
<y>299</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>fileOpen()</slot>
|
||||
@@ -2014,5 +2067,7 @@
|
||||
<slot>copy()</slot>
|
||||
<slot>closeSqlTab(int)</slot>
|
||||
<slot>openSqlTab()</slot>
|
||||
<slot>openSqlFile()</slot>
|
||||
<slot>saveSqlFile()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
<file alias="whatis">help.png</file>
|
||||
<file alias="open_tab">tab_add.png</file>
|
||||
<file alias="run">resultset_next.png</file>
|
||||
<file alias="save_sql">page_save.png</file>
|
||||
<file alias="open_sql">page_white_database.png</file>
|
||||
</qresource>
|
||||
<qresource prefix="/oldimages">
|
||||
<file alias="128">oldimages/128.png</file>
|
||||
|
||||
BIN
src/icons/page_save.png
Normal file
BIN
src/icons/page_save.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 774 B |
BIN
src/icons/page_white_database.png
Normal file
BIN
src/icons/page_white_database.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 579 B |
Reference in New Issue
Block a user