work save

This commit is contained in:
royqh1979@gmail.com 2021-09-10 15:03:47 +08:00
parent 9d28bcc735
commit e99d42a99f
2 changed files with 85 additions and 14 deletions

View File

@ -251,20 +251,63 @@ Editor *Project::openUnit(int index)
editor->setInProject(true); editor->setInProject(true);
return editor; return editor;
} }
try QByteArray encoding;
fEditor := MainForm.EditorList.NewEditor(FullPath, Encoding, true, false); if (mOptions.useUTF8) {
fEditor.InProject := True; encoding = ENCODING_UTF8;
Encoding := fEditor.EncodingOption; } else
LoadUnitLayout(fEditor, index); encoding = mOptions.encoding.toLocal8Bit();
Result := fEditor; editor = pMainWindow->editorList()->newEditor(fullPath, encoding, true, false);
except editor->setInProject(true);
MessageDlg(Format(Lang[ID_ERR_OPENFILE], [Filename]), mtError, [mbOK], 0); unit->setEditor(editor);
end; unit->setEncoding(encoding);
loadUnitLayout(editor,index);
return editor;
}
}
void Project::rebuildNodes()
{
// Remember if folder nodes were expanded or collapsed
// Create a list of expanded folder nodes
// QStringList oldPaths := TStringList.Create;
// with MainForm.ProjectView do
// for idx := 0 to Items.Count - 1 do begin
// tempnode := Items[idx];
// if tempnode.Expanded and (tempnode.Data = Pointer(-1)) then // data=pointer(-1) - it's folder
// oldPaths.Add(GetFolderPath(tempnode));
// end;
// Delete everything
mNode->children.clear();
// Recreate everything
createFolderNodes();
for (int idx=0;idx<mUnits.count();idx++) {
mUnits[idx]->setNode(
makeNewFileNode(
extractRelativePath(filename(),mUnits[idx]->fileName()),
false,
folderNodeFromName(mUnits[idx]->folder())
)
);
mUnits[idx]->node()->unitIndex = idx;
} }
if FileName <> '' then begin // // expand nodes expanded before recreating the project tree
end; // fNode.Collapse(True);
// with MainForm.ProjectView do
// for idx := 0 to Items.Count - 1 do begin
// tempnode := Items[idx];
// if (tempnode.Data = Pointer(-1)) then //it's a folder
// if oldPaths.IndexOf(GetFolderPath(tempnode)) >= 0 then
// tempnode.Expand(False);
// end;
// FreeAndNil(oldPaths);
// fNode.Expand(False);
emit nodesChanged();
} }
void Project::addFolder(const QString &s) void Project::addFolder(const QString &s)
@ -865,6 +908,7 @@ void Project::loadOptions()
mOptions.staticLink = mIniFile->value("StaticLink", true).toBool(); mOptions.staticLink = mIniFile->value("StaticLink", true).toBool();
mOptions.addCharset = mIniFile->value("AddCharset", true).toBool(); mOptions.addCharset = mIniFile->value("AddCharset", true).toBool();
mOptions.useUTF8 = mIniFile->value("UseUTF8", false).toBool(); mOptions.useUTF8 = mIniFile->value("UseUTF8", false).toBool();
mOptions.encoding = mIniFile->value("Encoding", ENCODING_SYSTEM_DEFAULT).toString();
mOptions.versionInfo.major = mIniFile->value("Major", 0).toInt(); mOptions.versionInfo.major = mIniFile->value("Major", 0).toInt();
mOptions.versionInfo.minor = mIniFile->value("Minor", 1).toInt(); mOptions.versionInfo.minor = mIniFile->value("Minor", 1).toInt();
mOptions.versionInfo.release = mIniFile->value("Release", 1).toInt(); mOptions.versionInfo.release = mIniFile->value("Release", 1).toInt();
@ -907,6 +951,19 @@ void Project::loadOptions()
} }
} }
void Project::loadUnitLayout(Editor *e, int index)
{
if (!e)
return;
QSettings layIni(changeFileExt(filename(), "layout"));
layIni.beginGroup(QString("Editor_%1").arg(index));
e->setCaretY(layIni.value("CursorRow",1).toInt());
e->setCaretX(layIni.value("CursorCol",1).toInt());
e->setTopLine(layIni.value("TopLine",1).toInt());
e->setLeftChar(layIni.value("LeftChar",1).toInt());
layIni.endGroup();
}
PCppParser Project::cppParser() PCppParser Project::cppParser()
{ {
return mParser; return mParser;
@ -937,6 +994,16 @@ int Project::indexInUnits(const Editor *editor) const
return indexInUnits(editor->filename()); return indexInUnits(editor->filename());
} }
const ProjectOptions &Project::options() const
{
return mOptions;
}
void Project::setOptions(const ProjectOptions &newOptions)
{
mOptions = newOptions;
}
const PFolderNode &Project::node() const const PFolderNode &Project::node() const
{ {
return mNode; return mNode;

View File

@ -135,6 +135,7 @@ struct ProjectOptions{
QString cmdLineArgs; QString cmdLineArgs;
bool staticLink; bool staticLink;
bool addCharset; bool addCharset;
QString encoding;
}; };
class Project : public QObject class Project : public QObject
@ -167,26 +168,26 @@ public:
QString listUnitStr(const QChar& separator); QString listUnitStr(const QChar& separator);
void loadLayout(); // load all [UnitX] void loadLayout(); // load all [UnitX]
void loadOptions(); void loadOptions();
void loadUnitLayout(Editor *e, int index); // load single [UnitX] cursor positions
PFolderNode makeNewFileNode(const QString& s, bool isFolder, PFolderNode newParent); PFolderNode makeNewFileNode(const QString& s, bool isFolder, PFolderNode newParent);
PFolderNode makeProjectNode(); PFolderNode makeProjectNode();
int newUnit(bool newProject, int newUnit(bool newProject,
PFolderNode parentNode, PFolderNode parentNode,
const QString customFileName); const QString customFileName);
Editor* openUnit(int index); Editor* openUnit(int index);
void rebuildNodes();
bool removeEditor(int index, bool doClose);
void updateFolders(); void updateFolders();
void saveUnitAs(int i, const QString& sFileName); // save single [UnitX] void saveUnitAs(int i, const QString& sFileName); // save single [UnitX]
void saveAll(); // save [Project] and all [UnitX] void saveAll(); // save [Project] and all [UnitX]
void loadUnitLayout(Editor *e, int index); // load single [UnitX] cursor positions
void saveLayout(); // save all [UnitX] void saveLayout(); // save all [UnitX]
void saveUnitLayout(Editor* e, int index); // save single [UnitX] cursor positions void saveUnitLayout(Editor* e, int index); // save single [UnitX] cursor positions
void saveOptions(); void saveOptions();
bool saveUnits(); bool saveUnits();
// procedure Open; // procedure Open;
bool removeFolder(PFolderNode node); bool removeFolder(PFolderNode node);
bool removeEditor(int index, bool doClose);
void rebuildNodes();
void showOptions(); void showOptions();
// bool assignTemplate(const QString& aFileName, const PTemplate& aTemplate); // bool assignTemplate(const QString& aFileName, const PTemplate& aTemplate);
@ -207,6 +208,9 @@ public:
const PFolderNode &node() const; const PFolderNode &node() const;
void setNode(const PFolderNode &newNode); void setNode(const PFolderNode &newNode);
const ProjectOptions &options() const;
void setOptions(const ProjectOptions &newOptions);
signals: signals:
void nodesChanged(); void nodesChanged();
void modifyChanged(bool value); void modifyChanged(bool value);