Browse Source

Can now open files and directories using the command line, for instance: juci . source.cc notebook.*

merge-requests/365/head
eidheim 11 years ago
parent
commit
efd1a6c2b8
  1. 46
      juci/juci.cc
  2. 15
      juci/juci.h

46
juci/juci.cc

@ -1,5 +1,4 @@
#include "window.h" #include "juci.h"
#include "logging.h"
void init_logging() { void init_logging() {
add_common_attributes(); add_common_attributes();
@ -8,12 +7,43 @@ void init_logging() {
INFO("Logging initalized"); INFO("Logging initalized");
} }
int Juci::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> &cmd) {
Glib::set_prgname("juci");
Glib::OptionContext ctx("[PATH ...]");
Glib::OptionGroup gtk_group(gtk_get_option_group(true));
ctx.add_group(gtk_group);
int argc;
char **argv = cmd->get_arguments(argc);
ctx.parse(argc, argv);
if(argc>=2) {
for(size_t c=1;c<argc;c++) {
boost::filesystem::path p=boost::filesystem::canonical(argv[c]);
if(boost::filesystem::exists(p)) {
if(boost::filesystem::is_regular_file(p))
files.emplace_back(p.string());
else if(directory=="" && boost::filesystem::is_directory(p))
directory=p.string();
}
}
}
activate();
return 0;
}
void Juci::on_activate() {
window = std::unique_ptr<Window>(new Window());
add_window(*window);
window->show();
if(directory!="") {
//TODO: use the following instead, window->notebook_.open_directory(directory);
window->notebook_.project_path=directory;
window->notebook_.directories().open_folder(directory);
}
for(auto &f: files)
window->notebook_.OnOpenFile(f);
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(
argc,
argv,
"no.sout.juci");
init_logging(); init_logging();
Window window; return Juci().run(argc, argv);
return app->run(window);
} }

15
juci/juci.h

@ -0,0 +1,15 @@
#include "window.h"
#include "logging.h"
class Juci : public Gtk::Application {
public:
Juci(): Gtk::Application("no.sout.juci", Gio::APPLICATION_HANDLES_COMMAND_LINE) {}
int on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> &cmd);
void on_activate();
private:
std::unique_ptr<Window> window;
std::string directory;
std::vector<std::string> files;
};
Loading…
Cancel
Save