File: renamedocform.c

package info (click to toggle)
plucker 1.8-34
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 21,340 kB
  • sloc: ansic: 47,691; cpp: 42,310; python: 17,043; makefile: 1,521; perl: 1,492; pascal: 1,123; sh: 474; sed: 64; java: 13; csh: 6
file content (168 lines) | stat: -rw-r--r-- 5,254 bytes parent folder | download | duplicates (4)
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * $Id: renamedocform.c,v 1.9 2004/05/08 09:04:54 nordstrom Exp $
 *
 * Viewer - a part of Plucker, the free off-line HTML viewer for PalmOS
 * Copyright (c) 1998-2002, Mark Ian Lillywhite and Michael Nordstrom
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

#include <VFSMgr.h>

#include "debug.h"
#include "doclist.h"
#include "genericfile.h"
#include "libraryform.h"
#include "resourceids.h"
#include "util.h"
#include "vfsfile.h"
#include "DIA.h"

#include "renamedocform.h"


/***********************************************************************
 *
 *      Private variables
 *
 ***********************************************************************/
static FieldType*    fldPtr;
static DocumentInfo* docInfo;


/***********************************************************************
 *
 *      Local functions
 *
 ***********************************************************************/
static void RenameDocFormInit( void ) RENAMEDOCFORM_SECTION;


/* Initialize the rename document form */
static void RenameDocFormInit( void )
{
    FormType* form;

    docInfo = DocInfo( ReturnLastIndex() );
    fldPtr = GetObjectPtr( frmRenameDocField );
    FldSetSelection( fldPtr, 0, 0 );
    FldInsert( fldPtr, docInfo->name, StrLen( docInfo->name ) );
    FldSetSelection( fldPtr, 0, StrLen( docInfo->name ) );
    FldSetDirty( fldPtr, false );

    form = FrmGetFormPtr( frmRenameDoc );
    FrmDrawForm( form );
    FrmSetFocus( form, FrmGetObjectIndex( form, frmRenameDocField ) );
}



/* Event handler for the rename document form */
Boolean RenameDocFormHandleEvent
    (
    EventType* event  /* pointer to an EventType structure */
    )
{
    Boolean handled;
    UInt16  libraryFormId;
    Char    filename[ PATH_LEN ];

    handled = false;

    switch ( event->eType ) {
        case ctlSelectEvent:
            if ( event->data.ctlEnter.controlID == frmRenameDocOK ) {

                if ( FldDirty( fldPtr ) ) {
                    Char* docName;

                    docName = FldGetTextPtr( fldPtr );
                    ErrTry {
                        RenameDocument( docName, docInfo, filename );
                        UpdateDocumentName( ReturnLastIndex(), docName, 
                            filename );
                        ReleaseDocInfoList();
                        InitializeDocInfoList();
                        FrmUpdateForm( GetValidForm( frmLibrary ), 
                            frmRedrawUpdateCode);
                    }
                    ErrCatch( err ) {
                        switch ( err ) {
                            case errNoDocumentName:
                                break;

                            case vfsErrFilePermissionDenied:
                            case dmErrReadOnly:
                                FrmAlert( errReadOnly );
                                break;

                            case vfsErrFileAlreadyExists:
                            case dmErrAlreadyExists:
                                FrmCustomAlert( errAlreadyExists, docName, NULL, NULL );
                                FldSetSelection( fldPtr, 0, StrLen( docName ) );
                                break;

                            default:
                                FrmCustomAlert( errCannotRenameDoc, docName, NULL, NULL );
                                break;
                        }
                        break;
                    } ErrEndCatch
                }
            }
            else if ( event->data.ctlEnter.controlID != frmRenameDocCancel ) {
                break;
            }
            libraryFormId = GetValidForm( frmLibrary );
            FrmReturnToForm( libraryFormId );
            if ( event->data.ctlEnter.controlID != frmRenameDocCancel )
                FrmUpdateForm( libraryFormId, frmUpdateList );
            handled = true;
            break;

        case winEnterEvent:
            handled = ResizeHandleWinEnterEvent();
            break;

        case winDisplayChangedEvent:
            handled = ResizeHandleWinDisplayChangedEvent();
            break;

        case winExitEvent:
            handled = ResizeHandleWinExitEvent();
            break;

        case frmOpenEvent:
#ifdef HAVE_SILKSCREEN
            ResizeHandleFrmOpenEvent();
#endif
            RenameDocFormInit();
            handled = true;
            break;

        case frmCloseEvent:
#ifdef HAVE_SILKSCREEN
            ResizeHandleFrmCloseEvent();
#endif
            handled = false;
            break;

        default:
            handled = false;
    }

    return handled;
}