1 /**
2  *  Yudit Unicode Editor Source File
3  *
4  *  GNU Copyright (C) 1997-2006  Gaspar Sinai <gaspar@yudit.org>
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License, version 2,
8  *  dated June 1991. See file COPYYING for details.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 
20 #ifndef SYudit_h
21 #define SYudit_h
22 
23 #include "stoolkit/SStringVector.h"
24 #include "stoolkit/SProperties.h"
25 #include "stoolkit/SProperties.h"
26 #include "stoolkit/sedy/SSedy.h"
27 #include "swidget/SFrame.h"
28 #include "swidget/STextEdit.h"
29 #include "swidget/SSlider.h"
30 #include "swidget/SFileDialog.h"
31 #include "swidget/SPasswordDialog.h"
32 #include "swidget/STextDialog.h"
33 #include "swidget/SFreeHand.h"
34 
35 #include "gui/SToolBar.h"
36 #include "gui/SMessageBar.h"
37 #include "gui/SMessageLabel.h"
38 #include "gui/SKMapDialog.h"
39 #include "gui/SHighlightD.h"
40 /**
41  * A caret that redraws itself differently for lr and rl text
42  */
43 class SYudit  : public SFrame,
44   public SFrameListener, public SToolBarListener, public STextEditLS,
45 public SDropListener, public SFreeHandListener
46 {
47 public:
48   SYudit (const SStringVector& args,  const SProperties& allprops, const SString& sedyLib);
49   virtual ~SYudit ();
50 protected:
51   STimer* deferredLoader;
52   virtual bool timeout (const SEventSource* s);
53 
54   virtual bool close (SPanel* comp);
55   virtual void toolBarButtonPressed (void* src, int which, bool accel);
56   virtual void toolBarButtonLeave (void* src, int which);
57   virtual void toolBarButtonEnter (void* src, int which);
58 
59   virtual void textChanged (void *source);
60   virtual void textEntered (void *source);
61   virtual void focusOutRequest (void *source);
62   virtual void focusChanged (void *source, bool in);
63   virtual void caretMoved (void *source, unsigned int line, unsigned int col, bool before);
64   virtual void freeHandTextChanged (void* source, const SString& lookup);
65 
66   STextEdit*  editor;
67   STextEdit*  command;
68   SSlider*    slider;
69   SToolBar*   toolbar;
70   SMessageBar* messagebar;
71   SMessageLabel* messagelabel;
72   SFreeHand* freehand;
73   bool freeHandShown;
74 
75   SFileDialog*     fileDialog;
76   SPasswordDialog*     passwordDialog;
77   SHighlightD*     highlightDialog;
78   STextDialog*     textDialog;
79   SKMapDialog*     kmapDialog;
80 
81   STextIndex             caretNow;
82   SHashtable<STextIndex> caretIndex;
83   virtual bool dropped (void* p, const SString& mimetype, const SString& data);
84 private:
85   enum SStatus { Canceled, Failed, Succeeded };
86   SYudit::SStatus decryptText (const SString& fileName, const SString& text, SString* ret);
87 
88   bool encrypted;
89   bool addMytoolPrefix (SString* executable);
90   void showFreeHand(bool is);
91 
92   void createFileDialog();
93   void createPasswordDialog();
94   void createTextDialog();
95   void createKMapDialog();
96   void createHighlightDialog();
97   void caretMoved ();
98 
99   SLayout editorLayout;
100   SLayout sliderLayout;
101   unsigned int freeHandHeight;
102 
103   SProperties originalProperties;
104   SProperties helpStrings;
105 
106   void print (const SStringVector& args, const SString& str);
107   void load (const SStringVector& args, const SString& str);
108   void save (const SStringVector& args, const SString& str);
109   void goLineRow (const SStringVector& args, const SString& str);
110   void find (const SStringVector& args, const SString& str);
111   void replace (const SStringVector& args, const SString& str);
112   bool newFileExists (const SString& filename);
113   SString    composeFileNameCommand ( const SString& prefix,
114         const SString& encoding, const SString& fileName);
115   SString    quoteFileName(const SString& file);
116   SString completeFileName(const SString& file);
117   bool    setHighlight (const SString& syntax);
118   void    setFileTitle ();
119 
120   void       saveProperties ();
121   SString    currentFileName;
122   SString    currentPassword;
123   SString    lastencoding;
124   SString    lastprinterOption;
125   SString    lastpreviewOption;
126   SString    sedyLibrary;
127   SString    cryptFileMatcher;
128   SSedy      sedy;
129 
130   SProperties userProps;
131   SString    configFile;
132   SStringVector    firstLoad;
133   bool isFirstLoad;
134 
135 };
136 
137 #endif /* SYudit_h */
138