5 //----------------------------------------------------------------------
7 /// Default constructor.
8 CTodoApp::CTodoApp (void)
15 /// Singleton interface.
16 /*static*/ CTodoApp
& CTodoApp::Instance (void)
18 static CTodoApp s_App
;
22 /// Set \p filename to a default value to be used when none is given on the cmdline.
23 void CTodoApp::GetDefaultFilename (string
& filename
) const
27 // This code gets the first available .todo in the current path.
28 // That is, it will use ./.todo, or ../.todo, etc.
30 // Get the nesting level to know how far back to check.
32 if (!getcwd (VectorBlock (cwd
)))
33 throw libc_exception ("getcwd");
34 const size_t nDirs
= count (cwd
, cwd
+ strlen(cwd
), '/');
35 assert (nDirs
&& "A path without root in it?");
37 // Check for existing .todo in each directory.
38 filename
.reserve (strlen("../") * nDirs
+ strlen(".todo"));
40 for (i
= 0; i
< int(nDirs
); ++i
)
44 if (access (filename
.iat (i
* strlen("../")), F_OK
) == 0)
47 // If there are no .todo files, create ./.todo
50 if (access (".", W_OK
) != 0) {
51 MessageBox ("You are not allowed to write to this directory");
52 CRootWindow::Instance().Close();
55 filename
.erase (filename
.begin(), i
* strlen("../"));
58 /// Initializes the output device.
59 void CTodoApp::OnCreate (argc_t argc
, argv_t argv
)
61 CApplication::OnCreate (argc
, argv
);
63 cerr
<< "Usage: todo [filename]\n";
64 return (CRootWindow::Instance().Close());
67 // Determine database name.
72 GetDefaultFilename (fullname
);
74 // Create the frame and register the document with it.
75 CTodoFrame
* pFrame
= new CTodoFrame
;
76 CRootWindow::Instance().AddChild (pFrame
);
77 m_Doc
.RegisterView (&m_Curlist
);
78 m_Curlist
.RegisterView (pFrame
);
82 m_Doc
.Open (fullname
);
84 string
msg (fullname
);
85 msg
+= " is corrupt or in an incompatible format.";
87 CRootWindow::Instance().Close();
89 throw; // to see the real error for debugging.
94 //----------------------------------------------------------------------
98 //----------------------------------------------------------------------