-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathRenameFileViewController.m
More file actions
133 lines (99 loc) · 4.08 KB
/
Copy pathRenameFileViewController.m
File metadata and controls
133 lines (99 loc) · 4.08 KB
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
//
// RenameFileViewController.m
// MyKeePass
//
// Created by Qiang Yu on 3/21/10.
// Copyright 2010 Qiang Yu. All rights reserved.
//
#import "RenameFileViewController.h"
#import "TextFieldCell.h"
#import "FileManager.h"
@implementation RenameFileViewController
@synthesize _filename;
/*
- (id)initWithStyle:(UITableViewStyle)style {
// Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
if (self = [super initWithStyle:style]) {
}
return self;
}
*/
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:YES];
TextFieldCell * cell = (TextFieldCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
[cell._field becomeFirstResponder];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = NSLocalizedString(@"Rename File", @"Rename File");
UIBarButtonItem * cancel = [[UIBarButtonItem alloc]initWithTitle:NSLocalizedString(@"Cancel", @"Cancel")
style:UIBarButtonItemStylePlain target:self action:@selector(cancelClicked:)];
self.navigationItem.leftBarButtonItem = cancel;
[cancel release];
UIBarButtonItem * done = [[UIBarButtonItem alloc]initWithTitle:NSLocalizedString(@"OK", @"OK")
style:UIBarButtonItemStyleDone target:self action:@selector(doneClicked:)];
self.navigationItem.rightBarButtonItem = done;
[done release];
}
-(IBAction)cancelClicked:(id)sender{
[[NSNotificationCenter defaultCenter] postNotificationName:@"DismissModalViewCancel" object:self];
}
-(IBAction)doneClicked:(id)sender{
NSString * filename = ((TextFieldCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]])._field.text;
if([filename length]!=0){
if([_filename hasSuffix:@".kdb"] && ![filename hasSuffix:@".kdb"]){
filename = [filename stringByAppendingPathExtension:@"kdb"];
}else if([_filename hasSuffix:@".kdbx"] && ![filename hasSuffix:@".kdbx"]){
filename = [filename stringByAppendingPathExtension:@"kdbx"];
}
NSString * name = [FileManager getFullFileName:filename];
if(!([filename isEqualToString:_filename])&&[[NSFileManager defaultManager] fileExistsAtPath:name]){
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:nil
message:NSLocalizedString(@"File already exsits", @"File already exists") delegate:self
cancelButtonTitle:NSLocalizedString(@"OK", @"OK")
otherButtonTitles:nil];
[alert show];
[alert release];
return;
}else{
[[NSFileManager defaultManager] moveItemAtPath:[FileManager getFullFileName:_filename] toPath:name error:nil];
}
}
[[NSNotificationCenter defaultCenter] postNotificationName:@"DismissModalViewOK" object:self];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
TextFieldCell *cell = (TextFieldCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[TextFieldCell alloc] initWithIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell._field.placeholder = _filename;
cell._field.text = _filename;
return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
return NSLocalizedString(@"New name of the file:", @"New name");
}
- (void)dealloc {
[super dealloc];
}
@end