fix: 修复克隆页右键菜单无效;修复终端主题修改输出颜色不改变;

This commit is contained in:
寂静的羽夏 2025-03-31 13:27:39 +08:00
parent 570f78994c
commit 7ee69b5ced
11 changed files with 99 additions and 71 deletions

View File

@ -5096,12 +5096,12 @@
<context>
<name>ShowTextDialog</name>
<message>
<location filename="../../src/dialog/showtextdialog.cpp" line="186"/>
<location filename="../../src/dialog/showtextdialog.cpp" line="155"/>
<source>General</source>
<translation></translation>
</message>
<message>
<location filename="../../src/dialog/showtextdialog.cpp" line="188"/>
<location filename="../../src/dialog/showtextdialog.cpp" line="157"/>
<source>Copy</source>
<translation></translation>
</message>
@ -5127,38 +5127,37 @@
</message>
<message>
<location filename="../../src/dialog/showtextdialog.cpp" line="131"/>
<location filename="../../src/dialog/showtextdialog.cpp" line="158"/>
<location filename="../../src/dialog/showtextdialog.cpp" line="227"/>
<location filename="../../src/dialog/showtextdialog.cpp" line="226"/>
<source>Loading...</source>
<translation>...</translation>
</message>
<message>
<location filename="../../src/dialog/showtextdialog.cpp" line="180"/>
<location filename="../../src/dialog/showtextdialog.cpp" line="149"/>
<source>Edit</source>
<translation></translation>
</message>
<message>
<location filename="../../src/dialog/showtextdialog.cpp" line="192"/>
<location filename="../../src/dialog/showtextdialog.cpp" line="161"/>
<source>Find</source>
<translation></translation>
</message>
<message>
<location filename="../../src/dialog/showtextdialog.cpp" line="196"/>
<location filename="../../src/dialog/showtextdialog.cpp" line="165"/>
<source>Goto</source>
<translation></translation>
</message>
<message>
<location filename="../../src/dialog/showtextdialog.cpp" line="201"/>
<location filename="../../src/dialog/showtextdialog.cpp" line="170"/>
<source>Encoding</source>
<translation></translation>
</message>
<message>
<location filename="../../src/dialog/showtextdialog.cpp" line="204"/>
<location filename="../../src/dialog/showtextdialog.cpp" line="173"/>
<source>UpdateDefs</source>
<translation></translation>
</message>
<message>
<location filename="../../src/dialog/showtextdialog.cpp" line="214"/>
<location filename="../../src/dialog/showtextdialog.cpp" line="183"/>
<source>CopyToClipBoard</source>
<translation></translation>
</message>

View File

@ -5096,12 +5096,12 @@
<context>
<name>ShowTextDialog</name>
<message>
<location filename="../../src/dialog/showtextdialog.cpp" line="186"/>
<location filename="../../src/dialog/showtextdialog.cpp" line="155"/>
<source>General</source>
<translation></translation>
</message>
<message>
<location filename="../../src/dialog/showtextdialog.cpp" line="188"/>
<location filename="../../src/dialog/showtextdialog.cpp" line="157"/>
<source>Copy</source>
<translation></translation>
</message>
@ -5127,38 +5127,37 @@
</message>
<message>
<location filename="../../src/dialog/showtextdialog.cpp" line="131"/>
<location filename="../../src/dialog/showtextdialog.cpp" line="158"/>
<location filename="../../src/dialog/showtextdialog.cpp" line="227"/>
<location filename="../../src/dialog/showtextdialog.cpp" line="226"/>
<source>Loading...</source>
<translation>...</translation>
</message>
<message>
<location filename="../../src/dialog/showtextdialog.cpp" line="180"/>
<location filename="../../src/dialog/showtextdialog.cpp" line="149"/>
<source>Edit</source>
<translation></translation>
</message>
<message>
<location filename="../../src/dialog/showtextdialog.cpp" line="192"/>
<location filename="../../src/dialog/showtextdialog.cpp" line="161"/>
<source>Find</source>
<translation></translation>
</message>
<message>
<location filename="../../src/dialog/showtextdialog.cpp" line="196"/>
<location filename="../../src/dialog/showtextdialog.cpp" line="165"/>
<source>Goto</source>
<translation></translation>
</message>
<message>
<location filename="../../src/dialog/showtextdialog.cpp" line="201"/>
<location filename="../../src/dialog/showtextdialog.cpp" line="170"/>
<source>Encoding</source>
<translation></translation>
</message>
<message>
<location filename="../../src/dialog/showtextdialog.cpp" line="204"/>
<location filename="../../src/dialog/showtextdialog.cpp" line="173"/>
<source>UpdateDefs</source>
<translation></translation>
</message>
<message>
<location filename="../../src/dialog/showtextdialog.cpp" line="214"/>
<location filename="../../src/dialog/showtextdialog.cpp" line="183"/>
<source>CopyToClipBoard</source>
<translation></translation>
</message>

