LibreOffice Module cui (master)  1
scriptdlg.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #pragma once
21 
22 #include <memory>
23 #include <sfx2/basedlgs.hxx>
24 #include <vcl/abstdlg.hxx>
25 #include <vcl/weld.hxx>
26 
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/script/browse/XBrowseNode.hpp>
29 #include <com/sun/star/frame/XModel.hpp>
30 #include <com/sun/star/uno/XComponentContext.hpp>
31 
32 #include <unordered_map>
33 
34 #define OBJTYPE_METHOD 2L
35 #define OBJTYPE_SCRIPTCONTAINER 3L
36 #define OBJTYPE_SFROOT 4L
37 
38 typedef std::unordered_map < OUString, OUString > Selection_hash;
39 
40 class SFEntry;
41 
42 enum class InputDialogMode {
43  NEWLIB = 1,
44  NEWMACRO = 2,
45  RENAME = 3,
46 };
47 
49 {
50 private:
51  std::unique_ptr<weld::Entry> m_xEdit;
52 public:
54  OUString GetObjectName() const { return m_xEdit->get_text(); }
55  void SetObjectName(const OUString& rName)
56  {
57  m_xEdit->set_text(rName);
58  m_xEdit->select_region(0, -1);
59  }
60 };
61 
62 class SFEntry final
63 {
64 private:
65  bool loaded;
66  css::uno::Reference< css::script::browse::XBrowseNode > nodes;
67  css::uno::Reference< css::frame::XModel > model;
68 public:
69  SFEntry( const css::uno::Reference< css::script::browse::XBrowseNode >& entryNodes ,
70  const css::uno::Reference< css::frame::XModel >& entryModel) { nodes = entryNodes; loaded=false; model = entryModel; }
71  SFEntry( const SFEntry& r ) { nodes = r.nodes; loaded = r.loaded; }
72  const css::uno::Reference< css::script::browse::XBrowseNode >& GetNode() const { return nodes ;}
73  const css::uno::Reference< css::frame::XModel >& GetModel() const { return model ;};
74  bool isLoaded() const { return loaded; }
75  void setLoaded() { loaded=true; }
76 };
77 
79 {
80 protected:
81  OUString m_sLanguage;
83  const OUString m_delErrStr;
84  const OUString m_delErrTitleStr;
85  const OUString m_delQueryStr;
86  const OUString m_delQueryTitleStr;
87  const OUString m_createErrStr;
88  const OUString m_createDupStr;
89  const OUString m_createErrTitleStr;
90  const OUString m_renameErrStr;
91  const OUString m_renameErrTitleStr;
92  const OUString m_sMyMacros;
93  const OUString m_sProdMacros;
94 
95  std::unique_ptr<weld::TreeView> m_xScriptsBox;
96  std::unique_ptr<weld::TreeIter> m_xScratchIter;
97  std::unique_ptr<weld::Button> m_xRunButton;
98  std::unique_ptr<weld::Button> m_xCloseButton;
99  std::unique_ptr<weld::Button> m_xCreateButton;
100  std::unique_ptr<weld::Button> m_xEditButton;
101  std::unique_ptr<weld::Button> m_xRenameButton;
102  std::unique_ptr<weld::Button> m_xDelButton;
103 
104  DECL_LINK( ScriptSelectHdl, weld::TreeView&, void );
105  DECL_LINK( ExpandingHdl, const weld::TreeIter&, bool );
106  DECL_LINK( ButtonHdl, weld::Button&, void );
107  static bool getBoolProperty( css::uno::Reference< css::beans::XPropertySet > const & xProps, OUString const & propName );
108  void CheckButtons( css::uno::Reference< css::script::browse::XBrowseNode > const & node );
109 
110  void createEntry(weld::TreeIter& rEntry);
111  void renameEntry(const weld::TreeIter& rEntry);
112  void deleteEntry(weld::TreeIter& rEntry);
113  css::uno::Reference<css::script::browse::XBrowseNode> getBrowseNode(const weld::TreeIter& rEntry);
114  css::uno::Reference<css::frame::XModel> getModel(const weld::TreeIter& rEntry);
115  OUString getListOfChildren( const css::uno::Reference< css::script::browse::XBrowseNode >& node, int depth );
116  void StoreCurrentSelection();
118 
119  void Init(const OUString& language);
120  void delUserData(const weld::TreeIter& rIter);
121  void deleteTree(weld::TreeIter& rIter);
122  void deleteAllTree();
123  void insertEntry(OUString const & rText, OUString const & rBitmap,
124  const weld::TreeIter* pParent,
125  bool bChildrenOnDemand,
126  std::unique_ptr< SFEntry > && aUserData,
127  const OUString& factoryURL, bool bSelect);
128  void insertEntry(OUString const & rText, OUString const & rBitmap,
129  const weld::TreeIter* pParent,
130  bool bChildrenOnDemand,
131  std::unique_ptr< SFEntry > && aUserData,
132  bool bSelect);
133 
134  void RequestSubEntries(const weld::TreeIter& rRootEntry,
135  css::uno::Reference< css::script::browse::XBrowseNode > const & node,
136  css::uno::Reference< css::frame::XModel>& model);
137 
138  static css::uno::Reference< css::script::browse::XBrowseNode >
139  getLangNodeFromRootNode( css::uno::Reference< css::script::browse::XBrowseNode > const & root, OUString const & language );
140 
141  static css::uno::Reference< css::uno::XInterface > getDocumentModel( css::uno::Reference< css::uno::XComponentContext > const & xCtx, OUString const & docName );
142 
143 public:
144  // prob need another arg in the ctor
145  // to specify the language or provider
146  SvxScriptOrgDialog(weld::Window* pParent, const OUString& language);
147  virtual ~SvxScriptOrgDialog() override;
148 
149  virtual short run() override;
150 };
151 
153 {
154 private:
155  struct DialogData {
157  OUString sMessage;
158  };
159 
160  DECL_STATIC_LINK( SvxScriptErrorDialog, ShowDialog, void*, void );
161 
162 public:
163 
164  static void ShowAsyncErrorDialog( weld::Window* pParent, css::uno::Any const & aException );
165 };
166 
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Button > m_xDelButton
Definition: scriptdlg.hxx:102
std::unique_ptr< weld::Entry > m_xEdit
Definition: scriptdlg.hxx:51
css::uno::Reference< css::script::browse::XBrowseNode > nodes
Definition: scriptdlg.hxx:66
const OUString m_renameErrTitleStr
Definition: scriptdlg.hxx:91
OUString getListOfChildren(const css::uno::Reference< css::script::browse::XBrowseNode > &node, int depth)
Definition: scriptdlg.cxx:990
const OUString m_renameErrStr
Definition: scriptdlg.hxx:90
static bool getBoolProperty(css::uno::Reference< css::beans::XPropertySet > const &xProps, OUString const &propName)
Definition: scriptdlg.cxx:975
void delUserData(const weld::TreeIter &rIter)
Definition: scriptdlg.cxx:62
static Selection_hash m_lastSelection
Definition: scriptdlg.hxx:82
void SetObjectName(const OUString &rName)
Definition: scriptdlg.hxx:55
OUString GetObjectName() const
Definition: scriptdlg.hxx:54
const OUString m_delQueryStr
Definition: scriptdlg.hxx:85
void setLoaded()
Definition: scriptdlg.hxx:75
static css::uno::Reference< css::uno::XInterface > getDocumentModel(css::uno::Reference< css::uno::XComponentContext > const &xCtx, OUString const &docName)
Definition: scriptdlg.cxx:205
bool loaded
Definition: scriptdlg.hxx:65
InputDialogMode
Definition: scriptdlg.hxx:42
std::unique_ptr< weld::TreeView > m_xScriptsBox
Definition: scriptdlg.hxx:95
std::unique_ptr< weld::Button > m_xCreateButton
Definition: scriptdlg.hxx:99
css::uno::Reference< css::script::browse::XBrowseNode > getBrowseNode(const weld::TreeIter &rEntry)
Definition: scriptdlg.cxx:676
const OUString m_delErrTitleStr
Definition: scriptdlg.hxx:84
const OUString m_createErrStr
Definition: scriptdlg.hxx:87
void insertEntry(OUString const &rText, OUString const &rBitmap, const weld::TreeIter *pParent, bool bChildrenOnDemand, std::unique_ptr< SFEntry > &&aUserData, const OUString &factoryURL, bool bSelect)
void RequestSubEntries(const weld::TreeIter &rRootEntry, css::uno::Reference< css::script::browse::XBrowseNode > const &node, css::uno::Reference< css::frame::XModel > &model)
Definition: scriptdlg.cxx:265
static css::uno::Reference< css::script::browse::XBrowseNode > getLangNodeFromRootNode(css::uno::Reference< css::script::browse::XBrowseNode > const &root, OUString const &language)
Definition: scriptdlg.cxx:232
OUString m_sLanguage
Definition: scriptdlg.hxx:81
virtual ~SvxScriptOrgDialog() override
Definition: scriptdlg.cxx:422
void deleteEntry(weld::TreeIter &rEntry)
Definition: scriptdlg.cxx:928
const OUString m_sProdMacros
Definition: scriptdlg.hxx:93
const OUString m_delQueryTitleStr
Definition: scriptdlg.hxx:86
void StoreCurrentSelection()
Definition: scriptdlg.cxx:1021
void Init(const OUString &language)
Definition: scriptdlg.cxx:116
const css::uno::Reference< css::frame::XModel > & GetModel() const
Definition: scriptdlg.hxx:73
virtual short run() override
Definition: scriptdlg.cxx:427
RENAME
const OUString m_createErrTitleStr
Definition: scriptdlg.hxx:89
DECL_LINK(ScriptSelectHdl, weld::TreeView &, void)
SFEntry(const SFEntry &r)
Definition: scriptdlg.hxx:71
std::unique_ptr< weld::Button > m_xCloseButton
Definition: scriptdlg.hxx:98
DECL_STATIC_LINK(SvxScriptErrorDialog, ShowDialog, void *, void)
css::uno::Reference< css::frame::XModel > getModel(const weld::TreeIter &rEntry)
Definition: scriptdlg.cxx:687
const OUString m_createDupStr
Definition: scriptdlg.hxx:88
std::unique_ptr< weld::Button > m_xEditButton
Definition: scriptdlg.hxx:100
CuiInputDialog(weld::Window *pParent, InputDialogMode nMode)
Definition: scriptdlg.cxx:343
const css::uno::Reference< css::script::browse::XBrowseNode > & GetNode() const
Definition: scriptdlg.hxx:72
bool isLoaded() const
Definition: scriptdlg.hxx:74
SFEntry(const css::uno::Reference< css::script::browse::XBrowseNode > &entryNodes, const css::uno::Reference< css::frame::XModel > &entryModel)
Definition: scriptdlg.hxx:69
void RestorePreviousSelection()
Definition: scriptdlg.cxx:1040
std::unique_ptr< weld::Button > m_xRenameButton
Definition: scriptdlg.hxx:101
void deleteTree(weld::TreeIter &rIter)
Definition: scriptdlg.cxx:76
SvxScriptOrgDialog(weld::Window *pParent, const OUString &language)
Definition: scriptdlg.cxx:371
std::unordered_map< OUString, OUString > Selection_hash
Definition: scriptdlg.hxx:38
static void ShowAsyncErrorDialog(weld::Window *pParent, css::uno::Any const &aException)
Definition: scriptdlg.cxx:1298
const OUString m_delErrStr
Definition: scriptdlg.hxx:83
const OUString m_sMyMacros
Definition: scriptdlg.hxx:92
css::uno::Reference< css::frame::XModel > model
Definition: scriptdlg.hxx:67
std::unique_ptr< weld::TreeIter > m_xScratchIter
Definition: scriptdlg.hxx:96
void createEntry(weld::TreeIter &rEntry)
Definition: scriptdlg.cxx:698
void CheckButtons(css::uno::Reference< css::script::browse::XBrowseNode > const &node)
Definition: scriptdlg.cxx:446
void renameEntry(const weld::TreeIter &rEntry)
Definition: scriptdlg.cxx:871
std::unique_ptr< weld::Button > m_xRunButton
Definition: scriptdlg.hxx:97