basctl/Library_basctl.mk | 1 basctl/inc/strings.hrc | 1 basctl/sdi/baside.sdi | 1 basctl/source/basicide/LineStatusControl.cxx | 45 ++++++++++++ basctl/source/basicide/baside2.cxx | 12 +++ basctl/source/basicide/basidesh.cxx | 2 basctl/source/basicide/moduldl2.cxx | 31 +++++++- basctl/source/basicide/moduldlg.hxx | 8 +- basctl/source/inc/LineStatusControl.hxx | 30 ++++++++ basctl/uiconfig/basicide/ui/gotolinedialog.ui | 92 +++++++++++--------------- 10 files changed, 162 insertions(+), 61 deletions(-)
New commits: commit d9d9ec70395ed5ad8ac4b985b8c9215af7436258 Author: Rafael Lima <rafael.palma.l...@gmail.com> AuthorDate: Mon Jan 15 18:08:12 2024 +0100 Commit: Rafael Lima <rafael.palma.l...@gmail.com> CommitDate: Tue Jan 23 12:11:33 2024 +0100 tdf#158749 Open "Go to Line" dialog from the statusbar in Basic IDE With this change, if the user clicks the StatusGetPosition item in the status bar, the Go To Line dialog will be shown. Change-Id: Iba75e2dbf6ba83fce24e1af237bdf9813d4ecb69 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162108 Tested-by: Jenkins Reviewed-by: Heiko Tietze <heiko.tie...@documentfoundation.org> diff --git a/basctl/Library_basctl.mk b/basctl/Library_basctl.mk index 13d3bce29e41..cb41fa9e461c 100644 --- a/basctl/Library_basctl.mk +++ b/basctl/Library_basctl.mk @@ -95,6 +95,7 @@ $(eval $(call gb_Library_add_exception_objects,basctl,\ basctl/source/basicide/iderdll \ basctl/source/basicide/layout \ basctl/source/basicide/linenumberwindow \ + basctl/source/basicide/LineStatusControl \ basctl/source/basicide/localizationmgr \ basctl/source/basicide/macrodlg \ basctl/source/basicide/moduldl2 \ diff --git a/basctl/inc/strings.hrc b/basctl/inc/strings.hrc index 44efc2f52ed8..ee83fbb543b0 100644 --- a/basctl/inc/strings.hrc +++ b/basctl/inc/strings.hrc @@ -113,6 +113,7 @@ #define RID_STR_READONLY NC_("RID_STR_READONLY", "Read-only") #define RID_STR_MODULE_READONLY NC_("RID_STR_READONLY_WARNING", "This module is read-only and cannot be edited.") #define RID_STR_DIALOG_READONLY NC_("RID_STR_READONLY_WARNING", "This dialog is read-only and cannot be edited.") +#define RID_LINE_STATUS_CONTROL NC_("RID_LINE_STATUS_CONTROL", "Current line and character. Click to open 'Go to Line' dialog.") // Color scheme names #define RID_STR_COLORSCHEME_DEFAULT NC_("RID_STR_COLORSCHEME_DEFAULT", "Default") diff --git a/basctl/sdi/baside.sdi b/basctl/sdi/baside.sdi index 40ddd8b3bfd7..74b425cf6db4 100644 --- a/basctl/sdi/baside.sdi +++ b/basctl/sdi/baside.sdi @@ -618,6 +618,7 @@ shell basctl_Shell SID_BASICIDE_STAT_POS [ + ExecMethod = ExecuteGlobal; StateMethod = GetState; ] diff --git a/basctl/source/basicide/LineStatusControl.cxx b/basctl/source/basicide/LineStatusControl.cxx new file mode 100644 index 000000000000..fd716b3901f7 --- /dev/null +++ b/basctl/source/basicide/LineStatusControl.cxx @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <strings.hrc> +#include <LineStatusControl.hxx> +#include <svl/stritem.hxx> +#include <vcl/status.hxx> +#include <iderid.hxx> + +namespace basctl +{ +SFX_IMPL_STATUSBAR_CONTROL(LineStatusControl, SfxStringItem); + +LineStatusControl::LineStatusControl(sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar& rStb) + : SfxStatusBarControl(_nSlotId, _nId, rStb) +{ +} + +LineStatusControl::~LineStatusControl() {} + +void LineStatusControl::StateChangedAtStatusBarControl(sal_uInt16 /*nSID*/, SfxItemState eState, + const SfxPoolItem* pState) +{ + if (eState == SfxItemState::DEFAULT) + { + // Can access pState + GetStatusBar().SetItemText(GetId(), static_cast<const SfxStringItem*>(pState)->GetValue()); + GetStatusBar().SetQuickHelpText(GetId(), IDEResId(RID_LINE_STATUS_CONTROL)); + } + else + { + GetStatusBar().SetItemText(GetId(), u""_ustr); + GetStatusBar().SetQuickHelpText(GetId(), u""_ustr); + } +} + +} // namespace basctl + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basctl/source/basicide/baside2.cxx b/basctl/source/basicide/baside2.cxx index 74c25d6f4631..98f016a57236 100644 --- a/basctl/source/basicide/baside2.cxx +++ b/basctl/source/basicide/baside2.cxx @@ -25,6 +25,7 @@ #include <iderdll.hxx> #include <iderid.hxx> #include "moduldlg.hxx" +#include <sfx2/dispatch.hxx> #include <docsignature.hxx> #include <colorscheme.hxx> #include <officecfg/Office/BasicIDE.hxx> @@ -1027,12 +1028,15 @@ void ModulWindow::ExecuteCommand (SfxRequest& rReq) break; case SID_GOTOLINE: { - GotoLineDialog aGotoDlg(GetFrameWeld()); + sal_uInt32 nCurLine = GetEditView()->GetSelection().GetStart().GetPara() + 1; + sal_uInt32 nLineCount = GetEditEngine()->GetParagraphCount(); + GotoLineDialog aGotoDlg(GetFrameWeld(), nCurLine, nLineCount); if (aGotoDlg.run() == RET_OK) { if (sal_Int32 const nLine = aGotoDlg.GetLineNumber()) { TextSelection const aSel(TextPaM(nLine - 1, 0), TextPaM(nLine - 1, 0)); + GrabFocus(); GetEditView()->SetSelection(aSel); } } @@ -1056,6 +1060,12 @@ void ModulWindow::ExecuteGlobal (SfxRequest& rReq) } } break; + + case SID_BASICIDE_STAT_POS: + { + GetDispatcher()->Execute(SID_GOTOLINE); + } + break; } } diff --git a/basctl/source/basicide/basidesh.cxx b/basctl/source/basicide/basidesh.cxx index 420a51a2de8b..c478d80fdf81 100644 --- a/basctl/source/basicide/basidesh.cxx +++ b/basctl/source/basicide/basidesh.cxx @@ -76,6 +76,7 @@ #include <cppuhelper/implbase.hxx> #include <BasicColorConfig.hxx> #include <officecfg/Office/BasicIDE.hxx> +#include <LineStatusControl.hxx> namespace basctl { @@ -193,6 +194,7 @@ void Shell::Init() LibBoxControl::RegisterControl( SID_BASICIDE_LIBSELECTOR ); LanguageBoxControl::RegisterControl( SID_BASICIDE_CURRENT_LANG ); SvxZoomSliderControl::RegisterControl( SID_ATTR_ZOOMSLIDER ); + LineStatusControl::RegisterControl(SID_BASICIDE_STAT_POS); GetViewFrame().GetWindow().SetBackground( GetViewFrame().GetWindow().GetSettings().GetStyleSettings().GetWindowColor() diff --git a/basctl/source/basicide/moduldl2.cxx b/basctl/source/basicide/moduldl2.cxx index 1221b0094218..cfb9adf03553 100644 --- a/basctl/source/basicide/moduldl2.cxx +++ b/basctl/source/basicide/moduldl2.cxx @@ -153,12 +153,24 @@ NewObjectDialog::NewObjectDialog(weld::Window * pParent, ObjectMode eMode, bool } // GotoLineDialog -GotoLineDialog::GotoLineDialog(weld::Window* pParent ) +GotoLineDialog::GotoLineDialog(weld::Window* pParent, sal_uInt32 nCurLine, sal_uInt32 nLineCount) : GenericDialogController(pParent, "modules/BasicIDE/ui/gotolinedialog.ui", "GotoLineDialog") - , m_xEdit(m_xBuilder->weld_entry("entry")) + , m_xSpinButton(m_xBuilder->weld_spin_button("spin")) + , m_xLineCount(m_xBuilder->weld_label("line_count")) , m_xOKButton(m_xBuilder->weld_button("ok")) + , m_nCurLine(nCurLine) + , m_nLineCount(nLineCount) { - m_xEdit->grab_focus(); + // Adjust line count label + OUString sLabel = m_xLineCount->get_label(); + m_xLineCount->set_label(sLabel.replaceFirst("$1", OUString::number(m_nLineCount))); + + // Initialize the spin button + m_xSpinButton->set_text(OUString::number(m_nCurLine)); + m_xSpinButton->set_range(1, m_nLineCount); + m_xSpinButton->grab_focus(); + m_xSpinButton->select_region(0, -1); + m_xOKButton->connect_clicked(LINK(this, GotoLineDialog, OkButtonHandler)); } @@ -168,15 +180,22 @@ GotoLineDialog::~GotoLineDialog() sal_Int32 GotoLineDialog::GetLineNumber() const { - return m_xEdit->get_text().toInt32(); + return m_xSpinButton->get_text().toInt32(); } IMPL_LINK_NOARG(GotoLineDialog, OkButtonHandler, weld::Button&, void) { - if (GetLineNumber()) + // The number must be in the range between 1 and the number of lines in the module + sal_Int32 nNumber = GetLineNumber(); + if (nNumber && nNumber >= 1 && nNumber <= static_cast<sal_Int32>(m_nLineCount)) + { m_xDialog->response(RET_OK); + } else - m_xEdit->select_region(0, -1); + { + m_xSpinButton->set_text(OUString::number(m_nCurLine)); + m_xSpinButton->select_region(0, -1); + } } // ExportDialog diff --git a/basctl/source/basicide/moduldlg.hxx b/basctl/source/basicide/moduldlg.hxx index 4f4cbcbda3ad..c6ff166c5bb7 100644 --- a/basctl/source/basicide/moduldlg.hxx +++ b/basctl/source/basicide/moduldlg.hxx @@ -59,11 +59,15 @@ public: class GotoLineDialog : public weld::GenericDialogController { - std::unique_ptr<weld::Entry> m_xEdit; + std::unique_ptr<weld::SpinButton> m_xSpinButton; + std::unique_ptr<weld::Label> m_xLineCount; std::unique_ptr<weld::Button> m_xOKButton; + sal_uInt32 m_nCurLine; + sal_uInt32 m_nLineCount; + DECL_LINK(OkButtonHandler, weld::Button&, void); public: - explicit GotoLineDialog(weld::Window* pParent); + explicit GotoLineDialog(weld::Window* pParent, sal_uInt32 nCurLine, sal_uInt32 nLineCount); virtual ~GotoLineDialog() override; sal_Int32 GetLineNumber() const; }; diff --git a/basctl/source/inc/LineStatusControl.hxx b/basctl/source/inc/LineStatusControl.hxx new file mode 100644 index 000000000000..268738f821d3 --- /dev/null +++ b/basctl/source/inc/LineStatusControl.hxx @@ -0,0 +1,30 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include <sfx2/stbitem.hxx> + +namespace basctl +{ +class LineStatusControl final : public SfxStatusBarControl +{ +public: + SFX_DECL_STATUSBAR_CONTROL(); + + LineStatusControl(sal_uInt16 nSlotId, sal_uInt16 nId, StatusBar& rStb); + virtual ~LineStatusControl() override; + + virtual void StateChangedAtStatusBarControl(sal_uInt16 nSID, SfxItemState eState, + const SfxPoolItem* pState) override; +}; + +} // namespace basctl + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basctl/uiconfig/basicide/ui/gotolinedialog.ui b/basctl/uiconfig/basicide/ui/gotolinedialog.ui index e5b5e13ab0fe..fdef2dec1f19 100644 --- a/basctl/uiconfig/basicide/ui/gotolinedialog.ui +++ b/basctl/uiconfig/basicide/ui/gotolinedialog.ui @@ -1,32 +1,32 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.20.4 --> +<!-- Generated with glade 3.40.0 --> <interface domain="basctl"> <requires lib="gtk+" version="3.20"/> <object class="GtkDialog" id="GotoLineDialog"> - <property name="can_focus">False</property> - <property name="border_width">6</property> + <property name="can-focus">False</property> + <property name="border-width">6</property> <property name="title" translatable="yes" context="gotolinedialog|GotoLineDialog">Go to Line</property> <property name="modal">True</property> - <property name="default_width">0</property> - <property name="default_height">0</property> - <property name="type_hint">dialog</property> + <property name="default-width">0</property> + <property name="default-height">0</property> + <property name="type-hint">dialog</property> <child internal-child="vbox"> <object class="GtkBox" id="dialog-vbox1"> - <property name="can_focus">False</property> + <property name="can-focus">False</property> <property name="orientation">vertical</property> <property name="spacing">12</property> <child internal-child="action_area"> <object class="GtkButtonBox" id="dialog-action_area1"> - <property name="can_focus">False</property> - <property name="layout_style">end</property> + <property name="can-focus">False</property> + <property name="layout-style">end</property> <child> <object class="GtkButton" id="ok"> <property name="label" translatable="yes" context="stock">_OK</property> <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="can_default">True</property> - <property name="has_default">True</property> - <property name="receives_default">True</property> + <property name="can-focus">True</property> + <property name="can-default">True</property> + <property name="has-default">True</property> + <property name="receives-default">True</property> <property name="use-underline">True</property> </object> <packing> @@ -39,8 +39,8 @@ <object class="GtkButton" id="cancel"> <property name="label" translatable="yes" context="stock">_Cancel</property> <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> + <property name="can-focus">True</property> + <property name="receives-default">True</property> <property name="use-underline">True</property> </object> <packing> @@ -49,63 +49,55 @@ <property name="position">1</property> </packing> </child> - <child> - <object class="GtkButton" id="help"> - <property name="label" translatable="yes" context="stock">_Help</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="margin-end">6</property> - <property name="use-underline">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">2</property> - <property name="secondary">True</property> - </packing> - </child> </object> <packing> <property name="expand">False</property> <property name="fill">True</property> - <property name="pack_type">end</property> + <property name="pack-type">end</property> <property name="position">2</property> </packing> </child> <child> - <!-- n-columns=1 n-rows=1 --> + <!-- n-columns=3 n-rows=1 --> <object class="GtkGrid" id="grid3"> <property name="visible">True</property> - <property name="can_focus">False</property> + <property name="can-focus">False</property> <property name="hexpand">True</property> - <property name="row_spacing">6</property> - <property name="column_spacing">12</property> + <property name="row-spacing">12</property> + <property name="column-spacing">12</property> <child> <object class="GtkLabel" id="area"> <property name="visible">True</property> - <property name="can_focus">False</property> + <property name="can-focus">False</property> <property name="label" translatable="yes" context="gotolinedialog|area">_Line number:</property> - <property name="use_underline">True</property> - <property name="mnemonic_widget">entry</property> + <property name="use-underline">True</property> + <property name="mnemonic-widget">spin</property> <property name="xalign">0</property> </object> <packing> - <property name="left_attach">0</property> - <property name="top_attach">0</property> + <property name="left-attach">0</property> + <property name="top-attach">0</property> + </packing> + </child> + <child> + <object class="GtkSpinButton" id="spin"> + <property name="visible">True</property> + <property name="can-focus">True</property> + </object> + <packing> + <property name="left-attach">1</property> + <property name="top-attach">0</property> </packing> </child> <child> - <object class="GtkEntry" id="entry"> + <object class="GtkLabel" id="line_count"> <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="hexpand">True</property> - <property name="truncate-multiline">True</property> - <property name="activates_default">True</property> + <property name="can-focus">False</property> + <property name="label" translatable="yes" context="gotolinedialog|line_count">of $1</property> </object> <packing> - <property name="left_attach">1</property> - <property name="top_attach">0</property> + <property name="left-attach">2</property> + <property name="top-attach">0</property> </packing> </child> </object> @@ -120,10 +112,6 @@ <action-widgets> <action-widget response="-5">ok</action-widget> <action-widget response="-6">cancel</action-widget> - <action-widget response="-11">help</action-widget> </action-widgets> - <child> - <placeholder/> - </child> </object> </interface>