From 2b6e35fd65597f74d296484dd37087d00b781a65 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sat, 1 Jun 2024 03:29:31 +0200 Subject: [PATCH] Add support for specifying line number when opening a file in single instance mode --- LiteEditor/app.cpp | 5 +++++ LiteEditor/frame.cpp | 8 +++++++- LiteEditor/singleinstancethreadjob.cpp | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/LiteEditor/app.cpp b/LiteEditor/app.cpp index cf9ad666c8..0f2427b7a2 100644 --- a/LiteEditor/app.cpp +++ b/LiteEditor/app.cpp @@ -842,6 +842,11 @@ bool CodeLiteApp::IsSingleInstance(const wxCmdLineParser& m_parser) JSON json(cJSON_Object); json.toElement().addProperty("args", files); + + long lineNumber(0); + m_parser.Found(wxT("l"), &lineNumber); + json.toElement().addProperty("lineno", lineNumber); + client.WriteMessage(json.toElement().format()); return false; diff --git a/LiteEditor/frame.cpp b/LiteEditor/frame.cpp index 34a0f79f2b..38702fb474 100644 --- a/LiteEditor/frame.cpp +++ b/LiteEditor/frame.cpp @@ -3954,7 +3954,13 @@ void clMainFrame::OnSingleInstanceOpenFiles(clCommandEvent& e) OnSwitchWorkspace(workspaceEvent); } else { - GetMainBook()->OpenFile(files.Item(i), wxEmptyString); + long lineNumber = e.GetLineNumber(); + if (lineNumber > 0) { + lineNumber--; + } else { + lineNumber = 0; + } + GetMainBook()->OpenFile(files.Item(i), wxEmptyString, lineNumber); } } diff --git a/LiteEditor/singleinstancethreadjob.cpp b/LiteEditor/singleinstancethreadjob.cpp index f17f9a0119..33112e7864 100644 --- a/LiteEditor/singleinstancethreadjob.cpp +++ b/LiteEditor/singleinstancethreadjob.cpp @@ -71,6 +71,8 @@ void* clSingleInstanceThread::Entry() } else { clCommandEvent event(wxEVT_CMD_SINGLE_INSTANCE_THREAD_OPEN_FILES); event.SetStrings(args); + long lineno = root.toElement().namedObject("lineno").toInt(); + event.SetLineNumber(lineno); EventNotifier::Get()->AddPendingEvent(event); } }