summaryrefslogtreecommitdiff
path: root/fpicker
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2019-10-20 20:43:25 +0100
committerCaolán McNamara <caolanm@redhat.com>2019-10-21 11:32:55 +0200
commit976d595a0f1c5d6a4e60b408f8c0e2340339e770 (patch)
tree4fe9c1bc9bacf0bbb6d0bcf0d1e81322a90a436f /fpicker
parent13d3b6e5b8323d7af686b7ade2785827b7854920 (diff)
move AutocompleteEdit to fpicker
Change-Id: I00b1b4f21ffcb183d098b8af296e1dea64a2a482 Reviewed-on: https://gerrit.libreoffice.org/81177 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'fpicker')
-rw-r--r--fpicker/Library_fps_office.mk1
-rw-r--r--fpicker/source/office/RemoteFilesDialog.hxx2
-rw-r--r--fpicker/source/office/autocmpledit.cxx107
-rw-r--r--fpicker/source/office/autocmpledit.hxx36
4 files changed, 145 insertions, 1 deletions
diff --git a/fpicker/Library_fps_office.mk b/fpicker/Library_fps_office.mk
index 626f357a98b3..eff3f5ebe84f 100644
--- a/fpicker/Library_fps_office.mk
+++ b/fpicker/Library_fps_office.mk
@@ -43,6 +43,7 @@ $(eval $(call gb_Library_use_libraries,fps_office,\
$(eval $(call gb_Library_add_exception_objects,fps_office,\
fpicker/source/office/asyncfilepicker \
+ fpicker/source/office/autocmpledit \
fpicker/source/office/breadcrumb \
fpicker/source/office/commonpicker \
fpicker/source/office/contentenumeration \
diff --git a/fpicker/source/office/RemoteFilesDialog.hxx b/fpicker/source/office/RemoteFilesDialog.hxx
index 5331107018d5..e37e9a37f7e4 100644
--- a/fpicker/source/office/RemoteFilesDialog.hxx
+++ b/fpicker/source/office/RemoteFilesDialog.hxx
@@ -10,7 +10,7 @@
#ifndef INCLUDED_SVTOOLS_REMOTEFILESDIALOG_HXX
#define INCLUDED_SVTOOLS_REMOTEFILESDIALOG_HXX
-#include <svtools/autocmpledit.hxx>
+#include "autocmpledit.hxx"
#include <svtools/place.hxx>
#include <svtools/PlaceEditDialog.hxx>
diff --git a/fpicker/source/office/autocmpledit.cxx b/fpicker/source/office/autocmpledit.cxx
new file mode 100644
index 000000000000..d7b5f6359da3
--- /dev/null
+++ b/fpicker/source/office/autocmpledit.cxx
@@ -0,0 +1,107 @@
+/* -*- 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 "autocmpledit.hxx"
+#include <vcl/svapp.hxx>
+#include <vcl/event.hxx>
+
+AutocompleteEdit::AutocompleteEdit( vcl::Window* pParent )
+ : Edit( pParent )
+ , m_nCurrent( 0 )
+{
+ SetAutocompleteHdl(LINK(this, AutocompleteEdit, AutoCompleteHdl_Impl));
+}
+
+void AutocompleteEdit::AddEntry( const OUString& rEntry )
+{
+ m_aEntries.push_back( rEntry );
+}
+
+void AutocompleteEdit::ClearEntries()
+{
+ m_aEntries.clear();
+ m_aMatching.clear();
+}
+
+IMPL_LINK_NOARG(AutocompleteEdit, AutoCompleteHdl_Impl, Edit&, void)
+{
+ if( Application::AnyInput( VclInputFlags::KEYBOARD ) )
+ return;
+
+ OUString aCurText = GetText();
+ Selection aSelection( GetSelection() );
+
+ if( aSelection.Max() != aCurText.getLength() )
+ return;
+
+ sal_uInt16 nLen = static_cast<sal_uInt16>(aSelection.Min());
+ aCurText = aCurText.copy( 0, nLen );
+ if( aCurText.isEmpty() )
+ return;
+
+ if( !m_aEntries.empty() )
+ {
+ if( Match( aCurText ) )
+ {
+ m_nCurrent = 0;
+ SetText( m_aMatching[0] );
+ sal_uInt16 nNewLen = m_aMatching[0].getLength();
+
+ Selection aSel( nLen, nNewLen );
+ SetSelection( aSel );
+ }
+ }
+}
+
+bool AutocompleteEdit::Match( const OUString& rText )
+{
+ bool bRet = false;
+
+ m_aMatching.clear();
+
+ for(const OUString & rEntry : m_aEntries)
+ {
+ if( rEntry.startsWithIgnoreAsciiCase( rText ) )
+ {
+ m_aMatching.push_back( rEntry );
+ bRet = true;
+ }
+ }
+
+ return bRet;
+}
+
+bool AutocompleteEdit::PreNotify( NotifyEvent& rNEvt )
+{
+ if( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
+ {
+ const KeyEvent& rEvent = *rNEvt.GetKeyEvent();
+ const vcl::KeyCode& rKey = rEvent.GetKeyCode();
+ vcl::KeyCode aCode( rKey.GetCode() );
+
+ if( ( aCode == KEY_UP || aCode == KEY_DOWN ) && !rKey.IsMod2() )
+ {
+ Selection aSelection( GetSelection() );
+ sal_uInt16 nLen = static_cast<sal_uInt16>(aSelection.Min());
+
+ if( !m_aMatching.empty() &&
+ ( ( aCode == KEY_DOWN && m_nCurrent + 1 < m_aMatching.size() )
+ || ( aCode == KEY_UP && m_nCurrent > 0 ) ) )
+ {
+ SetText( m_aMatching[ aCode == KEY_DOWN ? ++m_nCurrent : --m_nCurrent ] );
+ SetSelection( Selection( nLen, GetText().getLength() ) );
+ return true;
+ }
+ }
+ }
+
+ return Edit::PreNotify( rNEvt );
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/fpicker/source/office/autocmpledit.hxx b/fpicker/source/office/autocmpledit.hxx
new file mode 100644
index 000000000000..89b431ebc9e0
--- /dev/null
+++ b/fpicker/source/office/autocmpledit.hxx
@@ -0,0 +1,36 @@
+/* -*- 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/.
+ */
+
+#ifndef INCLUDED_SVTOOLS_AUTOCMPLEDIT_HXX
+#define INCLUDED_SVTOOLS_AUTOCMPLEDIT_HXX
+
+#include <vcl/edit.hxx>
+#include <vector>
+
+class AutocompleteEdit : public Edit
+{
+private:
+ std::vector< OUString > m_aEntries;
+ std::vector< OUString > m_aMatching;
+ std::vector< OUString >::size_type m_nCurrent;
+
+ DECL_LINK(AutoCompleteHdl_Impl, Edit&, void);
+ bool Match( const OUString& rText );
+ bool PreNotify( NotifyEvent& rNEvt ) override;
+
+public:
+ AutocompleteEdit( vcl::Window* pParent );
+
+ void AddEntry( const OUString& rEntry );
+ void ClearEntries();
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */