5 //----------------------------------------------------------------------
7 /// Default constructor.
8 CTodoApp::CTodoApp (void)
14 /// Singleton interface.
15 /*static*/ CTodoApp
& CTodoApp::Instance (void)
17 static CTodoApp s_App
;
21 /// Set \p filename to a default value to be used when none is given on the cmdline.
22 void CTodoApp::GetDefaultFilename (string
& filename
) const
26 // This code gets the first available .todo in the current path.
27 // That is, it will use ./.todo, or ../.todo, etc.
29 // Get the nesting level to know how far back to check.
31 if (!getcwd (VectorBlock (cwd
)))
32 throw libc_exception ("getcwd");
33 const size_t nDirs
= count (cwd
, cwd
+ strlen(cwd
), '/');
34 assert (nDirs
&& "A path without root in it?");
36 // Check for existing .todo in each directory.
37 filename
.reserve (strlen("../") * nDirs
+ strlen(".todo"));
39 for (i
= 0; i
< int(nDirs
); ++i
)
43 if (access (filename
.iat (i
* strlen("../")), F_OK
) == 0)
46 // If there are no .todo files, create ./.todo
49 if (access (".", W_OK
) != 0) {
50 MessageBox ("You are not allowed to write to this directory");
51 CRootWindow::Instance().Close();
54 filename
.erase (filename
.begin(), i
* strlen("../"));
57 /// Initializes the output device.
58 void CTodoApp::OnCreate (argc_t argc
, argv_t argv
)
60 CApplication::OnCreate (argc
, argv
);
62 cerr
<< "Usage: todo [filename]\n";
63 return (CRootWindow::Instance().Close());
66 // Determine database name.
71 GetDefaultFilename (fullname
);
73 // Create the frame and register the document with it.
74 CTodoFrame
* pFrame
= new CTodoFrame
;
75 AddChildWindow (pFrame
);
76 m_Doc
.RegisterView (pFrame
);
80 m_Doc
.Open (fullname
);
82 string
msg (fullname
);
83 msg
+= " is corrupt or in an incompatible format.";
85 CRootWindow::Instance().Close();
87 throw; // to see the real error for debugging.
92 //----------------------------------------------------------------------
96 //----------------------------------------------------------------------