* fix: new/opened editors is not auto focused
This commit is contained in:
parent
0d2a82e741
commit
84475f3b26
|
@ -4,10 +4,42 @@
|
|||
<context>
|
||||
<name>Editor</name>
|
||||
<message>
|
||||
<location filename="editor.cpp" line="26"/>
|
||||
<location filename="editor.cpp" line="45"/>
|
||||
<source>untitled</source>
|
||||
<translation>无标题</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="editor.cpp" line="127"/>
|
||||
<source>Error</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="editor.cpp" line="128"/>
|
||||
<source>Can't Open File %1:%2</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="editor.cpp" line="182"/>
|
||||
<source>Failed to Save file %1: %2</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="editor.cpp" line="186"/>
|
||||
<source>Failed to Open file %1: %2</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="editor.cpp" line="197"/>
|
||||
<location filename="editor.cpp" line="206"/>
|
||||
<location filename="editor.cpp" line="232"/>
|
||||
<source>Fail</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="editor.cpp" line="221"/>
|
||||
<source>Save As</source>
|
||||
<translation type="unfinished">另存为</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MainWindow</name>
|
||||
|
@ -18,68 +50,132 @@
|
|||
</message>
|
||||
<message>
|
||||
<location filename="mainwindow.ui" line="77"/>
|
||||
<location filename="mainwindow.ui" line="153"/>
|
||||
<location filename="mainwindow.ui" line="165"/>
|
||||
<source>Tab 1</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="mainwindow.ui" line="82"/>
|
||||
<location filename="mainwindow.ui" line="158"/>
|
||||
<location filename="mainwindow.ui" line="170"/>
|
||||
<source>Tab 2</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="mainwindow.ui" line="177"/>
|
||||
<location filename="mainwindow.ui" line="189"/>
|
||||
<source>File</source>
|
||||
<translation>文件</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="mainwindow.ui" line="191"/>
|
||||
<location filename="mainwindow.ui" line="203"/>
|
||||
<source>toolBar</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="mainwindow.ui" line="211"/>
|
||||
<location filename="mainwindow.ui" line="223"/>
|
||||
<source>New</source>
|
||||
<translation>新建</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="mainwindow.ui" line="221"/>
|
||||
<location filename="mainwindow.ui" line="226"/>
|
||||
<source>Ctrl+N</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="mainwindow.ui" line="236"/>
|
||||
<source>Open...</source>
|
||||
<translation>打开...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="mainwindow.ui" line="231"/>
|
||||
<location filename="mainwindow.ui" line="239"/>
|
||||
<source>Ctrl+O</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="mainwindow.ui" line="249"/>
|
||||
<source>Save</source>
|
||||
<translation>保存</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="mainwindow.ui" line="241"/>
|
||||
<location filename="mainwindow.ui" line="252"/>
|
||||
<source>Ctrl+S</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="mainwindow.ui" line="262"/>
|
||||
<source>Save As...</source>
|
||||
<translation>另存为...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="mainwindow.ui" line="244"/>
|
||||
<location filename="mainwindow.ui" line="265"/>
|
||||
<source>Save As</source>
|
||||
<translation>另存为</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="mainwindow.ui" line="254"/>
|
||||
<location filename="mainwindow.ui" line="275"/>
|
||||
<source>Save All</source>
|
||||
<translation>全部保存</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="mainwindow.ui" line="278"/>
|
||||
<source>Ctrl+Shift+S</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="mainwindow.cpp" line="51"/>
|
||||
<source>Line: %1 Col: %2 Lines: %3 Chars: %4</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="mainwindow.cpp" line="99"/>
|
||||
<source>Open</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>QObject</name>
|
||||
<message>
|
||||
<location filename="editorlist.cpp" line="80"/>
|
||||
<location filename="editorlist.cpp" line="76"/>
|
||||
<source>Save</source>
|
||||
<translation>保存</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="editorlist.cpp" line="80"/>
|
||||
<location filename="editorlist.cpp" line="77"/>
|
||||
<source>Save changes to %1?</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Save changes to %s?</source>
|
||||
<translation>保存修改后的内容到"%s"?</translation>
|
||||
<translation type="vanished">保存修改后的内容到"%s"?</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="editor.cpp" line="198"/>
|
||||
<source>File %s is not writable!</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="systemconsts.cpp" line="10"/>
|
||||
<source>C files</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="systemconsts.cpp" line="11"/>
|
||||
<source>C++ files</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="systemconsts.cpp" line="12"/>
|
||||
<source>Header files</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="systemconsts.cpp" line="13"/>
|
||||
<source>Text files</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="systemconsts.cpp" line="14"/>
|
||||
<source>All files</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
|
@ -107,7 +107,6 @@ Editor::Editor(QWidget *parent, const QString& filename,
|
|||
connect(this, SIGNAL(linesChanged()),
|
||||
this,SLOT(onLinesChanged()));
|
||||
|
||||
this->toggleComment
|
||||
}
|
||||
|
||||
Editor::~Editor() {
|
||||
|
@ -243,6 +242,11 @@ bool Editor::saveAs(){
|
|||
return true;
|
||||
}
|
||||
|
||||
void Editor::activate()
|
||||
{
|
||||
this->mParentPageControl->setCurrentWidget(this);
|
||||
}
|
||||
|
||||
const QByteArray& Editor::encodingOption() const noexcept{
|
||||
return mEncodingOption;
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ public:
|
|||
void saveFile(const QString& filename);
|
||||
bool save(bool force=false, bool reparse=true);
|
||||
bool saveAs();
|
||||
void activate();
|
||||
|
||||
QTabWidget* pageControl() noexcept;
|
||||
|
||||
|
|
|
@ -5,14 +5,6 @@
|
|||
#include <mainwindow.h>
|
||||
#include <iconv.h>
|
||||
|
||||
EditorList::UpdateLocker::UpdateLocker(EditorList* editorList): mEditorList(editorList){
|
||||
mEditorList->beginUpdate();
|
||||
}
|
||||
|
||||
EditorList::UpdateLocker::~UpdateLocker() {
|
||||
mEditorList->endUpdate();
|
||||
}
|
||||
|
||||
EditorList::EditorList(QTabWidget* leftPageWidget,
|
||||
QTabWidget* rightPageWidget,
|
||||
QSplitter* splitter,
|
||||
|
@ -65,7 +57,10 @@ Editor* EditorList::getEditor(int index, QTabWidget* tabsWidget) const {
|
|||
}
|
||||
|
||||
bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) {
|
||||
UpdateLocker locker(this); // use RAII to correctly pause/resume update of the panel widget
|
||||
beginUpdate();
|
||||
auto end = finally([this] {
|
||||
this->endUpdate();
|
||||
});
|
||||
if (editor == NULL)
|
||||
return false;
|
||||
if (force) {
|
||||
|
@ -109,7 +104,10 @@ void EditorList::endUpdate() {
|
|||
}
|
||||
|
||||
bool EditorList::closeAll(bool force) {
|
||||
UpdateLocker locker(this);
|
||||
beginUpdate();
|
||||
auto end = finally([this] {
|
||||
this->endUpdate();
|
||||
});
|
||||
while (mLeftPageWidget->count()>0) {
|
||||
if (!closeEditor(getEditor(0,mLeftPageWidget),false,force)) {
|
||||
return false;
|
||||
|
|
|
@ -17,14 +17,6 @@ public:
|
|||
lstBoth
|
||||
};
|
||||
|
||||
class UpdateLocker {
|
||||
public:
|
||||
UpdateLocker(EditorList* editorList);
|
||||
~UpdateLocker();
|
||||
private:
|
||||
EditorList* mEditorList;
|
||||
};
|
||||
|
||||
explicit EditorList(QTabWidget* leftPageWidget,
|
||||
QTabWidget* rightPageWidget,
|
||||
QSplitter* splitter,
|
||||
|
|
|
@ -2,10 +2,17 @@
|
|||
#include "settings.h"
|
||||
#include "systemconsts.h"
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
#include <QTranslator>
|
||||
#include <QDebug>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
QTranslator trans;
|
||||
qDebug()<<QDir::currentPath();
|
||||
trans.load(("RedPandaIDE_zh_CN"));
|
||||
app.installTranslator(&trans);
|
||||
SystemConsts systemConsts;
|
||||
pSystemConsts = &systemConsts;
|
||||
Settings settings;
|
||||
|
|
|
@ -56,6 +56,9 @@ void MainWindow::updateStatusBarForEditingInfo(int line,int col,int lines,int ch
|
|||
void MainWindow::openFiles(const QStringList &files)
|
||||
{
|
||||
mEditorList->beginUpdate();
|
||||
auto end = finally([this] {
|
||||
this->mEditorList->endUpdate();
|
||||
});
|
||||
for (QString file:files) {
|
||||
openFile(file);
|
||||
}
|
||||
|
@ -66,12 +69,12 @@ void MainWindow::openFile(const QString &filename)
|
|||
{
|
||||
Editor* editor = mEditorList->findOpenedEditor(filename);
|
||||
if (editor!=nullptr) {
|
||||
editor->setFocus();
|
||||
editor->activate();
|
||||
return;
|
||||
}
|
||||
editor = mEditorList->newEditor(filename,ENCODING_AUTO_DETECT,
|
||||
false,false);
|
||||
editor->setFocus();
|
||||
editor->activate();
|
||||
this->updateStatusBarForEncoding();
|
||||
}
|
||||
|
||||
|
@ -83,6 +86,7 @@ void MainWindow::setupActions() {
|
|||
void MainWindow::on_actionNew_triggered()
|
||||
{
|
||||
Editor * editor=mEditorList->newEditor("",ENCODING_AUTO_DETECT,false,true);
|
||||
editor->activate();
|
||||
updateStatusBarForEncoding();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
|
||||
class QByteArray;
|
||||
class QString;
|
||||
|
||||
|
@ -9,8 +13,44 @@ class QString;
|
|||
#define ENCODING_UTF8_BOM "UTF-8 BOM"
|
||||
#define ENCODING_SYSTEM_DEFAULT "SYSTEM"
|
||||
#define ENCODING_ASCII "ASCII"
|
||||
|
||||
const QByteArray GuessTextEncoding(const QByteArray& text);
|
||||
|
||||
bool isTextAllAscii(const QString& text);
|
||||
|
||||
template <class F>
|
||||
class final_action
|
||||
{
|
||||
public:
|
||||
static_assert(!std::is_reference<F>::value && !std::is_const<F>::value &&
|
||||
!std::is_volatile<F>::value,
|
||||
"Final_action should store its callable by value");
|
||||
|
||||
explicit final_action(F f) noexcept : f_(std::move(f)) {}
|
||||
|
||||
final_action(final_action&& other) noexcept
|
||||
: f_(std::move(other.f_)), invoke_(std::exchange(other.invoke_, false))
|
||||
{}
|
||||
|
||||
final_action(const final_action&) = delete;
|
||||
final_action& operator=(const final_action&) = delete;
|
||||
final_action& operator=(final_action&&) = delete;
|
||||
|
||||
~final_action() noexcept
|
||||
{
|
||||
if (invoke_) f_();
|
||||
}
|
||||
|
||||
private:
|
||||
F f_;
|
||||
bool invoke_{true};
|
||||
};
|
||||
|
||||
template <class F> final_action<typename std::remove_cv<typename std::remove_reference<F>::type>::type>
|
||||
finally(F&& f) noexcept
|
||||
{
|
||||
return final_action<typename std::remove_cv<typename std::remove_reference<F>::type>::type>(
|
||||
std::forward<F>(f));
|
||||
}
|
||||
|
||||
#endif // UTILS_H
|
||||
|
|
Loading…
Reference in New Issue