summaryrefslogtreecommitdiffstats
path: root/src/libgui/new_dialogs.cpp
blob: 919ad51b10b2fe72f532941c821219b7a4465df7 (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
/***************************************************************************
 *   Copyright (C) 2005-2007 Nicolas Hadacek <[email protected]>             *
 *   Copyright (C) 2003-2004 Alain Gibaud <[email protected]>           *
 *                                                                         *
 *   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.                                   *
 ***************************************************************************/
#include "new_dialogs.h"

#include <tdelocale.h>
#include <kiconloader.h>
#include <kpushbutton.h>

#include "common/gui/purl_gui.h"
#include "project.h"

//----------------------------------------------------------------------------
NewDialog::NewDialog(const TQString &caption, TQWidget *parent)
  : Dialog(parent, "new_dialog", true, caption, Ok|Cancel, Ok, false)
{
  _top = new TQGridLayout(mainWidget(), 0, 0, 10, 10);
  _top->setColStretch(2, 1);

  _fLabel = new TQLabel(mainWidget());
  _top->addWidget(_fLabel, 0, 0);
  _filename = new TQLineEdit(mainWidget());
  connect(_filename, TQ_SIGNAL(textChanged(const TQString &)), TQ_SLOT(changed()));
  _top->addMultiCellWidget(_filename, 0,0, 1,3);

  TQLabel *label= new TQLabel(i18n("Location:"), mainWidget());
  _top->addWidget(label, 1, 0);
  _dir = new TQLineEdit(mainWidget());
  connect(_dir, TQ_SIGNAL(textChanged(const TQString &)), TQ_SLOT(changed()));
  _top->addMultiCellWidget(_dir, 1,1, 1,2);
  TDEIconLoader loader;
  TQIconSet iconset = loader.loadIcon("document-open", TDEIcon::Toolbar);
  KPushButton *button = new KPushButton(iconset, TQString(), mainWidget());
  connect(button, TQ_SIGNAL(clicked()), TQ_SLOT(browse()));
  _top->addWidget(button, 1, 3);

  _filename->setFocus();
  enableButtonOK(false);
}

void NewDialog::changed()
{
  enableButtonOK(!_filename->text().isEmpty() && !_dir->text().isEmpty());
}

void NewDialog::browse()
{
  PURL::Directory dir = PURL::getExistingDirectory(startDir(), this, TQString());
  if ( dir.isEmpty() ) return;
  _dir->setText(dir.path());
}

//----------------------------------------------------------------------------
NewFileDialog::NewFileDialog(Project *project, TQWidget *parent)
  : NewDialog(i18n("Create New File"), parent), _project(project)
{
  _fLabel->setText(i18n("File Name:"));

  if (project) {
    _add = new TQCheckBox(i18n("Add to project"), mainWidget());
    _add->setChecked(project);
    _top->addMultiCellWidget(_add, 2,2, 1,2);
    _top->setRowStretch(3, 1);
    _dir->setText(project->directory().path());
  }
}

TQString NewFileDialog::startDir() const
{
  if (_project) return _project->directory().path();
  return ":new_file";
}

PURL::Url NewFileDialog::url() const
{
  return PURL::Url(PURL::Directory(_dir->text()), _filename->text());
}