Skip to content

Commit

Permalink
status bar syntax tab size and frontend status message
Browse files Browse the repository at this point in the history
  • Loading branch information
zoli committed Jul 28, 2016
1 parent 65375b8 commit 688d31c
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 96 deletions.
46 changes: 25 additions & 21 deletions main/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,21 @@ const (
keypad_mod = 0x20000000
)

// keeping track of frontend state
type frontend struct {
status_message string
lock sync.Mutex
windows map[*backend.Window]*window
Console *view
qmlDispatch chan qmlDispatch

promptWaitGroup sync.WaitGroup
promptResult string
}
type (
// keeping track of frontend state
frontend struct {
lock sync.Mutex
windows map[*backend.Window]*window
Console *view
qmlDispatch chan qmlDispatch

promptWaitGroup sync.WaitGroup
promptResult string
}

// Used for batching qml.Changed calls
type qmlDispatch struct{ value, field interface{} }
// Used for batching qml.Changed calls
qmlDispatch struct{ value, field interface{} }
)

var fe *frontend

Expand All @@ -62,7 +63,7 @@ func initFrontend() {
qml.Run(fe.loop)
}

func (f *frontend) Window(w *backend.Window) *window {
func (f *frontend) window(w *backend.Window) *window {
return f.windows[w]
}

Expand All @@ -76,9 +77,12 @@ func (f *frontend) VisibleRegion(bv *backend.View) Region {
}

func (f *frontend) StatusMessage(msg string) {
f.lock.Lock()
defer f.lock.Unlock()
f.status_message = msg
w := f.windows[backend.GetEditor().ActiveWindow()]
w.qw.Call("setFrontendStatus", msg)
go func() {
time.Sleep(5 * time.Second)
w.qw.Call("setFrontendStatus", "")

This comment has been minimized.

Copy link
@ricochet1k

ricochet1k Aug 1, 2016

Member

Where is it documented that the status_message only shows for 5 seconds? Also, what happens if a status message is set, and then 4 seconds later a second message is set? This goroutine is not a good solution.

This comment has been minimized.

Copy link
@zoli

zoli Aug 1, 2016

Author Member

Where is it documented that the status_message only shows for 5 seconds?

I didn't found any, just ran sublime.status_message('test') in sublime text console and counted.

This goroutine is not a good solution.

Yes will change that.

This comment has been minimized.

Copy link
@zoli

zoli Aug 25, 2016

Author Member

fixed via ab8ad36.

}()
}

const (
Expand Down Expand Up @@ -153,7 +157,7 @@ func (f *frontend) Prompt(title, folder string, flags int) []string {
files[i] = file[7:]
}
}
log.Debug("Selected %s files", files)
log.Fine("Selected %s files", files)
return files
}

Expand Down Expand Up @@ -207,13 +211,13 @@ func (f *frontend) qmlChanged(value, field interface{}) {
}

func (f *frontend) DefaultBg() color.RGBA {
c := f.ColorScheme().Spice(&render.ViewRegions{})
c := f.colorScheme().Spice(&render.ViewRegions{})
c.Background.A = 0xff
return color.RGBA(c.Background)
}

func (f *frontend) DefaultFg() color.RGBA {
c := f.ColorScheme().Spice(&render.ViewRegions{})
c := f.colorScheme().Spice(&render.ViewRegions{})
c.Foreground.A = 0xff
return color.RGBA(c.Foreground)
}
Expand Down Expand Up @@ -334,7 +338,7 @@ func (f *frontend) HandleInput(text string, keycode int, modifiers int) bool {
return false
}