View File

@ -41,7 +41,7 @@ def run_command_interactive(command):
def main():
parser = argparse.ArgumentParser(
prog="mkdeb.py", description="A deb installer maker for WingHexExplorer2")
prog="mkinnopak.py", description="A InnoSetup installer maker for WingHexExplorer2")
parser.add_argument(
"folder", help="A folder that has contained the binary build", type=str
@ -275,7 +275,7 @@ Source: {#MyAppExePath}; DestDir: "{app}"; Flags: ignoreversion
iss_content += r'Root: HKCR; Subkey: "WingHexExplorer2\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\{#MyAppExeName},1"; Flags: noerror uninsdeletevalue; ' + '\n'
iss_content += r'Root: HKCR; Subkey: "WingHexExplorer2\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\{#MyAppExeName}"" ""%1""" ;Flags: noerror uninsdeletevalue; ' + '\n'
iss_content += """
iss_content += r"""
[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"

View File

@ -1,6 +1,8 @@
#include "wingconsolehighligher.h"
#include <KSyntaxHighlighting/FoldingRegion>
#include <KSyntaxHighlighting/Format>
#include <KSyntaxHighlighting/Theme>
WingConsoleHighligher::WingConsoleHighligher(QTextDocument *document)
: WingSyntaxHighlighter(document) {}
@ -18,11 +20,15 @@ void WingConsoleHighligher::applyFormat(
auto off = offsetv.toInt(&b);
if (b) {
if (off < 0) {
// don't highlight
return;
if (off == -2) {
WingSyntaxHighlighter::applyFormat(
offset, length, KSyntaxHighlighting::Format());
}
} else {
if (offset <= off) {
auto div = off - offset;
WingSyntaxHighlighter::applyFormat(
offset, div, KSyntaxHighlighting::Format());
auto rest = length - div;
if (rest <= 0) {
return;

View File

@ -2033,6 +2033,19 @@ EditorView *EditorView::clone() {
this->m_cloneChildren[this->m_cloneChildren.indexOf(ev)] = nullptr;
});
connect(ev, &EditorView::sigOnCutFile, this, &EditorView::sigOnCutFile);
connect(ev, &EditorView::sigOnCutHex, this, &EditorView::sigOnCutHex);
connect(ev, &EditorView::sigOnCopyFile, this, &EditorView::sigOnCopyFile);
connect(ev, &EditorView::sigOnCopyHex, this, &EditorView::sigOnCopyHex);
connect(ev, &EditorView::sigOnPasteFile, this, &EditorView::sigOnPasteFile);
connect(ev, &EditorView::sigOnPasteHex, this, &EditorView::sigOnPasteHex);
connect(ev, &EditorView::sigOnDelete, this, &EditorView::sigOnDelete);
connect(ev, &EditorView::sigOnFindFile, this, &EditorView::sigOnFindFile);
connect(ev, &EditorView::sigOnGoToLine, this, &EditorView::sigOnGoToLine);
connect(ev, &EditorView::sigOnFill, this, &EditorView::sigOnFill);
connect(ev, &EditorView::sigOnMetadata, this, &EditorView::sigOnMetadata);
connect(ev, &EditorView::sigOnBookMark, this, &EditorView::sigOnBookMark);
auto doc = this->m_hex->document();
ev->m_cloneParent = this;

View File

@ -540,8 +540,6 @@ private:
void connectDocSavedFlag(EditorView *editor);
signals:
void sigFileSaved(QString filename, QString oldFileName);
void sigOnCutFile();
void sigOnCutHex();
void sigOnCopyFile();

View File

@ -68,7 +68,7 @@ void ScriptingConsole::handleReturnKey() {
// start new block
appendPlainText(QString());
dontHighlightLastLine();
dontHighlightLastLine(true);
setMode(Output);
QTextCursor textCursor = this->textCursor();

View File

@ -20,17 +20,17 @@ ScriptingConsoleBase::ScriptingConsoleBase(QWidget *parent)
void ScriptingConsoleBase::stdOut(const QString &str) {
writeStdOut(str);
dontHighlightLastLine();
dontHighlightLastLine(true);
}
void ScriptingConsoleBase::stdErr(const QString &str) {
writeStdErr(str);
dontHighlightLastLine();
dontHighlightLastLine(false);
}
void ScriptingConsoleBase::stdWarn(const QString &str) {
write(str, _warnCharFmt);
dontHighlightLastLine();
dontHighlightLastLine(false);
}
void ScriptingConsoleBase::newLine() { _s << Qt::endl; }
@ -65,14 +65,22 @@ void ScriptingConsoleBase::appendCommandPrompt(bool storeOnly) {
dontHighlightLastOffset(commandPrompt.length());
}
void ScriptingConsoleBase::dontHighlightLastLine() {
dontHighlightLastOffset(-1);
void ScriptingConsoleBase::dontHighlightLastLine(bool followTheme) {
dontHighlightLastOffset(-1, followTheme);
}
void ScriptingConsoleBase::dontHighlightLastOffset(int offset) {
void ScriptingConsoleBase::dontHighlightLastOffset(int offset,
bool followTheme) {
auto blk = document()->lastBlock();
auto hl = highlighter();
hl->setProperty(blk, "cmdoff", offset);
if (offset < 0) {
offset = -1;
}
if (offset == -1 && followTheme) {
hl->setProperty(blk, "cmdoff", -2);
} else {
hl->setProperty(blk, "cmdoff", offset);
}
hl->rehighlightBlock(blk);
}

View File

@ -26,9 +26,9 @@ public slots:
void appendCommandPrompt(bool storeOnly = false);
protected:
void dontHighlightLastLine();
void dontHighlightLastLine(bool followTheme);
void dontHighlightLastOffset(int offset);
void dontHighlightLastOffset(int offset, bool followTheme = true);
private:
QTextStream _s;

View File

@ -139,38 +139,7 @@ void ShowTextDialog::load(QHexBuffer *buffer, const QString &mime,
}
this->buffer = buffer->read(qsizetype(0), buffer->length());
m_cancelButton->setVisible(true);
m_continue = true;
auto e = Utilities::realEncodingName(enc);
auto en = QStringConverter::encodingForName(e.toUtf8());
QTextStream ss(this->buffer);
ss.setEncoding(en.value_or(QStringConverter::Utf8)); // fallback to UTF-8
ss.setAutoDetectUnicode(false);
auto total = this->buffer.size();
m_edit->clear();
m_edit->setEnabled(false);
while (m_continue && !ss.atEnd()) {
auto p = ss.readLine();
m_edit->appendPlainText(p);
m_edit->verticalScrollBar()->setValue(0);
m_status->showMessage(
tr("Loading...") + QStringLiteral(" (") +
QString::number(100.0 * ss.pos() / total, 'g', 3) +
QStringLiteral("%)"));
qApp->processEvents();
}
m_cancelButton->hide();
m_syntaxButton->setVisible(true);
m_edit->setEnabled(true);
m_continue = false;
auto cursor = m_edit->textCursor();
cursor.setPosition(0);
m_edit->setTextCursor(cursor);
m_status->showMessage(enc);
setEncoding(enc);
setSyntax(WingCodeEdit::syntaxRepo().definitionForMimeType(mime));
}
@ -224,9 +193,7 @@ void ShowTextDialog::on_encoding() {
EncodingDialog d;
if (d.exec()) {
auto res = d.getResult();
m_status->showMessage(tr("Loading..."));
m_edit->setPlainText(Utilities::decodingString(this->buffer, res));
m_status->showMessage(res);
setEncoding(res);
}
}
@ -239,8 +206,43 @@ void ShowTextDialog::on_updateDefs() {
downloadDialog->activateWindow();
}
void ShowTextDialog::setEncoding(const QString &enc) {
m_cancelButton->setVisible(true);
m_continue = true;
auto e = Utilities::realEncodingName(enc);
auto en = QStringConverter::encodingForName(e.toUtf8());
QTextStream ss(this->buffer);
ss.setEncoding(en.value_or(QStringConverter::Utf8)); // fallback to UTF-8
ss.setAutoDetectUnicode(false);
auto total = this->buffer.size();
m_edit->clear();
m_edit->setEnabled(false);
while (m_continue && !ss.atEnd()) {
auto p = ss.readLine();
m_edit->appendPlainText(p);
m_edit->verticalScrollBar()->setValue(0);
m_status->showMessage(
tr("Loading...") + QStringLiteral(" (") +
QString::number(100.0 * ss.pos() / total, 'g', 3) +
QStringLiteral("%)"));
qApp->processEvents();
}
m_cancelButton->hide();
m_syntaxButton->setVisible(true);
m_edit->setEnabled(true);
m_continue = false;
auto cursor = m_edit->textCursor();
cursor.setPosition(0);
m_edit->setTextCursor(cursor);
m_status->showMessage(enc);
}
void ShowTextDialog::closeEvent(QCloseEvent *event) {
m_continue = false;
m_edit->clear();
buffer.clear();
FramelessMainWindow::closeEvent(event);
}

View File

@ -121,6 +121,9 @@ private slots:
void on_encoding();
void on_updateDefs();
private:
void setEncoding(const QString &enc);
// QWidget interface
protected:
virtual void closeEvent(QCloseEvent *event) override;