summaryrefslogtreecommitdiffstats
path: root/parts/filecreate/filecreate_part.h
blob: 9d0904934cebc018313b403575e109f3fbb552ef (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/***************************************************************************
 *   Copyright (C) 2003 by Julian Rockey                                   *
 *   linux@jrockey.com                                                     *
 *                                                                         *
 *   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 __KDEVPART_FILECREATE_H__
#define __KDEVPART_FILECREATE_H__


#include <tqguardedptr.h>
#include <tqptrlist.h>

#include <tqwidget.h>
#include <kdevplugin.h>
#include <kdevcreatefile.h>

#include "filecreate_typechooser.h"

class TDEPopupMenu;

namespace FileCreate {
  class Widget;
  class FileType;
}

class KDialogBase;
class FCConfigWidget;
class ConfigWidgetProxy;

using namespace FileCreate;

class FileCreatePart : public KDevCreateFile
{
  Q_OBJECT
  

  friend class FCConfigWidget;
public:
  FileCreatePart(TQObject *parent, const char *name, const TQStringList &);
  virtual ~FileCreatePart();

  /**
   * Returns the list of available file types.
   */
  TQPtrList<FileType> getFileTypes() const { return m_filetypes; }

  /**
   * Call this method to create a new file, within or without the project. Supply as
   * much information as you know. Leave what you don't know as TQString().
   * The user will be prompted as necessary for the missing information, and the
   * file created, and added to the project as necessary.
   */
  virtual KDevCreateFile::CreatedFile createNewFile(TQString ext = TQString(),
                     TQString dir = TQString(),
                     TQString name = TQString(),
                     TQString subtype = TQString());

  /**
   * Finds the file type object for a given extension and optionally subtype.
   * You can omit the subtype and specify the extension as ext-subtype if you wish.
   */
  FileType * getType(const TQString & ext, const TQString subtype = TQString());
  /**
   * Finds the file type object for a given extension and optionally subtype.
   * You can omit the subtype and specify the extension as ext-subtype if you wish.
   * Returns only enabled type (i.e. used in the project).
   */
  FileType * getEnabledType(const TQString & ext, const TQString subtype = TQString());

public slots:

  void slotProjectOpened();
  void slotProjectClosed();
  void slotInitialize();
  void slotGlobalInitialize();

  /**
   * Called when a file type is selected from the docked widget.
   */
  void slotFiletypeSelected(const FileType *);

  /**
   * Called when a new file is required - for example, from the "New.." menu action.
   */
  void slotNewFile();

  /**
   * Called from TDEToolBarPopupMenu to request a new file action
   * @param pFileType is acutally a pointer to FileType
   */
  void slotNewFilePopup(int pFileType);

protected slots:
  void slotNoteFiletype(const FileType * filetype);
  void slotAboutToShowNewPopupMenu();
  void insertConfigWidget( const KDialogBase * dlg, TQWidget * page, unsigned int );

private:
  /**
   * If a file has been successfully created, open it
   */
  void openCreatedFile(const KDevCreateFile::CreatedFile & createdFile);

  /**
   * Reads in file type definitions from a config DOM and adds them
   * to the file type list. If enable is true, sets them all to
   * enabled=true by default.
   */
  int readTypes(const TQDomDocument & dom, TQPtrList<FileType> &m_filetypes, bool enable);

  /**
   * Add a file type
   */
  void addFileType(const TQString & filename);

  /**
   * Finds the global XML file that has the same version as KDevelop
   */
  TQString findGlobalXMLFile() const;

  /**
   * List of file types from which the user can choose
   */
  TQPtrList<FileType> m_filetypes;

  /**
   * The file type selected by the new file dialog, if appropriate.
   */
  const FileType * m_filedialogFiletype;

  ConfigWidgetProxy * _configProxy;

  TDEPopupMenu* m_newPopupMenu;
  TQPtrList<TDEPopupMenu>* m_subPopups;
};


#endif