1 /* 2 * Copyright 2002-2012, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Mattias Sundblad 7 * Andrew Bachmann 8 * Jonas Sundström 9 */ 10 #ifndef STYLED_EDIT_WINDOW_H 11 #define STYLED_EDIT_WINDOW_H 12 13 14 #include <Alert.h> 15 #include <Node.h> 16 #include <Window.h> 17 18 struct entry_ref; 19 20 class BFilePanel; 21 class BMenu; 22 class BMenuBar; 23 class BMenuItem; 24 class BMessage; 25 class BScrollView; 26 class StatusView; 27 class StyledEditView; 28 class ColorMenuItem; 29 30 31 class StyledEditWindow : public BWindow { 32 public: 33 StyledEditWindow(BRect frame, int32 id, 34 uint32 encoding = 0); 35 StyledEditWindow(BRect frame, entry_ref* ref, 36 uint32 encoding = 0); 37 virtual ~StyledEditWindow(); 38 39 virtual void Quit(); 40 virtual bool QuitRequested(); 41 virtual void MessageReceived(BMessage* message); 42 virtual void MenusBeginning(); 43 44 status_t Save(BMessage* message = NULL); 45 status_t SaveAs(BMessage* message = NULL); 46 void OpenFile(entry_ref* ref); 47 status_t PageSetup(const char* documentName); 48 void Print(const char* documentName); 49 void SearchAllWindows(BString find, BString replace, 50 bool caseSensitive); 51 bool IsDocumentEntryRef(const entry_ref* ref); 52 53 private: 54 void _InitWindow(uint32 encoding = 0); 55 void _BuildFontColorMenu(BMenu* menu); 56 void _LoadAttrs(); 57 void _SaveAttrs(); 58 status_t _LoadFile(entry_ref* ref, 59 const char* forceEncoding = NULL); 60 void _ReloadDocument(BMessage *message); 61 status_t _UnlockFile(); 62 bool _Search(BString searchFor, bool caseSensitive, 63 bool wrap, bool backSearch, 64 bool scrollToOccurence = true); 65 void _FindSelection(); 66 bool _Replace(BString findThis, BString replaceWith, 67 bool caseSensitive, bool wrap, 68 bool backSearch); 69 void _ReplaceAll(BString find, BString replace, 70 bool caseSensitive); 71 void _SetFontSize(float fontSize); 72 void _SetFontColor(const rgb_color* color); 73 void _SetFontStyle(const char* fontFamily, 74 const char* fontStyle); 75 int32 _ShowStatistics(); 76 void _SetReadOnly(bool editable); 77 void _UpdateCleanUndoRedoSaveRevert(); 78 int32 _ShowAlert(const BString& text, 79 const BString& label, const BString& label2, 80 const BString& label3, 81 alert_type type) const; 82 BMenu* _PopulateEncodingMenu(BMenu* menu, 83 const char* encoding); 84 85 // node monitoring helper 86 class _NodeMonitorSuspender { 87 StyledEditWindow *fWindow; 88 public: 89 _NodeMonitorSuspender(StyledEditWindow *w) : fWindow(w) { 90 fWindow->_SwitchNodeMonitor(false); 91 } 92 93 ~_NodeMonitorSuspender() { 94 fWindow->_SwitchNodeMonitor(true); 95 } 96 }; 97 98 friend class _NodeMonitorSuspender; 99 100 void _HandleNodeMonitorEvent(BMessage *message); 101 void _ShowNodeChangeAlert(const char* name, 102 bool removed); 103 void _SwitchNodeMonitor(bool on, 104 entry_ref* ref = NULL); 105 106 private: 107 BMessage* fPrintSettings; 108 BMessage* fSaveMessage; 109 110 BMenu* fFontMenu; 111 BMenu* fFontSizeMenu; 112 BMenu* fFontColorMenu; 113 BMenuItem* fCurrentFontItem; 114 BMenuItem* fCurrentStyleItem; 115 116 BMenuItem* fSaveItem; 117 BMenuItem* fReloadItem; 118 119 BMenuItem* fUndoItem; 120 BMenuItem* fCutItem; 121 BMenuItem* fCopyItem; 122 123 BMenuItem* fFindAgainItem; 124 BMenuItem* fReplaceItem; 125 BMenuItem* fReplaceSameItem; 126 127 BMenuItem* fBoldItem; 128 BMenuItem* fItalicItem; 129 130 BMenuItem* fWrapItem; 131 BMenuItem* fAlignLeft; 132 BMenuItem* fAlignCenter; 133 BMenuItem* fAlignRight; 134 BMenuItem* fEncodingItem; 135 BMenuItem* fRecentMenuItem; 136 137 BString fStringToFind; 138 BString fReplaceString; 139 140 ColorMenuItem* fDefaultFontColorItem; 141 142 // undo modes 143 bool fUndoFlag; // we just did an undo action 144 bool fCanUndo; // we can do an undo action next 145 bool fRedoFlag; // we just did a redo action 146 bool fCanRedo; // we can do a redo action next 147 148 // clean modes 149 bool fUndoCleans; 150 // an undo action will put us in a clean state 151 bool fRedoCleans; 152 // a redo action will put us in a clean state 153 bool fClean; // we are in a clean state 154 155 bool fCaseSensitive; 156 bool fWrapAround; 157 bool fBackSearch; 158 159 StyledEditView* fTextView; 160 BScrollView* fScrollView; 161 StatusView* fStatusView; 162 163 BFilePanel* fSavePanel; 164 BMenu* fSavePanelEncodingMenu; 165 // node monitoring 166 node_ref fNodeRef; 167 node_ref fFolderNodeRef; 168 bool fNagOnNodeChange; 169 170 BWindow* fFindWindow; 171 BWindow* fReplaceWindow; 172 }; 173 174 175 #endif // STYLED_EDIT_WINDOW_H 176