func (f *frontend) ColorScheme() backend.ColorScheme {
func (f *frontend) colorScheme() backend.ColorScheme {
ed := backend.GetEditor()
return ed.GetColorScheme(ed.Settings().String("color_scheme", ""))
}
Expand Down
137 changes: 65 additions & 72 deletions main/qml/Window.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,35 @@ ApplicationWindow {
property string themeFolder: "../../packages/Soda/Soda Dark"

function view() {
return mainView.view();
return mainView.view();
}

function addTab(tabId, view) {
return mainView.addTab(tabId, view);
return mainView.addTab(tabId, view);
}

function activateTab(tabId) {
return mainView.activateTab(tabId);
return mainView.activateTab(tabId);
}

function removeTab(tabId) {
return mainView.removeTab(tabId);
return mainView.removeTab(tabId);
}

function setTabTitle(tabId, title) {
return mainView.setTabTitle(tabId, title);
return mainView.setTabTitle(tabId, title);
}

function setFrontendStatus(text) {
frontendStatus.text = text
}

function setIndentStatus(text) {
indentStatus.text = text
}

function setSyntaxStatus(text) {
syntaxStatus.text = text
}

menuBar: MenuBar {
Expand Down Expand Up @@ -79,8 +91,8 @@ ApplicationWindow {
MenuSeparator{}
MenuItem {
text: qsTr("Quit")
// TODO: frontend.runCommand("quit");
onTriggered: Qt.quit();
// TODO: frontend.runCommand("quit");
onTriggered: Qt.quit();
}
}
Menu {
Expand Down Expand Up @@ -134,10 +146,10 @@ ApplicationWindow {
MenuItem {
text: qsTr("Show/Hide Minimap")
onTriggered: {
var tab = tabs.getTab(tabs.currentIndex);
var tab = tabs.getTab(tabs.currentIndex);

if (tab.item)
tab.item.minimapVisible = !tab.item.minimapVisible;
if (tab.item)
tab.item.minimapVisible = !tab.item.minimapVisible;
}
}
MenuItem {
Expand All @@ -148,105 +160,85 @@ ApplicationWindow {
}

property Tab currentTab: mainView.currentTab()
property var statusBarMap: (currentTab == null || currentTab.item == null) ? null : currentTab.item.statusBar
property var statusBarSorted: []
onStatusBarMapChanged: {
if (statusBarMap == null) {
statusBarSorted = [["a", "git branch: master"], ["b", "INSERT MODE"], ["c", "Line xx, Column yy"]];
return;
}

console.log("status bar map:", statusBarMap);
var keys = Object.keys(statusBarMap);
keys.sort();
console.log("status bar keys:", keys);
var sorted = [];
for (var i = 0; i < keys.length; i++)
sorted.push([keys[i], statusBarMap[keys[i]]]);

statusBarSorted = sorted;

This comment has been minimized.

Copy link
@ricochet1k

ricochet1k Aug 1, 2016

Member

Why did you remove all this code? This code is part of the implementation of the view.set_status, view.erase_status, the "dynamic" part of #3.

This comment has been minimized.

Copy link
@ricochet1k

ricochet1k Aug 1, 2016

Member

https://www.sublimetext.com/docs/3/api_reference.html
set_status(key, value) Adds the status key to the view. The value will be displayed in the status bar, in a comma separated list of all status values, ordered by key. Setting the value to the empty string will clear the status.

This comment has been minimized.

Copy link
@zoli

zoli Aug 1, 2016

Author Member

I didn't exactly removed I'm modifying it but the view part isn't finished yet some of the code will come back after it's completed.

This comment has been minimized.

Copy link
@erbridge

erbridge Aug 1, 2016

Contributor

Sounds like this would have been better in a branch...

This comment has been minimized.

Copy link
@ricochet1k

ricochet1k Aug 2, 2016

Member

I agree. We should never have broken code in master where we can help it.

Component {
id: tabTemplate
View {}
}

Item {
anchors.fill: parent
Keys.onPressed: {
var v = view(); if (v === undefined) return;
v.ctrl = (event.key == Qt.Key_Control) ? true : false;
event.accepted = frontend.handleInput(event.text, event.key, event.modifiers)
event.accepted = true;
}
Keys.onReleased: {
var v = view(); if (v === undefined) return;
v.ctrl = (event.key == Qt.Key_Control) ? false : view().ctrl;
}
focus: true // Focus required for Keys.onPressed
SplitView {
anchors.fill: parent
orientation: Qt.Vertical
MainView {
id: mainView
}
View {
id: consoleView
myView: frontend.console
visible: false
minimapVisible: false
height: 100
}
}
}

statusBar: StatusBar {
id: statusBar
property color textColor: "#969696"

style: StatusBarStyle {
background: Image {
source: themeFolder + "/status-bar-background.png"
source: themeFolder + "/status-bar-background.png"
}
}

property color textColor: "#969696"

RowLayout {
anchors.fill: parent
id: statusBarRowLayout
spacing: 15

RowLayout {
anchors.fill: parent
spacing: 3
Repeater {
model: statusBarSorted
delegate:
model: statusBarSorted
delegate:
Label {
text: modelData[1]
color: statusBar.textColor
}
}
Label {
id: frontendStatus
color: statusBar.textColor
}
}

Label {
id: statusBarIndent
text: "Tab Size/Spaces: 4"
id: indentStatus
color: statusBar.textColor
Layout.alignment: Qt.AlignRight
}

Label {
id: statusBarLanguage
text: "Go"
id: syntaxStatus
color: statusBar.textColor
Layout.alignment: Qt.AlignRight
}
}
}

Component {
id: tabTemplate

View {}
}

Item {
anchors.fill: parent
Keys.onPressed: {
var v = view(); if (v === undefined) return;
v.ctrl = (event.key == Qt.Key_Control) ? true : false;
event.accepted = frontend.handleInput(event.text, event.key, event.modifiers)
// if (event.key == Qt.Key_Alt)
event.accepted = true;
}
Keys.onReleased: {
var v = view(); if (v === undefined) return;
v.ctrl = (event.key == Qt.Key_Control) ? false : view().ctrl;
}
focus: true // Focus required for Keys.onPressed
SplitView {
anchors.fill: parent
orientation: Qt.Vertical
MainView {
id: mainView
}
View {
id: consoleView
myView: frontend.console
visible: false
minimapVisible: false
height: 100
}
}
}
MessageDialog {
objectName: "messageDialog"
onAccepted: frontend.promptClosed("accepted")
Expand All @@ -258,6 +250,7 @@ ApplicationWindow {
onReset: frontend.promptClosed("reset")
onYes: frontend.promptClosed("yes")
}

FileDialog {
objectName: "fileDialog"
onAccepted: frontend.promptClosed("accepted")
Expand Down
18 changes: 18 additions & 0 deletions main/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main

import (
"fmt"
"strconv"

"github.com/limetext/backend"
"github.com/limetext/backend/render"
Expand All @@ -29,6 +30,23 @@ func newView(bv *backend.View) *view {
id: int(bv.Id()),
bv: bv,
}
bv.Settings().AddOnChange("qml.view.syntax", func(name string) {
if name != "syntax" {
return
}
syn := bv.Settings().String("syntax", "Plain Text")
syntax := backend.GetEditor().GetSyntax(syn)
w := fe.windows[bv.Window()]
w.qw.Call("setSyntaxStatus", syntax.Name())
})
bv.Settings().AddOnChange("qml.view.tabSize", func(name string) {
if name != "tab_size" {
return
}
ts := bv.Settings().Int("tab_size", 4)
w := fe.windows[bv.Window()]
w.qw.Call("setIndentStatus", strconv.Itoa(ts))
})
return v
}

Expand Down
5 changes: 2 additions & 3 deletions main/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ func (w *window) launch(wg *sync.WaitGroup, component qml.Object) {
}

func (w *window) addView(bv *backend.View) *view {
v := w.views[bv]
if v != nil {
if v := w.views[bv]; v != nil {
return v
}
v = newView(bv)
v := newView(bv)
w.views[bv] = v
return v
}
Expand Down

0 comments on commit 688d31c

Please sign in to comment.