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 BMenuItem* fUnderlineItem; 130 131 BMenuItem* fWrapItem; 132 BMenuItem* fAlignLeft; 133 BMenuItem* fAlignCenter; 134 BMenuItem* fAlignRight; 135 BMenuItem* fEncodingItem; 136 BMenuItem* fRecentMenuItem; 137 138 BString fStringToFind; 139 BString fReplaceString; 140 141 ColorMenuItem* fDefaultFontColorItem; 142 143 // undo modes 144 bool fUndoFlag; // we just did an undo action 145 bool fCanUndo; // we can do an undo action next 146 bool fRedoFlag; // we just did a redo action 147 bool fCanRedo; // we can do a redo action next 148 149 // clean modes 150 bool fUndoCleans; 151 // an undo action will put us in a clean state 152 bool fRedoCleans; 153 // a redo action will put us in a clean state 154 bool fClean; // we are in a clean state 155 156 bool fCaseSensitive; 157 bool fWrapAround; 158 bool fBackSearch; 159 160 StyledEditView* fTextView; 161 BScrollView* fScrollView; 162 StatusView* fStatusView; 163 164 BFilePanel* fSavePanel; 165 BMenu* fSavePanelEncodingMenu; 166 // node monitoring 167 node_ref fNodeRef; 168 node_ref fFolderNodeRef; 169 bool fNagOnNodeChange; 170 171 BWindow* fFindWindow; 172 BWindow* fReplaceWindow; 173 }; 174 175 176 #endif // STYLED_EDIT_WINDOW_H 177