summaryrefslogtreecommitdiffstats
path: root/src/libgui/editor_manager.h
blob: fd2b59a2c29f6d97e9ddd558fdd6cf7bc3ee623d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/***************************************************************************
 *   Copyright (C) 2005 Nicolas Hadacek <hadacek@kde.org>                  *
 *   Copyright (C) 2003-2004 Alain Gibaud <alain.gibaud@free.fr>           *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/
#ifndef EDITOR_MANAGER_H
#define EDITOR_MANAGER_H

class TQEvent;
#include <ktabbar.h>
#include <ktabwidget.h>
#include <klineedit.h>

#include "text_editor.h"
#include "common/gui/misc_gui.h"
#include "common/gui/dialog.h"

//-----------------------------------------------------------------------------
class SwitchToDialog : public Dialog
{
TQ_OBJECT
  
public:
  SwitchToDialog(const TQStringList &names, TQWidget *parent);
  TQString name() const { return _edit->text(); }

private:
  KLineEdit *_edit;
};

//-----------------------------------------------------------------------------
class EditorTabBar : public TabBar
{
TQ_OBJECT
  
public:
  EditorTabBar(TQWidget *parent) : TabBar(parent, "editor_tab_bar") {}
  void setReadOnly(uint index, bool readOnly) { _readOnly[tabAt(index)] = readOnly; }

private:
  TQMap<TQTab *, bool> _readOnly;
  virtual void paintLabel(TQPainter *p, const TQRect &br, TQTab *t, bool has_focus) const;
};

//-----------------------------------------------------------------------------
class EditorHistory
{
public:
  EditorHistory() : _current(0) {}
  bool hasBack() const { return _current!=0; }
  bool hasForward() const { return (_current+1)<_names.count(); }
  void add(const TQString &name);
  void closedLast();
  TQString goBack();
  TQString goForward();

private:
  uint _current;
  TQValueVector<TQString> _names;
};

//-----------------------------------------------------------------------------
class EditorManager : public TabWidget
{
TQ_OBJECT
  
public:
  EditorManager(TQWidget *parent);

  PURL::UrlList files() const;
  TQValueList<Editor *> &editors() { return _editors; }
  uint nbEditors() const { return _editors.count(); }
  Editor *createEditor(PURL::FileType type, const PURL::Url &url);
  void addEditor(Editor *e);
  Editor *currentEditor() const { return _current; }
  Editor *findEditor(const PURL::Url &file);
  Editor *findEditor(const TQString &tag);
  void showEditor(Editor *e);
  bool closeEditor(const PURL::Url &url);
  bool closeEditor(Editor *e, bool ask);
  bool openFile(const PURL::Url &url);
  Editor *openEditor(const PURL::Url &url);
  void connectEditor(Editor *editor);
  void disconnectEditor(Editor *editor);
  const EditorHistory &history() const { return _history; }
  enum EditorType { DeviceEditor = 0, RegisterEditor, Nb_EditorTypes };
  Editor *openEditor(EditorType type);

public slots:
  void updateTitles();
  void slotDropEvent(TQDropEvent *e);
  void saveAllFiles();
  bool closeCurrentEditor();
  bool closeAllEditors();
  bool closeAllOtherEditors();
  void switchHeaderImplementation();
  void switchToEditor();
  void goBack();
  void goForward();

signals:
  void modified(const PURL::Url &url);
  void guiChanged();
  void statusChanged(const TQString &);

private:
  void changeToEditor(Editor *e);
  void enableActions(bool enable);
  TQString title(const Editor &e) const;
  TQString name(const Editor &e) const;
  virtual void contextMenu(int i, const TQPoint &p);
  void saveBookmarks(const Editor &e);
  void restoreBookmarks(Editor &e);

private slots:
  void showEditor(TQWidget *w) { showEditor(static_cast<Editor *>(w)); }
  void closeRequest(int i);
  void modifiedSlot();

private:
  Editor *_current;
  TQValueList<Editor *> _editors;
  EditorHistory _history;
  static const char * const EDITOR_TAGS[Nb_EditorTypes];
};

#endif