@@ -505,6 +505,7 @@ qmdiClientState qmdiEditor::getState() const {
505505 state[StateConstants::ROW ] = row;
506506 state[StateConstants::ZOOM ] = zoom;
507507 state[StateConstants::READ_ONLY ] = textEditor->isReadOnly ();
508+ state[StateConstants::BASE_DIR ] = diffMetadata.baseDir ;
508509
509510 if (!uid.isEmpty ()) {
510511 state[StateConstants::UUID ] = uid;
@@ -562,6 +563,7 @@ void qmdiEditor::setState(const qmdiClientState &state) {
562563 if (state.contains (StateConstants::READ_ONLY )) {
563564 textEditor->setReadOnly (state[StateConstants::READ_ONLY ].toBool ());
564565 }
566+ diffMetadata.baseDir = state[StateConstants::BASE_DIR ].toString ();
565567}
566568
567569void qmdiEditor::on_client_unmerged (qmdiHost *host) {
@@ -934,9 +936,19 @@ bool qmdiEditor::eventFilter(QObject *watched, QEvent *event) {
934936 if (block.isValid ()) {
935937 auto blockNumber = block.blockNumber ();
936938 auto text = block.text ();
937- if (patchMappings.contains (blockNumber)) {
938- auto l = patchMappings[blockNumber];
939- qDebug () << " Should open " << l.file << " line: " << l.newLine ;
939+ if (diffMetadata.mappings .contains (blockNumber)) {
940+ auto l = diffMetadata.mappings [blockNumber];
941+ auto pluginManager = dynamic_cast <PluginManager *>(mdiServer->mdiHost );
942+ if (pluginManager) {
943+ // Lines start on the editor from 0
944+ if (l.newLine >= 0 ) {
945+ pluginManager->openFile (l.file , l.newLine - 1 );
946+ } else {
947+ pluginManager->openFile (l.file , l.oldLine - 1 );
948+ }
949+ } else {
950+ qDebug () << " qmdiEditor::eventFilter - cannot open file from diff/patch" ;
951+ }
940952 }
941953 }
942954 }
@@ -1397,7 +1409,7 @@ void qmdiEditor::loadContent(bool useBackup) {
13971409
13981410 updateClientName ();
13991411 setState (savedState);
1400- updateInternalMappings ();
1412+ updateInternalMappings (savedState[StateConstants:: BASE_DIR ]. toString () );
14011413}
14021414
14031415void qmdiEditor::chooseHighliter (const QString &newText) {
@@ -1427,8 +1439,10 @@ void qmdiEditor::findText(const QString &text) {
14271439 textEditor->setTextCursor (c);
14281440}
14291441
1430- void qmdiEditor::updateInternalMappings () {
1431- patchMappings.clear ();
1442+ void qmdiEditor::updateInternalMappings (const QString& baseDir) {
1443+ diffMetadata.mappings .clear ();
1444+ diffMetadata.baseDir = baseDir;
1445+
14321446 if (!mdiClientName.endsWith (" .diff" ,Qt::CaseInsensitive) && mdiClientName.endsWith (" .patch" , Qt::CaseInsensitive)) {
14331447 return ;
14341448 }
@@ -1511,18 +1525,17 @@ void qmdiEditor::updateInternalMappings() {
15111525
15121526 auto i = line.lineNumber ();
15131527 if (text.startsWith (' ' )) {
1514- patchMappings [i] = {current_file,old_line,new_line};
1528+ diffMetadata. mappings [i] = {baseDir + " / " + current_file,old_line,new_line};
15151529 old_line += 1 ;
15161530 new_line += 1 ;
15171531 } else if (text.startsWith (' -' )) {
1518- patchMappings [i] = {current_file,old_line,-1 };
1532+ diffMetadata. mappings [i] = {baseDir + " / " + current_file,old_line,-1 };
15191533 old_line += 1 ;
15201534 } else if (text.startsWith (' +' )) {
1521- patchMappings [i] = {current_file,-1 ,new_line};
1535+ diffMetadata. mappings [i] = {baseDir + " / " + current_file,-1 ,new_line};
15221536 new_line += 1 ;
15231537 }
15241538 }
1525-
15261539}
15271540
15281541/* *
0 commit comments