2 #include "confirmsave.h"
4 #include "filesystem.h"
7 #include "mwindowgui.h"
8 #include "neworappend.h"
12 #define _(String) gettext(String)
13 #define gettext_noop(String) String
14 #define N_(String) gettext_noop (String)
17 NewOrAppend::NewOrAppend(MWindow *mwindow)
19 this->mwindow = mwindow;
22 NewOrAppend::~NewOrAppend()
26 // give the user three options if the file exists
27 int NewOrAppend::test_file(Asset *asset, FileXML *script)
31 if(file = fopen(asset->path, "r"))
36 // Don't ask user if running a script.
37 ConfirmSaveWindow window(mwindow, asset->path);
38 window.create_objects();
39 result = window.run_window();
60 NewOrAppendWindow::NewOrAppendWindow(MWindow *mwindow, Asset *asset, int confidence)
61 : BC_Window(PROGRAM_NAME ": Overwrite",
62 mwindow->gui->get_abs_cursor_x(),
63 mwindow->gui->get_abs_cursor_y(),
67 this->mwindow = mwindow;
69 this->confidence = confidence;
72 NewOrAppendWindow::~NewOrAppendWindow()
79 int NewOrAppendWindow::create_objects()
81 char string[1024], filename[1024];
83 fs.extract_name(filename, asset->path);
85 sprintf(string, _("%s exists!"), filename);
86 add_subwindow(new BC_Title(5, 5, string));
88 sprintf(string, _("But is in the same format as your new file."));
90 sprintf(string, _("But might be in the same format as your new file."));
91 add_subwindow(new BC_Title(5, 25, string));
92 add_subwindow(ok = new NewOrAppendNewButton(this));
93 add_subwindow(append = new NewOrAppendAppendButton(this));
94 add_subwindow(cancel = new NewOrAppendCancelButton(this));
98 NewOrAppendNewButton::NewOrAppendNewButton(NewOrAppendWindow *nwindow)
99 : BC_Button(30, 45, 0)
101 this->nwindow = nwindow;
104 int NewOrAppendNewButton::handle_event()
106 nwindow->set_done(0);
109 int NewOrAppendNewButton::keypress_event()
111 if(nwindow->get_keypress() == 13) { handle_event(); return 1; }
115 NewOrAppendAppendButton::NewOrAppendAppendButton(NewOrAppendWindow *nwindow)
116 : BC_Button(30, 80, 0)
118 this->nwindow = nwindow;
121 int NewOrAppendAppendButton::handle_event()
123 nwindow->set_done(2);
126 int NewOrAppendAppendButton::keypress_event()
128 if(nwindow->get_keypress() == 13) { handle_event(); return 1; }
132 NewOrAppendCancelButton::NewOrAppendCancelButton(NewOrAppendWindow *nwindow)
133 : BC_Button(30, 115, 0)
135 this->nwindow = nwindow;
138 int NewOrAppendCancelButton::handle_event()
140 nwindow->set_done(1);
143 int NewOrAppendCancelButton::keypress_event()
145 if(nwindow->get_keypress() == ESC) { handle_event(); return 1; }