File indexing completed on 2023-09-24 09:47:28
0001 /* 0002 This file is part of Lokalize 0003 0004 SPDX-FileCopyrightText: 2007-2014 Nick Shaforostoff <shafff@ukr.net> 0005 SPDX-FileCopyrightText: 2018-2019 Simon Depiets <sdepiets@gmail.com> 0006 0007 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0008 */ 0009 0010 #ifndef EDITORTAB_H 0011 #define EDITORTAB_H 0012 0013 #ifdef HAVE_CONFIG_H 0014 #include <config.h> 0015 #endif 0016 0017 #include "pos.h" 0018 #include "lokalizesubwindowbase.h" 0019 0020 #include <QHash> 0021 #include <QMdiSubWindow> 0022 #include <QMap> 0023 #include <KProcess> 0024 0025 namespace Sonnet 0026 { 0027 class Dialog; 0028 } 0029 namespace Sonnet 0030 { 0031 class BackgroundChecker; 0032 } 0033 0034 #include <kxmlguiclient.h> 0035 0036 class KFind; 0037 class KReplace; 0038 class KActionCategory; 0039 0040 class Project; 0041 class Catalog; 0042 class EditorView; 0043 class MergeView; 0044 class CatalogView; 0045 class MsgCtxtView; 0046 class AltTransView; 0047 namespace GlossaryNS 0048 { 0049 class GlossaryView; 0050 } 0051 0052 0053 0054 struct EditorState { 0055 public: 0056 EditorState(): entry(0) {} 0057 EditorState(const EditorState& s): dockWidgets(s.dockWidgets), filePath(s.filePath), entry(0) {} 0058 ~EditorState() {} 0059 0060 QByteArray dockWidgets; 0061 QString filePath; 0062 QString mergeFilePath; 0063 int entry; 0064 //int offset; 0065 }; 0066 0067 0068 /** 0069 * @short Editor tab 0070 * 0071 * This class can be called a dispatcher for one message catalog. 0072 * 0073 * It is accessible via Lokalize.currentEditor() from kross scripts and via 0074 * '/ThisIsWhatYouWant/Editor/# : org.kde.Lokalize.Editor' from qdbusviewer 0075 * 0076 * @author Nick Shaforostoff <shafff@ukr.net> 0077 */ 0078 class EditorTab: public LokalizeSubwindowBase2 0079 { 0080 Q_OBJECT 0081 Q_CLASSINFO("D-Bus Interface", "org.kde.Lokalize.Editor") 0082 //qdbuscpp2xml -m -s editortab.h -o org.kde.lokalize.Editor.xml 0083 #define qdbuscpp2xml 0084 0085 public: 0086 explicit EditorTab(QWidget* parent, bool valid = true); 0087 ~EditorTab() override; 0088 0089 0090 //interface for LokalizeMainWindow 0091 void hideDocks() override; 0092 void showDocks() override; 0093 QString currentFilePath() override; 0094 void setFullPathShown(bool); 0095 void setProperCaption(QString, bool); //reimpl to remove ' - Lokalize' 0096 public Q_SLOTS: 0097 void setProperFocus(); 0098 public: 0099 bool queryClose() override; 0100 EditorState state(); 0101 KXMLGUIClient* guiClient() override 0102 { 0103 return (KXMLGUIClient*)this; 0104 } 0105 QString dbusObjectPath(); 0106 int dbusId() 0107 { 0108 return m_dbusId; 0109 } 0110 QObject* adaptor() 0111 { 0112 return m_adaptor; 0113 } 0114 0115 //wrapper for cmdline handling 0116 void mergeOpen(QString mergeFilePath); 0117 0118 bool fileOpen(QString filePath = QString(), QString suggestedDirPath = QString(), QMap<QString, QMdiSubWindow*> openedFiles = QMap<QString, QMdiSubWindow*>(), bool silent = false); 0119 public Q_SLOTS: 0120 //for undo/redo, views 0121 void gotoEntry(DocPosition pos); 0122 void gotoEntry(DocPosition pos, int selection); 0123 #ifdef qdbuscpp2xml 0124 Q_SCRIPTABLE void gotoEntry(int entry) 0125 { 0126 gotoEntry(DocPosition(entry)); 0127 } 0128 Q_SCRIPTABLE void gotoEntryForm(int entry, int form) 0129 { 0130 gotoEntry(DocPosition(entry, form)); 0131 } 0132 Q_SCRIPTABLE void gotoEntryFormOffset(int entry, int form, int offset) 0133 { 0134 gotoEntry(DocPosition(entry, form, offset)); 0135 } 0136 Q_SCRIPTABLE void gotoEntryFormOffsetSelection(int entry, int form, int offset, int selection) 0137 { 0138 gotoEntry(DocPosition(entry, form, offset), selection); 0139 } 0140 0141 Q_SCRIPTABLE QString currentEntryId(); 0142 Q_SCRIPTABLE int currentEntry() 0143 { 0144 return m_currentPos.entry; 0145 } 0146 Q_SCRIPTABLE int currentForm() 0147 { 0148 return m_currentPos.form; 0149 } 0150 Q_SCRIPTABLE QString selectionInTarget(); 0151 Q_SCRIPTABLE QString selectionInSource(); 0152 0153 Q_SCRIPTABLE void setEntryFilteredOut(int entry, bool filteredOut); 0154 Q_SCRIPTABLE void setEntriesFilteredOut(bool filteredOut); 0155 0156 Q_SCRIPTABLE int entryCount(); 0157 Q_SCRIPTABLE QString entrySource(int entry, int form); 0158 Q_SCRIPTABLE QString entryTarget(int entry, int form); 0159 Q_SCRIPTABLE void setEntryTarget(int entry, int form, const QString& content); 0160 Q_SCRIPTABLE int entryPluralFormCount(int entry); 0161 Q_SCRIPTABLE bool entryReady(int entry); 0162 Q_SCRIPTABLE void addEntryNote(int entry, const QString& note); 0163 Q_SCRIPTABLE void addTemporaryEntryNote(int entry, const QString& note); 0164 0165 Q_SCRIPTABLE void addAlternateTranslation(int entry, const QString& translation); 0166 Q_SCRIPTABLE void addTemporaryAlternateTranslation(int entry, const QString& translation); 0167 0168 Q_SCRIPTABLE QString currentFile() 0169 { 0170 return currentFilePath(); 0171 } 0172 Q_SCRIPTABLE QByteArray currentFileContents(); 0173 Q_SCRIPTABLE QString sourceLangCode(); 0174 Q_SCRIPTABLE QString targetLangCode(); 0175 0176 Q_SCRIPTABLE void attachAlternateTranslationFile(const QString& path); 0177 Q_SCRIPTABLE void openSyncSource(QString path) 0178 { 0179 mergeOpen(path); 0180 } 0181 Q_SCRIPTABLE void reloadFile(); 0182 #endif 0183 Q_SCRIPTABLE bool saveFile(const QString& filePath = QString()); 0184 Q_SCRIPTABLE bool saveFileAs(const QString& defaultPath = QString()); 0185 Q_SCRIPTABLE void close() 0186 { 0187 return parent()->deleteLater(); 0188 } 0189 Q_SCRIPTABLE void gotoNextUnfiltered(); 0190 Q_SCRIPTABLE void gotoPrevUnfiltered(); 0191 Q_SCRIPTABLE void gotoFirstUnfiltered(); 0192 Q_SCRIPTABLE void gotoLastUnfiltered(); 0193 Q_SCRIPTABLE void gotoNext(); 0194 Q_SCRIPTABLE void gotoPrev(); 0195 Q_SCRIPTABLE void gotoFirst(); 0196 Q_SCRIPTABLE void gotoLast(); 0197 0198 Q_SCRIPTABLE void mergeIntoOpenDocument(); 0199 0200 Q_SCRIPTABLE bool findEntryBySourceContext(const QString& source, const QString& ctxt); 0201 0202 Q_SCRIPTABLE bool isValid() 0203 { 0204 return m_valid; 0205 } 0206 Q_SCRIPTABLE void setSrcFileOpenRequestAccepted(bool a) 0207 { 0208 m_srcFileOpenRequestAccepted = a; 0209 } 0210 0211 private Q_SLOTS: 0212 void highlightFound(const QString &, int, int); //for find/replace 0213 void highlightFound_(const QString &, int, int); //for find/replace 0214 0215 void lookupSelectionInTranslationMemory(); 0216 0217 //statusbar indication 0218 void numberOfFuzziesChanged(); 0219 void numberOfUntranslatedChanged(); 0220 //fuzzy, untr [statusbar] indication 0221 void msgStrChanged(); 0222 //modif [caption] indication 0223 void setModificationSign(); 0224 void updateCaptionPath(); 0225 0226 //gui 0227 void switchForm(int); 0228 0229 void undo(); 0230 void redo(); 0231 void findNext(); 0232 void findPrev(); 0233 void find(); 0234 0235 void replace(); 0236 void replaceNext();//internal 0237 void doReplace(const QString&, int, int, int); //internal 0238 void cleanupReplace();//internal 0239 0240 // void selectAll(); 0241 // void deselectAll(); 0242 // void clear(); 0243 // void search2msgstr(); 0244 // void plural2msgstr(); 0245 0246 void gotoEntry(); 0247 0248 void gotoPrevFuzzyUntr(); 0249 bool gotoNextFuzzyUntr(const DocPosition& pos); 0250 bool gotoNextFuzzyUntr(); 0251 void gotoNextFuzzy(); 0252 void gotoPrevFuzzy(); 0253 void gotoNextUntranslated(); 0254 void gotoPrevUntranslated(); 0255 0256 void toggleApprovementGotoNextFuzzyUntr(); 0257 void setApproveActionTitle(); 0258 0259 0260 void spellcheck(); 0261 void spellcheckNext(); 0262 void spellcheckShow(const QString&, int); 0263 void spellcheckReplace(QString, int, const QString&); 0264 void spellcheckStop(); 0265 void spellcheckCancel(); 0266 0267 void gotoNextBookmark(); 0268 void gotoPrevBookmark(); 0269 0270 void displayWordCount(); 0271 void clearTranslatedEntries(); 0272 void launchPology(); 0273 0274 void openPhasesWindow(); 0275 0276 void defineNewTerm(); 0277 0278 void initLater(); 0279 void showStatesMenu(); 0280 void setState(QAction*); 0281 void dispatchSrcFileOpenRequest(const QString& srcPath, int line); 0282 void indexWordsForCompletion(); 0283 0284 void fileAutoSaveFailedWarning(const QString&); 0285 0286 void pologyHasFinished(int exitCode, QProcess::ExitStatus exitStatus); 0287 0288 protected: 0289 void paintEvent(QPaintEvent* event) override; 0290 0291 private: 0292 void setupAccel(); 0293 void setupActions(); 0294 void setupStatusBar(); 0295 0296 void findNext(const DocPosition& startingPos); 0297 void replaceNext(const DocPosition&); 0298 0299 private: 0300 Project* m_project{}; 0301 Catalog* m_catalog{}; 0302 0303 EditorView* m_view{}; 0304 QAction* m_approveAndGoAction{}; 0305 QAction* m_approveAction{}; 0306 QAction* m_stateAction{}; 0307 0308 KProcess* m_pologyProcess{}; 0309 bool m_pologyProcessInProgress{}; 0310 0311 DocPosition m_currentPos{}; 0312 DocPosition _searchingPos{}; //for find/replace 0313 DocPosition _replacingPos{}; 0314 DocPosition _spellcheckPos{}; 0315 DocPosition _spellcheckStartPos{}; 0316 0317 Sonnet::BackgroundChecker* m_sonnetChecker{}; 0318 Sonnet::Dialog* m_sonnetDialog{}; 0319 int m_spellcheckStartUndoIndex{}; 0320 bool m_spellcheckStop{}; 0321 0322 bool m_currentIsApproved{true}; //for statusbar animation 0323 bool m_currentIsUntr{true}; //for statusbar animation 0324 0325 bool m_fullPathShown{}; 0326 0327 bool m_doReplaceCalled{}; //used to prevent non-clean catalog status 0328 KFind* m_find{}; 0329 KReplace* m_replace{}; 0330 0331 //BEGIN views 0332 MergeView* m_syncView{}; 0333 MergeView* m_syncViewSecondary{}; 0334 CatalogView* m_transUnitsView{}; 0335 MsgCtxtView* m_notesView{}; 0336 AltTransView* m_altTransView{}; 0337 //END views 0338 0339 QString _captionPath; 0340 0341 bool m_srcFileOpenRequestAccepted{}; 0342 0343 //BEGIN dbus 0344 bool m_valid{}; 0345 QObject* m_adaptor{}; 0346 int m_dbusId{-1}; 0347 static QList<int> ids; 0348 //END dbus 0349 0350 Q_SIGNALS: 0351 void tmLookupRequested(DocPosition::Part, const QString&); 0352 void tmLookupRequested(const QString& source, const QString& target); 0353 0354 Q_SCRIPTABLE void srcFileOpenRequested(const QString& srcPath, int line); 0355 0356 void fileOpenRequested(const QString& filePath, const QString& str, const QString& ctxt, const bool setAsActive); 0357 0358 //emitted when mainwindow is closed or another file is opened 0359 void fileClosed(); 0360 Q_SCRIPTABLE void fileClosed(const QString& path); 0361 Q_SCRIPTABLE void fileSaved(const QString& path); 0362 Q_SCRIPTABLE void fileAboutToBeClosed();//old catalog is still accessible 0363 Q_SCRIPTABLE void fileOpened(); 0364 0365 Q_SCRIPTABLE void entryDisplayed(); 0366 void signalNewEntryDisplayed(const DocPosition&); 0367 void signalEntryWithMergeDisplayed(bool, const DocPosition&); 0368 void signalFirstDisplayed(bool); 0369 void signalLastDisplayed(bool); 0370 0371 void signalEquivTranslatedEntryDisplayed(bool); 0372 void signalApprovedEntryDisplayed(bool); 0373 0374 void signalFuzzyEntryDisplayed(bool); 0375 void signalPriorFuzzyAvailable(bool); 0376 void signalNextFuzzyAvailable(bool); 0377 0378 void signalPriorUntranslatedAvailable(bool); 0379 void signalNextUntranslatedAvailable(bool); 0380 0381 void signalPriorFuzzyOrUntrAvailable(bool); 0382 void signalNextFuzzyOrUntrAvailable(bool); 0383 0384 // merge mode signals gone to the view 0385 //NOTE move these to catalog tree view? 0386 void signalPriorBookmarkAvailable(bool); 0387 void signalNextBookmarkAvailable(bool); 0388 void signalBookmarkDisplayed(bool); 0389 0390 Q_SCRIPTABLE void xliffFileOpened(bool); 0391 }; 0392 0393 #endif