Skip to content

Commit

Permalink
Cross-session persistent checkable menu item to disable the "proposal…
Browse files Browse the repository at this point in the history
…s" experiments
  • Loading branch information
hostilefork committed Mar 14, 2015
1 parent 418c75f commit a0aa09d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 29 deletions.
23 changes: 20 additions & 3 deletions examples/workbench/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ MainWindow::MainWindow() :
addDockWidget(Qt::TopDockWidgetArea, dockValueExplorer);
dockValueExplorer->hide();

readSettings();

createActions();
createMenus();
createStatusBar();
Expand Down Expand Up @@ -139,9 +141,6 @@ MainWindow::MainWindow() :
Qt::DirectConnection
);


readSettings();

setWindowTitle(tr("Ren Garden"));
setUnifiedTitleAndToolBarOnMac(true);
}
Expand Down Expand Up @@ -234,6 +233,18 @@ void MainWindow::createActions()
Qt::DirectConnection
);

proposalsAct = new QAction(tr("Use &Proposals "), this);
proposalsAct->setStatusTip(tr("Enable or disable experimental language "
"proposals curated by @HostileFork."));
proposalsAct->setCheckable(true);
proposalsAct->setChecked(console->getUseProposals());
connect(
proposalsAct, &QAction::triggered,
[this](bool checked) {
console->setUseProposals(checked);
}
);

newTabAct = new QAction(tr("New &Tab"), this);
newTabAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_T));
newTabAct->setStatusTip(tr("Create a new tab (not multithreaded!)"));
Expand Down Expand Up @@ -341,6 +352,9 @@ void MainWindow::createMenus()
windowMenu->addAction(watchListAct);
windowMenu->addAction(valueExplorerAct);

languageMenu = menuBar()->addMenu(tr("&Language"));
languageMenu->addAction(proposalsAct);

menuBar()->addSeparator();

helpMenu = menuBar()->addMenu(tr("&Help"));
Expand All @@ -360,10 +374,12 @@ void MainWindow::readSettings()
QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
QSize size = settings.value("size", QSize(400, 400)).toSize();
int zoom = settings.value("zoom", 0).toInt();
bool useProposals = settings.value("useProposals", true).toBool();

move(pos);
resize(size);
console->repl().setZoom(zoom);
console->setUseProposals(useProposals);
}


Expand All @@ -373,6 +389,7 @@ void MainWindow::writeSettings()
settings.setValue("pos", pos());
settings.setValue("size", size());
settings.setValue("zoom", console->repl().getZoom());
settings.setValue("useProposals", console->getUseProposals());
}


Expand Down
14 changes: 8 additions & 6 deletions examples/workbench/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,28 @@ private slots:
QDockWidget * dockValueExplorer;

private:
QMenu * fileMenu;
QMenu * editMenu;
QMenu * windowMenu;
QMenu * helpMenu;
QAction * separatorAct;

QMenu * fileMenu;
QAction * exitAct;

QMenu * editMenu;
QAction * cutAct;
QAction * copyAct;
QAction * pasteAct;

QMenu * languageMenu;
QAction * proposalsAct;

QMenu * windowMenu;
QAction * newTabAct;
QAction * nextTabAct;
QAction * previousTabAct;
QAction * closeTabAct;
QAction * watchListAct;
QAction * valueExplorerAct;

QAction * separatorAct;

QMenu * helpMenu;
QAction * aboutAct;

private slots:
Expand Down
52 changes: 32 additions & 20 deletions examples/workbench/renconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ using namespace ren;
extern bool forcingQuit;


///
/// WORKER OBJECT FOR HANDLING REN EVALUATIONS
///
//#
//# WORKER OBJECT FOR HANDLING REN EVALUATIONS
//#

//
// We push this item to the worker thread and let it do the actual evaluation
Expand Down Expand Up @@ -159,9 +159,9 @@ public slots:



///
/// CONSOLE CONSTRUCTION
///
//#
//# CONSOLE CONSTRUCTION
//#

//
// The console doesn't inherit from ReplPad, it *contains* it. This
Expand All @@ -179,7 +179,8 @@ RenConsole::RenConsole (QWidget * parent) :
bannerPrinted (false),
evaluatingRepl (nullptr),
target (none),
proposalsContext () // we will copy it from userContext when ready...
proposalsContext (), // we will copy it from userContext when ready...
useProposals (true)
{
// Set up the Evaluator so it's wired up for signals and slots
// and on another thread from the GUI. This technique is taken directly
Expand Down Expand Up @@ -596,7 +597,9 @@ void RenConsole::createNewTab() {

auto pad = new ReplPad {*this, *this, this};

auto context = proposalsContext->copy();
Context context = useProposals
? proposalsContext->copy()
: userContext.copy();

auto emplacement = tabinfos.emplace(std::make_pair(pad,
TabInfo {
Expand Down Expand Up @@ -778,9 +781,9 @@ void RenConsole::printBanner() {



///
/// REPLPAD HOOKS
///
//#
//# REPLPAD HOOKS
//#

//
// The ReplPad is language-and-evaluator agnostic. It offers an interface
Expand Down Expand Up @@ -881,9 +884,9 @@ QString RenConsole::getPromptString(ReplPad & pad) {



///
/// EVALUATION RESULT HANDLER
///
//#
//# EVALUATION RESULT HANDLER
//#

//
// When the evaluator has finished running, we want to print out the
Expand Down Expand Up @@ -975,9 +978,9 @@ void RenConsole::handleResults(



///
/// SYNTAX-SENSITIVE HOOKS
///
//#
//# SYNTAX-SENSITIVE HOOKS
//#

//
// Ideally this would be done with separately sandboxed "Engines", a feature
Expand Down Expand Up @@ -1100,9 +1103,9 @@ std::pair<QString, int> RenConsole::autoComplete(



///
/// DESTRUCTOR
///
//#
//# DESTRUCTOR
//#

//
// If we try to destroy a RenConsole, there may be a worker thread still
Expand All @@ -1127,6 +1130,15 @@ RenConsole::~RenConsole() {
}


void RenConsole::setUseProposals(bool useProposals) {
this->useProposals = useProposals;

std::string command {"console system/contexts/"};
command += useProposals ? "proposals" : "user";
getTabInfo(repl()).context(command.c_str());
}



// This bit is necessary because we're defining a Q_OBJECT class in a .cpp
// file instead of a header file (Worker)
Expand Down
6 changes: 6 additions & 0 deletions examples/workbench/renconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ public slots:
void createNewTab();
void tryCloseTab(int index);
void updateTabLabels();

private:
bool useProposals;
public:
void setUseProposals(bool useProposals);
bool getUseProposals() { return useProposals; }
};

#endif

0 comments on commit a0aa09d

Please sign in to comment.