Skip to content

Commit

Permalink
Merge pull request #31 from parallaxinc/newfromtemplate
Browse files Browse the repository at this point in the history
Add "New From Template" dialog (IDE-133)
  • Loading branch information
bweir committed Jan 21, 2016
2 parents e834ad2 + b7fa079 commit bb85935
Show file tree
Hide file tree
Showing 13 changed files with 634 additions and 29 deletions.
52 changes: 52 additions & 0 deletions src/propelleride/filemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,58 @@ int FileManager::openFile(const QString & fileName)
return 0;
}


void FileManager::newFromFile()
{
QSettings settings;
settings.beginGroup("Paths");

QString lastDir = settings.value("lastDirectory",
QDir(tabToolTip(currentIndex())).path()).toString();

QString fileName = QFileDialog::getOpenFileName(this,
tr("New From File..."), lastDir, "Spin Files (*.spin);;All Files (*)");

if (!fileName.isEmpty())
newFromFile(fileName);

settings.endGroup();
}


int FileManager::newFromFile(const QString & fileName)
{
qCDebug(ideFileManager) << "newFromFile(" << fileName << ")";

if (fileName.isEmpty())
return 1;

QFile file(fileName);
if (!file.open(QFile::ReadOnly))
{
QMessageBox::warning(this, tr("Warning"),
tr("Cannot read file %1:\n%2.")
.arg(fileName)
.arg(file.errorString()));
return 1;
}

int index = newFile();

QTextStream in(&file);
in.setAutoDetectUnicode(true);
in.setCodec("UTF-8");
getEditor(index)->setPlainText(reformatText(in.readAll()));

getEditor(index)->saveContent();
fileChanged();

emit fileUpdated(index);

return 0;
}


void FileManager::save()
{
save(currentIndex());
Expand Down
2 changes: 2 additions & 0 deletions src/propelleride/filemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class FileManager : public QTabWidget

public slots:
int newFile();
void newFromFile();
int newFromFile(const QString & fileName);
void open();
int openFile(const QString & fileName);
void fileChanged();
Expand Down
28 changes: 25 additions & 3 deletions src/propelleride/forms/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>717</width>
<height>443</height>
<width>916</width>
<height>609</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -80,7 +80,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>717</width>
<width>916</width>
<height>28</height>
</rect>
</property>
Expand All @@ -89,6 +89,9 @@
<string>&amp;File</string>
</property>
<addaction name="action_New"/>
<addaction name="actionNew_From_Template"/>
<addaction name="actionNew_From_File"/>
<addaction name="separator"/>
<addaction name="action_Open"/>
<addaction name="separator"/>
<addaction name="action_Save"/>
Expand Down Expand Up @@ -816,6 +819,25 @@
<string>View the Propeller quick reference chart</string>
</property>
</action>
<action name="actionNew_From_Template">
<property name="text">
<string>New From &amp;Template</string>
</property>
<property name="statusTip">
<string>Create a new file from a pre-defined template</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+T</string>
</property>
</action>
<action name="actionNew_From_File">
<property name="text">
<string>New From &amp;File</string>
</property>
<property name="statusTip">
<string>Create a new file from an existing one</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down
98 changes: 78 additions & 20 deletions src/propelleride/forms/newfromtemplate.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>612</width>
<height>363</height>
<width>526</width>
<height>378</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -36,11 +36,6 @@
<property name="showDropIndicator" stdset="0">
<bool>false</bool>
</property>
<item>
<property name="text">
<string>Spin</string>
</property>
</item>
</widget>
</item>
<item>
Expand Down Expand Up @@ -112,38 +107,101 @@
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<widget class="QWidget" name="templateArea">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>393</width>
<height>317</height>
<width>398</width>
<height>321</height>
</rect>
</property>
<zorder>buttonBox</zorder>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QWidget" name="grid" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>138</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>300</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Click the language, then double-click to select a template.</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::Cancel</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Click the language, then double-click to select a template.</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
Expand Down
Loading

0 comments on commit bb85935

Please sign in to comment.